Skip to content

Commit

Permalink
add mappings for some overhauled texture names
Browse files Browse the repository at this point in the history
katycat5e committed Jun 28, 2023
1 parent 63d0a54 commit 9b5c8e5
Showing 2 changed files with 105 additions and 3 deletions.
87 changes: 86 additions & 1 deletion SkinManagerMod/Remaps.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using DV.ThingTypes;
using System;
using System.Collections;
using System.Collections.Generic;

namespace SkinManagerMod
{
internal static class Remaps
{
public static Dictionary<TrainCarType, string> OldCarTypeIDs = new Dictionary<TrainCarType, string>()
public static readonly Dictionary<TrainCarType, string> OldCarTypeIDs = new Dictionary<TrainCarType, string>()
{
{ TrainCarType.LocoShunter, "loco_621" },
{ TrainCarType.LocoSteamHeavy, "loco_steam_H" },
@@ -55,5 +56,89 @@ internal static class Remaps
{ TrainCarType.CabooseRed, "CarCaboose_Red" },
{ TrainCarType.NuclearFlask, "CarNuclearFlask" },
};

private class TextureMapping : IEnumerable<KeyValuePair<string, string>>
{
private readonly Dictionary<string, string> _map =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

public static readonly char[] DE = { 'd', 'e' };
public static readonly char[] DNS = { 'd', 'n', 's' };

public void Add(string oldName, string newName)
{
_map.Add(oldName, newName);
}

public void Add(string oldBase, string newBase, char[] suffixes)
{
foreach (char suffix in suffixes)
{
_map.Add($"{oldBase}{suffix}", $"{newBase}{suffix}");
}
}

public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
return ((IEnumerable<KeyValuePair<string, string>>)_map).GetEnumerator();
}

public bool TryGetUpdatedName(string oldName, out string newName)
{
return _map.TryGetValue(oldName, out newName);
}

IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_map).GetEnumerator();
}
}

/// <summary>Old texture name -> new texture name</summary>
private static readonly Dictionary<TrainCarType, TextureMapping> _legacyTextureNameMap =
new Dictionary<TrainCarType, TextureMapping>()
{
{
TrainCarType.LocoShunter,
new TextureMapping
{
{ "exterior_", "LocoDE2_Body_01", TextureMapping.DNS },
}
},

// 282 & tender new UVs -> no mappings :(

{
TrainCarType.LocoDiesel,
new TextureMapping
{
{ "LocoDiesel_bogies_", "LocoDE6_Body_01", TextureMapping.DNS },
{ "LocoDiesel_cab_", "LocoDE6_Interior_01", TextureMapping.DNS },
{ "LocoDiesel_engine_", "LocoDE6_Engine_01", TextureMapping.DNS },
{ "LocoDiesel_exterior_", "LocoDE6_Body_01", TextureMapping.DNS },
{ "LocoDiesel_gauges_01", "LocoDE6_Gauges_01", TextureMapping.DE },
}
},

{
TrainCarType.CabooseRed,
new TextureMapping
{
{ "CabooseExterior_", "CarCabooseRed_Body_01", TextureMapping.DNS },
{ "CabooseInterior_", "CarCabooseRed_Interior_01", TextureMapping.DNS },
}
},
};

public static bool TryGetUpdatedTextureName(TrainCarType carType, string oldName, out string newName)
{
if (_legacyTextureNameMap.TryGetValue(carType, out TextureMapping textureMapping))
{
return textureMapping.TryGetUpdatedName(oldName, out newName);
}

newName = null;
return false;
}
}
}
21 changes: 19 additions & 2 deletions SkinManagerMod/SkinManager.cs
Original file line number Diff line number Diff line change
@@ -294,7 +294,24 @@ private static Skin CreateDefaultSkin(TrainCarLivery carType)
return defaultSkin;
}


private static bool TryGetTextureForFilename(TrainCarType carType, ref string filename, Dictionary<string, string> textureNames, out string textureProp)
{
if (textureNames.TryGetValue(filename, out textureProp))
{
return true;
}

if ((carType != TrainCarType.NotSet) && Remaps.TryGetUpdatedTextureName(carType, filename, out string newName))
{
if (textureNames.TryGetValue(newName, out textureProp))
{
filename = newName;
return true;
}
}

return false;
}

/// <summary>
/// Create a skin from the given directory, load textures, and add it to the given group
@@ -313,7 +330,7 @@ private static void BeginLoadSkin(SkinGroup skinGroup, Dictionary<string, string
continue;
string fileName = Path.GetFileNameWithoutExtension(file.Name);

if (!loading.Contains(fileName) && textureNames.TryGetValue(fileName, out string textureProp))
if (!loading.Contains(fileName) && TryGetTextureForFilename(skinGroup.TrainCarType.v1, ref fileName, textureNames, out string textureProp))
{
var linear = textureProp == "_BumpMap";
loading.Add(fileName);

0 comments on commit 9b5c8e5

Please sign in to comment.