public string GetSpecialtyBuilding() { string specialtyBuilding = ""; string projPath = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\"; if (!Directory.Exists(projPath + "SpecialtyDefinitions")) //dir not found, return nothing { return(specialtyBuilding); } foreach (var x in Directory.GetFiles(projPath + "SpecialtyDefinitions")) { string json = File.ReadAllText(x); if (JSON_Reader.IsValidJson(json)) { SpecialtyBuildingClass s = new SpecialtyBuildingClass(); s = SpecialtyBuildingClass.FromJson(json); if (s != null) { if (s.RelatedTower != null) { if (s.RelatedTower == towerTypeName) { specialtyBuilding = x.Replace(projPath + "SpecialtyDefinitions\\", ""); towerTypeName = s.RelatedTower; break; } } } } } return(specialtyBuilding); }
private string GetTowerName() { string towerName = ""; string projPath = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\"; if (!Directory.Exists(projPath + "TowerDefinitions")) { return(towerName); } foreach (var x in Directory.GetFiles(projPath + "TowerDefinitions")) { string json = File.ReadAllText(x); if (JSON_Reader.IsValidJson(json)) { Tower_Class.Tower t = new Tower_Class.Tower(); t = Tower_Class.Tower.FromJson(json); if (t != null) { if (t.SpriteUpgradeDefinition != null) { if (t.SpriteUpgradeDefinition.Replace(".json", "") == file.Replace(".json", "")) { towerName = x.Replace(projPath + "TowerDefinitions\\", ""); towerTypeName = t.TypeName; break; } } } } } return(towerName); }
private void CheckJSON(string text) { if (JSON_Reader.IsValidJson(text) == true) { if (!path.EndsWith(".xml")) { this.lintPanel.BackgroundImage = Properties.Resources.JSON_valid; JsonError_Label.Visible = false; jsonError = false; New_JsonEditor.isJsonError = false; } } else { if (!path.EndsWith(".xml")) { this.lintPanel.BackgroundImage = Properties.Resources.JSON_Invalid; JsonError_Label.Visible = true; jsonError = true; New_JsonEditor.isJsonError = true; } } }
private int CountStartingCards() { numStarterCards = 0; string cardPath = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\BattleCardDefinitions"; var cardFiles = Directory.GetFiles(cardPath); string[] cards_length2 = new string[0]; string[] cards_length3 = new string[0]; foreach (var item in cardFiles) { if (!item.Contains("CacheList")) { json = File.ReadAllText(item); if (JSON_Reader.IsValidJson(json)) { newCard = new Card(); newCard = Card.FromJson(json); if (newCard.StartingCard) { numStarterCards++; string[] split = item.Split('\\'); string filename = split[split.Length - 1].Replace("\\", ""); if (filename.Replace(".json", "").Length == 1) { Array.Resize(ref startingCards_array, startingCards_array.Length + 1); startingCards_array[startingCards_array.Length - 1] = filename; } else if (filename.Replace(".json", "").Length == 2) { Array.Resize(ref cards_length2, cards_length2.Length + 1); cards_length2[cards_length2.Length - 1] = filename; } else if (filename.Replace(".json", "").Length == 3) { Array.Resize(ref cards_length3, cards_length3.Length + 1); cards_length3[cards_length3.Length - 1] = filename; } } } else { ConsoleHandler.append_Force_CanRepeat(item + " has invalid JSON"); } } } //organize cards in numeric order int startingCards_arraySize = startingCards_array.Length; Array.Resize(ref startingCards_array, startingCards_array.Length + cards_length2.Length + cards_length3.Length); Array.Copy(cards_length2, 0, startingCards_array, startingCards_arraySize, cards_length2.Length); Array.Copy(cards_length3, 0, startingCards_array, startingCards_arraySize + cards_length2.Length, cards_length3.Length); TotalStartingCards_Label.Text = "Total starting cards : " + numStarterCards; return(numStarterCards); }
private void CheckJSON(string text) { if (JSON_Reader.IsValidJson(text) == true) { this.lintPanel.BackgroundImage = Properties.Resources.JSON_valid; jsonError = false; } else { this.lintPanel.BackgroundImage = Properties.Resources.JSON_Invalid; jsonError = true; } }
public void CreateJSONObject(string filepath) { string json = File.ReadAllText(filepath); if (JSON_Reader.IsValidJson(json)) { ResetUI(); //Populate UI } else { ConsoleHandler.append_Force_CanRepeat("The file you are trying to load has invalid JSON, and as a result, can't be loaded..."); } }
private void EZCard_Button_Click(object sender, EventArgs e) { if (JSON_Reader.IsValidJson(Editor_TextBox.Text)) { var ezCard = new EZCard_Editor(); ezCard.path = path; ezCard.Show(); } else { ConsoleHandler.force_append_Notice("ERROR! This file doesn't have valid Json. Please fix the Json to continue"); this.Focus(); } }
public void CreateBloonObject(string bloonPath) { if (bloonPath.EndsWith(".bloon")) { path = bloonPath; json = File.ReadAllText(bloonPath); if (JSON_Reader.IsValidJson(json)) { bloon = Bloon.FromJson(json); PopulateUI(); } else { ConsoleHandler.append_Force_CanRepeat("The file you are trying to load has invalid JSON, and as a result, can't be loaded..."); } } else { ConsoleHandler.append_CanRepeat("Error! Thats not a valid bloon file"); } }
public void CreateCardObject(string cardPath) { path = cardPath; json = File.ReadAllText(cardPath); if (JSON_Reader.IsValidJson(json)) { card = Card.FromJson(json); if (card.CardSet == "Power") { HandlePowerCards(); } else { Hide_PowerCardStuff(); } PopulateUI_Cards(); } else { ConsoleHandler.append_Force_CanRepeat("The file you are trying to load has invalid JSON, and as a result, can't be loaded..."); } }
public static bool IsProjectVald(string projFile) { string json = File.ReadAllText(projFile); bool isValid = JSON_Reader.IsValidJson(json); if (!isValid) { json = json.Replace("\\\\", "\\").Replace("\\", "\\\\"); isValid = JSON_Reader.IsValidJson(json); if (!isValid) { if (JetProps.get().Count() > 0) { MessageBox.Show("Project File has invalid JSON. Please contact BTD Toolbox devs for assistance. Click \"Help\" at the top, then click \"Contact Us\""); try { JetProps.getForm(JetProps.get().Count() - 1).Close(); } catch (System.InvalidOperationException) { } } return(false); } } return(true); }
public static Config LoadSettings() { if (serializer == null) { serializer = new Serializer(); } if (!File.Exists(settingsPath)) { ConsoleHandler.append("Settings file doesn't exist! Creating a new settings file."); serializer.CreateNewSettings(); } if (!JSON_Reader.IsValidJson(File.ReadAllText(settingsPath))) { ConsoleHandler.append("Settings file has invalid JSON and therefore can't be loaded. Creating a new settings file."); serializer.CreateNewSettings(); } string json = File.ReadAllText(Environment.CurrentDirectory + "\\settings.json"); cfg = JsonConvert.DeserializeObject <Config>(json); return(cfg); }
private void PopulateOpenButton() { if (path.EndsWith("tower") || path.EndsWith("upgrades") || path.EndsWith("weapon") || path.Contains("TowerSpriteUpgradeDefinitions") || path.Contains("SpecialtyDefinitions")) { Open_Button.Visible = true; Weapons_Button.DropDownItems.Clear(); file = filename.Replace(".tower", "").Replace(".upgrades", "").Replace(".weapon", "").Replace(".json", ""); string projPath = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\"; towerName = GetTowerName(); if (towerName != "") { file = towerName.Replace(".tower", "").Replace(".upgrades", "").Replace(".weapon", "").Replace(".json", ""); } specialty = GetSpecialtyBuilding(); if (path.Contains("SpecialtyDefinitions")) { string json = File.ReadAllText(path); if (JSON_Reader.IsValidJson(json)) { SpecialtyBuildingClass s = new SpecialtyBuildingClass(); s = SpecialtyBuildingClass.FromJson(json); towerTypeName = s.RelatedTower; } file = towerTypeName; } if (File.Exists(projPath + "TowerDefinitions\\" + file + ".tower")) { TowerFile_Button.Visible = true; TowerFile_Button.Text = file + ".tower"; } else { TowerFile_Button.Visible = false; } if (File.Exists(projPath + "UpgradeDefinitions\\" + file + ".upgrades")) { UpgradeFIle_Button.Text = file + ".upgrades"; } else { UpgradeFIle_Button.Visible = false; } if (!specialty.Contains(".json")) { specialty = specialty + ".json"; } if (specialty != null && specialty != "") { if (File.Exists(projPath + "SpecialtyDefinitions\\" + specialty)) { specialtyBuildingToolStripMenuItem.Visible = true; } else { specialtyBuildingToolStripMenuItem.Visible = false; } } if (Directory.Exists(projPath + "WeaponDefinitions\\" + file)) { string weaponDir = projPath + "WeaponDefinitions\\" + file; foreach (var x in Directory.GetFiles(weaponDir)) { string[] split = x.Split('\\'); Weapons_Button.DropDownItems.Add(split[split.Length - 1]); } } else { Weapons_Button.Visible = false; } //TowerSpriteUpgradeDef //Attempting to get the TowerSpriteUpgradeDef from tower file Tower_Class.Tower tower = new Tower_Class.Tower(); string towerfile = CurrentProjectVariables.PathToProjectFiles + "\\Assets\\JSON\\TowerDefinitions\\" + file + ".tower"; if (File.Exists(towerfile)) { string json = File.ReadAllText(towerfile); if (JSON_Reader.IsValidJson(json)) { tower = Tower_Class.Tower.FromJson(json); if (tower != null) { if (tower.SpriteUpgradeDefinition == null || tower.SpriteUpgradeDefinition == "") { TowerSpriteUpgradeDef_Button.Visible = false; } else { towerSpriteUpgradeDef = tower.SpriteUpgradeDefinition; } } } else { if (File.Exists(projPath + "TowerSpriteUpgradeDefinitions\\" + file + ".json")) { ConsoleHandler.append_Force_CanRepeat("Tower file has invalid JSON, and therefore, unable to get current TowerSpriteDefinition file. Using default one instead..."); } else { ConsoleHandler.append_Force_CanRepeat("Tower file has invalid JSON, and therefore, unable to get current TowerSpriteDefinition file. Additionally, the default one does not exist. Unable to open TowerSpriteUpgradeDef"); TowerSpriteUpgradeDef_Button.Visible = false; } } } else { if (!File.Exists(projPath + "TowerSpriteUpgradeDefinitions\\" + file + ".json")) { TowerSpriteUpgradeDef_Button.Visible = false; } } } else if (!path.EndsWith("tower") && !path.EndsWith("upgrades") && !path.EndsWith("weapon") && !path.Contains("TowerSpriteUpgradeDefinitions")) { Open_Button.Visible = false; } }