Drop TopLeft and BottomRight from MapFormat 5. Use Bounds directly.

This commit is contained in:
Paul Chote
2011-02-11 11:01:06 +13:00
parent 7332c5a6df
commit 9407c55262
4 changed files with 23 additions and 15 deletions

View File

@@ -132,8 +132,7 @@ namespace OpenRA.Editor
Map.Tileset = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
Map.MapSize.X = MapSize;
Map.MapSize.Y = MapSize;
Map.TopLeft = new int2(XOffset, YOffset);
Map.BottomRight = new int2(XOffset + Width, YOffset + Height);
Map.Bounds = Rectangle.FromLTRB(XOffset, YOffset, XOffset + Width, YOffset + Height);
Map.Selectable = true;
if (legacyMapFormat == IniMapFormat.RedAlert)

View File

@@ -178,6 +178,11 @@ namespace OpenRA.FileFormats
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
return new float2(xx, yy);
}
else if (fieldType == typeof(Rectangle))
{
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return new Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
}
UnknownFieldAction("[Type] {0}".F(x),fieldType);
return null;
@@ -295,6 +300,11 @@ namespace OpenRA.FileFormats
((int)c.G).Clamp(0, 255),
((int)c.B).Clamp(0, 255));
}
else if (f.FieldType == typeof(Rectangle))
{
var r = (Rectangle)v;
return "{0},{1},{2},{3}".F(r.X, r.Y, r.Width, r.Height);
}
return f.FieldType.IsArray
? string.Join(",", ((Array)v).OfType<object>().Select(a => a.ToString()).ToArray())

View File

@@ -38,13 +38,13 @@ namespace OpenRA.FileFormats
public int PlayerCount { get { return StartPoints.Count(); } }
[FieldLoader.LoadUsing( "LoadWaypoints" )]
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
public IEnumerable<int2> SpawnPoints{ get { return Waypoints.Where(kv => StartPoints.Contains(kv.Key)).Select(kv => kv.Value); } }
[FieldLoader.Load] public Rectangle Bounds;
// TODO: Remove these once we stop supporting MapFormat < 5
[FieldLoader.Load] public int2 TopLeft;
[FieldLoader.Load] public int2 BottomRight;
public Rectangle Bounds;
public MapStub() {} // Hack for the editor - not used for anything important
@@ -55,12 +55,14 @@ namespace OpenRA.FileFormats
var yaml = MiniYaml.FromStream(Container.GetContent("map.yaml"));
FieldLoader.Load( this, new MiniYaml( null, yaml ) );
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
Uid = ComputeHash();
// Upgrade maps to define StartPoints
if (MapFormat < 5)
{
StartPoints = Waypoints.Select(kv => kv.Key).ToArray();
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
}
}
string ComputeHash()

View File

@@ -236,8 +236,7 @@ namespace OpenRA
"Author",
"Tileset",
"MapSize",
"TopLeft",
"BottomRight",
"Bounds",
"UseAsShellmap",
"Type",
"StartPoints"
@@ -394,9 +393,7 @@ namespace OpenRA
public void ResizeCordon(int left, int top, int right, int bottom)
{
TopLeft = new int2(left, top);
BottomRight = new int2(right, bottom);
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
Bounds = Rectangle.FromLTRB(left, top, right, bottom);
}
}
}