Add ITemplatedTerrainInfo interface.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.GameRules;
|
||||
@@ -97,6 +98,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly Bridge[] neighbours = new Bridge[2];
|
||||
readonly LegacyBridgeHut[] huts = new LegacyBridgeHut[2]; // Huts before this / first & after this / last
|
||||
readonly ITiledTerrainRenderer terrainRenderer;
|
||||
readonly ITemplatedTerrainInfo terrainInfo;
|
||||
readonly Health health;
|
||||
readonly Actor self;
|
||||
readonly BridgeInfo info;
|
||||
@@ -118,7 +120,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
type = self.Info.Name;
|
||||
isDangling = new Lazy<bool>(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null));
|
||||
buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||
|
||||
terrainRenderer = self.World.WorldActor.Trait<ITiledTerrainRenderer>();
|
||||
terrainInfo = self.World.Map.Rules.TerrainInfo as ITemplatedTerrainInfo;
|
||||
if (terrainInfo == null)
|
||||
throw new InvalidDataException("Bridge requires a template-based tileset.");
|
||||
}
|
||||
|
||||
public Bridge Neighbour(int direction) { return neighbours[direction]; }
|
||||
@@ -149,9 +155,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
byte GetTerrainType(CPos cell)
|
||||
{
|
||||
var dx = cell - self.Location;
|
||||
var tileSet = self.World.Map.Rules.TileSet;
|
||||
var index = dx.X + tileSet.Templates[template].Size.X * dx.Y;
|
||||
return tileSet.GetTerrainIndex(new TerrainTile(template, (byte)index));
|
||||
var index = dx.X + terrainInfo.Templates[template].Size.X * dx.Y;
|
||||
return terrainInfo.GetTerrainIndex(new TerrainTile(template, (byte)index));
|
||||
}
|
||||
|
||||
public void LinkNeighbouringBridges(World world, LegacyBridgeLayer bridges)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
@@ -29,12 +30,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
readonly LegacyBridgeLayerInfo info;
|
||||
readonly Dictionary<ushort, (string Template, int Health)> bridgeTypes = new Dictionary<ushort, (string, int)>();
|
||||
readonly ITemplatedTerrainInfo terrainInfo;
|
||||
|
||||
CellLayer<Bridge> bridges;
|
||||
|
||||
public LegacyBridgeLayer(Actor self, LegacyBridgeLayerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
terrainInfo = self.World.Map.Rules.TerrainInfo as ITemplatedTerrainInfo;
|
||||
if (terrainInfo == null)
|
||||
throw new InvalidDataException("LegacyBridgeLayer requires a template-based tileset.");
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
@@ -68,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var ti = w.Map.Tiles[cell];
|
||||
var tile = ti.Type;
|
||||
var index = ti.Index;
|
||||
var template = w.Map.Rules.TileSet.Templates[tile];
|
||||
var template = terrainInfo.Templates[tile];
|
||||
var ni = cell.X - index % template.Size.X;
|
||||
var nj = cell.Y - index / template.Size.X;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
@@ -25,18 +26,21 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
readonly Map map;
|
||||
readonly Dictionary<string, TerrainSpriteLayer> spriteLayers = new Dictionary<string, TerrainSpriteLayer>();
|
||||
readonly TileSet terrainInfo;
|
||||
readonly Theater theater;
|
||||
bool disposed;
|
||||
|
||||
public TerrainRenderer(World world)
|
||||
{
|
||||
map = world.Map;
|
||||
theater = new Theater(world.Map.Rules.TileSet);
|
||||
|
||||
terrainInfo = map.Rules.TileSet;
|
||||
theater = new Theater(terrainInfo);
|
||||
}
|
||||
|
||||
void IWorldLoaded.WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
foreach (var template in map.Rules.TileSet.Templates)
|
||||
foreach (var template in terrainInfo.Templates)
|
||||
{
|
||||
var palette = template.Value.Palette ?? TileSet.TerrainPaletteInternalName;
|
||||
spriteLayers.GetOrAdd(palette, pal =>
|
||||
@@ -54,8 +58,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var tile = map.Tiles[cell];
|
||||
var palette = TileSet.TerrainPaletteInternalName;
|
||||
if (map.Rules.TileSet.Templates.ContainsKey(tile.Type))
|
||||
palette = map.Rules.TileSet.Templates[tile.Type].Palette ?? palette;
|
||||
if (terrainInfo.Templates.TryGetValue(tile.Type, out var template))
|
||||
palette = template.Palette ?? palette;
|
||||
|
||||
foreach (var kv in spriteLayers)
|
||||
kv.Value.Update(cell, palette == kv.Key ? theater.TileSprite(tile) : null, false);
|
||||
@@ -103,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
for (var x = 0; x < template.Size.X; x++)
|
||||
{
|
||||
var tile = new TerrainTile(template.Id, (byte)(i++));
|
||||
if (!map.Rules.TileSet.TryGetTileInfo(tile, out var tileInfo))
|
||||
if (!terrainInfo.TryGetTileInfo(tile, out var tileInfo))
|
||||
continue;
|
||||
|
||||
var sprite = theater.TileSprite(tile);
|
||||
|
||||
Reference in New Issue
Block a user