Fix tileset templates to appear in the map editor in their order in YAML.

Fixes regression from 649e7e8c28. When the Templates was changed from a Dictionary to a FrozenDictionary, this caused the items to be reordered. Some code was relying on the previous behaviour where the Dictionary ordering would happen to remain the same as the YAML input.

Fix this by creating a TemplatesInDefinitionOrder which can be used to iterate in the same ordering as given in YAML. Code that depends on the ordering can use this, and other code that does lookups can use the FrozenDictionary.
This commit is contained in:
RoosterDragon
2025-12-31 21:46:05 +00:00
committed by Paul Chote
parent 2c0a4f5873
commit c47ebfbb52
6 changed files with 24 additions and 22 deletions

View File

@@ -87,6 +87,8 @@ namespace OpenRA.Mods.Common.Terrain
[FieldLoader.Ignore]
public readonly FrozenDictionary<ushort, TerrainTemplateInfo> Templates;
[FieldLoader.Ignore]
public readonly ImmutableArray<TerrainTemplateInfo> TemplatesInDefinitionOrder;
[FieldLoader.Ignore]
public readonly FrozenDictionary<string, ImmutableArray<MultiBrushInfo>> MultiBrushCollections;
[FieldLoader.Ignore]
@@ -125,10 +127,11 @@ namespace OpenRA.Mods.Common.Terrain
defaultWalkableTerrainIndex = GetTerrainIndex("Clear");
// Templates
Templates = yaml["Templates"].ToDictionary().Values
.Select(y => (TerrainTemplateInfo)new DefaultTerrainTemplateInfo(this, y))
.ToDictionary(t => t.Id)
.ToFrozenDictionary();
TemplatesInDefinitionOrder = yaml["Templates"].Nodes
.Select(n => (TerrainTemplateInfo)new DefaultTerrainTemplateInfo(this, n.Value))
.ToImmutableArray();
Templates = TemplatesInDefinitionOrder
.ToFrozenDictionary(t => t.Id);
MultiBrushCollections =
yaml.TryGetValue("MultiBrushCollections", out var collectionDefinitions)
@@ -187,10 +190,11 @@ namespace OpenRA.Mods.Common.Terrain
float ITerrainInfo.MinHeightColorBrightness => MinHeightColorBrightness;
float ITerrainInfo.MaxHeightColorBrightness => MaxHeightColorBrightness;
TerrainTile ITerrainInfo.DefaultTerrainTile => new(Templates.First().Key, 0);
TerrainTile ITerrainInfo.DefaultTerrainTile => new(TemplatesInDefinitionOrder[0].Id, 0);
ImmutableArray<string> ITemplatedTerrainInfo.EditorTemplateOrder => EditorTemplateOrder;
FrozenDictionary<ushort, TerrainTemplateInfo> ITemplatedTerrainInfo.Templates => Templates;
ImmutableArray<TerrainTemplateInfo> ITemplatedTerrainInfo.TemplatesInDefinitionOrder => TemplatesInDefinitionOrder;
FrozenDictionary<string, ImmutableArray<MultiBrushInfo>> ITemplatedTerrainInfo.MultiBrushCollections => MultiBrushCollections;
void IDumpSheetsTerrainInfo.DumpSheets(string terrainName, ImmutablePalette palette, ref int sheetCount)