Replace invalid tiles on map load.

This commit is contained in:
Paul Chote
2020-12-14 17:52:57 +00:00
committed by Matthias Mailänder
parent 09db4a0e25
commit c02846e2cb
2 changed files with 24 additions and 6 deletions

View File

@@ -287,7 +287,6 @@ namespace OpenRA
this.modData = modData; this.modData = modData;
var size = new Size(width, height); var size = new Size(width, height);
Grid = modData.Manifest.Get<MapGrid>(); Grid = modData.Manifest.Get<MapGrid>();
var tileRef = new TerrainTile(tileset.Templates.First().Key, 0);
Title = "Name your map here"; Title = "Name your map here";
Author = "Your name here"; Author = "Your name here";
@@ -310,7 +309,7 @@ namespace OpenRA
Tiles.CellEntryChanged += UpdateRamp; Tiles.CellEntryChanged += UpdateRamp;
} }
Tiles.Clear(tileRef); Tiles.Clear(tileset.DefaultTerrainTile);
PostInit(); PostInit();
} }
@@ -430,12 +429,17 @@ namespace OpenRA
foreach (var uv in AllCells.MapCoords) foreach (var uv in AllCells.MapCoords)
CustomTerrain[uv] = byte.MaxValue; CustomTerrain[uv] = byte.MaxValue;
// Cache initial ramp state // Replace invalid tiles and cache ramp state
var tileset = Rules.TileSet; var tileset = Rules.TileSet;
foreach (var uv in AllCells) foreach (var uv in AllCells.MapCoords)
{ {
var tile = tileset.GetTileInfo(Tiles[uv]); if (!tileset.TryGetTileInfo(Tiles[uv], out var info))
Ramp[uv] = tile != null ? tile.RampType : (byte)0; {
Tiles[uv] = tileset.DefaultTerrainTile;
info = tileset.GetTileInfo(tileset.DefaultTerrainTile);
}
Ramp[uv] = info.RampType;
} }
AllEdgeCells = UpdateEdgeCells(); AllEdgeCells = UpdateEdgeCells();

View File

@@ -241,5 +241,19 @@ namespace OpenRA
return tpl.Contains(r.Index) ? tpl[r.Index] : null; return tpl.Contains(r.Index) ? tpl[r.Index] : null;
} }
public bool TryGetTileInfo(TerrainTile r, out TerrainTileInfo info)
{
if (!Templates.TryGetValue(r.Type, out var tpl) || !tpl.Contains(r.Index))
{
info = null;
return false;
}
info = tpl[r.Index];
return info != null;
}
public TerrainTile DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } }
} }
} }