示例#1
0
        // Save keybind for a single mod to config file.
        public static void SaveModBinds(Mod mod)
        {
            KeybindList list = new KeybindList();
            string      path =
                Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");

            Keybind[] binds = Keybind.Get(mod).ToArray();
            for (int i = 0; i < binds.Length; i++)
            {
                if (binds[i].ID == null || binds[i].Vals != null)
                {
                    continue;
                }
                Keybinds keybinds = new Keybinds {
                    ID       = binds[i].ID, Key = binds[i].Key,
                    Modifier = binds[i].Modifier
                };

                list.keybinds.Add(keybinds);
            }

            string serializedData = JsonConvert.SerializeObject(list, Formatting.Indented);

            File.WriteAllText(path, serializedData);
        }
示例#2
0
        // Load all keybinds.
        public static void LoadBinds()
        {
            foreach (Mod mod in ModLoader.LoadedMods.Where(mod => Keybind.Get(mod).Count > 0))
            {
                // Check if there is custom keybinds file (if not, create)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");
                if (!File.Exists(path))
                {
                    SaveModBinds(mod);
                    continue;
                }

                //Load and deserialize
                KeybindList keybinds = Newtonsoft.Json.JsonConvert.DeserializeObject <KeybindList>(File.ReadAllText(path));

                if (keybinds.keybinds.Count == 0)
                {
                    continue;
                }

                foreach (Keybinds kb in keybinds.keybinds)
                {
                    Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == kb.ID);

                    if (bind == null)
                    {
                        continue;
                    }

                    bind.Key      = kb.Key;
                    bind.Modifier = kb.Modifier;
                }
            }
        }
示例#3
0
        // Save keybind for a single mod to config file.
        public static void SaveModBinds(Mod mod)
        {
            KeybindList list = new KeybindList();

            foreach (Keybind bind in Keybind.Get(mod))
            {
                if (bind.ID == null || bind.Vals != null)
                {
                    continue;
                }

                Keybinds keybinds = new Keybinds
                {
                    ID       = bind.ID,
                    Key      = bind.Key,
                    Modifier = bind.Modifier
                };

                list.keybinds.Add(keybinds);
            }

            if (list.keybinds.Count > 0)
            {
                File.WriteAllText(Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json"), Newtonsoft.Json.JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented));
            }
        }
示例#4
0
        // Load all keybinds.
        public static void LoadBinds()
        {
            Mod[] binds =
                ModLoader.LoadedMods.Where(mod => Keybind.Get(mod).Count > 0).ToArray();
            for (int i = 0; i < binds.Length; i++)
            {
                // delete old xml file (if exists)
                string path =
                    Path.Combine(ModLoader.GetModSettingsFolder(binds[i]), "keybinds.xml");
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                // Check if there is custom keybinds file (if not, create)
                path =
                    Path.Combine(ModLoader.GetModSettingsFolder(binds[i]), "keybinds.json");
                if (!File.Exists(path))
                {
                    SaveModBinds(binds[i]);
                    continue;
                }

                // Load and deserialize
                KeybindList keybinds =
                    JsonConvert.DeserializeObject <KeybindList>(File.ReadAllText(path));
                if (keybinds.keybinds.Count == 0)
                {
                    continue;
                }
                for (int k = 0; k < keybinds.keybinds.Count; k++)
                {
                    Keybind bind = Keybind.Keybinds.Find(
                        x => x.Mod == binds[i] && x.ID == keybinds.keybinds[k].ID);
                    if (bind == null)
                    {
                        continue;
                    }
                    bind.Key      = keybinds.keybinds[k].Key;
                    bind.Modifier = keybinds.keybinds[k].Modifier;
                }
            }
        }
示例#5
0
        // Save keybind for a single mod to config file.
        public static void SaveModBinds(Mod mod)
        {
            KeybindList list = new KeybindList();
            string      path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");

            foreach (Keybind bind in Keybind.Get(mod))
            {
                Keybinds keybinds = new Keybinds
                {
                    ID       = bind.ID,
                    Key      = bind.Key,
                    Modifier = bind.Modifier
                };

                list.keybinds.Add(keybinds);
            }

            string serializedData = JsonConvert.SerializeObject(list, Formatting.Indented);

            File.WriteAllText(path, serializedData);
        }
示例#6
0
        // Load all keybinds.
        public static void LoadBinds()
        {
            foreach (Mod mod in ModLoader.LoadedMods)
            {
                //delete old xml file (if exists)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.xml");
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                // Check if there is custom keybinds file (if not, create)
                path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");
                if (!File.Exists(path))
                {
                    SaveModBinds(mod);
                    continue;
                }

                //Load and deserialize
                KeybindList keybinds       = new KeybindList();
                string      serializedData = File.ReadAllText(path);
                keybinds = JsonConvert.DeserializeObject <KeybindList>(serializedData);
                if (keybinds.keybinds.Count == 0)
                {
                    continue;
                }
                foreach (var kb in keybinds.keybinds)
                {
                    Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == kb.ID);
                    if (bind == null)
                    {
                        continue;
                    }
                    bind.Key      = kb.Key;
                    bind.Modifier = kb.Modifier;
                }
            }
        }