UpgradeMap() public static method

public static UpgradeMap ( ModData modData, IReadWritePackage package, int engineDate ) : void
modData ModData
package IReadWritePackage
engineDate int
return void
Exemplo n.º 1
0
        void IUtilityCommand.Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            var modData = Game.ModData = utility.ModData;

            var engineDate = Exts.ParseIntegerInvariant(args[1]);

            if (engineDate < UpgradeRules.MinimumSupportedVersion)
            {
                Console.WriteLine("Unsupported engine version. Use the release-{0} utility to update to that version, and then try again",
                                  UpgradeRules.MinimumSupportedVersion);
                return;
            }

            ProcessYaml("Rules", modData.Manifest.Rules, modData, engineDate, UpgradeRules.UpgradeActorRules);
            ProcessYaml("Weapons", modData.Manifest.Weapons, modData, engineDate, UpgradeRules.UpgradeWeaponRules);
            ProcessYaml("Sequences", modData.Manifest.Sequences, modData, engineDate, UpgradeRules.UpgradeSequences);
            ProcessYaml("Tilesets", modData.Manifest.TileSets, modData, engineDate, UpgradeRules.UpgradeTileset);
            ProcessYaml("Cursors", modData.Manifest.Cursors, modData, engineDate, UpgradeRules.UpgradeCursors);
            ProcessYaml("Chrome Metrics", modData.Manifest.ChromeMetrics, modData, engineDate, UpgradeRules.UpgradeChromeMetrics);
            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 System Maps:");
            foreach (var map in modData.MapCache.EnumerateMapsWithoutCaching())
            {
                try
                {
                    Console.WriteLine(map.Package.Name);
                    UpgradeMapCommand.UpgradeMap(modData, (IReadWritePackage)map.Package, engineDate);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to upgrade map {0}", map);
                    Console.WriteLine("Error was: {0}", e.ToString());
                }
            }
        }
        void IUtilityCommand.Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            var modData = Game.ModData = utility.ModData;

            modData.MapCache.LoadMaps();

            var engineDate = Exts.ParseIntegerInvariant(args[1]);

            if (engineDate < UpgradeRules.MinimumSupportedVersion)
            {
                Console.WriteLine("Unsupported engine version. Use the release-{0} utility to update to that version, and then try again",
                                  UpgradeRules.MinimumSupportedVersion);
                return;
            }

            ProcessYaml("Rules", modData.Manifest.Rules, modData, engineDate, UpgradeRules.UpgradeActorRules);
            ProcessYaml("Weapons", modData.Manifest.Weapons, modData, engineDate, UpgradeRules.UpgradeWeaponRules);
            ProcessYaml("Sequences", modData.Manifest.Sequences, modData, engineDate, UpgradeRules.UpgradeSequences);
            ProcessYaml("Tilesets", modData.Manifest.TileSets, modData, engineDate, UpgradeRules.UpgradeTileset);
            ProcessYaml("Cursors", modData.Manifest.Cursors, modData, engineDate, UpgradeRules.UpgradeCursors);
            ProcessYaml("Chrome Metrics", modData.Manifest.ChromeMetrics, modData, engineDate, UpgradeRules.UpgradeChromeMetrics);
            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:");
            foreach (var kv in modData.Manifest.MapFolders)
            {
                var name           = kv.Key;
                var classification = string.IsNullOrEmpty(kv.Value)
                                        ? MapClassification.Unknown : Enum <MapClassification> .Parse(kv.Value);

                if (classification != MapClassification.System)
                {
                    continue;
                }

                var optional = name.StartsWith("~");
                if (optional)
                {
                    name = name.Substring(1);
                }

                try
                {
                    using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(name))
                    {
                        foreach (var map in package.Contents)
                        {
                            try
                            {
                                using (var mapPackage = package.OpenPackage(map, modData.ModFiles))
                                {
                                    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 { }
            }
        }