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; } } } }
public ModuleFile(Module module, string alias, string filePath) { mModule = module; mAlias = alias; mOriginalFilePath = filePath; mRootFile = JsonHelper.GetFileFromFileJson(filePath, module.Path); int lastColon = Alias.LastIndexOf(':'); mShortName = lastColon > -1 ? Alias.Substring(lastColon + 1) : Alias; DetermineFileType(); }
private void SetSelfAsOwner(Dictionary <string, string> children, Dictionary <string, GameMasterNode> toUpdate, Dictionary <string, GameMasterNode> allNodes) { int lastIndexOfSlash = NodeFile.Path.LastIndexOf('/'); string nodeFilePathWithoutFileName = NodeFile.Path.Substring(0, lastIndexOfSlash); foreach (KeyValuePair <string, string> child in children) { string absoluteFilePath = JsonHelper.GetFileFromFileJson(child.Value, nodeFilePathWithoutFileName); GameMasterNode otherFile = null; if (allNodes.TryGetValue(absoluteFilePath, out otherFile)) { // this is a proper edge otherFile.Owner = NodeFile; toUpdate.Add(child.Key, otherFile); mNumArcNodes++; } } }
/// <summary> /// Attempts to resolve a reference. /// </summary> /// <param name="path">Reference that was given</param> /// <param name="parentDirectory">Parent directory, required to resolve relative paths.</param> /// <param name="moduleFile">The file that was found.</param> /// <returns><c>true</c> if the file was found, <c>false</c> otherwise.</returns> public bool TryGetModuleFile(string path, string parentDirectory, out ModuleFile moduleFile) { moduleFile = null; // Alias? if (path.Contains(":")) { moduleFile = this.GetModuleFile(path); return(true); } else { var fileName = JsonHelper.GetFileFromFileJson(path, parentDirectory); // Is it a valid filename? if (!File.Exists(fileName)) { return(false); // Not a valid file => we don't stand a chance to begin with } // Cut away the unrequired bits string temp = ModuleDataManager.GetInstance().TryReplaceModsDirectory(fileName, "", ""); temp = ModuleDataManager.GetInstance().TryReplaceSteamUploadsDirectory(temp, "", ""); temp = temp.TrimStart(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar); var simplifiedFileName = temp; // Split it into mod/path within mod var parts = simplifiedFileName.Split(new[] { System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }, 2); var mod = ModuleDataManager.GetInstance().GetMod(parts[0]); if (mod == null) { return(false); } // The file exists, but isn't a global alias, so create a temporary entry so the caller can access it. moduleFile = new ModuleFile(mod, "<no-alias>", parts[1]); return(true); ////// Get all aliases that match this file ////var aliases = mod.GetAliases().Where(alias => alias.ResolvedPath == fileName).ToList(); ////return null; } }
public ModuleFile(Module module, string alias, string filePath) { mModule = module; mAlias = alias; mOriginalFilePath = filePath; mRootFile = JsonHelper.GetFileFromFileJson(filePath, module.Path); int lastColon = Name.LastIndexOf(':'); mShortName = lastColon > -1 ? Name.Substring(lastColon + 1) : Name; if (mShortName.Equals("fine")) { string oneBefore = Name.Substring(0, lastColon); int secondToLastColon = oneBefore.LastIndexOf(':'); oneBefore = secondToLastColon > -1 ? oneBefore.Substring(secondToLastColon + 1) : oneBefore; mShortName = oneBefore; mIsFineVersion = true; } DetermineFileType(); }
public override void LoadData(Dictionary <string, GameMasterNode> allNodes) { mEncounters = new Dictionary <string, string>(); mEncounterFiles = new List <GameMasterNode>(); mRarity = NodeFile.Json["rarity"].ToString(); mEncounters = JsonConvert.DeserializeObject <Dictionary <string, string> >(NodeFile.Json["encounters"].ToString()); int lastIndexOfSlash = NodeFile.Path.LastIndexOf('/'); string nodeFilePathWithoutFileName = NodeFile.Path.Substring(0, lastIndexOfSlash); foreach (string filename in mEncounters.Values) { string absoluteFilePath = JsonHelper.GetFileFromFileJson(filename, nodeFilePathWithoutFileName); GameMasterNode otherFile = null; if (allNodes.TryGetValue(absoluteFilePath, out otherFile)) { // this is a proper edge otherFile.Owner = NodeFile; mEncounterFiles.Add(otherFile); } } }
public Dictionary <string, JsonFileData> GetIconicJsons(bool baseModsOnly = false) { Dictionary <string, JsonFileData> entityJsonFiles = GetJsonsOfType(JSONTYPE.ENTITY, baseModsOnly); Dictionary <string, JsonFileData> iconicJsonFiles = new Dictionary <string, JsonFileData>(); foreach (KeyValuePair <string, JsonFileData> entry in entityJsonFiles) { JsonFileData jsonFileData = entry.Value; JToken iconicForm = jsonFileData.Json.SelectToken("components.stonehearth:entity_forms.iconic_form"); if (iconicForm != null) { string iconicFilePath = JsonHelper.GetFileFromFileJson(iconicForm.ToString(), jsonFileData.Directory); iconicFilePath = JsonHelper.NormalizeSystemPath(iconicFilePath); JsonFileData iconicFileData = (JsonFileData)jsonFileData.OpenedFiles.Find(e => e is JsonFileData && e.Path == iconicFilePath); if (iconicFileData != null) { iconicJsonFiles.Add(iconicFilePath, iconicFileData); } } } return(iconicJsonFiles); }
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(); }