Example #1
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()
                {
                    (mapPackage, "map.yaml", yaml.Nodes)
                };

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

                var mapActorsNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Actors");
                if (mapActorsNode != null)
                {
                    var mapActors = new YamlFileSet()
                    {
                        (null, "map.yaml", mapActorsNode.Value.Nodes)
                    };

                    manualSteps.AddRange(ApplyTopLevelTransform(modData, mapActors, rule.UpdateMapActorNode));
                    files.AddRange(mapActors);
                }

                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);
                }

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

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

            return(manualSteps);
        }
Example #2
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 modSequences      = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.Sequences, externalFilenames));
            var modTilesets       = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.TileSets, externalFilenames));
            var modChromeLayout   = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.ChromeLayout, externalFilenames));
            var modChromeProvider = LoadModYaml(modData, FilterExternalModFiles(modData, modData.Manifest.Chrome, 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);
                            }
                        }
                    }

                    var mapSequencesNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Sequences");
                    if (mapSequencesNode != null)
                    {
                        foreach (var f in LoadExternalMapYaml(modData, mapSequencesNode.Value, externalFilenames))
                        {
                            if (!modSequences.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2))
                            {
                                modSequences.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, modSequences, rule.UpdateSequenceNode));
            manualSteps.AddRange(ApplyTopLevelTransform(modData, modTilesets, rule.UpdateTilesetNode));
            manualSteps.AddRange(ApplyChromeTransform(modData, modChromeLayout, rule.UpdateChromeNode));
            manualSteps.AddRange(ApplyTopLevelTransform(modData, modChromeProvider, rule.UpdateChromeProviderNode));
            manualSteps.AddRange(rule.AfterUpdate(modData));

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

            return(manualSteps);
        }