Пример #1
0
 private void copyFromComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (copyFromComboBox.SelectedIndex == -1)
     {
         return;
     }
     // TODO: selector for items, and show what mod they're from
     main_monster = Program.LoadedObjectDictionary.GetMtypes(copyFromComboBox.Text)[0].DeepCopy();
     UpdateMainMonsterBindings();
 }
Пример #2
0
            static public void Add(string id, Mtype mon)
            {
                List <Mtype> temp_list;

                if (mtypes_by_id.TryGetValue(id, out temp_list))
                {
                    temp_list.Add(mon);
                    mtypes_by_id[id] = temp_list;
                }
                else
                {
                    temp_list = new List <Mtype> {
                        mon
                    };
                    mtypes_by_id.Add(id, temp_list);
                }
            }
Пример #3
0
        private void TryLoadObjectLists()
        {
            string cdda_path;

            try
            {
                string cdda_path_file = System.Windows.Forms.Application.StartupPath + "\\cdda_data_path";
                cdda_path = File.ReadAllText(cdda_path_file);
            }
            catch
            {
                cddaFolderBrowserDialog.ShowDialog();
                cdda_path = cddaFolderBrowserDialog.SelectedPath;
            }
            currentPathLabel.Text = cdda_path;
            if (cdda_path == "")
            {
                return;
            }
            else
            {
                File.WriteAllText(Application.StartupPath + "\\cdda_data_path", cdda_path);
            }
            DirectoryInfo  dir   = new DirectoryInfo(cdda_path);
            JsonSerializer j_ser = new JsonSerializer
            {
                ContractResolver = new IgnoreEmptyEnumerablesResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                }
            };

            foreach (FileInfo file in dir.GetFiles("*.json", SearchOption.AllDirectories))
            {
                string file_text = File.ReadAllText(file.FullName);
                try
                {
                    JArray         ja        = JArray.Parse(file_text);
                    List <JObject> temp_list = (List <JObject>)ja.ToObject(typeof(List <JObject>));
                    foreach (JObject obj in temp_list)
                    {
                        GenericTypedObject generic_object = (GenericTypedObject)obj.ToObject(typeof(GenericTypedObject), j_ser);
                        if (generic_object.valid())
                        {
                            Program.LoadedObjectDictionary.Add(generic_object.Type, generic_object.GetId());
                            switch (generic_object.Type)
                            {
                            case "MONSTER":
                                Mtype temp = (Mtype)obj.ToObject(typeof(Mtype), j_ser);
                                Program.LoadedObjectDictionary.Add(generic_object.Id, temp);
                                break;

                            case "SPELL":
                                Program.LoadedObjectDictionary.Add(generic_object.Id, (spell.spell_type)obj.ToObject(typeof(spell.spell_type), j_ser));
                                break;

                            case "monster_attack":
                                MonsterAttack loaded_attack = (MonsterAttack)obj.ToObject(typeof(MonsterAttack), j_ser);
                                switch (loaded_attack.AttackType)
                                {
                                case "hardcoded":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, loaded_attack);
                                    break;

                                case "leap":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackLeap)obj.ToObject(typeof(MonsterAttackLeap), j_ser));
                                    break;

                                case "bite":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackBite)obj.ToObject(typeof(MonsterAttackBite), j_ser));
                                    break;

                                case "melee":
                                    string melee = obj.ToString();
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackMelee)obj.ToObject(typeof(MonsterAttackMelee), j_ser));
                                    break;

                                case "spell":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackSpell)obj.ToObject(typeof(MonsterAttackSpell), j_ser));
                                    break;

                                case "gun":
                                    Program.LoadedObjectDictionary.Add(generic_object.Id, (MonsterAttackGun)obj.ToObject(typeof(MonsterAttackGun), j_ser));
                                    break;

                                default: break;
                                }
                                break;

                            case "material":
                                Program.LoadedObjectDictionary.Add(generic_object.Ident, (MaterialType)obj.ToObject(typeof(MaterialType), j_ser));
                                break;

                            default: break;
                            }
                        }
                    }
                } catch (Newtonsoft.Json.JsonReaderException)
                {
                } catch (System.ArgumentException)
                {
                }
            }
        }