Tell apart the halves of a unit that share one skin

The ET42-026 dresses both halves in 112E-026 and the scenery tells them apart
by the model. Textures were keyed by the skin alone, so the B half became a
second A: not part of the set, and listed on its own. A shared skin now gets
the model in its id, vehicles are looked up by skin and model, and the
vehicle cache is rebuilt for the new ids.
This commit is contained in:
maj00r
2026-10-04 19:05:32 +02:00
parent 37dd038b96
commit e5c46d23ea
12 changed files with 99 additions and 30 deletions

View File

@@ -27,6 +27,9 @@ public sealed class VehicleCatalog
public Dictionary<string, VehicleTexture> TextureBySkin { get; } = new();
/// <summary>For a skin shared by several models, which one dresses which.</summary>
private readonly Dictionary<string, VehicleTexture> _textureBySkinAndModel = new();
public void BeginLoad()
{
Textures.Clear();
@@ -35,6 +38,7 @@ public sealed class VehicleCatalog
SetByTextureUuid.Clear();
TextureByUuid.Clear();
TextureBySkin.Clear();
_textureBySkinAndModel.Clear();
}
public void Ingest(VehicleEntry entry)
@@ -49,7 +53,10 @@ public sealed class VehicleCatalog
TextureByUuid[texture.Uuid] = texture;
if (!string.IsNullOrEmpty(texture.Skinfile))
TextureBySkin.TryAdd(Path.GetFileNameWithoutExtension(texture.Skinfile).ToLowerInvariant(), texture);
{
TextureBySkin.TryAdd(Key(texture.Skinfile), texture);
_textureBySkinAndModel.TryAdd(Key(texture.Skinfile, texture.Model), texture);
}
if (texture.Wreck)
continue;
@@ -105,18 +112,38 @@ public sealed class VehicleCatalog
return texture.TextureMini;
}
public string? MiniForSkin(string? skinFile) =>
TextureForSkin(skinFile) is { } texture ? ResolveMiniName(texture) : null;
public string? MiniFor(string? skinFile, string? model) =>
TextureFor(skinFile, model) is { } texture ? ResolveMiniName(texture) : null;
/// <summary>
/// The texture a vehicle wears: by the skin, and where one skin dresses several
/// models, by the model too - the scenery names both.
/// </summary>
public VehicleTexture? TextureFor(string? skinFile, string? model)
{
if (string.IsNullOrEmpty(skinFile))
return null;
if (!string.IsNullOrEmpty(model) &&
_textureBySkinAndModel.TryGetValue(Key(skinFile, model), out var exact))
return exact;
return TextureForSkin(skinFile);
}
public VehicleTexture? TextureForSkin(string? skinFile)
{
if (string.IsNullOrEmpty(skinFile))
return null;
string key = Path.GetFileNameWithoutExtension(skinFile).ToLowerInvariant();
return TextureBySkin.TryGetValue(key, out var texture) ? texture : null;
return TextureBySkin.TryGetValue(Key(skinFile), out var texture) ? texture : null;
}
private static string Key(string skinFile) => Path.GetFileNameWithoutExtension(skinFile).ToLowerInvariant();
private static string Key(string skinFile, string? model) =>
Key(skinFile) + "|" + (string.IsNullOrEmpty(model) ? "" : Path.GetFileNameWithoutExtension(model).ToLowerInvariant());
public string GroupHeader(string? groupId)
{
if (string.IsNullOrEmpty(groupId) || !GroupsById.TryGetValue(groupId, out var group))