From a8074ea23a45bbf64fe1871d0515d673a0f013e8 Mon Sep 17 00:00:00 2001 From: Igor Popov Date: Fri, 20 Dec 2013 01:46:13 +0400 Subject: [PATCH] initialize Options in Editor for a new map; fix when trying to add custom assets for map which does not exist yet; ( fixes #4333 ) --- OpenRA.Game/Map.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 6130a0a783..4b40075232 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -121,6 +121,7 @@ namespace OpenRA Author = "Your name here", MapSize = new int2(1, 1), Tileset = tileset.Id, + Options = new MapOptions(), MapResources = Lazy.New(() => new TileReference[1, 1]), MapTiles = Lazy.New(() => new TileReference[1, 1] { { tileRef } }), Actors = Lazy.New(() => new Dictionary()), @@ -258,17 +259,20 @@ namespace OpenRA foreach (var field in fields) { var f = this.GetType().GetField(field); - if (f.GetValue(this) == null) continue; + if (f.GetValue(this) == null) + continue; root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f))); } root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions()))); root.Add(new MiniYamlNode("Players", null, - Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList())); + Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList()) + ); root.Add(new MiniYamlNode("Actors", null, - Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList())); + Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList()) + ); root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList(Smudges.Value))); root.Add(new MiniYamlNode("Rules", null, Rules)); @@ -285,12 +289,15 @@ namespace OpenRA entries.Add("map.yaml", Encoding.UTF8.GetBytes(s)); // Add any custom assets - foreach (var file in Container.AllFileNames()) + if (Container != null) { - if (file == "map.bin" || file == "map.yaml") - continue; + foreach (var file in Container.AllFileNames()) + { + if (file == "map.bin" || file == "map.yaml") + continue; - entries.Add(file, Container.GetContent(file).ReadAllBytes()); + entries.Add(file, Container.GetContent(file).ReadAllBytes()); + } } // Saving the map to a new location @@ -299,7 +306,6 @@ namespace OpenRA Path = toPath; // Create a new map package - // TODO: Add other files (custom assets) to the entries list Container = FileSystem.CreatePackage(Path, int.MaxValue, entries); }