Kill MapStub
This commit is contained in:
@@ -20,8 +20,32 @@ using System.Text;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class Map : MapStub
|
||||
public class Map
|
||||
{
|
||||
protected IFolder Container;
|
||||
public string Path {get; protected set;}
|
||||
|
||||
// Yaml map data
|
||||
public string Uid { get; protected set; }
|
||||
[FieldLoader.Load] public int MapFormat;
|
||||
[FieldLoader.Load] public bool Selectable;
|
||||
[FieldLoader.Load] public bool UseAsShellmap;
|
||||
[FieldLoader.Load] public string RequiresMod;
|
||||
|
||||
[FieldLoader.Load] public string Title;
|
||||
[FieldLoader.Load] public string Type = "Conquest";
|
||||
[FieldLoader.Load] public string Description;
|
||||
[FieldLoader.Load] public string Author;
|
||||
[FieldLoader.Load] public string Tileset;
|
||||
|
||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||
|
||||
public int PlayerCount { get { return SpawnPoints.Count(); } }
|
||||
public IEnumerable<int2> SpawnPoints { get { return Actors.Values.Where(a => a.Type == "mpspawn").Select(a => a.InitDict.Get<LocationInit>().value); } }
|
||||
|
||||
[FieldLoader.Load] public Rectangle Bounds;
|
||||
|
||||
|
||||
// Yaml map data
|
||||
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
|
||||
public List<SmudgeReference> Smudges = new List<SmudgeReference>();
|
||||
@@ -81,10 +105,13 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public Map(string path)
|
||||
: base(path)
|
||||
{
|
||||
var yaml = new MiniYaml( null, MiniYaml.FromStream( Container.GetContent( "map.yaml" ) ) );
|
||||
|
||||
Path = path;
|
||||
Container = FileSystem.OpenPackage(path, int.MaxValue);
|
||||
var yaml = new MiniYaml( null, MiniYaml.FromStream(Container.GetContent("map.yaml")) );
|
||||
FieldLoader.Load(this, yaml);
|
||||
Uid = ComputeHash();
|
||||
|
||||
// 'Simple' metadata
|
||||
FieldLoader.Load( this, yaml );
|
||||
|
||||
@@ -92,6 +119,11 @@ namespace OpenRA
|
||||
// Use release-20110207 to convert older maps to format 4
|
||||
if (MapFormat < 4)
|
||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
||||
|
||||
// Load actors
|
||||
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
|
||||
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
||||
|
||||
|
||||
// Load players
|
||||
foreach (var kv in yaml.NodesDict["Players"].NodesDict)
|
||||
@@ -100,9 +132,26 @@ namespace OpenRA
|
||||
Players.Add(player.Name, player);
|
||||
}
|
||||
|
||||
// Creep player
|
||||
// Upgrade map to format 5
|
||||
if (MapFormat < 5)
|
||||
{
|
||||
{
|
||||
// Define RequiresMod for map installer
|
||||
RequiresMod = Game.CurrentMods.Keys.First();
|
||||
|
||||
// Add waypoint actors
|
||||
foreach( var wp in yaml.NodesDict[ "Waypoints" ].NodesDict )
|
||||
{
|
||||
string[] loc = wp.Value.Value.Split( ',' );
|
||||
var a = new ActorReference("mpspawn");
|
||||
a.Add(new LocationInit(new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) )));
|
||||
Actors.Add(wp.Key, a);
|
||||
}
|
||||
|
||||
var TopLeft = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["TopLeft"].Value);
|
||||
var BottomRight = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["BottomRight"].Value);
|
||||
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
||||
|
||||
// Creep player
|
||||
foreach (var mp in Players.Where(p => !p.Value.NonCombatant && !p.Value.Enemies.Contains("Creeps")))
|
||||
mp.Value.Enemies = mp.Value.Enemies.Concat(new[] {"Creeps"}).ToArray();
|
||||
|
||||
@@ -361,5 +410,17 @@ namespace OpenRA
|
||||
{
|
||||
Bounds = Rectangle.FromLTRB(left, top, right, bottom);
|
||||
}
|
||||
|
||||
string ComputeHash()
|
||||
{
|
||||
// UID is calculated by taking an SHA1 of the yaml and binary data
|
||||
// Read the relevant data into a buffer
|
||||
var data = Container.GetContent("map.yaml").ReadAllBytes()
|
||||
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
|
||||
|
||||
// Take the SHA1
|
||||
using (var csp = SHA1.Create())
|
||||
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user