Exemplo n.º 1
0
        public HotkeyManager(IReadOnlyFileSystem fileSystem, Dictionary <string, Hotkey> settings, Manifest manifest)
        {
            this.settings = settings;

            var keyDefinitions = MiniYaml.Load(fileSystem, manifest.Hotkeys, null);

            foreach (var kd in keyDefinitions)
            {
                var definition = new HotkeyDefinition(kd.Key, kd.Value);
                definitions[kd.Key] = definition;
                keys[kd.Key]        = definition.Default;
            }

            foreach (var kv in settings)
            {
                if (definitions.ContainsKey(kv.Key))
                {
                    keys[kv.Key] = kv.Value;
                }
            }

            foreach (var hd in definitions)
            {
                hd.Value.HasDuplicates = GetFirstDuplicate(hd.Value.Name, this[hd.Value.Name].GetValue(), hd.Value) != null;
            }
        }
Exemplo n.º 2
0
        public Map PrepareMap(string uid)
        {
            if (LoadScreen != null)
            {
                LoadScreen.Display();
            }

            if (MapCache[uid].Status != MapStatus.Available)
            {
                throw new InvalidDataException("Invalid map uid: {0}".F(uid));
            }

            Map map;

            using (new Support.PerfTimer("Map"))
                map = new Map(this, MapCache[uid].Package);

            LoadTranslations(map);

            // Reinitialize all our assets
            InitializeLoaders(map);

            // Load music with map assets mounted
            using (new Support.PerfTimer("Map.Music"))
                foreach (var entry in map.Rules.Music)
                {
                    entry.Value.Load(map);
                }

            VoxelProvider.Initialize(VoxelLoader, map, MiniYaml.Load(map, Manifest.VoxelSequences, map.VoxelSequenceDefinitions));
            VoxelLoader.Finish();

            return(map);
        }
Exemplo n.º 3
0
        static IReadOnlyDictionary <string, T> MergeOrDefault <T>(string name, IReadOnlyFileSystem fileSystem, IEnumerable <string> files, MiniYaml additional,
                                                                  IReadOnlyDictionary <string, T> defaults, Func <MiniYamlNode, T> makeObject)
        {
            if (additional == null && defaults != null)
            {
                return(defaults);
            }

            var result = MiniYaml.Load(fileSystem, files, additional)
                         .ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">");

            return(new ReadOnlyDictionary <string, T>(result));
        }
Exemplo n.º 4
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 yaml = MiniYaml.Load(map, Manifest.Translations, map.TranslationDefinitions);

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

            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.º 5
0
        public HotkeyManager(IReadOnlyFileSystem fileSystem, Dictionary <string, Hotkey> settings, Manifest manifest)
        {
            this.settings = settings;

            var keyDefinitions = MiniYaml.Load(fileSystem, manifest.Hotkeys, null);

            foreach (var kd in keyDefinitions)
            {
                var definition = new HotkeyDefinition(kd.Key, kd.Value);
                definitions[kd.Key] = definition;
                keys[kd.Key]        = definition.Default;
            }

            foreach (var kv in settings)
            {
                keys[kv.Key] = kv.Value;
            }
        }
Exemplo n.º 6
0
        static IReadOnlyDictionary <string, T> MergeOrDefault <T>(string name,
                                                                  IReadOnlyFileSystem fileSystem,
                                                                  IEnumerable <string> files,
                                                                  MiniYaml additional,
                                                                  IReadOnlyDictionary <string, T> defaults,
                                                                  Func <MiniYamlNode, T> makeObject,
                                                                  Func <MiniYamlNode, bool> filterNode = null)
        {
            if (additional == null && defaults != null)
            {
                return(defaults);
            }

            IEnumerable <MiniYamlNode> yamlNodes = MiniYaml.Load(fileSystem, files, additional);

            // Optionally, the caller can filter out elements from the loaded set of nodes. Default behavior is unfiltered.
            if (filterNode != null)
            {
                yamlNodes = yamlNodes.Where(k => !filterNode(k));
            }

            return(new ReadOnlyDictionary <string, T>(yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">")));
        }