diff --git a/MapConverter/MapConverter.cs b/MapConverter/MapConverter.cs index 45a94e6cf0..be121bf1e2 100644 --- a/MapConverter/MapConverter.cs +++ b/MapConverter/MapConverter.cs @@ -326,8 +326,7 @@ namespace MapConverter public void Save(string filepath) { - Map.Tiledata = filepath+".bin"; - Map.Save(filepath+".yaml"); + Map.Save(filepath); } } } diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index acf18c313f..1f765309a5 100644 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -19,6 +19,7 @@ #endregion using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -38,6 +39,16 @@ namespace OpenRA.FileFormats if (!x.Key.StartsWith("-")) LoadField( self, x.Key, x.Value.Value ); } + + public static void LoadFields( object self, Dictionary my, IEnumerable fields ) + { + foreach (var field in fields) + { + if (!my.ContainsKey(field)) continue; + FieldLoader.LoadField(self,field,my[field].Value); + } + } + public static void LoadField( object self, string key, string value ) { diff --git a/OpenRA.FileFormats/Map/Map.cs b/OpenRA.FileFormats/Map/Map.cs index 0f77ce8fcc..e2f1ed6a07 100644 --- a/OpenRA.FileFormats/Map/Map.cs +++ b/OpenRA.FileFormats/Map/Map.cs @@ -29,13 +29,14 @@ namespace OpenRA.FileFormats { public class Map { + public IFolder Package; + // Yaml map data public int MapFormat = 1; public string Title; public string Description; public string Author; public int PlayerCount; - public string Preview; public string Tileset; public Dictionary Actors = new Dictionary(); @@ -43,7 +44,6 @@ namespace OpenRA.FileFormats public Dictionary Rules = new Dictionary(); // Binary map data - public string Tiledata; public byte TileFormat = 1; public int2 MapSize; @@ -62,22 +62,19 @@ namespace OpenRA.FileFormats public string Theater {get {return Tileset;}} public IEnumerable SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}} - List SimpleFields = new List() { - "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "MapSize", "TopLeft", "BottomRight" + static List SimpleFields = new List() { + "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight" }; public Map() {} - public Map(string filename) + public Map(IFolder package) { - var yaml = MiniYaml.FromFileInPackage(filename); + Package = package; + var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml")); // 'Simple' metadata - foreach (var field in SimpleFields) - { - if (!yaml.ContainsKey(field)) continue; - FieldLoader.LoadField(this,field,yaml[field].Value); - } + FieldLoader.LoadFields(this,yaml,SimpleFields); // Waypoints foreach (var wp in yaml["Waypoints"].Nodes) @@ -100,7 +97,7 @@ namespace OpenRA.FileFormats // Rules Rules = yaml["Rules"].Nodes; - LoadBinaryData(Tiledata); + LoadBinaryData(); } @@ -120,8 +117,8 @@ namespace OpenRA.FileFormats // TODO: Players root.Add("Rules",new MiniYaml(null,Rules)); - SaveBinaryData(Tiledata); - root.WriteToFile(filepath); + SaveBinaryData(filepath+"map.bin"); + root.WriteToFile(filepath+"map.yaml"); } static byte ReadByte( Stream s ) @@ -140,16 +137,17 @@ namespace OpenRA.FileFormats return ret; } - public void LoadBinaryData(string filename) - { - Console.Write("path: {0}",filename); - - Stream dataStream = FileSystem.Open(filename); + public void LoadBinaryData() + { + Stream dataStream = Package.GetContent("map.bin"); // Load header info byte version = ReadByte(dataStream); - MapSize.X = ReadWord(dataStream); - MapSize.Y = ReadWord(dataStream); + var width = ReadWord(dataStream); + var height = ReadWord(dataStream); + + if (width != MapSize.X || height != MapSize.Y) + throw new InvalidDataException("Invalid tile data"); MapTiles = new TileReference[ MapSize.X, MapSize.Y ]; MapResources = new TileReference[ MapSize.X, MapSize.Y ]; diff --git a/OpenRA.FileFormats/Session.cs b/OpenRA.FileFormats/Session.cs index 245d91365e..615bc9b9b3 100644 --- a/OpenRA.FileFormats/Session.cs +++ b/OpenRA.FileFormats/Session.cs @@ -48,7 +48,7 @@ namespace OpenRA.FileFormats public class Global { - public string Map = "testmap.yaml"; + public string Map = "testmap"; public string[] Packages = {}; // filename:sha1 pairs. public string[] Mods = { "ra" }; // mod names public int OrderLatency = 3; diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 2c8b59b137..d413be9f94 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -258,7 +258,7 @@ namespace OpenRA } } - + /* class MapInfo { public readonly string Filename; @@ -278,11 +278,12 @@ namespace OpenRA var mapsFolderMaps = Directory.GetFiles("maps/"); return builtinMaps.Concat(mapsFolderMaps).Select(a => new MapInfo(a)).ToList(); }); - + + bool showMapChooser = false; MapInfo currentMap; bool mapPreviewDirty = true; - + */ void AddUiButton(int2 pos, string text, Action a) { var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24); @@ -293,7 +294,7 @@ namespace OpenRA public void DrawMapChooser() { - var w = 800; + /*var w = 800; var h = 600; var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); DrawDialogBackground(r, "dialog"); @@ -381,6 +382,7 @@ namespace OpenRA }); AddButton(r, _ => { }); + */ } bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); } bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); } @@ -437,13 +439,14 @@ namespace OpenRA { buttons.Clear(); DrawDownloadBar(); - + /* if (showMapChooser) { DrawMapChooser(); return; } - + */ + var w = 800; var h = 600; var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); @@ -456,7 +459,7 @@ namespace OpenRA world.Minimap.Update(); world.Minimap.Draw(minimapRect, true); world.Minimap.DrawSpawnPoints(minimapRect); - + /* if (Game.IsHost) { AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map", @@ -468,7 +471,8 @@ namespace OpenRA mapPreviewDirty = true; }); } - + */ + var f = renderer.BoldFont; f.DrawText(rgbaRenderer, "Name", new int2(r.Left + 40, r.Top + 50), Color.White); f.DrawText(rgbaRenderer, "Color", new int2(r.Left + 140, r.Top + 50), Color.White); diff --git a/OpenRA.Game/GameRules/UserSettings.cs b/OpenRA.Game/GameRules/UserSettings.cs index 1444f5ccf8..3dca5655d0 100644 --- a/OpenRA.Game/GameRules/UserSettings.cs +++ b/OpenRA.Game/GameRules/UserSettings.cs @@ -41,7 +41,7 @@ namespace OpenRA.GameRules // External game settings public readonly string NetworkHost = ""; public readonly int NetworkPort = 0; - public readonly string Map = "testmap.yaml"; + public readonly string Map = "testmap"; public readonly int Player = 1; public readonly string Replay = ""; public readonly string PlayerName = ""; diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 2ffd574fc8..4979f42c13 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.IO; using OpenRA.Collections; using OpenRA.Effects; using OpenRA.FileFormats; @@ -78,7 +79,27 @@ namespace OpenRA { Timer.Time( "----World.ctor" ); - Map = new Map( Game.LobbyInfo.GlobalSettings.Map ); + // TODO: Do this properly + string mapPath = null; + foreach (var mod in Game.LobbyInfo.GlobalSettings.Mods) + { + var path = "mods/"+mod+"/maps/"+Game.LobbyInfo.GlobalSettings.Map+"/"; + if (Directory.Exists(path)) + { + mapPath = path; + break; + } + } + if (mapPath == null) + { + var path = "maps/"+Game.LobbyInfo.GlobalSettings.Map+"/"; + if (!Directory.Exists(path)) + throw new InvalidDataException("Unknown map `{0}`".F(Game.LobbyInfo.GlobalSettings.Map)); + mapPath = path; + } + Map = new Map( new Folder(mapPath) ); + + customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y]; Timer.Time( "new Map: {0}" ); diff --git a/mods/cnc/testmap.bin b/mods/cnc/maps/testmap/map.bin similarity index 100% rename from mods/cnc/testmap.bin rename to mods/cnc/maps/testmap/map.bin diff --git a/mods/cnc/testmap.yaml b/mods/cnc/maps/testmap/map.yaml similarity index 89% rename from mods/cnc/testmap.yaml rename to mods/cnc/maps/testmap/map.yaml index b44b88ee4e..8d9fb34e1d 100644 --- a/mods/cnc/testmap.yaml +++ b/mods/cnc/maps/testmap/map.yaml @@ -1,19 +1,10 @@ MapFormat: 1 - -Title: (null) - +Title: GDI Mission 2 Author: Westwood Studios - -PlayerCount: 7 - +PlayerCount: 1 Tileset: TEMPERAT - -Tiledata: testmap.bin - MapSize: 64,64 - TopLeft: 31,31 - BottomRight: 62,62 Actors: @@ -95,21 +86,21 @@ Actors: Actor75: tc01 Neutral 54,42 Actor76: t01 Neutral 32,31 Actor77: tc02 Neutral 33,31 - Actor78: pyle GoodGuy 55,51 +# Actor78: pyle GoodGuy 55,51 Actor79: silo BadGuy 57,32 Actor80: silo BadGuy 59,32 Actor81: nuke BadGuy 55,32 Actor82: fact BadGuy 52,32 - Actor83: nuke GoodGuy 53,52 +# Actor83: nuke GoodGuy 53,52 Actor84: proc BadGuy 57,34 Actor85: bggy BadGuy 52,39 Actor86: harv BadGuy 50,35 - Actor87: jeep GoodGuy 54,49 - Actor88: jeep GoodGuy 57,49 +# Actor87: jeep GoodGuy 54,49 +# Actor88: jeep GoodGuy 57,49 Actor89: bggy BadGuy 33,37 Actor90: bggy BadGuy 51,50 Actor91: bggy BadGuy 59,39 - Actor92: jeep GoodGuy 56,54 +# Actor92: jeep GoodGuy 56,54 Actor93: e1 BadGuy 48,32 Actor94: e1 BadGuy 35,31 Actor95: e1 BadGuy 39,31 @@ -147,13 +138,13 @@ Actors: Actor127: e1 BadGuy 38,48 Actor128: e1 BadGuy 53,40 Actor129: e1 BadGuy 45,36 - Actor130: e1 GoodGuy 50,51 - Actor131: e1 GoodGuy 50,50 - Actor132: e1 GoodGuy 53,49 - Actor133: e1 GoodGuy 51,49 +# Actor130: e1 GoodGuy 50,51 +# Actor131: e1 GoodGuy 50,50 +# Actor132: e1 GoodGuy 53,49 +# Actor133: e1 GoodGuy 51,49 Actor134: e1 BadGuy 52,40 - Actor135: e1 GoodGuy 52,50 - Actor136: e1 GoodGuy 56,49 +# Actor135: e1 GoodGuy 52,50 +# Actor136: e1 GoodGuy 56,49 Actor137: e1 BadGuy 55,42 Actor138: e1 BadGuy 56,42 Actor139: e1 BadGuy 45,36 @@ -168,13 +159,7 @@ Actors: Actor148: e1 BadGuy 48,36 Waypoints: - spawn6: 54,39 - spawn5: 46,37 - spawn4: 46,41 - spawn3: 59,41 - spawn2: 54,55 - spawn1: 38,54 - spawn0: 35,33 + spawn0: 54,55 Rules: diff --git a/mods/ra/testmap.bin b/mods/ra/maps/testmap/map.bin similarity index 100% rename from mods/ra/testmap.bin rename to mods/ra/maps/testmap/map.bin diff --git a/mods/ra/testmap.yaml b/mods/ra/maps/testmap/map.yaml similarity index 100% rename from mods/ra/testmap.yaml rename to mods/ra/maps/testmap/map.yaml