Skip to content

Commit

Permalink
Merge pull request #20 from derail-valley-modding/sim-update
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
katycat5e authored Jul 25, 2023
2 parents dbf4a13 + 3d48156 commit 5d00589
Show file tree
Hide file tree
Showing 17 changed files with 690 additions and 157 deletions.
15 changes: 8 additions & 7 deletions SMShared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class Constants
{
public const string MOD_ID = "SkinManagerMod";
public const string MOD_NAME = "Skin Manager";
public const string MOD_VERSION = "3.1.0";
public const string MOD_VERSION = "3.1.1";

public const string SKIN_FOLDER_NAME = "Skins";
public const string EXPORT_FOLDER_NAME = "Exported";
Expand All @@ -28,6 +28,13 @@ public static bool IsSupportedExtension(string extension)
public static readonly string[] LiveryNames =
{
CUSTOM_TYPE,
"LocoDE2",
"LocoDE6",
"LocoDH4",
"LocoDM3",
"LocoS282A",
"LocoS282B",
"LocoS060",
"AutorackBlue",
"AutorackGreen",
"AutorackRed",
Expand All @@ -48,12 +55,6 @@ public static bool IsSupportedExtension(string extension)
"HopperBrown",
"HopperTeal",
"HopperYellow",
"LocoDE2",
"LocoDE6",
"LocoDH4",
"LocoDM3",
"LocoS282A",
"LocoS282B",
"NuclearFlask",
"PassengerBlue",
"PassengerGreen",
Expand Down
47 changes: 0 additions & 47 deletions SMShared/MockTrainCarType.cs

This file was deleted.

2 changes: 1 addition & 1 deletion SMShared/Remaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ IEnumerator IEnumerable.GetEnumerator()
"LocoDE6",
new TextureMapping
{
{ "LocoDiesel_bogies_", "LocoDE6_Body_01", TextureMapping.DNS },
{ "LocoDiesel_bogies_", "LocoDE6_Bogie_01", TextureMapping.DNS },
{ "LocoDiesel_cab_", "LocoDE6_Interior_01", TextureMapping.DNS },
{ "LocoDiesel_engine_", "LocoDE6_Engine_01", TextureMapping.DNS },
{ "LocoDiesel_exterior_", "LocoDE6_Body_01", TextureMapping.DNS },
Expand Down
1 change: 0 additions & 1 deletion SMShared/SMShared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Constants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MockTrainCarType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Remaps.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SkinConfigBase.cs" />
</ItemGroup>
Expand Down
100 changes: 100 additions & 0 deletions SkinConfigurator/ConfiguratorSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace SkinConfigurator
{
[Serializable]
public class ConfiguratorSettings
{
private static string SettingsFile => Path.Combine(Environment.CurrentDirectory, "settings.json");
private static JsonSerializerOptions _serializeOptions = new()
{
IncludeFields = true,
WriteIndented = true,
};

public string DefaultSkinWorkFolder;
public string DerailValleyDirectory;

public ConfiguratorSettings()
{
DefaultSkinWorkFolder = Environment.CurrentDirectory;
DerailValleyDirectory = SteamHelper.GetModsDirectory() ?? Environment.CurrentDirectory;
}

public ConfiguratorSettings(ConfiguratorSettings other)
{
DefaultSkinWorkFolder = other.DefaultSkinWorkFolder;
DerailValleyDirectory = other.DerailValleyDirectory;
}

public static ConfiguratorSettings LoadConfig()
{
try
{
using var stream = File.OpenRead(SettingsFile);
return JsonSerializer.Deserialize<ConfiguratorSettings>(stream, _serializeOptions) ?? new ConfiguratorSettings();
}
catch
{
return new ConfiguratorSettings();
}
}

public static void SaveConfig(ConfiguratorSettings settings)
{
try
{
using var stream = File.Open(SettingsFile, FileMode.Create);
JsonSerializer.Serialize(stream, settings, _serializeOptions);
}
catch
{

}
}
}

public class SettingsModel : INotifyPropertyChanged
{
public ConfiguratorSettings Data { get; private set; }

public SettingsModel(ConfiguratorSettings data)
{
Data = new ConfiguratorSettings(data);
}

[JsonIgnore]
public string WorkingFolder
{
get => Data.DefaultSkinWorkFolder;
set
{
Data.DefaultSkinWorkFolder = value;
OnPropertyChanged(nameof(WorkingFolder));
}
}

[JsonIgnore]
public string DerailValleyDirectory
{
get => Data.DerailValleyDirectory;
set
{
Data.DerailValleyDirectory = value;
OnPropertyChanged(nameof(DerailValleyDirectory));
}
}


public event PropertyChangedEventHandler? PropertyChanged;

private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
60 changes: 60 additions & 0 deletions SkinConfigurator/FolderPackager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using SMShared;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace SkinConfigurator
{
internal class FolderPackager : SkinPackager
{
public FolderPackager(string path, SkinPackModel model) : base(path, model)
{
Directory.CreateDirectory(path);
ClearDirectory(_destPath);
}

private static void ClearDirectory(string dirPath)
{
foreach (var file in Directory.EnumerateFiles(dirPath))
{
File.Delete(file);
}
foreach (var dir in Directory.EnumerateDirectories(dirPath))
{
Directory.Delete(dir, true);
}
}

private string GetAbsoluteDestination(string relativeDest) => Path.Combine(_destPath, relativeDest);

protected override void WriteModInfo()
{
string dest = GetAbsoluteDestination(Constants.MOD_INFO_FILE);
using var stream = File.Open(dest, FileMode.Create);
JsonSerializer.Serialize(stream, _model.ModInfoModel, _serializeOptions);
}

protected override void WriteSkin(SkinConfigModel skin)
{
string folderName = GetSkinFolderName(skin.Name, skin.CarId);
string folderPath = GetAbsoluteDestination(folderName);
Directory.CreateDirectory(folderPath);

string jsonPath = Path.Combine(folderPath, Constants.SKIN_CONFIG_FILE);
using var jsonStream = File.Open(jsonPath, FileMode.Create);
JsonSerializer.Serialize(jsonStream, skin, _serializeOptions);

// textures & whatever else
foreach (var sourceFile in Directory.EnumerateFiles(skin.FolderPath))
{
string relativePath = GetTargetFileName(folderName, sourceFile, skin.CarId);
string absPath = GetAbsoluteDestination(relativePath);
File.Copy(sourceFile, absPath, true);
}
}
}
}
25 changes: 21 additions & 4 deletions SkinConfigurator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
xmlns:local="clr-namespace:SkinConfigurator"
mc:Ignorable="d"
Title="Skin Configurator" Height="450" Width="800"
d:DataContext="{d:DesignInstance {x:Type local:SkinPackModel}}">
d:DataContext="{d:DesignInstance {x:Type local:SkinPackModel}}"
Closing="Window_Closing">
<Window.Resources>
<local:NullToVisibilityConverter x:Key="nullVisibilityConverter"/>
<local:NullToBoolConverter x:Key="nullToBoolConverter"/>
Expand All @@ -27,8 +28,11 @@
<!-- Main mod info -->
<DockPanel LastChildFill="False">
<Menu DockPanel.Dock="Top">
<MenuItem x:Name="CreatePackButton" Header="New Pack" Click="CreatePackButton_Click"/>
<MenuItem x:Name="ImportPackButton" Header="Upgrade Pack..." Click="ImportPackButton_Click"/>
<MenuItem x:Name="CreatePackButton" Header="New Pack" Click="CreatePackButton_Click" ToolTip="Clear all fields and start anew"/>
<MenuItem Header="Import...">
<MenuItem x:Name="ImportPackButton" Header="Import Folder..." Click="ImportPackButton_Click" ToolTip="Import multiple skins from a folder"/>
<MenuItem x:Name="ImportZipButton" Header="Import Old Zip..." Click="ImportZipButton_Click" ToolTip="Import skins from an old UMM or BepInEx pack"/>
</MenuItem>
</Menu>

<Grid DataContext="{Binding ModInfoModel}" DockPanel.Dock="Top"
Expand All @@ -53,9 +57,15 @@
<TextBox Text="{Binding BindingAuthor}" Grid.Row="2" Grid.Column="1"/>
</Grid>

<Button x:Name="PackageButton" DockPanel.Dock="Bottom" Content="Package..." Click="PackageButton_Click"
<Button x:Name="PackageButton" DockPanel.Dock="Bottom" Content="Zip for Release..." Click="PackageButton_Click"
ToolTip="Create a Zip file that can be installed with UMM"
IsEnabled="{Binding IsValid}"
Background="#FF94E2A4" Padding="0,10"/>

<Button x:Name="TestPackButton" DockPanel.Dock="Bottom" Content="Install Unzipped..." Click="TestPackButton_Click"
ToolTip="Save the pack directly to a folder or mods directory (bypass UMM)"
IsEnabled="{Binding IsValid}"
Background="#FFFFFF80" Padding="0,10"/>
</DockPanel>

<GridSplitter Grid.Column="1" Width="7" HorizontalAlignment="Left"/>
Expand All @@ -65,11 +75,18 @@
<!-- Individual Skins -->
<DockPanel Grid.Column="1" LastChildFill="True" Margin="5,0,0,0">
<Menu DockPanel.Dock="Top">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>

<MenuItem x:Name="AddSkinButton" Header="Add Skin..." Click="AddSkinButton_Click"/>
<MenuItem x:Name="AddManySkinButton" Header="Add Multiple..." Click="AddManySkinButton_Click"/>
<MenuItem x:Name="RemoveSkinButton" Header="Remove Skin" HorizontalAlignment="Right"
Visibility="{Binding SelectedSkinConfig, Converter={StaticResource nullVisibilityConverter}, FallbackValue=Hidden}"
Click="RemoveSkinButton_Click"/>
<MenuItem x:Name="SettingsButton" Header="Settings..." Click="SettingsButton_Click" HorizontalAlignment="Right"/>
</Menu>

<!-- Skin Properties -->
Expand Down
Loading

0 comments on commit 5d00589

Please sign in to comment.