Maps as packages. Disable broken map selector.

This commit is contained in:
Paul Chote
2010-04-03 18:33:32 +13:00
committed by Bob
parent fd5539d110
commit 4e0170a437
11 changed files with 81 additions and 63 deletions

View File

@@ -326,8 +326,7 @@ namespace MapConverter
public void Save(string filepath) public void Save(string filepath)
{ {
Map.Tiledata = filepath+".bin"; Map.Save(filepath);
Map.Save(filepath+".yaml");
} }
} }
} }

View File

@@ -19,6 +19,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@@ -38,6 +39,16 @@ namespace OpenRA.FileFormats
if (!x.Key.StartsWith("-")) if (!x.Key.StartsWith("-"))
LoadField( self, x.Key, x.Value.Value ); LoadField( self, x.Key, x.Value.Value );
} }
public static void LoadFields( object self, Dictionary<string,MiniYaml> my, IEnumerable<string> 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 ) public static void LoadField( object self, string key, string value )
{ {

View File

@@ -29,13 +29,14 @@ namespace OpenRA.FileFormats
{ {
public class Map public class Map
{ {
public IFolder Package;
// Yaml map data // Yaml map data
public int MapFormat = 1; public int MapFormat = 1;
public string Title; public string Title;
public string Description; public string Description;
public string Author; public string Author;
public int PlayerCount; public int PlayerCount;
public string Preview;
public string Tileset; public string Tileset;
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>(); public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
@@ -43,7 +44,6 @@ namespace OpenRA.FileFormats
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>(); public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
// Binary map data // Binary map data
public string Tiledata;
public byte TileFormat = 1; public byte TileFormat = 1;
public int2 MapSize; public int2 MapSize;
@@ -62,22 +62,19 @@ namespace OpenRA.FileFormats
public string Theater {get {return Tileset;}} public string Theater {get {return Tileset;}}
public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}} public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}}
List<string> SimpleFields = new List<string>() { static List<string> SimpleFields = new List<string>() {
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "MapSize", "TopLeft", "BottomRight" "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"
}; };
public Map() {} 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 // 'Simple' metadata
foreach (var field in SimpleFields) FieldLoader.LoadFields(this,yaml,SimpleFields);
{
if (!yaml.ContainsKey(field)) continue;
FieldLoader.LoadField(this,field,yaml[field].Value);
}
// Waypoints // Waypoints
foreach (var wp in yaml["Waypoints"].Nodes) foreach (var wp in yaml["Waypoints"].Nodes)
@@ -100,7 +97,7 @@ namespace OpenRA.FileFormats
// Rules // Rules
Rules = yaml["Rules"].Nodes; Rules = yaml["Rules"].Nodes;
LoadBinaryData(Tiledata); LoadBinaryData();
} }
@@ -120,8 +117,8 @@ namespace OpenRA.FileFormats
// TODO: Players // TODO: Players
root.Add("Rules",new MiniYaml(null,Rules)); root.Add("Rules",new MiniYaml(null,Rules));
SaveBinaryData(Tiledata); SaveBinaryData(filepath+"map.bin");
root.WriteToFile(filepath); root.WriteToFile(filepath+"map.yaml");
} }
static byte ReadByte( Stream s ) static byte ReadByte( Stream s )
@@ -140,16 +137,17 @@ namespace OpenRA.FileFormats
return ret; return ret;
} }
public void LoadBinaryData(string filename) public void LoadBinaryData()
{ {
Console.Write("path: {0}",filename); Stream dataStream = Package.GetContent("map.bin");
Stream dataStream = FileSystem.Open(filename);
// Load header info // Load header info
byte version = ReadByte(dataStream); byte version = ReadByte(dataStream);
MapSize.X = ReadWord(dataStream); var width = ReadWord(dataStream);
MapSize.Y = ReadWord(dataStream); var height = ReadWord(dataStream);
if (width != MapSize.X || height != MapSize.Y)
throw new InvalidDataException("Invalid tile data");
MapTiles = new TileReference<ushort, byte>[ MapSize.X, MapSize.Y ]; MapTiles = new TileReference<ushort, byte>[ MapSize.X, MapSize.Y ];
MapResources = new TileReference<byte, byte>[ MapSize.X, MapSize.Y ]; MapResources = new TileReference<byte, byte>[ MapSize.X, MapSize.Y ];

View File

@@ -48,7 +48,7 @@ namespace OpenRA.FileFormats
public class Global public class Global
{ {
public string Map = "testmap.yaml"; public string Map = "testmap";
public string[] Packages = {}; // filename:sha1 pairs. public string[] Packages = {}; // filename:sha1 pairs.
public string[] Mods = { "ra" }; // mod names public string[] Mods = { "ra" }; // mod names
public int OrderLatency = 3; public int OrderLatency = 3;

View File

@@ -258,7 +258,7 @@ namespace OpenRA
} }
} }
/*
class MapInfo class MapInfo
{ {
public readonly string Filename; public readonly string Filename;
@@ -278,11 +278,12 @@ namespace OpenRA
var mapsFolderMaps = Directory.GetFiles("maps/"); var mapsFolderMaps = Directory.GetFiles("maps/");
return builtinMaps.Concat(mapsFolderMaps).Select(a => new MapInfo(a)).ToList(); return builtinMaps.Concat(mapsFolderMaps).Select(a => new MapInfo(a)).ToList();
}); });
bool showMapChooser = false; bool showMapChooser = false;
MapInfo currentMap; MapInfo currentMap;
bool mapPreviewDirty = true; bool mapPreviewDirty = true;
*/
void AddUiButton(int2 pos, string text, Action<bool> a) void AddUiButton(int2 pos, string text, Action<bool> a)
{ {
var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24); var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24);
@@ -293,7 +294,7 @@ namespace OpenRA
public void DrawMapChooser() public void DrawMapChooser()
{ {
var w = 800; /*var w = 800;
var h = 600; var h = 600;
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
DrawDialogBackground(r, "dialog"); DrawDialogBackground(r, "dialog");
@@ -381,6 +382,7 @@ namespace OpenRA
}); });
AddButton(r, _ => { }); AddButton(r, _ => { });
*/
} }
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); } 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); } bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
@@ -437,13 +439,14 @@ namespace OpenRA
{ {
buttons.Clear(); buttons.Clear();
DrawDownloadBar(); DrawDownloadBar();
/*
if (showMapChooser) if (showMapChooser)
{ {
DrawMapChooser(); DrawMapChooser();
return; return;
} }
*/
var w = 800; var w = 800;
var h = 600; var h = 600;
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); 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.Update();
world.Minimap.Draw(minimapRect, true); world.Minimap.Draw(minimapRect, true);
world.Minimap.DrawSpawnPoints(minimapRect); world.Minimap.DrawSpawnPoints(minimapRect);
/*
if (Game.IsHost) if (Game.IsHost)
{ {
AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map", AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map",
@@ -468,7 +471,8 @@ namespace OpenRA
mapPreviewDirty = true; mapPreviewDirty = true;
}); });
} }
*/
var f = renderer.BoldFont; var f = renderer.BoldFont;
f.DrawText(rgbaRenderer, "Name", new int2(r.Left + 40, r.Top + 50), Color.White); 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); f.DrawText(rgbaRenderer, "Color", new int2(r.Left + 140, r.Top + 50), Color.White);

View File

@@ -41,7 +41,7 @@ namespace OpenRA.GameRules
// External game settings // External game settings
public readonly string NetworkHost = ""; public readonly string NetworkHost = "";
public readonly int NetworkPort = 0; public readonly int NetworkPort = 0;
public readonly string Map = "testmap.yaml"; public readonly string Map = "testmap";
public readonly int Player = 1; public readonly int Player = 1;
public readonly string Replay = ""; public readonly string Replay = "";
public readonly string PlayerName = ""; public readonly string PlayerName = "";

View File

@@ -21,6 +21,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.IO;
using OpenRA.Collections; using OpenRA.Collections;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.FileFormats; using OpenRA.FileFormats;
@@ -78,7 +79,27 @@ namespace OpenRA
{ {
Timer.Time( "----World.ctor" ); 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]; customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y];
Timer.Time( "new Map: {0}" ); Timer.Time( "new Map: {0}" );

View File

@@ -1,19 +1,10 @@
MapFormat: 1 MapFormat: 1
Title: GDI Mission 2
Title: (null)
Author: Westwood Studios Author: Westwood Studios
PlayerCount: 1
PlayerCount: 7
Tileset: TEMPERAT Tileset: TEMPERAT
Tiledata: testmap.bin
MapSize: 64,64 MapSize: 64,64
TopLeft: 31,31 TopLeft: 31,31
BottomRight: 62,62 BottomRight: 62,62
Actors: Actors:
@@ -95,21 +86,21 @@ Actors:
Actor75: tc01 Neutral 54,42 Actor75: tc01 Neutral 54,42
Actor76: t01 Neutral 32,31 Actor76: t01 Neutral 32,31
Actor77: tc02 Neutral 33,31 Actor77: tc02 Neutral 33,31
Actor78: pyle GoodGuy 55,51 # Actor78: pyle GoodGuy 55,51
Actor79: silo BadGuy 57,32 Actor79: silo BadGuy 57,32
Actor80: silo BadGuy 59,32 Actor80: silo BadGuy 59,32
Actor81: nuke BadGuy 55,32 Actor81: nuke BadGuy 55,32
Actor82: fact BadGuy 52,32 Actor82: fact BadGuy 52,32
Actor83: nuke GoodGuy 53,52 # Actor83: nuke GoodGuy 53,52
Actor84: proc BadGuy 57,34 Actor84: proc BadGuy 57,34
Actor85: bggy BadGuy 52,39 Actor85: bggy BadGuy 52,39
Actor86: harv BadGuy 50,35 Actor86: harv BadGuy 50,35
Actor87: jeep GoodGuy 54,49 # Actor87: jeep GoodGuy 54,49
Actor88: jeep GoodGuy 57,49 # Actor88: jeep GoodGuy 57,49
Actor89: bggy BadGuy 33,37 Actor89: bggy BadGuy 33,37
Actor90: bggy BadGuy 51,50 Actor90: bggy BadGuy 51,50
Actor91: bggy BadGuy 59,39 Actor91: bggy BadGuy 59,39
Actor92: jeep GoodGuy 56,54 # Actor92: jeep GoodGuy 56,54
Actor93: e1 BadGuy 48,32 Actor93: e1 BadGuy 48,32
Actor94: e1 BadGuy 35,31 Actor94: e1 BadGuy 35,31
Actor95: e1 BadGuy 39,31 Actor95: e1 BadGuy 39,31
@@ -147,13 +138,13 @@ Actors:
Actor127: e1 BadGuy 38,48 Actor127: e1 BadGuy 38,48
Actor128: e1 BadGuy 53,40 Actor128: e1 BadGuy 53,40
Actor129: e1 BadGuy 45,36 Actor129: e1 BadGuy 45,36
Actor130: e1 GoodGuy 50,51 # Actor130: e1 GoodGuy 50,51
Actor131: e1 GoodGuy 50,50 # Actor131: e1 GoodGuy 50,50
Actor132: e1 GoodGuy 53,49 # Actor132: e1 GoodGuy 53,49
Actor133: e1 GoodGuy 51,49 # Actor133: e1 GoodGuy 51,49
Actor134: e1 BadGuy 52,40 Actor134: e1 BadGuy 52,40
Actor135: e1 GoodGuy 52,50 # Actor135: e1 GoodGuy 52,50
Actor136: e1 GoodGuy 56,49 # Actor136: e1 GoodGuy 56,49
Actor137: e1 BadGuy 55,42 Actor137: e1 BadGuy 55,42
Actor138: e1 BadGuy 56,42 Actor138: e1 BadGuy 56,42
Actor139: e1 BadGuy 45,36 Actor139: e1 BadGuy 45,36
@@ -168,13 +159,7 @@ Actors:
Actor148: e1 BadGuy 48,36 Actor148: e1 BadGuy 48,36
Waypoints: Waypoints:
spawn6: 54,39 spawn0: 54,55
spawn5: 46,37
spawn4: 46,41
spawn3: 59,41
spawn2: 54,55
spawn1: 38,54
spawn0: 35,33
Rules: Rules: