Skip to content

Commit

Permalink
Merge pull request #28 from derail-valley-modding/shared-skins
Browse files Browse the repository at this point in the history
Shared skins
  • Loading branch information
katycat5e authored Sep 6, 2023
2 parents a7615ef + 9e20292 commit 5b3a61b
Show file tree
Hide file tree
Showing 32 changed files with 1,978 additions and 407 deletions.
8 changes: 8 additions & 0 deletions SMShared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class Constants

public const string MOD_INFO_FILE = "Info.json";
public const string SKIN_CONFIG_FILE = "skin.json";
public const string SKIN_RESOURCE_FILE = "skin_resource.json";

public static readonly string[] SupportedImageExtensions = { ".png", ".jpeg", ".jpg" };

Expand All @@ -23,6 +24,13 @@ public static bool IsSupportedExtension(string extension)
return SupportedImageExtensions.Contains(ext);
}

public static bool IsSkinConfigFile(string filename)
{
return filename.EndsWith(MOD_INFO_FILE) ||
filename.EndsWith(SKIN_CONFIG_FILE) ||
filename.EndsWith(SKIN_RESOURCE_FILE);
}

public const string CUSTOM_TYPE = "CUSTOM";

public static readonly string[] LiveryNames =
Expand Down
19 changes: 19 additions & 0 deletions SMShared/Json/ModInfoJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

#if PACKAGER
#nullable disable
#endif

namespace SMShared.Json
{
[Serializable]
public class ModInfoJson
{
public string Id;
public string DisplayName;
public string Version = "1.0.0";
public string Author;
public readonly string ManagerVersion = "0.27.3";
public readonly string[] Requirements = { "SkinManagerMod" };
}
}
15 changes: 15 additions & 0 deletions SMShared/Json/ResourceConfigJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

#if PACKAGER
#nullable disable
#endif

namespace SMShared.Json
{
[Serializable]
public class ResourceConfigJson
{
public string Name;
public string CarId;
}
}
14 changes: 14 additions & 0 deletions SMShared/Json/SkinConfigJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

#if PACKAGER
#nullable disable
#endif

namespace SMShared.Json
{
[Serializable]
public class SkinConfigJson : ResourceConfigJson
{
public string[] ResourceNames;
}
}
4 changes: 3 additions & 1 deletion SMShared/SMShared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Constants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Json\ModInfoJson.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Json\ResourceConfigJson.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Json\SkinConfigJson.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Remaps.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SkinConfigBase.cs" />
</ItemGroup>
</Project>
21 changes: 0 additions & 21 deletions SMShared/SkinConfigBase.cs

This file was deleted.

3 changes: 2 additions & 1 deletion SkinConfigurator/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SkinConfigurator"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml"
Exit="Application_Exit">
<Application.Resources>

</Application.Resources>
Expand Down
13 changes: 13 additions & 0 deletions SkinConfigurator/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -13,5 +14,17 @@ namespace SkinConfigurator
/// </summary>
public partial class App : Application
{
private void Application_Exit(object sender, ExitEventArgs e)
{
try
{
string tempFolder = Path.Combine(Environment.CurrentDirectory, "Temp");
if (Directory.Exists(tempFolder))
{
Directory.Delete(tempFolder, true);
}
}
catch { }
}
}
}
22 changes: 13 additions & 9 deletions SkinConfigurator/FolderPackager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SMShared;
using SkinConfigurator.ViewModels;
using SMShared;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -35,25 +36,28 @@ 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);
JsonSerializer.Serialize(stream, _model.ModInfoModel.JsonModel(), JsonSettings);
}

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

string jsonPath = Path.Combine(folderPath, Constants.SKIN_CONFIG_FILE);
string jsonFileName = skin.Type == PackComponentType.Skin ? Constants.SKIN_CONFIG_FILE : Constants.SKIN_RESOURCE_FILE;
string jsonPath = Path.Combine(folderPath, jsonFileName);
using var jsonStream = File.Open(jsonPath, FileMode.Create);
JsonSerializer.Serialize(jsonStream, skin, _serializeOptions);

var json = skin.JsonModel();
JsonSerializer.Serialize(jsonStream, json, json.GetType(), JsonSettings);

// textures & whatever else
foreach (var sourceFile in Directory.EnumerateFiles(skin.FolderPath))
foreach (var sourceFile in skin.Items)
{
string relativePath = GetTargetFileName(folderName, sourceFile, skin.CarId);
string relativePath = Path.Combine(folderName, sourceFile.FileName);
string absPath = GetAbsoluteDestination(relativePath);
File.Copy(sourceFile, absPath, true);
File.Copy(sourceFile.TempPath, absPath, true);
}
}
}
Expand Down
Loading

0 comments on commit 5b3a61b

Please sign in to comment.