From 9407c55262d8470e68f6acb8ecb4ada5cd1bd9ea Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 11 Feb 2011 11:01:06 +1300 Subject: [PATCH] Drop TopLeft and BottomRight from MapFormat 5. Use Bounds directly. --- OpenRA.Editor/LegacyMapImporter.cs | 3 +-- OpenRA.FileFormats/FieldLoader.cs | 14 ++++++++++++-- OpenRA.FileFormats/Map/MapStub.cs | 14 ++++++++------ OpenRA.Game/Map.cs | 7 ++----- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/OpenRA.Editor/LegacyMapImporter.cs b/OpenRA.Editor/LegacyMapImporter.cs index bdfbabe089..cf0937ec1a 100644 --- a/OpenRA.Editor/LegacyMapImporter.cs +++ b/OpenRA.Editor/LegacyMapImporter.cs @@ -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) diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index a52d0ec781..74f07967e1 100755 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -178,7 +178,12 @@ 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,7 +300,12 @@ 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().Select(a => a.ToString()).ToArray()) : v.ToString(); diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.FileFormats/Map/MapStub.cs index 9d071bb0a3..cc66907f10 100644 --- a/OpenRA.FileFormats/Map/MapStub.cs +++ b/OpenRA.FileFormats/Map/MapStub.cs @@ -37,14 +37,14 @@ namespace OpenRA.FileFormats [FieldLoader.Load] public string[] StartPoints; public int PlayerCount { get { return StartPoints.Count(); } } [FieldLoader.LoadUsing( "LoadWaypoints" )] - public Dictionary Waypoints = new Dictionary(); - - - public IEnumerable SpawnPoints{ get { return Waypoints.Where(kv => StartPoints.Contains(kv.Key)).Select(kv => kv.Value); } } + public Dictionary Waypoints = new Dictionary(); + public IEnumerable 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() diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 57fd8197d2..b1d45e9ac5 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -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); } } }