public void Run(Action <string> emitError, Action <string> emitWarning, ModData modData)
        {
            // Build the list of valid hotkey names
            var namedKeys = modData.Hotkeys.Definitions.Select(d => d.Name).ToArray();

            // Build the list of widget keys to validate
            var checkWidgetFields = modData.ObjectCreator.GetTypesImplementing <Widget>()
                                    .SelectMany(w => w.GetFields()
                                                .Where(f => f.FieldType == typeof(HotkeyReference))
                                                .Select(f => (w.Name.Substring(0, w.Name.Length - 6), f.Name)))
                                    .ToArray();

            var customLintMethods = new Dictionary <string, List <string> >();

            foreach (var w in modData.ObjectCreator.GetTypesImplementing <Widget>())
            {
                foreach (var m in w.GetMethods().Where(m => m.HasAttribute <CustomLintableHotkeyNames>()))
                {
                    var p = m.GetParameters();
                    if (p.Length == 3 && p[0].ParameterType == typeof(MiniYamlNode) && p[1].ParameterType == typeof(Action <string>) &&
                        p[2].ParameterType == typeof(Action <string>))
                    {
                        customLintMethods.GetOrAdd(w.Name.Substring(0, w.Name.Length - 6)).Add(m.Name);
                    }
                }
            }

            foreach (var filename in modData.Manifest.ChromeLayout)
            {
                var yaml = MiniYaml.FromStream(modData.DefaultFileSystem.Open(filename), filename);
                CheckInner(modData, namedKeys, checkWidgetFields, customLintMethods, yaml, filename, null, emitError, emitWarning);
            }
        }
Exemple #2
0
        public static void Initialize(ModData modData)
        {
            Deinitialize();

            // Load higher resolution images if available on HiDPI displays
            if (Game.Renderer != null)
            {
                dpiScale = Game.Renderer.WindowScale;
            }

            fileSystem             = modData.DefaultFileSystem;
            collections            = new Dictionary <string, Collection>();
            cachedSheets           = new Dictionary <string, Pair <Sheet, int> >();
            cachedSprites          = new Dictionary <string, Dictionary <string, Sprite> >();
            cachedPanelSprites     = new Dictionary <string, Sprite[]>();
            cachedCollectionSheets = new Dictionary <Collection, Pair <Sheet, int> >();

            Collections = new ReadOnlyDictionary <string, Collection>(collections);

            var chrome = MiniYaml.Merge(modData.Manifest.Chrome
                                        .Select(s => MiniYaml.FromStream(fileSystem.Open(s), s)));

            foreach (var c in chrome)
            {
                if (!c.Key.StartsWith("^", StringComparison.Ordinal))
                {
                    LoadCollection(c.Key, c.Value);
                }
            }
        }
Exemple #3
0
        static void ProcessYaml(ModData modData, Map map, MiniYaml yaml, int engineDate, UpgradeAction processYaml)
        {
            if (yaml == null)
            {
                return;
            }

            if (yaml.Value != null)
            {
                var files = FieldLoader.GetValue <string[]>("value", yaml.Value);
                foreach (var filename in files)
                {
                    var fileNodes = MiniYaml.FromStream(map.Open(filename), filename);
                    processYaml(modData, engineDate, ref fileNodes, null, 0);

                    // HACK: Obtain the writable save path using knowledge of the underlying filesystem workings
                    var packagePath = filename;
                    var package     = map.Package;
                    if (filename.Contains("|"))
                    {
                        modData.DefaultFileSystem.TryGetPackageContaining(filename, out package, out packagePath);
                    }

                    ((IReadWritePackage)package).Update(packagePath, Encoding.ASCII.GetBytes(fileNodes.WriteToString()));
                }
            }

            processYaml(modData, engineDate, ref yaml.Nodes, null, 1);
        }
Exemple #4
0
        internal static void UpgradeMapFormat(ModData modData, IReadWritePackage package)
        {
            if (package == null)
            {
                return;
            }

            var yamlStream = package.GetStream("map.yaml");

            if (yamlStream == null)
            {
                return;
            }

            var yaml      = new MiniYaml(null, MiniYaml.FromStream(yamlStream, package.Name));
            var nd        = yaml.ToDictionary();
            var mapFormat = FieldLoader.GetValue <int>("MapFormat", nd["MapFormat"].Value);

            if (mapFormat < 11)
            {
                throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(mapFormat, package.Name));
            }

            if (mapFormat < Map.SupportedMapFormat)
            {
                yaml.Nodes.First(n => n.Key == "MapFormat").Value = new MiniYaml(Map.SupportedMapFormat.ToString());
                Console.WriteLine("Converted {0} to MapFormat {1}.", package.Name, Map.SupportedMapFormat);
            }

            package.Update("map.yaml", Encoding.UTF8.GetBytes(yaml.Nodes.WriteToString()));
        }
Exemple #5
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 #6
0
        void CheckMapYaml(Action <string> emitError, ModData modData, IReadOnlyFileSystem fileSystem, MiniYaml ruleDefinitions)
        {
            if (ruleDefinitions == null)
            {
                return;
            }

            var files = modData.Manifest.Rules.AsEnumerable();

            if (ruleDefinitions.Value != null)
            {
                var mapFiles = FieldLoader.GetValue <string[]>("value", ruleDefinitions.Value);
                files = files.Append(mapFiles);
            }

            var nodes = new List <MiniYamlNode>();

            foreach (var f in files)
            {
                nodes.AddRange(MiniYaml.FromStream(fileSystem.Open(f), f));
            }

            nodes.AddRange(ruleDefinitions.Nodes);
            Run(emitError, nodes);
        }
        void IUtilityCommand.Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            var modData = Game.ModData = utility.ModData;

            var failed = false;

            modData.SpriteSequenceLoader.OnMissingSpriteError = s => { Console.WriteLine("\t" + s); failed = true; };

            foreach (var t in modData.Manifest.TileSets)
            {
                var ts = new TileSet(modData.DefaultFileSystem, t);
                Console.WriteLine("Tileset: " + ts.Name);
                var sc    = new SpriteCache(modData.DefaultFileSystem, modData.SpriteLoaders);
                var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(modData.DefaultFileSystem.Open(s), s)));
                foreach (var n in nodes.Where(node => !node.Key.StartsWith(ActorInfo.AbstractActorPrefix, StringComparison.Ordinal)))
                {
                    modData.SpriteSequenceLoader.ParseSequences(modData, ts, sc, n);
                }
            }

            if (failed)
            {
                Environment.Exit(1);
            }
        }
Exemple #8
0
        public bool TryParsePackage(Stream s, string filename, FS context, out IReadOnlyPackage package)
        {
            if (filename.EndsWith(".lpk"))
            {
                s = Crypter.Decrypt(s);
            }

            var signature = s.ReadASCII(4);

            s.Position -= 4;

            if (!signature.Equals("DATA") && !signature.Equals("DAT2"))
            {
                package = null;
                return(false);
            }

            Stream lvlLookup;

            context.TryOpen("LvlLookup.yaml", out lvlLookup);

            package = new LvlPackage(s, filename, MiniYaml.FromStream(lvlLookup).ToDictionary(x => x.Key, x => x.Value));

            return(true);
        }
Exemple #9
0
        public void Run(ModData modData, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            Game.ModData = modData;

            var failed = false;

            modData.SpriteSequenceLoader.OnMissingSpriteError = s => { Console.WriteLine("\t" + s); failed = true; };

            foreach (var t in modData.Manifest.TileSets)
            {
                var ts = new TileSet(modData.DefaultFileSystem, t);
                Console.WriteLine("Tileset: " + ts.Name);
                var sc    = new SpriteCache(modData.DefaultFileSystem, modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed));
                var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(modData.DefaultFileSystem.Open(s), s)));
                foreach (var n in nodes)
                {
                    modData.SpriteSequenceLoader.ParseSequences(modData, ts, sc, n);
                }
            }

            if (failed)
            {
                Environment.Exit(1);
            }
        }
Exemple #10
0
 public void Run(Action <string> emitError, Action <string> emitWarning, ModData modData)
 {
     foreach (var filename in modData.Manifest.ChromeLayout)
     {
         CheckInner(MiniYaml.FromStream(modData.DefaultFileSystem.Open(filename), filename), filename, emitError);
     }
 }
Exemple #11
0
        public static void Initialize(ModData modData)
        {
            if (Initialized)
            {
                return;
            }

            Deinitialize();

            fileSystem   = modData.DefaultFileSystem;
            collections  = new Dictionary <string, Collection>();
            cachedSheets = new Dictionary <string, Sheet>();

            cachedSheets2d = new Dictionary <string, SheetCache>();
            cachedSprites  = new Dictionary <string, Dictionary <string, Sprite> >();

            var chrome = MiniYaml.Merge(modData.Manifest.Chrome
                                        .Select(s => MiniYaml.FromStream(fileSystem.Open(s), s)));

            foreach (var c in chrome)
            {
                LoadCollection(c.Key, c.Value);
            }
            Initialized = true;
        }
Exemple #12
0
        void MergeAndPrint(Map map, string key, MiniYaml value)
        {
            var nodes    = new List <MiniYamlNode>();
            var includes = new List <string>();

            if (value != null && value.Value != null)
            {
                // The order of the included files matter, so we can defer to system files
                // only as long as they are included first.
                var include = false;
                var files   = FieldLoader.GetValue <string[]>("value", value.Value);
                foreach (var f in files)
                {
                    include |= map.Package.Contains(f);
                    if (include)
                    {
                        nodes.AddRange(MiniYaml.FromStream(map.Open(f), f, false));
                    }
                    else
                    {
                        includes.Add(f);
                    }
                }
            }

            if (value != null)
            {
                nodes.AddRange(value.Nodes);
            }

            var output = new MiniYaml(includes.JoinWith(", "), nodes);

            Console.WriteLine(output.ToLines(key).JoinWith("\n"));
        }
 void ILintPass.Run(Action <string> emitError, Action <string> emitWarning, ModData modData)
 {
     foreach (var f in modData.Manifest.Weapons)
     {
         CheckWeapons(MiniYaml.FromStream(modData.DefaultFileSystem.Open(f), f), emitError, emitWarning, modData);
     }
 }
Exemple #14
0
        void ILintPass.Run(Action <string> emitError, Action <string> emitWarning, ModData modData)
        {
            var nodes = new List <MiniYamlNode>();

            foreach (var f in modData.Manifest.Rules)
            {
                nodes.AddRange(MiniYaml.FromStream(modData.DefaultFileSystem.Open(f), f));
            }

            Run(emitError, nodes);
        }
        void CheckMapYaml(Action<string> emitError, Action<string> emitWarning, ModData modData, IReadOnlyFileSystem fileSystem, MiniYaml weaponDefinitions)
        {
            if (weaponDefinitions == null)
                return;

            var mapFiles = FieldLoader.GetValue<string[]>("value", weaponDefinitions.Value);
            foreach (var f in mapFiles)
                CheckWeapons(MiniYaml.FromStream(fileSystem.Open(f), f), emitError, emitWarning, modData);

            if (weaponDefinitions.Nodes.Any())
                CheckWeapons(weaponDefinitions.Nodes, emitError, emitWarning, modData);
        }
Exemple #16
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);
                }

                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);
        }
Exemple #17
0
        public static void Initialize(ModData modData)
        {
            data = new Dictionary <string, string>();
            var metrics = MiniYaml.Merge(modData.Manifest.ChromeMetrics.Select(
                                             y => MiniYaml.FromStream(modData.DefaultFileSystem.Open(y), y)));

            foreach (var m in metrics)
            {
                foreach (var n in m.Value.Nodes)
                {
                    data[n.Key] = n.Value.Value;
                }
            }
        }
        void ILintMapPass.Run(Action <string> emitError, Action <string> emitWarning, ModData modData, Map map)
        {
            if (map.WeaponDefinitions != null && map.WeaponDefinitions.Value != null)
            {
                var mapFiles = FieldLoader.GetValue <string[]>("value", map.WeaponDefinitions.Value);
                foreach (var f in mapFiles)
                {
                    CheckWeapons(MiniYaml.FromStream(map.Open(f), f), emitError, emitWarning, modData);
                }

                if (map.WeaponDefinitions.Nodes.Any())
                {
                    CheckWeapons(map.WeaponDefinitions.Nodes, emitError, emitWarning, modData);
                }
            }
        }
        public void Run(Utility utility, string[] args)
        {
            var modData = utility.ModData;

            var localizationName = args[1];

            var localizationFile = localizationName + ".yaml";

            if (File.Exists(localizationFile))
            {
                File.Delete(localizationFile);
            }
            using (StreamWriter writer = new StreamWriter(File.Create(localizationName + ".yaml")))
            {
                List <MiniYamlNode> subNodes  = new List <MiniYamlNode>();
                List <MiniYamlNode> ruleNodes = new List <MiniYamlNode>();
                foreach (var f in modData.Manifest.Rules)
                {
                    var actors = MiniYaml.FromStream(modData.DefaultFileSystem.Open(f), f);

                    // TODO: maybe can export actorInfos
                    foreach (var actor in actors)
                    {
                        foreach (var trait in actor.Value.Nodes)
                        {
                            // TODO: export the string which has translation attribute
                            if (trait.Key == "Tooltip")
                            {
                                ruleNodes.Add(new MiniYamlNode(actor.Key, new MiniYaml(trait.Value.Nodes[0].Value.Value)));
                            }
                        }
                    }
                }
                subNodes.Add(new MiniYamlNode("Rules", new MiniYaml(null, ruleNodes)));

                List <MiniYamlNode> nodes = new List <MiniYamlNode>();
                MiniYamlNode        node  = new MiniYamlNode(localizationName, new MiniYaml(localizationName.SetFirstLetterUpper(), subNodes));
                nodes.Add(node);

                MiniYaml tranlsation = new MiniYaml(null, nodes);
                foreach (var line in tranlsation.ToLines(localizationName))
                {
                    writer.WriteLine(line);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Loads a YamlFileSet from a list of mod files.
        /// </summary>
        static YamlFileSet LoadModYaml(ModData modData, IEnumerable <string> files)
        {
            var yaml = new YamlFileSet();

            foreach (var filename in files)
            {
                if (!modData.ModFiles.TryGetPackageContaining(filename, out var package, out var name) || !(package is IReadWritePackage))
                {
                    Console.WriteLine("Failed to load file `{0}` for writing. It will not be updated.", filename);
                    continue;
                }

                yaml.Add(((IReadWritePackage)package, name, MiniYaml.FromStream(package.GetStream(name), name, false)));
            }

            return(yaml);
        }
Exemple #21
0
        public WidgetLoader(ModData modData)
        {
            this.modData = modData;

            foreach (var file in modData.Manifest.ChromeLayout.Select(a => MiniYaml.FromStream(modData.DefaultFileSystem.Open(a), a)))
            {
                foreach (var w in file)
                {
                    var key = w.Key.Substring(w.Key.IndexOf('@') + 1);
                    if (widgets.ContainsKey(key))
                    {
                        throw new InvalidDataException("Widget has duplicate Key '{0}' at {1}".F(w.Key, w.Location));
                    }
                    widgets.Add(key, w);
                }
            }
        }
Exemple #22
0
        void Run(Action <string> emitError, ModData modData, Ruleset rules)
        {
            var fileSystem   = modData.DefaultFileSystem;
            var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s)));
            var nodesDict    = new MiniYaml(null, sequenceYaml).ToDictionary();

            // Avoid using CursorProvider as it attempts to load palettes from the file system.
            var cursors = new List <string>();

            foreach (var s in nodesDict["Cursors"].Nodes)
            {
                foreach (var sequence in s.Value.Nodes)
                {
                    cursors.Add(sequence.Key);
                }
            }

            foreach (var actorInfo in rules.Actors)
            {
                foreach (var traitInfo in actorInfo.Value.TraitInfos <TraitInfo>())
                {
                    var fields = traitInfo.GetType().GetFields();
                    foreach (var field in fields)
                    {
                        var cursorReference = field.GetCustomAttributes <CursorReferenceAttribute>(true).FirstOrDefault();
                        if (cursorReference == null)
                        {
                            continue;
                        }

                        var cursor = LintExts.GetFieldValues(traitInfo, field, emitError, cursorReference.DictionaryReference).FirstOrDefault();
                        if (string.IsNullOrEmpty(cursor))
                        {
                            continue;
                        }

                        if (!cursors.Contains(cursor))
                        {
                            emitError("Undefined cursor {0} for actor {1} with trait {2}.".F(cursor, actorInfo.Value.Name, traitInfo));
                        }
                    }
                }
            }
        }
Exemple #23
0
        void CheckMapYaml(Action <string> emitError, ModData modData, IReadOnlyFileSystem fileSystem, MiniYaml ruleDefinitions)
        {
            if (ruleDefinitions == null)
            {
                return;
            }

            var mapFiles = FieldLoader.GetValue <string[]>("value", ruleDefinitions.Value);

            foreach (var f in mapFiles)
            {
                CheckActors(MiniYaml.FromStream(fileSystem.Open(f), f), emitError, modData);
            }

            if (ruleDefinitions.Nodes.Any())
            {
                CheckActors(ruleDefinitions.Nodes, emitError, modData);
            }
        }
Exemple #24
0
        static void ProcessYaml(Map map, MiniYaml yaml, int engineDate, UpgradeAction processYaml)
        {
            if (yaml == null)
            {
                return;
            }

            if (yaml.Value != null)
            {
                var files = FieldLoader.GetValue <string[]>("value", yaml.Value);
                foreach (var filename in files)
                {
                    var fileNodes = MiniYaml.FromStream(map.Package.GetStream(filename));
                    processYaml(engineDate, ref fileNodes, null, 0);
                    ((IReadWritePackage)map.Package).Update(filename, Encoding.ASCII.GetBytes(fileNodes.WriteToString()));
                }
            }

            processYaml(engineDate, ref yaml.Nodes, null, 1);
        }
Exemple #25
0
        public WDTData Read(ModData modData)
        {
            WDTData wdtData = new WDTData();

            List <MiniYamlNode> miniYaml = MiniYaml.FromStream(modData.DefaultFileSystem.Open("wdt_data.yaml"));
            var rootNode = miniYaml.FirstOrDefault();

            if (rootNode != null)
            {
                var scenarioNode = rootNode.Value.Nodes[0];
                var blocksNode   = rootNode.Value.Nodes[1];

                if (scenarioNode != null && blocksNode != null)
                {
                    foreach (var node in scenarioNode.Value.Nodes)
                    {
                        WDTScenario wdtScenario = new WDTScenario();
                        wdtScenario.Key             = node.Key;
                        wdtScenario.Name            = node.Value.Nodes[0].Value.Value;
                        wdtScenario.BackgroundImage = node.Value.Nodes[1].Value.Value;
                        wdtData.Scenarios.Add(wdtScenario);
                    }
                    foreach (var scenarioKeyNode in blocksNode.Value.Nodes)
                    {
                        foreach (var blockNode in scenarioKeyNode.Value.Nodes)
                        {
                            if (!wdtData.Blocks.ContainsKey(scenarioKeyNode.Key))
                            {
                                wdtData.Blocks.Add(scenarioKeyNode.Key, new List <WDTBlock>());
                            }
                            WDTBlock block = new WDTBlock();
                            block.Name  = blockNode.Value.Nodes[0].Value.Value;
                            block.Image = blockNode.Value.Nodes[1].Value.Value;
                            wdtData.Blocks[scenarioKeyNode.Key].Add(block);
                        }
                    }
                }
            }

            return(wdtData);
        }
Exemple #26
0
        public CursorProvider(ModData modData)
        {
            var fileSystem   = modData.DefaultFileSystem;
            var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select(
                                                  s => MiniYaml.FromStream(fileSystem.Open(s), s)));

            var shadowIndex = new int[] { };

            var nodesDict = new MiniYaml(null, sequenceYaml).ToDictionary();

            if (nodesDict.ContainsKey("ShadowIndex"))
            {
                Array.Resize(ref shadowIndex, shadowIndex.Length + 1);
                Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value,
                                              out shadowIndex[shadowIndex.Length - 1]);
            }

            var palettes = new Dictionary <string, ImmutablePalette>();

            foreach (var p in nodesDict["Palettes"].Nodes)
            {
                palettes.Add(p.Key, new ImmutablePalette(fileSystem.Open(p.Value.Value), shadowIndex));
            }

            Palettes = palettes.AsReadOnly();

            var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders);
            var cursors    = new Dictionary <string, CursorSequence>();

            foreach (var s in nodesDict["Cursors"].Nodes)
            {
                foreach (var sequence in s.Value.Nodes)
                {
                    cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value));
                }
            }

            Cursors = cursors.AsReadOnly();
        }
Exemple #27
0
        public CursorProvider(ModData modData)
        {
            var fileSystem   = modData.DefaultFileSystem;
            var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select(
                                                  s => MiniYaml.FromStream(fileSystem.Open(s), s)));

            var nodesDict = new MiniYaml(null, sequenceYaml).ToDictionary();

            // Overwrite previous definitions if there are duplicates
            var pals = new Dictionary <string, IProvidesCursorPaletteInfo>();

            foreach (var p in modData.DefaultRules.Actors["world"].TraitInfos <IProvidesCursorPaletteInfo>())
            {
                if (p.Palette != null)
                {
                    pals[p.Palette] = p;
                }
            }

            Palettes = nodesDict["Cursors"].Nodes.Select(n => n.Value.Value)
                       .Where(p => p != null)
                       .Distinct()
                       .ToDictionary(p => p, p => pals[p].ReadPalette(modData.DefaultFileSystem))
                       .AsReadOnly();

            var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders);
            var cursors    = new Dictionary <string, CursorSequence>();

            foreach (var s in nodesDict["Cursors"].Nodes)
            {
                foreach (var sequence in s.Value.Nodes)
                {
                    cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value));
                }
            }

            Cursors = cursors.AsReadOnly();
        }
Exemple #28
0
        void ProcessYaml(string type, IEnumerable <string> files, ModData modData, int engineDate, UpgradeAction processFile)
        {
            Console.WriteLine("Processing {0}:", type);
            foreach (var filename in files)
            {
                Console.WriteLine("\t" + filename);
                string           name;
                IReadOnlyPackage package;
                if (!modData.ModFiles.TryGetPackageContaining(filename, out package, out name) || !(package is Folder))
                {
                    Console.WriteLine("\t\tFile cannot be opened for writing! Ignoring...");
                    continue;
                }

                var yaml = MiniYaml.FromStream(package.GetStream(name), name);
                processFile(modData, engineDate, ref yaml, null, 0);

                // Generate the on-disk path
                var path = Path.Combine(package.Name, name);
                using (var file = new StreamWriter(path))
                    file.Write(yaml.WriteToString());
            }
        }
Exemple #29
0
        public void Run(Action <string> emitError, Action <string> emitWarning, ModData modData)
        {
            // Build the list of valid key names
            // For now they are hardcoded, but this will change.
            var namedKeys = typeof(KeySettings).GetFields()
                            .Where(x => x.Name.EndsWith("Key", StringComparison.Ordinal))
                            .Select(x => x.Name.Substring(0, x.Name.Length - 3))
                            .ToArray();

            // Build the list of widget keys to validate
            var checkWidgetFields = modData.ObjectCreator.GetTypesImplementing <Widget>()
                                    .SelectMany(w => w.GetFields()
                                                .Where(f => f.FieldType == typeof(NamedHotkey))
                                                .Select(f => Pair.New(w.Name.Substring(0, w.Name.Length - 6), f.Name)))
                                    .ToArray();

            var customLintMethods = new Dictionary <string, List <string> >();

            foreach (var w in modData.ObjectCreator.GetTypesImplementing <Widget>())
            {
                foreach (var m in w.GetMethods().Where(m => m.HasAttribute <CustomLintableHotkeyNames>()))
                {
                    var p = m.GetParameters();
                    if (p.Length == 3 && p[0].ParameterType == typeof(MiniYamlNode) && p[1].ParameterType == typeof(Action <string>) &&
                        p[2].ParameterType == typeof(Action <string>))
                    {
                        customLintMethods.GetOrAdd(w.Name.Substring(0, w.Name.Length - 6)).Add(m.Name);
                    }
                }
            }

            foreach (var filename in modData.Manifest.ChromeLayout)
            {
                var yaml = MiniYaml.FromStream(modData.DefaultFileSystem.Open(filename), filename);
                CheckInner(modData, namedKeys, checkWidgetFields, customLintMethods, yaml, filename, null, emitError, emitWarning);
            }
        }
Exemple #30
0
        public CustomTerrain(IReadOnlyFileSystem fileSystem, string filepath)
        {
            var yaml = MiniYaml.FromStream(fileSystem.Open(filepath), filepath)
                       .ToDictionary(x => x.Key, x => x.Value);

            // General info
            FieldLoader.Load(this, yaml["General"]);

            // TerrainTypes
            TerrainInfo = yaml["Terrain"].ToDictionary().Values
                          .Select(y => new TerrainTypeInfo(y))
                          .OrderBy(tt => tt.Type)
                          .ToArray();

            if (TerrainInfo.Length >= byte.MaxValue)
            {
                throw new YamlException("Too many terrain types.");
            }

            for (byte i = 0; i < TerrainInfo.Length; i++)
            {
                var tt = TerrainInfo[i].Type;

                if (terrainIndexByType.ContainsKey(tt))
                {
                    throw new YamlException("Duplicate terrain type '{0}' in '{1}'.".F(tt, filepath));
                }

                terrainIndexByType.Add(tt, i);
            }

            defaultWalkableTerrainIndex = GetTerrainIndex("Clear");

            // Templates
            Templates = yaml["Templates"].ToDictionary().Values
                        .Select(y => (TerrainTemplateInfo) new CustomTerrainTemplateInfo(this, y)).ToDictionary(t => t.Id);
        }