Exemplo n.º 1
0
        void LoadTranslations(Map map)
        {
            var selectedTranslations = new Dictionary <string, string>();
            var defaultTranslations  = new Dictionary <string, string>();

            if (!Manifest.Translations.Any())
            {
                Languages = new string[0];
                return;
            }

            var partial = Manifest.Translations.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergePartial);

            Languages = partial.Select(t => t.Key).ToArray();

            var yaml = MiniYaml.Merge(map.TranslationDefinitions, partial);

            foreach (var y in yaml)
            {
                if (y.Key == Game.Settings.Graphics.Language)
                {
                    selectedTranslations = y.Value.ToDictionary(my => my.Value ?? "");
                }
                else if (y.Key == Game.Settings.Graphics.DefaultLanguage)
                {
                    defaultTranslations = y.Value.ToDictionary(my => my.Value ?? "");
                }
            }

            var translations = new Dictionary <string, string>();

            foreach (var tkv in defaultTranslations.Concat(selectedTranslations))
            {
                if (translations.ContainsKey(tkv.Key))
                {
                    continue;
                }
                if (selectedTranslations.ContainsKey(tkv.Key))
                {
                    translations.Add(tkv.Key, selectedTranslations[tkv.Key]);
                }
                else
                {
                    translations.Add(tkv.Key, tkv.Value);
                }
            }

            FieldLoader.SetTranslations(translations);
        }
Exemplo n.º 2
0
        public static List <MiniYamlNode> Load(IReadOnlyFileSystem fileSystem, IEnumerable <string> files, MiniYaml mapRules)
        {
            if (mapRules != null && mapRules.Value != null)
            {
                var mapFiles = FieldLoader.GetValue <string[]>("value", mapRules.Value);
                files = files.Append(mapFiles);
            }

            var yaml = files.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s));

            if (mapRules != null && mapRules.Nodes.Any())
            {
                yaml = yaml.Append(mapRules.Nodes);
            }

            return(MiniYaml.Merge(yaml));
        }
Exemplo n.º 3
0
            public void SetCustomRules(ModData modData, IReadOnlyFileSystem fileSystem, Dictionary <string, MiniYaml> yaml)
            {
                RuleDefinitions          = LoadRuleSection(yaml, "Rules");
                WeaponDefinitions        = LoadRuleSection(yaml, "Weapons");
                VoiceDefinitions         = LoadRuleSection(yaml, "Voices");
                MusicDefinitions         = LoadRuleSection(yaml, "Music");
                NotificationDefinitions  = LoadRuleSection(yaml, "Notifications");
                SequenceDefinitions      = LoadRuleSection(yaml, "Sequences");
                ModelSequenceDefinitions = LoadRuleSection(yaml, "ModelSequences");

                try
                {
                    // PERF: Implement a minimal custom loader for custom world and player actors to minimize loading time
                    // This assumes/enforces that these actor types can only inherit abstract definitions (starting with ^)
                    if (RuleDefinitions != null)
                    {
                        var files = modData.Manifest.Rules.AsEnumerable();
                        if (RuleDefinitions.Value != null)
                        {
                            var mapFiles = FieldLoader.GetValue <string[]>("value", RuleDefinitions.Value);
                            files = files.Append(mapFiles);
                        }

                        var sources = files.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s).Where(IsLoadableRuleDefinition).ToList());
                        if (RuleDefinitions.Nodes.Any())
                        {
                            sources = sources.Append(RuleDefinitions.Nodes.Where(IsLoadableRuleDefinition).ToList());
                        }

                        var yamlNodes = MiniYaml.Merge(sources);
                        WorldActorInfo  = new ActorInfo(modData.ObjectCreator, "world", yamlNodes.First(n => n.Key.ToLowerInvariant() == "world").Value);
                        PlayerActorInfo = new ActorInfo(modData.ObjectCreator, "player", yamlNodes.First(n => n.Key.ToLowerInvariant() == "player").Value);
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log.Write("debug", "Failed to load rules for `{0}` with error: {1}", Title, e.Message);
                }

                WorldActorInfo  = modData.DefaultRules.Actors[SystemActors.World];
                PlayerActorInfo = modData.DefaultRules.Actors[SystemActors.Player];
            }
Exemplo n.º 4
0
        public Manifest(string modId, IReadOnlyPackage package)
        {
            Id      = modId;
            Package = package;

            var nodes = MiniYaml.FromStream(package.GetStream("mod.yaml"), "mod.yaml");

            for (var i = nodes.Count - 1; i >= 0; i--)
            {
                if (nodes[i].Key != "Include")
                {
                    continue;
                }

                // Replace `Includes: filename.yaml` with the contents of filename.yaml
                var filename = nodes[i].Value.Value;
                var contents = package.GetStream(filename);
                if (contents == null)
                {
                    throw new YamlException("{0}: File `{1}` not found.".F(nodes[i].Location, filename));
                }

                nodes.RemoveAt(i);
                nodes.InsertRange(i, MiniYaml.FromStream(contents, filename));
            }

            // Merge inherited overrides
            yaml = new MiniYaml(null, MiniYaml.Merge(new[] { nodes })).ToDictionary();

            Metadata = FieldLoader.Load <ModMetadata>(yaml["Metadata"]);

            // TODO: Use fieldloader
            MapFolders = YamlDictionary(yaml, "MapFolders");

            if (yaml.TryGetValue("Packages", out var packages))
            {
                Packages = packages.ToDictionary(x => x.Value);
            }

            Rules          = YamlList(yaml, "Rules");
            Sequences      = YamlList(yaml, "Sequences");
            ModelSequences = YamlList(yaml, "ModelSequences");
            Cursors        = YamlList(yaml, "Cursors");
            Chrome         = YamlList(yaml, "Chrome");
            Assemblies     = YamlList(yaml, "Assemblies");
            ChromeLayout   = YamlList(yaml, "ChromeLayout");
            Weapons        = YamlList(yaml, "Weapons");
            Voices         = YamlList(yaml, "Voices");
            Notifications  = YamlList(yaml, "Notifications");
            Music          = YamlList(yaml, "Music");
            TileSets       = YamlList(yaml, "TileSets");
            ChromeMetrics  = YamlList(yaml, "ChromeMetrics");
            Missions       = YamlList(yaml, "Missions");
            Hotkeys        = YamlList(yaml, "Hotkeys");

            ServerTraits = YamlList(yaml, "ServerTraits");

            if (!yaml.TryGetValue("LoadScreen", out LoadScreen))
            {
                throw new InvalidDataException("`LoadScreen` section is not defined.");
            }

            // Allow inherited mods to import parent maps.
            var compat = new List <string> {
                Id
            };

            if (yaml.ContainsKey("SupportsMapsFrom"))
            {
                compat.AddRange(yaml["SupportsMapsFrom"].Value.Split(',').Select(c => c.Trim()));
            }

            MapCompatibility = compat.ToArray();

            if (yaml.ContainsKey("PackageFormats"))
            {
                PackageFormats = FieldLoader.GetValue <string[]>("PackageFormats", yaml["PackageFormats"].Value);
            }

            if (yaml.ContainsKey("SoundFormats"))
            {
                SoundFormats = FieldLoader.GetValue <string[]>("SoundFormats", yaml["SoundFormats"].Value);
            }

            if (yaml.ContainsKey("SpriteFormats"))
            {
                SpriteFormats = FieldLoader.GetValue <string[]>("SpriteFormats", yaml["SpriteFormats"].Value);
            }

            if (yaml.ContainsKey("VideoFormats"))
            {
                VideoFormats = FieldLoader.GetValue <string[]>("VideoFormats", yaml["VideoFormats"].Value);
            }
        }