From 9b5c8e51e64a8b4637b116a524cfb9db2bb98972 Mon Sep 17 00:00:00 2001 From: Katy Fox Date: Wed, 28 Jun 2023 15:45:57 -0400 Subject: [PATCH] add mappings for some overhauled texture names --- SkinManagerMod/Remaps.cs | 87 ++++++++++++++++++++++++++++++++++- SkinManagerMod/SkinManager.cs | 21 ++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/SkinManagerMod/Remaps.cs b/SkinManagerMod/Remaps.cs index 64fe693..53829c8 100644 --- a/SkinManagerMod/Remaps.cs +++ b/SkinManagerMod/Remaps.cs @@ -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 OldCarTypeIDs = new Dictionary() + public static readonly Dictionary OldCarTypeIDs = new Dictionary() { { 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> + { + private readonly Dictionary _map = + new Dictionary(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> GetEnumerator() + { + return ((IEnumerable>)_map).GetEnumerator(); + } + + public bool TryGetUpdatedName(string oldName, out string newName) + { + return _map.TryGetValue(oldName, out newName); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)_map).GetEnumerator(); + } + } + + /// Old texture name -> new texture name + private static readonly Dictionary _legacyTextureNameMap = + new Dictionary() + { + { + 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; + } } } diff --git a/SkinManagerMod/SkinManager.cs b/SkinManagerMod/SkinManager.cs index 7859dc9..3419745 100644 --- a/SkinManagerMod/SkinManager.cs +++ b/SkinManagerMod/SkinManager.cs @@ -294,7 +294,24 @@ private static Skin CreateDefaultSkin(TrainCarLivery carType) return defaultSkin; } - + private static bool TryGetTextureForFilename(TrainCarType carType, ref string filename, Dictionary 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; + } /// /// 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