Esempio n. 1
0
        private FileData GetFileDataFactory(string path)
        {
            string extension = System.IO.Path.GetExtension(path);

            switch (extension)
            {
            case ".qb":
                QubicleFileData qubicleFile = new QubicleFileData(path);
                qubicleFile.AddLinkingJsonFile(this);
                qubicleFile.RelatedFiles.Add(this);
                qubicleFile.Load();
                return(qubicleFile);

            case ".png":
                ImageFileData imageFile = new ImageFileData(path);
                imageFile.AddLinkingJsonFile(this);
                imageFile.RelatedFiles.Add(this);
                return(imageFile);

            case ".json":
                JsonFileData jsonFileData = new JsonFileData(path);
                jsonFileData.Load();
                jsonFileData.RelatedFiles.Add(this);
                return(jsonFileData);
            }

            return(null);
        }
Esempio n. 2
0
        private void ParseJsonSpecificData()
        {
            string directory = Directory;

            switch (mJsonType)
            {
            case JSONTYPE.ENTITY:
                JToken entityFormsComponent = mJson.SelectToken("components.stonehearth:entity_forms");
                if (entityFormsComponent != null)
                {
                    // Look for stonehearth:entity_forms
                    JToken ghostForm = entityFormsComponent["ghost_form"];
                    if (ghostForm != null)
                    {
                        string ghostFilePath = JsonHelper.GetFileFromFileJson(ghostForm.ToString(), directory);
                        ghostFilePath = JsonHelper.NormalizeSystemPath(ghostFilePath);
                        JsonFileData ghost = new JsonFileData(ghostFilePath);
                        ghost.Load();
                        ghost.AddMixin("stonehearth:mixins:placed_object");
                        OpenedFiles.Add(ghost);
                        ghost.PostLoad();
                    }

                    JToken iconicForm = entityFormsComponent["iconic_form"];
                    if (iconicForm != null)
                    {
                        string iconicFilePath = JsonHelper.GetFileFromFileJson(iconicForm.ToString(), directory);
                        iconicFilePath = JsonHelper.NormalizeSystemPath(iconicFilePath);
                        JsonFileData iconic = new JsonFileData(iconicFilePath);
                        iconic.Load();
                        OpenedFiles.Add(iconic);
                    }

                    CheckForNoNetWorth();
                }
                else
                {
                    if (GetModuleFile() != null && mJson.SelectToken("components.item") != null)
                    {
                        CheckForNoNetWorth();
                    }
                }

                break;

            case JSONTYPE.JOB:
                // Parse crafter stuff
                JToken crafter = mJson["crafter"];
                if (crafter != null)
                {
                    // This is a crafter, load its recipes
                    string recipeListLocation = crafter["recipe_list"].ToString();
                    recipeListLocation = JsonHelper.GetFileFromFileJson(recipeListLocation, directory);
                    JsonFileData recipes = new JsonFileData(recipeListLocation);
                    recipes.Load();
                    foreach (FileData recipe in recipes.LinkedFileData.Values)
                    {
                        recipes.RelatedFiles.Add(recipe);
                    }

                    OpenedFiles.Add(recipes);
                    recipes.ReferencedByFileData[GetAliasOrFlatName()] = this;
                }

                JObject jobEquipment = mJson["equipment"] as JObject;
                if (jobEquipment != null)
                {
                    foreach (JToken equippedItem in jobEquipment.Children())
                    {
                        string   equipmentJson = equippedItem.Last.ToString();
                        FileData fileData      = null;
                        if (equipmentJson.IndexOf(':') >= 0)
                        {
                            foreach (ModuleFile alias in LinkedAliases)
                            {
                                if (alias.FullAlias.Equals(equipmentJson))
                                {
                                    fileData = alias.FileData;
                                }
                            }
                        }
                        else
                        {
                            equipmentJson = JsonHelper.GetFileFromFileJson(equipmentJson, directory);
                            LinkedFileData.TryGetValue(equipmentJson, out fileData);
                        }

                        JsonFileData jsonFileData = fileData as JsonFileData;
                        if (jsonFileData != null)
                        {
                            JToken equipment_piece = jsonFileData.mJson.SelectToken("components.stonehearth:equipment_piece");
                            if (equipment_piece != null)
                            {
                                JToken ilevel = equipment_piece["ilevel"];
                                if (ilevel != null && ilevel.Value <int>() > 0)
                                {
                                    JToken noDrop = equipment_piece["no_drop"];
                                    if (noDrop == null || !noDrop.Value <bool>())
                                    {
                                        AddError("Equipment piece " + equipmentJson + " is not set to no_drop=true even through it is a job equipment!");
                                    }
                                }
                            }
                        }
                    }
                }

                ////AlterJobExperience();
                break;

            case JSONTYPE.RECIPE:
                JToken portrait = mJson["portrait"];
                if (portrait != null)
                {
                    string portraitImageLocation = portrait.ToString();
                    portraitImageLocation = JsonHelper.GetFileFromFileJson(portraitImageLocation, directory);
                    ImageFileData image = new ImageFileData(portraitImageLocation);
                    LinkedFileData.Add(portraitImageLocation, image);
                }

                break;

            case JSONTYPE.AI_PACK:
                JArray actions = mJson["actions"] as JArray;
                if (actions != null)
                {
                    foreach (JToken action in actions)
                    {
                        string     fullAlias   = action.ToString();
                        ModuleFile linkedAlias = ModuleDataManager.GetInstance().GetModuleFile(fullAlias);
                        if (linkedAlias == null)
                        {
                            AddError("links to alias " + fullAlias + " which does not exist!");
                        }
                    }
                }
                break;

            case JSONTYPE.MONSTER_TUNING:
                JToken experience = mJson.SelectToken("attributes.exp_reward");
                if (experience != null)
                {
                    //Console.WriteLine(GetAliasOrFlatName() + "\t" + experience.ToString());
                }
                break;
            }

            CheckDisplayName();
            if (Json != null && Json.SelectToken("components.effect_list.effects") != null)
            {
                AddError("effect_list component is using 'effects' to specify a list of effects. This is bad because these effects will not restart after save load. You should put all the effects into a single file and reference that file as 'default'");
            }

            FixUpAllCombatData();
        }