Move map format upgrades to an explicit upgrade rule.
This commit is contained in:
@@ -109,7 +109,7 @@ namespace OpenRA
|
||||
|
||||
public class Map
|
||||
{
|
||||
public const int MinimumSupportedMapFormat = 6;
|
||||
public const int SupportedMapFormat = 8;
|
||||
|
||||
public const int MaxTilesInCircleRange = 50;
|
||||
public readonly MapGrid Grid;
|
||||
@@ -312,73 +312,9 @@ namespace OpenRA
|
||||
var yaml = new MiniYaml(null, MiniYaml.FromStream(Container.GetStream("map.yaml"), path));
|
||||
FieldLoader.Load(this, yaml);
|
||||
|
||||
// Support for formats 1-3 dropped 2011-02-11.
|
||||
// Use release-20110207 to convert older maps to format 4
|
||||
// Use release-20110511 to convert older maps to format 5
|
||||
// Use release-20141029 to convert older maps to format 6
|
||||
if (MapFormat < MinimumSupportedMapFormat)
|
||||
if (MapFormat != SupportedMapFormat)
|
||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
||||
|
||||
var nd = yaml.ToDictionary();
|
||||
|
||||
// Format 6 -> 7 combined the Selectable and UseAsShellmap flags into the Class enum
|
||||
if (MapFormat < 7)
|
||||
{
|
||||
MiniYaml useAsShellmap;
|
||||
if (nd.TryGetValue("UseAsShellmap", out useAsShellmap) && bool.Parse(useAsShellmap.Value))
|
||||
Visibility = MapVisibility.Shellmap;
|
||||
else if (Type == "Mission" || Type == "Campaign")
|
||||
Visibility = MapVisibility.MissionSelector;
|
||||
}
|
||||
|
||||
// Format 7 -> 8 replaced normalized HSL triples with rgb(a) hex colors
|
||||
if (MapFormat < 8)
|
||||
{
|
||||
var players = yaml.Nodes.FirstOrDefault(n => n.Key == "Players");
|
||||
if (players != null)
|
||||
{
|
||||
bool noteHexColors = false;
|
||||
bool noteColorRamp = false;
|
||||
foreach (var player in players.Value.Nodes)
|
||||
{
|
||||
var colorRampNode = player.Value.Nodes.FirstOrDefault(n => n.Key == "ColorRamp");
|
||||
if (colorRampNode != null)
|
||||
{
|
||||
Color dummy;
|
||||
var parts = colorRampNode.Value.Value.Split(',');
|
||||
if (parts.Length == 3 || parts.Length == 4)
|
||||
{
|
||||
// Try to convert old normalized HSL value to a rgb hex color
|
||||
try
|
||||
{
|
||||
HSLColor color = new HSLColor(
|
||||
(byte)Exts.ParseIntegerInvariant(parts[0].Trim()).Clamp(0, 255),
|
||||
(byte)Exts.ParseIntegerInvariant(parts[1].Trim()).Clamp(0, 255),
|
||||
(byte)Exts.ParseIntegerInvariant(parts[2].Trim()).Clamp(0, 255));
|
||||
colorRampNode.Value.Value = FieldSaver.FormatValue(color);
|
||||
noteHexColors = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new InvalidDataException("Invalid ColorRamp value.\n File: " + path);
|
||||
}
|
||||
}
|
||||
else if (parts.Length != 1 || !HSLColor.TryParseRGB(parts[0], out dummy))
|
||||
throw new InvalidDataException("Invalid ColorRamp value.\n File: " + path);
|
||||
|
||||
colorRampNode.Key = "Color";
|
||||
noteColorRamp = true;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Converted " + path + " to MapFormat 8.");
|
||||
if (noteHexColors)
|
||||
Console.WriteLine("ColorRamp is now called Color and uses rgb(a) hex value - rrggbb[aa].");
|
||||
else if (noteColorRamp)
|
||||
Console.WriteLine("ColorRamp is now called Color.");
|
||||
}
|
||||
}
|
||||
|
||||
SpawnPoints = Exts.Lazy(() =>
|
||||
{
|
||||
var spawns = new List<CPos>();
|
||||
|
||||
Reference in New Issue
Block a user