Lazy smudges, fix importer.

This commit is contained in:
Paul Chote
2011-02-11 21:49:04 +13:00
parent 79f3fccceb
commit 1d1d0e8bd2
3 changed files with 43 additions and 41 deletions

View File

@@ -135,7 +135,12 @@ namespace OpenRA.Editor
Map.MapSize.Y = MapSize; Map.MapSize.Y = MapSize;
Map.Bounds = Rectangle.FromLTRB(XOffset, YOffset, XOffset + Width, YOffset + Height); Map.Bounds = Rectangle.FromLTRB(XOffset, YOffset, XOffset + Width, YOffset + Height);
Map.Selectable = true; Map.Selectable = true;
/*
Map.Smudges = Lazy.New(() => new List<SmudgeReference>());
Map.Actors = Lazy.New(() => new Dictionary<string, ActorReference>());
Map.MapResources = Lazy.New(() => new TileReference<byte, byte>[MapSize, MapSize]);
Map.MapTiles = Lazy.New(() => new TileReference<ushort, byte>[MapSize, MapSize]);
if (legacyMapFormat == IniMapFormat.RedAlert) if (legacyMapFormat == IniMapFormat.RedAlert)
{ {
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack"))); UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
@@ -153,7 +158,7 @@ namespace OpenRA.Editor
LoadActors(file, "UNITS"); LoadActors(file, "UNITS");
LoadActors(file, "INFANTRY"); LoadActors(file, "INFANTRY");
LoadSmudges(file, "SMUDGE"); LoadSmudges(file, "SMUDGE");
*/
foreach (var p in Players) foreach (var p in Players)
LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert)); LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert));
@@ -163,15 +168,15 @@ namespace OpenRA.Editor
LocationFromMapOffset(int.Parse(kv.Value), MapSize))) LocationFromMapOffset(int.Parse(kv.Value), MapSize)))
.ToArray(); .ToArray();
/*
// Add waypoint actors // Add waypoint actors
foreach( var kv in wps ) foreach( var kv in wps )
{ {
var a = new ActorReference("mpspawn"); var a = new ActorReference("mpspawn");
a.Add(new LocationInit(kv.Second)); a.Add(new LocationInit(kv.Second));
Map.Actors.Add("spawn" + kv.First, a); Map.Actors.Value.Add("spawn" + kv.First, a);
} }
*/
} }
static int2 LocationFromMapOffset(int offset, int mapSize) static int2 LocationFromMapOffset(int offset, int mapSize)
@@ -235,30 +240,24 @@ namespace OpenRA.Editor
return ret; return ret;
} }
/*
void UnpackRATileData(MemoryStream ms) void UnpackRATileData(MemoryStream ms)
{ {
Map.MapTiles = new TileReference<ushort, byte>[MapSize, MapSize];
for (int i = 0; i < MapSize; i++) for (int i = 0; i < MapSize; i++)
for (int j = 0; j < MapSize; j++) for (int j = 0; j < MapSize; j++)
Map.MapTiles[i, j] = new TileReference<ushort, byte>(); Map.MapTiles.Value[i, j] = new TileReference<ushort, byte>();
for (int j = 0; j < MapSize; j++) for (int j = 0; j < MapSize; j++)
for (int i = 0; i < MapSize; i++) for (int i = 0; i < MapSize; i++)
Map.MapTiles[i, j].type = ReadWord(ms); Map.MapTiles.Value[i, j].type = ReadWord(ms);
for (int j = 0; j < MapSize; j++) for (int j = 0; j < MapSize; j++)
for (int i = 0; i < MapSize; i++) for (int i = 0; i < MapSize; i++)
{ Map.MapTiles.Value[i, j].index = ReadByte(ms);
Map.MapTiles[i, j].index = ReadByte(ms);
if (Map.MapTiles[i, j].type == 0xff || Map.MapTiles[i, j].type == 0xffff)
Map.MapTiles[i, j].index = byte.MaxValue;
}
} }
void UnpackRAOverlayData(MemoryStream ms) void UnpackRAOverlayData(MemoryStream ms)
{ {
Map.MapResources = new TileReference<byte, byte>[MapSize, MapSize];
for (int j = 0; j < MapSize; j++) for (int j = 0; j < MapSize; j++)
for (int i = 0; i < MapSize; i++) for (int i = 0; i < MapSize; i++)
{ {
@@ -268,10 +267,10 @@ namespace OpenRA.Editor
if (o != 255 && overlayResourceMapping.ContainsKey(raOverlayNames[o])) if (o != 255 && overlayResourceMapping.ContainsKey(raOverlayNames[o]))
res = overlayResourceMapping[raOverlayNames[o]]; res = overlayResourceMapping[raOverlayNames[o]];
Map.MapResources[i, j] = new TileReference<byte, byte>(res.First, res.Second); Map.MapResources.Value[i, j] = new TileReference<byte, byte>(res.First, res.Second);
if (o != 255 && overlayActorMapping.ContainsKey(raOverlayNames[o])) if (o != 255 && overlayActorMapping.ContainsKey(raOverlayNames[o]))
Map.Actors.Add("Actor" + ActorCount++, Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(overlayActorMapping[raOverlayNames[o]]) new ActorReference(overlayActorMapping[raOverlayNames[o]])
{ {
new LocationInit( new int2(i, j) ), new LocationInit( new int2(i, j) ),
@@ -289,7 +288,7 @@ namespace OpenRA.Editor
foreach (KeyValuePair<string, string> kv in terrain) foreach (KeyValuePair<string, string> kv in terrain)
{ {
var loc = int.Parse(kv.Key); var loc = int.Parse(kv.Key);
Map.Actors.Add("Actor" + ActorCount++, Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(kv.Value.ToLowerInvariant()) new ActorReference(kv.Value.ToLowerInvariant())
{ {
new LocationInit(new int2(loc % MapSize, loc / MapSize)), new LocationInit(new int2(loc % MapSize, loc / MapSize)),
@@ -300,19 +299,15 @@ namespace OpenRA.Editor
void UnpackCncTileData(Stream ms) void UnpackCncTileData(Stream ms)
{ {
Map.MapTiles = new TileReference<ushort, byte>[MapSize, MapSize];
for (int i = 0; i < MapSize; i++) for (int i = 0; i < MapSize; i++)
for (int j = 0; j < MapSize; j++) for (int j = 0; j < MapSize; j++)
Map.MapTiles[i, j] = new TileReference<ushort, byte>(); Map.MapTiles.Value[i, j] = new TileReference<ushort, byte>();
for (int j = 0; j < MapSize; j++) for (int j = 0; j < MapSize; j++)
for (int i = 0; i < MapSize; i++) for (int i = 0; i < MapSize; i++)
{ {
Map.MapTiles[i, j].type = ReadByte(ms); Map.MapTiles.Value[i, j].type = ReadByte(ms);
Map.MapTiles[i, j].index = ReadByte(ms); Map.MapTiles.Value[i, j].index = ReadByte(ms);
if (Map.MapTiles[i, j].type == 0xff)
Map.MapTiles[i, j].index = byte.MaxValue;
} }
} }
@@ -322,7 +317,6 @@ namespace OpenRA.Editor
if (overlay == null) if (overlay == null)
return; return;
Map.MapResources = new TileReference<byte, byte>[MapSize, MapSize];
foreach (KeyValuePair<string, string> kv in overlay) foreach (KeyValuePair<string, string> kv in overlay)
{ {
var loc = int.Parse(kv.Key); var loc = int.Parse(kv.Key);
@@ -332,10 +326,10 @@ namespace OpenRA.Editor
if (overlayResourceMapping.ContainsKey(kv.Value.ToLower())) if (overlayResourceMapping.ContainsKey(kv.Value.ToLower()))
res = overlayResourceMapping[kv.Value.ToLower()]; res = overlayResourceMapping[kv.Value.ToLower()];
Map.MapResources[cell.X, cell.Y] = new TileReference<byte, byte>(res.First, res.Second); Map.MapResources.Value[cell.X, cell.Y] = new TileReference<byte, byte>(res.First, res.Second);
if (overlayActorMapping.ContainsKey(kv.Value.ToLower())) if (overlayActorMapping.ContainsKey(kv.Value.ToLower()))
Map.Actors.Add("Actor" + ActorCount++, Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(overlayActorMapping[kv.Value.ToLower()]) new ActorReference(overlayActorMapping[kv.Value.ToLower()])
{ {
new LocationInit(cell), new LocationInit(cell),
@@ -353,7 +347,7 @@ namespace OpenRA.Editor
foreach (KeyValuePair<string, string> kv in terrain) foreach (KeyValuePair<string, string> kv in terrain)
{ {
var loc = int.Parse(kv.Key); var loc = int.Parse(kv.Key);
Map.Actors.Add("Actor" + ActorCount++, Map.Actors.Value.Add("Actor" + ActorCount++,
new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant()) new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant())
{ {
new LocationInit(new int2(loc % MapSize, loc / MapSize)), new LocationInit(new int2(loc % MapSize, loc / MapSize)),
@@ -415,11 +409,11 @@ namespace OpenRA.Editor
if (section == "INFANTRY") if (section == "INFANTRY")
actor.Add(new SubCellInit(int.Parse(parts[4]))); actor.Add(new SubCellInit(int.Parse(parts[4])));
Map.Actors.Add("Actor" + ActorCount++,actor); Map.Actors.Value.Add("Actor" + ActorCount++,actor);
} }
} }
*/
void LoadSmudges(IniFile file, string section) void LoadSmudges(IniFile file, string section)
{ {
foreach (var s in file.GetSection(section, true)) foreach (var s in file.GetSection(section, true))
@@ -427,7 +421,7 @@ namespace OpenRA.Editor
//loc=type,loc,depth //loc=type,loc,depth
var parts = s.Value.Split(','); var parts = s.Value.Split(',');
var loc = int.Parse(parts[1]); var loc = int.Parse(parts[1]);
Map.Smudges.Add(new SmudgeReference(parts[0].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), int.Parse(parts[2]))); Map.Smudges.Value.Add(new SmudgeReference(parts[0].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), int.Parse(parts[2])));
} }
} }

View File

@@ -48,7 +48,7 @@ namespace OpenRA
// Yaml map data // Yaml map data
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>(); public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
public List<SmudgeReference> Smudges = new List<SmudgeReference>(); public Lazy<List<SmudgeReference>> Smudges;
// Rules overrides // Rules overrides
public List<MiniYamlNode> Rules = new List<MiniYamlNode>(); public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
@@ -91,7 +91,8 @@ namespace OpenRA
type = tile.Key, type = tile.Key,
index = (byte)0 } index = (byte)0 }
} }), } }),
Actors = Lazy.New(() => new Dictionary<string, ActorReference>()) Actors = Lazy.New(() => new Dictionary<string, ActorReference>()),
Smudges = Lazy.New(() => new List<SmudgeReference>())
}; };
return map; return map;
@@ -191,12 +192,19 @@ namespace OpenRA
} }
// Smudges // Smudges
foreach (var kv in yaml.NodesDict["Smudges"].NodesDict) Smudges = Lazy.New(() =>
{ {
string[] vals = kv.Key.Split(' '); var ret = new List<SmudgeReference>();
string[] loc = vals[1].Split(','); foreach (var kv in yaml.NodesDict["Smudges"].NodesDict)
Smudges.Add(new SmudgeReference(vals[0], new int2(int.Parse(loc[0]), int.Parse(loc[1])), int.Parse(vals[2]))); {
} string[] vals = kv.Key.Split(' ');
string[] loc = vals[1].Split(',');
ret.Add(new SmudgeReference(vals[0], new int2(int.Parse(loc[0]), int.Parse(loc[1])), int.Parse(vals[2])));
}
return ret;
});
// Rules // Rules
Rules = yaml.NodesDict["Rules"].Nodes; Rules = yaml.NodesDict["Rules"].Nodes;
@@ -254,7 +262,7 @@ namespace OpenRA
x.Key, x.Key,
x.Value.Save() ) ).ToList() ) ); x.Value.Save() ) ).ToList() ) );
root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>( Smudges ))); root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>( Smudges.Value )));
root.Add(new MiniYamlNode("Rules", null, Rules)); root.Add(new MiniYamlNode("Rules", null, Rules));
root.Add(new MiniYamlNode("Sequences", null, Sequences)); root.Add(new MiniYamlNode("Sequences", null, Sequences));
root.Add(new MiniYamlNode("Weapons", null, Weapons)); root.Add(new MiniYamlNode("Weapons", null, Weapons));

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA
tiles = new Dictionary<int2,TileReference<byte,byte>>(); tiles = new Dictionary<int2,TileReference<byte,byte>>();
// Add map smudges // Add map smudges
foreach (var s in w.Map.Smudges.Where( s => Info.Types.Contains(s.Type ))) foreach (var s in w.Map.Smudges.Value.Where( s => Info.Types.Contains(s.Type )))
tiles.Add(s.Location,new TileReference<byte,byte>((byte)Array.IndexOf(Info.Types,s.Type), tiles.Add(s.Location,new TileReference<byte,byte>((byte)Array.IndexOf(Info.Types,s.Type),
(byte)s.Depth)); (byte)s.Depth));
} }