fix maploader to be backwards compatible. InitDict-based format is now 3. Formats 1,2 are translated on load, and will be saved back as Format 3 if saved in the editor.
This commit is contained in:
@@ -88,6 +88,14 @@ namespace OpenRA
|
|||||||
Author = "Your name here";
|
Author = "Your name here";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Format2ActorReference
|
||||||
|
{
|
||||||
|
public string Id;
|
||||||
|
public string Type;
|
||||||
|
public int2 Location;
|
||||||
|
public string Owner;
|
||||||
|
}
|
||||||
|
|
||||||
public Map(IFolder package)
|
public Map(IFolder package)
|
||||||
{
|
{
|
||||||
Package = package;
|
Package = package;
|
||||||
@@ -103,39 +111,64 @@ namespace OpenRA
|
|||||||
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
|
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Players
|
// Players & Actors -- this has changed several times.
|
||||||
if (MapFormat == 1)
|
// - Be backwards compatible wherever possible.
|
||||||
{
|
// - Loading a map then saving it out upgrades to latest.
|
||||||
Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true));
|
// Minimum criteria for dropping a format:
|
||||||
}
|
// - There are no maps of this format left in tree
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (var kv in yaml["Players"].Nodes)
|
|
||||||
{
|
|
||||||
var player = new PlayerReference(kv.Value);
|
|
||||||
Players.Add(player.Name, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actors
|
switch (MapFormat)
|
||||||
if (MapFormat == 1)
|
|
||||||
{
|
{
|
||||||
int actors = 0;
|
case 1:
|
||||||
foreach (var kv in yaml["Actors"].Nodes)
|
|
||||||
{
|
|
||||||
string[] vals = kv.Value.Value.Split(' ');
|
|
||||||
string[] loc = vals[2].Split(',');
|
|
||||||
Actors.Add( "Actor" + actors++, new ActorReference( vals[ 0 ] )
|
|
||||||
{
|
{
|
||||||
new LocationInit( new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) ),
|
Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true));
|
||||||
new OwnerInit( "Neutral" ),
|
|
||||||
} );
|
int actors = 0;
|
||||||
}
|
foreach (var kv in yaml["Actors"].Nodes)
|
||||||
}
|
{
|
||||||
else
|
string[] vals = kv.Value.Value.Split(' ');
|
||||||
{
|
string[] loc = vals[2].Split(',');
|
||||||
foreach( var kv in yaml[ "Actors" ].Nodes )
|
Actors.Add("Actor" + actors++, new ActorReference(vals[0])
|
||||||
Actors.Add( kv.Key, new ActorReference( kv.Value.Value, kv.Value.Nodes ) );
|
{
|
||||||
|
new LocationInit( new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) ),
|
||||||
|
new OwnerInit( "Neutral" ),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
foreach (var kv in yaml["Players"].Nodes)
|
||||||
|
{
|
||||||
|
var player = new PlayerReference(kv.Value);
|
||||||
|
Players.Add(player.Name, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var kv in yaml["Actors"].Nodes)
|
||||||
|
{
|
||||||
|
var oldActorReference = FieldLoader.Load<Format2ActorReference>(kv.Value);
|
||||||
|
Actors.Add(oldActorReference.Id, new ActorReference(oldActorReference.Type)
|
||||||
|
{
|
||||||
|
new LocationInit( oldActorReference.Location ),
|
||||||
|
new OwnerInit( oldActorReference.Owner )
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
foreach (var kv in yaml["Players"].Nodes)
|
||||||
|
{
|
||||||
|
var player = new PlayerReference(kv.Value);
|
||||||
|
Players.Add(player.Name, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var kv in yaml["Actors"].Nodes)
|
||||||
|
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.Nodes));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new InvalidDataException("Map format {0} is not supported.".F(MapFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Smudges
|
// Smudges
|
||||||
@@ -156,7 +189,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void Save(string filepath)
|
public void Save(string filepath)
|
||||||
{
|
{
|
||||||
MapFormat = 2;
|
MapFormat = 3;
|
||||||
|
|
||||||
var root = new Dictionary<string, MiniYaml>();
|
var root = new Dictionary<string, MiniYaml>();
|
||||||
foreach (var field in SimpleFields)
|
foreach (var field in SimpleFields)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Selectable: True
|
Selectable: True
|
||||||
|
|
||||||
MapFormat: 2
|
MapFormat: 3
|
||||||
|
|
||||||
Title: Test
|
Title: Test
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Selectable: False
|
Selectable: False
|
||||||
|
|
||||||
MapFormat: 2
|
MapFormat: 3
|
||||||
|
|
||||||
Title: <none>
|
Title: <none>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user