Move smudge definitions from Map to SmudgeLayer.
This commit is contained in:
@@ -155,7 +155,6 @@ namespace OpenRA
|
|||||||
[FieldLoader.Ignore] public List<MiniYamlNode> PlayerDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> PlayerDefinitions = new List<MiniYamlNode>();
|
||||||
|
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> ActorDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> ActorDefinitions = new List<MiniYamlNode>();
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> SmudgeDefinitions = new List<MiniYamlNode>();
|
|
||||||
|
|
||||||
// Binary map data
|
// Binary map data
|
||||||
[FieldLoader.Ignore] public byte TileFormat = 2;
|
[FieldLoader.Ignore] public byte TileFormat = 2;
|
||||||
@@ -268,7 +267,6 @@ namespace OpenRA
|
|||||||
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
|
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
|
||||||
|
|
||||||
ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
|
ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
|
||||||
SmudgeDefinitions = MiniYaml.NodesOrEmpty(yaml, "Smudges");
|
|
||||||
|
|
||||||
MapTiles = Exts.Lazy(LoadMapTiles);
|
MapTiles = Exts.Lazy(LoadMapTiles);
|
||||||
MapResources = Exts.Lazy(LoadResourceTiles);
|
MapResources = Exts.Lazy(LoadResourceTiles);
|
||||||
@@ -445,7 +443,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));
|
root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));
|
||||||
root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
|
root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
|
||||||
root.Add(new MiniYamlNode("Smudges", null, SmudgeDefinitions));
|
|
||||||
root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
|
root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
|
||||||
root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
|
root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
|
||||||
root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
|
root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
|
public struct MapSmudge
|
||||||
|
{
|
||||||
|
public string Type;
|
||||||
|
public int Depth;
|
||||||
|
}
|
||||||
|
|
||||||
[Desc("Attach this to the world actor.", "Order of the layers defines the Z sorting.")]
|
[Desc("Attach this to the world actor.", "Order of the layers defines the Z sorting.")]
|
||||||
public class SmudgeLayerInfo : ITraitInfo
|
public class SmudgeLayerInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
@@ -36,6 +42,33 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
[PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
[PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
||||||
|
|
||||||
|
[FieldLoader.LoadUsing("LoadInitialSmudges")]
|
||||||
|
public readonly Dictionary<CPos, MapSmudge> InitialSmudges;
|
||||||
|
|
||||||
|
public static object LoadInitialSmudges(MiniYaml yaml)
|
||||||
|
{
|
||||||
|
MiniYaml smudgeYaml;
|
||||||
|
var nd = yaml.ToDictionary();
|
||||||
|
var smudges = new Dictionary<CPos, MapSmudge>();
|
||||||
|
if (nd.TryGetValue("InitialSmudges", out smudgeYaml))
|
||||||
|
{
|
||||||
|
foreach (var node in smudgeYaml.Nodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var cell = FieldLoader.GetValue<CPos>("key", node.Key);
|
||||||
|
var parts = node.Value.Value.Split(',');
|
||||||
|
var type = parts[0];
|
||||||
|
var depth = FieldLoader.GetValue<int>("depth", parts[1]);
|
||||||
|
smudges.Add(cell, new MapSmudge { Type = type, Depth = depth });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return smudges;
|
||||||
|
}
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new SmudgeLayer(init.Self, this); }
|
public object Create(ActorInitializer init) { return new SmudgeLayer(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,28 +118,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor);
|
render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor);
|
||||||
|
|
||||||
// Add map smudges
|
// Add map smudges
|
||||||
foreach (var s in w.Map.SmudgeDefinitions)
|
foreach (var kv in Info.InitialSmudges)
|
||||||
{
|
{
|
||||||
var name = s.Key;
|
var s = kv.Value;
|
||||||
var vals = name.Split(' ');
|
if (!smudges.ContainsKey(s.Type))
|
||||||
var type = vals[0];
|
|
||||||
|
|
||||||
if (!smudges.ContainsKey(type))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var loc = vals[1].Split(',');
|
|
||||||
var cell = new CPos(Exts.ParseIntegerInvariant(loc[0]), Exts.ParseIntegerInvariant(loc[1]));
|
|
||||||
var depth = Exts.ParseIntegerInvariant(vals[2]);
|
|
||||||
|
|
||||||
var smudge = new Smudge
|
var smudge = new Smudge
|
||||||
{
|
{
|
||||||
Type = type,
|
Type = s.Type,
|
||||||
Depth = depth,
|
Depth = s.Depth,
|
||||||
Sprite = smudges[type][depth]
|
Sprite = smudges[s.Type][s.Depth]
|
||||||
};
|
};
|
||||||
|
|
||||||
tiles.Add(cell, smudge);
|
tiles.Add(kv.Key, smudge);
|
||||||
render.Update(cell, smudge.Sprite);
|
render.Update(kv.Key, smudge.Sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,14 +273,40 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
static void LoadSmudges(IniFile file, string section, int mapSize, Map map)
|
static void LoadSmudges(IniFile file, string section, int mapSize, Map map)
|
||||||
{
|
{
|
||||||
|
var scorches = new List<MiniYamlNode>();
|
||||||
|
var craters = new List<MiniYamlNode>();
|
||||||
foreach (var s in file.GetSection(section, true))
|
foreach (var s in file.GetSection(section, true))
|
||||||
{
|
{
|
||||||
// loc=type,loc,depth
|
// loc=type,loc,depth
|
||||||
var parts = s.Value.Split(',');
|
var parts = s.Value.Split(',');
|
||||||
var loc = Exts.ParseIntegerInvariant(parts[1]);
|
var loc = Exts.ParseIntegerInvariant(parts[1]);
|
||||||
var key = "{0} {1},{2} {3}".F(parts[0].ToLowerInvariant(), loc % mapSize, loc / mapSize, Exts.ParseIntegerInvariant(parts[2]));
|
var type = parts[0].ToLowerInvariant();
|
||||||
map.SmudgeDefinitions.Add(new MiniYamlNode(key, ""));
|
var key = "{0},{1}".F(loc % mapSize, loc / mapSize);
|
||||||
|
var value = "{0},{1}".F(type, parts[2]);
|
||||||
|
var node = new MiniYamlNode(key, value);
|
||||||
|
if (type.StartsWith("sc"))
|
||||||
|
scorches.Add(node);
|
||||||
|
else if (type.StartsWith("cr"))
|
||||||
|
craters.Add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var worldNode = new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>()));
|
||||||
|
if (scorches.Any())
|
||||||
|
{
|
||||||
|
var initialScorches = new MiniYamlNode("InitialSmudges", new MiniYaml("", scorches));
|
||||||
|
var smudgeLayer = new MiniYamlNode("SmudgeLayer@SCORCH", new MiniYaml("", new List<MiniYamlNode>() { initialScorches }));
|
||||||
|
worldNode.Value.Nodes.Add(smudgeLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (craters.Any())
|
||||||
|
{
|
||||||
|
var initialCraters = new MiniYamlNode("InitialSmudges", new MiniYaml("", craters));
|
||||||
|
var smudgeLayer = new MiniYamlNode("SmudgeLayer@CRATER", new MiniYaml("", new List<MiniYamlNode>() { initialCraters }));
|
||||||
|
worldNode.Value.Nodes.Add(smudgeLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worldNode.Value.Nodes.Any())
|
||||||
|
map.RuleDefinitions.Add(worldNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix this -- will have bitrotted pretty badly.
|
// TODO: fix this -- will have bitrotted pretty badly.
|
||||||
|
|||||||
Reference in New Issue
Block a user