Fix automated map format upgrades.
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
using OpenRA.FileSystem;
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
@@ -23,13 +25,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
return args.Length >= 3;
|
return args.Length >= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("MAP", "CURRENTENGINE", "Upgrade map rules to the latest engine version.")]
|
public static void UpgradeMap(ModData modData, IReadWritePackage package, int engineDate)
|
||||||
public void Run(ModData modData, string[] args)
|
|
||||||
{
|
{
|
||||||
// HACK: The engine code assumes that Game.modData is set.
|
UpgradeRules.UpgradeMapFormat(modData, package);
|
||||||
Game.ModData = modData;
|
|
||||||
|
|
||||||
var engineDate = Exts.ParseIntegerInvariant(args[2]);
|
|
||||||
if (engineDate < UpgradeRules.MinimumSupportedVersion)
|
if (engineDate < UpgradeRules.MinimumSupportedVersion)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Unsupported engine version. Use the release-{0} utility to update to that version, and then try again",
|
Console.WriteLine("Unsupported engine version. Use the release-{0} utility to update to that version, and then try again",
|
||||||
@@ -37,9 +36,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var package = modData.ModFiles.OpenWritablePackage(args[1]);
|
|
||||||
UpgradeRules.UpgradeMapFormat(modData, package);
|
|
||||||
|
|
||||||
var map = new Map(modData, package);
|
var map = new Map(modData, package);
|
||||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||||
@@ -47,5 +43,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||||
map.Save(package);
|
map.Save(package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Desc("MAP", "CURRENTENGINE", "Upgrade map rules to the latest engine version.")]
|
||||||
|
public void Run(ModData modData, string[] args)
|
||||||
|
{
|
||||||
|
// HACK: The engine code assumes that Game.modData is set.
|
||||||
|
Game.ModData = modData;
|
||||||
|
|
||||||
|
var package = modData.ModFiles.OpenWritablePackage(args[1]);
|
||||||
|
var engineDate = Exts.ParseIntegerInvariant(args[2]);
|
||||||
|
UpgradeMap(modData, package, engineDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,22 +74,45 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
ProcessYaml("Chrome Metrics", modData.Manifest.ChromeMetrics, modData, engineDate, UpgradeRules.UpgradeChromeMetrics);
|
ProcessYaml("Chrome Metrics", modData.Manifest.ChromeMetrics, modData, engineDate, UpgradeRules.UpgradeChromeMetrics);
|
||||||
ProcessYaml("Chrome Layout", modData.Manifest.ChromeLayout, modData, engineDate, UpgradeRules.UpgradeChromeLayout);
|
ProcessYaml("Chrome Layout", modData.Manifest.ChromeLayout, modData, engineDate, UpgradeRules.UpgradeChromeLayout);
|
||||||
|
|
||||||
|
// The map cache won't be valid if there was a map format upgrade, so walk the map packages manually
|
||||||
|
// Only upgrade system maps - user maps must be updated manually using --upgrade-map
|
||||||
Console.WriteLine("Processing Maps:");
|
Console.WriteLine("Processing Maps:");
|
||||||
var mapPreviews = modData.MapCache
|
foreach (var kv in modData.Manifest.MapFolders)
|
||||||
.Where(m => m.Status == MapStatus.Available);
|
|
||||||
|
|
||||||
foreach (var p in mapPreviews)
|
|
||||||
{
|
{
|
||||||
var package = (IReadWritePackage)p.Package;
|
var name = kv.Key;
|
||||||
Console.WriteLine("\t" + package.Name);
|
var classification = string.IsNullOrEmpty(kv.Value)
|
||||||
UpgradeRules.UpgradeMapFormat(modData, package);
|
? MapClassification.Unknown : Enum<MapClassification>.Parse(kv.Value);
|
||||||
|
|
||||||
var map = new Map(modData, package);
|
if (classification != MapClassification.System)
|
||||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
continue;
|
||||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
|
||||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
var optional = name.StartsWith("~");
|
||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
if (optional)
|
||||||
map.Save(package);
|
name = name.Substring(1);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(name))
|
||||||
|
{
|
||||||
|
foreach (var map in package.Contents)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var mapPackage = modData.ModFiles.OpenPackage(map, package))
|
||||||
|
{
|
||||||
|
if (mapPackage != null)
|
||||||
|
UpgradeMapCommand.UpgradeMap(modData, (IReadWritePackage)mapPackage, engineDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to upgrade map {0}", map);
|
||||||
|
Console.WriteLine("Error was: {0}", e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user