Пример #1
0
        private void ParseLinkedFiles(string jsonString)
        {
            string directory = Directory;
            Regex  matcher   = new Regex("file\\([\\S]+\\)");

            foreach (Match match in matcher.Matches(jsonString))
            {
                string matchValue = match.Value;

                // Sigh, special case these because they're more like folders instead of files
                if (matchValue != "file(animations)" && matchValue != "file(effects)")
                {
                    string linkedFile = JsonHelper.GetFileFromFileJson(match.Value, directory);
                    linkedFile = JsonHelper.NormalizeSystemPath(linkedFile);

                    if (!System.IO.File.Exists(linkedFile) && !System.IO.Directory.Exists(linkedFile))
                    {
                        AddError("Links to non-existent file " + linkedFile);
                        continue;
                    }

                    if (LinkedFileData.ContainsKey(linkedFile))
                    {
                        continue;
                    }

                    FileData linkedFileData = GetFileDataFactory(linkedFile);
                    if (linkedFileData != null)
                    {
                        LinkedFileData.Add(linkedFile, linkedFileData);
                        linkedFileData.ReferencedByFileData[GetAliasOrFlatName()] = this;
                    }
                }
            }
        }
Пример #2
0
        public override bool Clone(string newPath, CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute)
        {
            if (execute)
            {
                string newDirectory = System.IO.Path.GetDirectoryName(newPath);
                System.IO.Directory.CreateDirectory(newDirectory);
                if (!System.IO.File.Exists(newPath))
                {
                    System.IO.File.Copy(Path, newPath);
                }
            }

            string qmoPath = GetQmoPath();

            if (mIsQb && LinkedFileData.ContainsKey(qmoPath))
            {
                string newQmoPath = newPath.Replace(".qb", ".qmo");
                if (!alreadyCloned.Contains(newQmoPath))
                {
                    alreadyCloned.Add(newQmoPath);
                    LinkedFileData[qmoPath].Clone(newQmoPath, parameters, alreadyCloned, execute);
                }
            }

            return(true);
        }
Пример #3
0
 protected override void LoadInternal()
 {
     if (mIsQb)
     {
         // see if the qmo exists
         string qmoPath = GetQmoPath();
         if (System.IO.File.Exists(qmoPath))
         {
             mHasQmo = true;
             QubicleFileData qmoFile = new QubicleFileData(qmoPath);
             LinkedFileData.Add(qmoPath, qmoFile);
         }
     }
 }
Пример #4
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();
        }