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:
Chris Forbes
2010-08-01 21:00:17 +12:00
parent 3521319095
commit b77bddddbc
3 changed files with 69 additions and 36 deletions

View File

@@ -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,23 +111,18 @@ 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.
// Minimum criteria for dropping a format:
// - There are no maps of this format left in tree
switch (MapFormat)
{
case 1:
{ {
Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true)); Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true));
}
else
{
foreach (var kv in yaml["Players"].Nodes)
{
var player = new PlayerReference(kv.Value);
Players.Add(player.Name, player);
}
}
// Actors
if (MapFormat == 1)
{
int actors = 0; int actors = 0;
foreach (var kv in yaml["Actors"].Nodes) foreach (var kv in yaml["Actors"].Nodes)
{ {
@@ -131,11 +134,41 @@ namespace OpenRA
new OwnerInit( "Neutral" ), new OwnerInit( "Neutral" ),
}); });
} }
} } break;
else
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) foreach (var kv in yaml["Actors"].Nodes)
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.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)

View File

@@ -1,6 +1,6 @@
Selectable: True Selectable: True
MapFormat: 2 MapFormat: 3
Title: Test Title: Test

View File

@@ -1,6 +1,6 @@
Selectable: False Selectable: False
MapFormat: 2 MapFormat: 3
Title: <none> Title: <none>