public void TryLoad() { IModuleFileData fileData = null; // only load Json if (mType == FileType.JSON) { fileData = new JsonFileData(ResolvedPath); } else if (mType == FileType.LUA) { fileData = new LuaFileData(ResolvedPath); } if (fileData != null) { fileData.SetModuleFile(this); mFileData = fileData as FileData; mFileData.Load(); if (mAlias == "ui:stockpile:filters") { foreach (JToken filter in (mFileData as JsonFileData).Json.SelectTokens("stockpile.*.categories.*.filter")) { ModuleDataManager.GetInstance().StockpileFilters.Add(filter.ToString()); } } foreach (KeyValuePair<string, FileData> data in mReferencesCache) { mFileData.ReferencedByFileData[data.Key] = data.Value; } } }
public int GetAverageMaterialCost(string material) { if (mAverageMaterialCost.ContainsKey(material)) { return(mAverageMaterialCost[material]); } int sumCost = 0; int numItems = 0; string[] split = material.Split(' '); foreach (Module mod in ModuleDataManager.GetInstance().GetAllModules()) { foreach (ModuleFile file in mod.GetAliases()) { JsonFileData data = file.FileData as JsonFileData; if (data == null) { continue; } int netWorth = data.NetWorth; if (netWorth <= 0) { continue; } JToken tags = data.Json.SelectToken("components.stonehearth:material.tags"); if (tags != null) { string tagString = tags.ToString(); string[] currentTagSplit = tagString.Split(' '); HashSet <string> currentTagSet = new HashSet <string>(currentTagSplit); bool isMaterial = true; foreach (string tag in split) { if (!currentTagSet.Contains(tag)) { isMaterial = false; break; } } if (isMaterial) { numItems++; sumCost = sumCost + netWorth; } } } } if (numItems > 0) { int averageCost = sumCost / numItems; mAverageMaterialCost[material] = averageCost; return(averageCost); } return(0); }
private void RecommendNetWorth() { JsonFileData jsonFileData = FileData as JsonFileData; if (jsonFileData == null) { return; } foreach (FileData reference in jsonFileData.ReferencedByFileData.Values) { JsonFileData refJson = reference as JsonFileData; if (refJson != null && refJson.JsonType == JSONTYPE.RECIPE) { JArray produces = refJson.Json["produces"] as JArray; int productCount = 0; foreach (JToken product in produces) { JToken item = product["item"]; if (item != null && item.ToString().Equals(FullAlias)) { productCount++; } JToken fine = product["fine"]; if (fine != null && fine.ToString().Equals(FullAlias)) { productCount++; } } if (productCount <= 0) { continue; } int totalCost = 0; // If we are created by a recipe, look at the ingredients for the recipe to calculate net worth of all ingredients ... JArray ingredients = refJson.Json["ingredients"] as JArray; if (ingredients != null) { foreach (JToken ingredient in ingredients) { int costPer = 0; JToken material = ingredient["material"]; if (material != null) { // try get cost of material string materialString = material.ToString(); costPer = ModuleDataManager.GetInstance().GetAverageMaterialCost(materialString); } JToken uri = ingredient["uri"]; if (uri != null) { // try get cost of material string uriString = uri.ToString(); ModuleFile file = ModuleDataManager.GetInstance().GetModuleFile(uriString); if (file != null) { costPer = (file.FileData as JsonFileData).NetWorth; } } int count = int.Parse(ingredient["count"].ToString()); totalCost = totalCost + (costPer * count); } } jsonFileData.RecommendedMinNetWorth = totalCost / productCount; JToken workUnits = refJson.Json["work_units"]; if (workUnits != null) { int units = int.Parse(workUnits.ToString()); totalCost = totalCost + (units * kWorkUnitsWorth); } jsonFileData.RecommendedMaxNetWorth = totalCost / productCount; } } }
private string FindImageForFile(JsonFileData data) { foreach (FileData openedFile in data.OpenedFiles) { foreach (KeyValuePair<string, FileData> linkedFile in openedFile.LinkedFileData) { if ((linkedFile.Value is ImageFileData) && System.IO.File.Exists(linkedFile.Value.Path)) { return linkedFile.Value.Path; } } } return string.Empty; }
private void canvas_MouseMove(object sender, MouseEventArgs e) { Point pos = canvas.PointToClient(Cursor.Position); int cellSizeZoomed = (int)Math.Round(kCellSize * mZoom); int maxRows = Math.Min(mItemCount, kMaxRows); int x = pos.X / cellSizeZoomed; int y = (canvas.Height - pos.Y - maxRows - kBottomOffset) / cellSizeZoomed; List<JsonFileData> list; if (mNetWorthValues.TryGetValue(x + 1, out list)) { if (y < list.Count && y >= 0) { if (list[y] != mHoveredFileData) { pos.X = pos.X + 2; pos.Y = pos.Y + 2; mHoveredFileData = list[y]; string tooltip = mHoveredFileData.FileName; if (mHoveredFileData.RecommendedMinNetWorth >= 0) { tooltip = tooltip + "\n Recommended Net Worth: " + mHoveredFileData.RecommendedMinNetWorth + " - " + (mHoveredFileData.RecommendedMaxNetWorth * kMaxRecommendedMultiplier); tooltip = tooltip + "\n Average: " + mHoveredFileData.RecommendedMaxNetWorth; } imageTooltip.Show(tooltip, canvas, pos); } return; } } mHoveredFileData = null; imageTooltip.Hide(canvas); }
private void canvas_Paint(object sender, PaintEventArgs e) { Graphics graphics = e.Graphics; int cellSizeZoomed = (int)Math.Round(kCellSize * mZoom); int maxCols = Math.Min(mMaxNetWorth, kMaxRows); int maxRows = Math.Min(mItemCount, kMaxRows); int canvasWidth = maxCols * (cellSizeZoomed + 1); int canvasHeightLimit = maxRows * (cellSizeZoomed + 1); int canvasHeight = (maxRows * (cellSizeZoomed + 1)) + kBottomOffset; canvas.Width = canvasWidth; canvas.Height = canvasHeight; for (int i = 0; i < maxCols; ++i) { if (mZoom > 0.25f || (mZoom == 0.25f && ((i + 1) % 10) == 0)) { string colName = "" + (i + 1); Point position = new Point(i * cellSizeZoomed, canvasHeight - kStringOffset); graphics.DrawString(colName, SystemFonts.DefaultFont, Brushes.Black, position); } else { } List <JsonFileData> list; if (mNetWorthValues.TryGetValue(i + 1, out list)) { int count = Math.Min(maxRows, list.Count); for (int j = 0; j < count; j++) { JsonFileData data = list[j]; string imageFile = data.GetImageForFile(); if (string.IsNullOrEmpty(imageFile)) { Console.WriteLine("file " + data.FileName + " has no icon!"); } else { Image thumbnail = ThumbnailCache.GetThumbnail(imageFile); int ylocation = canvasHeight - ((j + 1) * cellSizeZoomed) - maxRows - kBottomOffset - 1; Rectangle location = new Rectangle(i * cellSizeZoomed, ylocation, cellSizeZoomed, cellSizeZoomed); graphics.DrawImage(thumbnail, location); if (data.RecommendedMaxNetWorth > 0) { int cost = i + 1; bool shouldWarn = false; JToken sellable = data.Json.SelectToken("entity_data.stonehearth:net_worth.shop_info.sellable"); if (sellable != null && sellable.ToString() == "False") { shouldWarn = true; } if (cost < data.RecommendedMinNetWorth * kMinRecommendedMultiplier) { shouldWarn = true; } if (cost > ((data.RecommendedMaxNetWorth * kMaxRecommendedMultiplier) + 1)) { shouldWarn = true; } if (shouldWarn) { Pen semiRed = new Pen(Color.FromArgb(100, Color.Red)); graphics.FillRectangle(semiRed.Brush, location); } } } } } } for (int i = 0; i < canvasWidth; i += cellSizeZoomed) { graphics.DrawLine(System.Drawing.Pens.Black, new Point(i, 0), new Point(i, canvasHeightLimit)); } for (int j = 0; j < canvasHeightLimit; j += cellSizeZoomed) { graphics.DrawLine(System.Drawing.Pens.Black, new Point(0, j), new Point(canvasWidth, j)); } }
public void AddLinkingJsonFile(JsonFileData file) { RelatedFiles.Add(file); }
private void addIconicVersionToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode selectedNode = treeView.SelectedNode; FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode); if (!CanAddEntityForm(selectedFileData, "iconic")) { return; } JsonFileData jsonFileData = selectedFileData as JsonFileData; string originalFileName = jsonFileData.FileName; string iconicFilePath = jsonFileData.Directory + "/" + originalFileName + "_iconic.json"; try { string iconicJson = System.Text.Encoding.UTF8.GetString(StonehearthEditor.Properties.Resources.defaultIconic); if (iconicJson != null) { // Get a linked qb file string newQbFile = null; JToken defaultModelVariant = jsonFileData.Json.SelectToken("components.model_variants.default"); string defaultModelVariantNames = defaultModelVariant != null?defaultModelVariant.ToString() : ""; foreach (FileData data in jsonFileData.LinkedFileData.Values) { if (data is QubicleFileData) { string fileName = data.FileName + ".qb"; if (defaultModelVariantNames.Contains(fileName)) { CloneObjectParameters parameters = new CloneObjectParameters(); parameters.AddStringReplacement(data.FileName, data.FileName + "_iconic"); newQbFile = data.Path.Replace(".qb", "_iconic.qb"); data.Clone(newQbFile, parameters, new HashSet <string>(), true); } } } if (newQbFile != null) { string relativePath = JsonHelper.MakeRelativePath(iconicFilePath, newQbFile); iconicJson = iconicJson.Replace("default_iconic.qb", relativePath); } try { JObject parsedIconicJson = JObject.Parse(iconicJson); iconicJson = JsonHelper.GetFormattedJsonString(parsedIconicJson); // put it in the parser and back again to make sure we get valid json. using (StreamWriter wr = new StreamWriter(iconicFilePath, false, new UTF8Encoding(false))) { wr.Write(iconicJson); } } catch (Exception e2) { MessageBox.Show("Unable to write new iconic file because " + e2.Message); return; } JObject json = jsonFileData.Json; JToken entityFormsComponent = json.SelectToken("components.stonehearth:entity_forms"); if (entityFormsComponent == null) { if (json["components"] == null) { json["components"] = new JObject(); } JObject entityForms = new JObject(); json["components"]["stonehearth:entity_forms"] = entityForms; entityFormsComponent = entityForms; } (entityFormsComponent as JObject).Add("iconic_form", "file(" + originalFileName + "_iconic.json" + ")"); jsonFileData.TrySetFlatFileData(jsonFileData.GetJsonFileString()); jsonFileData.TrySaveFile(); MessageBox.Show("Adding file " + iconicFilePath); } } catch (Exception ee) { MessageBox.Show("Unable to add iconic file because " + ee.Message); return; } Reload(); }
private void PopulateFileDetails(JsonFileData fileData) { fileDetailsListBox.Items.Clear(); // Stats with (adjustable) weights for difficulty equation to give a rough calculation of difficulty // Can help us see if our manual difficulty estimates (in monster tuning files) are off // estimatedDifficulty = 1*max_heath + 0*speed + 10*additive_armor_modifier + 5*weapon_dmg ... Dictionary <string, double> attrWeights = new Dictionary <string, double>() { { "max_health", 1 }, { "speed", 0.5 }, { "menace", 0.5 }, { "courage", 0.5 }, { "additive_armor_modifier", 10 }, { "muscle", 3 }, { "exp_reward", 0 } }; int weaponWeight = 15; int equationDivisor = 450; float totalWeaponBaseDamage = 0; int numWeapons = 0; double estimatedDifficulty = 0; JToken attributes = fileData.Json.SelectToken("attributes"); if (attributes != null) { foreach (KeyValuePair <string, double> entry in attrWeights) { string attribute = entry.Key; JToken jToken = fileData.Json.SelectToken("attributes." + attribute); JValue jAttribute = jToken as JValue; if (jToken != null && jAttribute == null) { // Add calculations for scaled attributes, which have a base and max value JValue baseValue = jToken["base"] as JValue; JValue maxValue = jToken["max"] as JValue; if (baseValue != null && maxValue != null) { estimatedDifficulty += ((2 * baseValue.Value <double>()) + maxValue.Value <double>()) / 4; } } else if (jAttribute != null) { estimatedDifficulty += jAttribute.Value <double>() * entry.Value; } } JArray weapon = fileData.Json.SelectToken("equipment.weapon") as JArray; if (weapon != null) { foreach (JValue weaponAlias in weapon.Children()) { string weaponString = weaponAlias.ToString(); ModuleFile weaponModuleFile = ModuleDataManager.GetInstance().GetModuleFile(weaponString); if (weaponModuleFile != null) { JToken baseDamage = (weaponModuleFile.FileData as JsonFileData).Json.SelectToken("entity_data.stonehearth:combat:weapon_data.base_damage"); if (baseDamage != null) { int dmg = baseDamage.Value <int>(); string weaponShortName = weaponString.Split(':').Last <string>(); fileDetailsListBox.Items.Add(weaponShortName + " damage : " + dmg); totalWeaponBaseDamage = totalWeaponBaseDamage + dmg; numWeapons += 1; } } } float avgWeaponDmg = totalWeaponBaseDamage / numWeapons; fileDetailsListBox.Items.Add("average weapon damage : " + avgWeaponDmg); estimatedDifficulty += avgWeaponDmg * weaponWeight; } fileDetailsListBox.Items.Add(" "); fileDetailsListBox.Items.Add("flat difficulty value : " + estimatedDifficulty); fileDetailsListBox.Items.Add("estimated difficulty : " + Math.Round(estimatedDifficulty / equationDivisor, 3)); } }
public void AddLinkingJsonFile(JsonFileData file) { RelatedFiles.Add(file); }
private void PopulateFileDetails(GameMasterNode node) { fileDetailsListBox.Items.Clear(); if (node == null) { // remove details return; } Dictionary <string, float> stats = new Dictionary <string, float>(); if (node.NodeType == GameMasterNodeType.ENCOUNTER) { EncounterNodeData encounterData = node.NodeData as EncounterNodeData; if (encounterData.EncounterType == "create_mission" || encounterData.EncounterType == "city_raid") { JToken members = node.Json.SelectToken("create_mission_info.mission.members"); if (members == null) { JToken missions = node.Json.SelectToken("city_raid_info.missions"); foreach (JProperty content in missions.Children()) { // Only gets stats for the first mission of city raids members = content.Value["members"]; } } int maxEnemies = 0; float totalWeaponBaseDamage = 0; Dictionary <string, float> allStats = new Dictionary <string, float>(); foreach (string attribute in kAttributesOfInterest) { allStats[attribute] = 0; } if (members != null) { foreach (JToken member in members.Children()) { // grab name, max number of members, and tuning JProperty memberProperty = member as JProperty; if (memberProperty != null) { JValue jMax = memberProperty.Value.SelectToken("from_population.max") as JValue; int max = 0; if (jMax != null) { max = jMax.Value <int>(); maxEnemies = maxEnemies + max; } JValue tuning = memberProperty.Value.SelectToken("tuning") as JValue; if (tuning != null) { string alias = tuning.ToString(); ModuleFile tuningFile = ModuleDataManager.GetInstance().GetModuleFile(alias); if (tuningFile != null) { JsonFileData jsonFileData = tuningFile.FileData as JsonFileData; if (jsonFileData != null) { foreach (string attribute in kAttributesOfInterest) { JValue jAttribute = jsonFileData.Json.SelectToken("attributes." + attribute) as JValue; if (jAttribute != null) { allStats[attribute] = allStats[attribute] + (max * jAttribute.Value <int>()); } } JArray weapon = jsonFileData.Json.SelectToken("equipment.weapon") as JArray; if (weapon != null) { foreach (JValue weaponAlias in weapon.Children()) { ModuleFile weaponModuleFile = ModuleDataManager.GetInstance().GetModuleFile(weaponAlias.ToString()); if (weaponModuleFile != null) { JToken baseDamage = (weaponModuleFile.FileData as JsonFileData).Json.SelectToken("entity_data.stonehearth:combat:weapon_data.base_damage"); if (baseDamage != null) { totalWeaponBaseDamage = totalWeaponBaseDamage + (max * baseDamage.Value <int>()); } } } } } } } } } } fileDetailsListBox.Items.Add("max enemies : " + maxEnemies); fileDetailsListBox.Items.Add("total weapon damage : " + totalWeaponBaseDamage); foreach (string attribute in kAttributesOfInterest) { fileDetailsListBox.Items.Add("total " + attribute + " : " + allStats[attribute]); } fileDetailsListBox.Items.Add("average weapon damage : " + totalWeaponBaseDamage / maxEnemies); foreach (string attribute in kAttributesOfInterest) { fileDetailsListBox.Items.Add("average " + attribute + " : " + allStats[attribute] / maxEnemies); } } } }
private void InitializeNetWorthItemsView() { netWorthListView.BeginUpdate(); netWorthListView.Items.Clear(); netWorthImagePaths = new Dictionary <string, string>(); netWorthJsonFiles = ModuleDataManager.GetInstance().GetJsonsByTerm("entity_data.stonehearth:net_worth"); ImageList imageList = new ImageList(); // populate listView int index = 0; foreach (KeyValuePair <string, JsonFileData> entry in netWorthJsonFiles) { JsonFileData jsonFileData = entry.Value; JObject json = jsonFileData.Json; ListViewItem item = new ListViewItem(entry.Key); // Item alias JToken token = json.SelectToken("entity_data.stonehearth:net_worth.value_in_gold"); string goldValue = token == null ? "" : token.ToString(); float goldValueNumber = float.Parse(goldValue); item.SubItems.Add(goldValue); // Net Worth string material = ""; string category = ""; foreach (JsonFileData file in jsonFileData.OpenedFiles) { JObject fileJson = file.Json; JToken categoryToken = fileJson.SelectToken("entity_data.stonehearth:catalog.category"); JToken materialToken = fileJson.SelectToken("entity_data.stonehearth:catalog.material_tags"); if (categoryToken != null) { if (category != "" && category != categoryToken.ToString()) { item.BackColor = Color.Red; item.ToolTipText = "WARNING: Category specified in more than one place and are not identical"; break; } category = categoryToken.ToString(); } if (materialToken != null) { if (material != "" && material != materialToken.ToString()) { item.BackColor = Color.Red; item.ToolTipText = "WARNING: Material specified in more than one place and are not identical"; break; } material = materialToken.ToString(); } } if (goldValueNumber > 0 && (!string.IsNullOrEmpty(category)) && (category != "uncategorized") && (!ModuleDataManager.GetInstance().ContainsStockpileMaterial(material))) { item.BackColor = Color.Red; item.ToolTipText = "WARNING: Material does not contain a stockpile filter"; } item.SubItems.Add(category); // Category string modName = ModuleDataManager.GetInstance().GetModNameFromAlias(entry.Key); item.SubItems.Add(modName); // Mod Name item.SubItems.Add(material); this.addImages(jsonFileData, netWorthImagePaths, imageList, item, entry, ref index); netWorthListView.Items.Add(item); } netWorthListView.SmallImageList = imageList; netWorthListView.EndUpdate(); }
private FileData GetFileDataFromPath(string filePath) { FileData fileData; mFileDataMap.TryGetValue(filePath, out fileData); if (fileData == null) { JsonFileData json = new JsonFileData(filePath); if (json != null) { json.Load(); fileData = json.OpenedFiles.First(); mFileDataMap[filePath] = fileData; } } return fileData; }
public void Load(Dictionary<string, GameMasterNode> allNodes) { try { mJsonFileData = new JsonFileData(mPath); mJsonFileData.Load(); OnFileChanged(allNodes); } catch (Exception e) { MessageBox.Show("Unable to load " + mPath + ". Error: " + e.Message); } if (mNodeData != null) { mNodeData.PostLoadFixup(); } }
private void addGhostToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode selectedNode = treeView.SelectedNode; FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode); if (!CanAddEntityForm(selectedFileData, "ghost")) { return; } JsonFileData jsonFileData = selectedFileData as JsonFileData; string originalFileName = jsonFileData.FileName; string ghostFilePath = jsonFileData.Directory + "/" + originalFileName + "_ghost.json"; try { JObject ghostJson = new JObject(); ghostJson.Add("type", "entity"); // Get a linked qb file string qbFilePath = null; foreach (FileData data in jsonFileData.LinkedFileData.Values) { if (data is QubicleFileData) { qbFilePath = data.Path; } } JObject ghostComponents = new JObject(); ghostJson["components"] = ghostComponents; JObject json = jsonFileData.Json; JObject existingComponents = json["components"] as JObject; if (existingComponents != null) { TryMoveJToken("unit_info", existingComponents, ghostComponents); TryMoveJToken("render_info", existingComponents, ghostComponents); TryMoveJToken("mob", existingComponents, ghostComponents); // Only move the default model variant to the ghost: JObject defaultModelVariant = existingComponents["model_variants"] as JObject; if (defaultModelVariant != null && defaultModelVariant.Count == 1) { TryMoveJToken("model_variants", existingComponents, ghostComponents); } else { JObject modelVariants = new JObject(); ghostComponents["model_variants"] = modelVariants; TryMoveJToken("default", defaultModelVariant, modelVariants); } } string ghostJsonString = JsonHelper.GetFormattedJsonString(ghostJson); using (StreamWriter wr = new StreamWriter(ghostFilePath, false, new UTF8Encoding(false))) { wr.Write(ghostJsonString); } JToken entityFormsComponent = json.SelectToken("components.stonehearth:entity_forms"); if (entityFormsComponent == null) { if (json["components"] == null) { json["components"] = new JObject(); } JObject entityForms = new JObject(); json["components"]["stonehearth:entity_forms"] = entityForms; entityFormsComponent = entityForms; } JToken mixins = json["mixins"]; if (mixins == null) { json.First.AddAfterSelf(new JProperty("mixins", "file(" + originalFileName + "_ghost.json" + ")")); } else { JArray mixinsArray = mixins as JArray; if (mixinsArray == null) { mixinsArray = new JArray(); json["mixins"] = mixinsArray; mixinsArray.Add(mixins.ToString()); } mixinsArray.Add("file(" + originalFileName + "_ghost.json" + ")"); } (entityFormsComponent as JObject).Add("ghost_form", "file(" + originalFileName + "_ghost.json" + ")"); jsonFileData.TrySetFlatFileData(jsonFileData.GetJsonFileString()); jsonFileData.TrySaveFile(); MessageBox.Show("Adding file " + ghostFilePath); } catch (Exception ee) { MessageBox.Show("Unable to add iconic file because " + ee.Message); return; } Reload(); }
private void InitializeNetWorthItemsView() { netWorthListView.BeginUpdate(); netWorthListView.Items.Clear(); netWorthImagePaths = new Dictionary <string, string>(); object[] data = ModuleDataManager.GetInstance().FilterJsonByTerm(netWorthListView, "entity_data.stonehearth:net_worth"); netWorthJsonFiles = (Dictionary <string, JsonFileData>)data[0]; modNames = (Dictionary <string, string>)data[1]; ImageList imageList = new ImageList(); // populate listView int index = 0; foreach (KeyValuePair <string, JsonFileData> entry in netWorthJsonFiles) { JsonFileData jsonFileData = entry.Value; JObject json = jsonFileData.Json; ListViewItem item = new ListViewItem(entry.Key); // Item alias JToken token = json.SelectToken("entity_data.stonehearth:net_worth.value_in_gold"); string goldValue = token == null ? "" : token.ToString(); item.SubItems.Add(goldValue); // Net Worth string material = ""; string category = ""; foreach (JsonFileData file in jsonFileData.OpenedFiles) { JObject fileJson = file.Json; JToken categoryToken = fileJson.SelectToken("components.item.category"); JToken materialToken = fileJson.SelectToken("components.stonehearth:material.tags"); if (categoryToken != null) { if (category != "" && category != categoryToken.ToString()) { item.BackColor = Color.Red; item.ToolTipText = "WARNING: Category specified in more than one place and are not identical"; break; } category = categoryToken.ToString(); } if (materialToken != null) { if (material != "" && material != materialToken.ToString()) { item.BackColor = Color.Red; item.ToolTipText = "WARNING: Material specified in more than one place and are not identical"; break; } material = materialToken.ToString(); } } item.SubItems.Add(category); // Category string modName = modNames[entry.Key]; item.SubItems.Add(modName); // Mod Name item.SubItems.Add(material); this.addImages(jsonFileData, netWorthImagePaths, imageList, item, entry, ref index); netWorthListView.Items.Add(item); } netWorthListView.SmallImageList = imageList; netWorthListView.EndUpdate(); }
private void OnJsonFileDataSelected() { JsonFileData fileData = mSelectedFileData as JsonFileData; if (fileData.TreeNode != null) { treeView.SelectedNode = fileData.TreeNode; } List <string> addedOpenFiles = new List <string>(); bool hasImage = false; foreach (FileData openedFile in fileData.OpenedFiles) { TabPage newTabPage = new TabPage(); newTabPage.Text = openedFile.FileName; if (ModuleDataManager.GetInstance().ModifiedFiles.Contains(openedFile)) { newTabPage.Text = newTabPage.Text + "*"; } if (openedFile.HasErrors) { newTabPage.ImageIndex = 0; newTabPage.ToolTipText = openedFile.Errors; } FilePreview filePreview = new FilePreview(this, openedFile); filePreview.Dock = DockStyle.Fill; newTabPage.Controls.Add(filePreview); filePreviewTabs.TabPages.Add(newTabPage); foreach (KeyValuePair <string, FileData> linkedFile in openedFile.LinkedFileData) { if (addedOpenFiles.Contains(linkedFile.Key)) { continue; } addedOpenFiles.Add(linkedFile.Key); if (linkedFile.Value is QubicleFileData) { QubicleFileData qbFileData = linkedFile.Value as QubicleFileData; string fileName = qbFileData.FileName; Button openFileButton = new Button(); openFileButton.Name = qbFileData.GetOpenFilePath(); openFileButton.BackgroundImage = global::StonehearthEditor.Properties.Resources.qmofileicon_small; openFileButton.BackgroundImageLayout = ImageLayout.None; openFileButton.Text = Path.GetFileName(openFileButton.Name); openFileButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; openFileButton.UseVisualStyleBackColor = true; openFileButton.Click += new System.EventHandler(openFileButton_Click); openFileButton.Padding = new Padding(22, 2, 2, 2); openFileButton.AutoSize = true; openFileButtonPanel.Controls.Add(openFileButton); } else if (linkedFile.Value is ImageFileData) { string imageFilePath = linkedFile.Value.Path; if (System.IO.File.Exists(imageFilePath)) { if (!hasImage) { iconView.ImageLocation = imageFilePath; hasImage = true; } Button openFileButton = new Button(); openFileButton.Name = imageFilePath; Image thumbnail = ThumbnailCache.GetThumbnail(imageFilePath); openFileButton.BackgroundImage = thumbnail; openFileButton.BackgroundImageLayout = ImageLayout.None; openFileButton.Text = Path.GetFileName(openFileButton.Name); openFileButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; openFileButton.UseVisualStyleBackColor = true; openFileButton.Click += new System.EventHandler(openFileButton_Click); openFileButton.Padding = new Padding(22, 2, 2, 2); openFileButton.AutoSize = true; openFileButtonPanel.Controls.Add(openFileButton); } } } } }
private void ParseJsonSpecificData() { string directory = Directory; string categoryOverride = null; switch (mJsonType) { case JSONTYPE.ENTITY: JToken entityFormsComponent = mJson.SelectToken("components.stonehearth:entity_forms"); if (entityFormsComponent != null) { 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(); categoryOverride = iconic.Category; Category = iconic.Category; OpenedFiles.Add(iconic); } // 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.Category = categoryOverride; ghost.Load(); ghost.AddMixin("stonehearth:mixins:placed_object"); OpenedFiles.Add(ghost); ghost.PostLoad(); } CheckForNoNetWorth(); } else { // Make sure to check if items have no net worth or set mNetWorth from their net worth data JToken catalog_data = mJson.SelectToken("entity_data.stonehearth:catalog.is_item"); if (catalog_data != null && catalog_data.Value <bool>()) { CheckForNoNetWorth(); } if (GetModuleFile() != null && mJson.SelectToken("components.item") != null) { CheckForNoNetWorth(); } if (mJson.SelectToken("entity_data.stonehearth:net_worth") != 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); if (recipeListLocation != null) { 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; } FixUnitInfo(); CheckDisplayName(); FixUpAllCombatData(); }