Exemple #1
0
        public static List <string> UpdateMod(ModData modData, UpdateRule rule, out YamlFileSet files, HashSet <string> externalFilenames)
        {
            var manualSteps = new List <string>();

            var modRules        = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.Rules, externalFilenames));
            var modWeapons      = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.Weapons, externalFilenames));
            var modTilesets     = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.TileSets, externalFilenames));
            var modChromeLayout = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.ChromeLayout, externalFilenames));

            // Find and add shared map includes
            foreach (var package in modData.MapCache.EnumerateMapPackagesWithoutCaching())
            {
                using (var mapStream = package.GetStream("map.yaml"))
                {
                    if (mapStream == null)
                    {
                        continue;
                    }

                    var yaml         = new MiniYaml(null, MiniYaml.FromStream(mapStream, package.Name, false));
                    var mapRulesNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Rules");
                    if (mapRulesNode != null)
                    {
                        foreach (var f in LoadExternalMapYaml(modData, mapRulesNode.Value, externalFilenames))
                        {
                            if (!modRules.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2))
                            {
                                modRules.Add(f);
                            }
                        }
                    }

                    var mapWeaponsNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Weapons");
                    if (mapWeaponsNode != null)
                    {
                        foreach (var f in LoadExternalMapYaml(modData, mapWeaponsNode.Value, externalFilenames))
                        {
                            if (!modWeapons.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2))
                            {
                                modWeapons.Add(f);
                            }
                        }
                    }
                }
            }

            manualSteps.AddRange(rule.BeforeUpdate(modData));
            manualSteps.AddRange(ApplyTopLevelTransform(modData, modRules, rule.UpdateActorNode));
            manualSteps.AddRange(ApplyTopLevelTransform(modData, modWeapons, rule.UpdateWeaponNode));
            manualSteps.AddRange(ApplyTopLevelTransform(modData, modTilesets, rule.UpdateTilesetNode));
            manualSteps.AddRange(ApplyChromeTransform(modData, modChromeLayout, rule.UpdateChromeNode));
            manualSteps.AddRange(rule.AfterUpdate(modData));

            files = modRules.ToList();
            files.AddRange(modWeapons);
            files.AddRange(modTilesets);
            files.AddRange(modChromeLayout);

            return(manualSteps);
        }
Exemple #2
0
        /// <summary>
        /// Run a given update rule on a map.
        /// The rule is only applied to internal files - external includes are assumed to be handled separately
        /// but are noted in the externalFilenames list for informational purposes.
        /// </summary>
        public static List <string> UpdateMap(ModData modData, IReadWritePackage mapPackage, UpdateRule rule, out YamlFileSet files, HashSet <string> externalFilenames)
        {
            var manualSteps = new List <string>();

            using (var mapStream = mapPackage.GetStream("map.yaml"))
            {
                if (mapStream == null)
                {
                    // Not a valid map
                    files = new YamlFileSet();
                    return(manualSteps);
                }

                var yaml = new MiniYaml(null, MiniYaml.FromStream(mapStream, mapPackage.Name, false));
                files = new YamlFileSet()
                {
                    Tuple.Create(mapPackage, "map.yaml", yaml.Nodes)
                };

                manualSteps.AddRange(rule.BeforeUpdate(modData));

                var mapRulesNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Rules");
                if (mapRulesNode != null)
                {
                    var mapRules = LoadInternalMapYaml(modData, mapPackage, mapRulesNode.Value, externalFilenames);
                    manualSteps.AddRange(ApplyTopLevelTransform(modData, mapRules, rule.UpdateActorNode));
                    files.AddRange(mapRules);
                }

                var mapWeaponsNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Weapons");
                if (mapWeaponsNode != null)
                {
                    var mapWeapons = LoadInternalMapYaml(modData, mapPackage, mapWeaponsNode.Value, externalFilenames);
                    manualSteps.AddRange(ApplyTopLevelTransform(modData, mapWeapons, rule.UpdateWeaponNode));
                    files.AddRange(mapWeapons);
                }

                manualSteps.AddRange(rule.AfterUpdate(modData));
            }

            return(manualSteps);
        }