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); }
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 void LintPanel_MouseClick(object sender, MouseEventArgs e) { if (jsonError) { try { string error = JSON_Reader.GetJSON_Error(Editor_TextBox.Text); ConsoleHandler.force_append_Notice(error); //Line number string[] split = error.Split(','); string[] line = split[split.Length - 2].Split(' '); int lineNumber = Int32.Parse(line[line.Length - 1].Replace(".", "").Replace(",", "")); //Position in line string[] pos = split[split.Length - 1].Split(' '); int linePos = Int32.Parse(pos[pos.Length - 1].Replace(".", "").Replace(",", "")); //Scroll to the line above error int index = Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 3) + linePos; Editor_TextBox.Select(index, 1); Editor_TextBox.ScrollToCaret(); int numChars = (Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 1)) - (Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 2)); //highlight line with error index = Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 2) + linePos; Editor_TextBox.Focus(); Editor_TextBox.Select(index, numChars - 2); } catch { ConsoleHandler.append_CanRepeat("Something went wrong... Unable to find the bad json"); } } }
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 void SearchForSubtask() { int i = 0; bool found = false; foreach (char c in Editor_TextBox.Text) { if (c == ':') { string subtaskNum = JSON_Reader.GetSubtaskNum(i, Editor_TextBox.Text); if (subtaskNum.Replace(" ", "").Replace(",", "") == Find_TextBox.Text.Replace(" ", "").Replace(",", "")) { found = true; int startHighlighht = Editor_TextBox.Text.LastIndexOf("\"", i - 2); Editor_TextBox.SelectionStart = i; Editor_TextBox.Select(i, -(i - startHighlighht)); Editor_TextBox.ScrollToCaret(); HideFindButton(); searchSubtask = false; break; } } i++; } if (!found) { ConsoleHandler.append_Force_CanRepeat("That subtask was not found"); } }
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; } }
private void GetSubtaskNum() { string subtaskNum = JSON_Reader.GetSubtaskNum(CharIndex_UnderMouse, Editor_TextBox.Text); if (subtaskNum != "" && subtaskNum != " " && subtaskNum != null) { ConsoleHandler.append_Force_CanRepeat("Subtask: [" + subtaskNum + " ]"); } else { ConsoleHandler.append_Force("Unable to detect subtask. Please try clicking somewhere else..."); } }
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 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 GetSubtaskNum() { if (jsonError == false) { string subtaskNum = JSON_Reader.GetSubtaskNum(CharIndex_UnderMouse, Editor_TextBox.Text); if (subtaskNum != "" && subtaskNum != " " && subtaskNum != null) { ConsoleHandler.append_Force_CanRepeat("Subtask: [" + subtaskNum + " ]"); } else { ConsoleHandler.append_Force_CanRepeat("Unable to detect subtask. Please try clicking somewhere else..."); this.Focus(); } } else { ConsoleHandler.append_Force("JSON error detected... You need to fix the JSON error before you can get the subtask"); } }
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; } }
static void Chk_NextTalk(ref JSON_Reader json_reader) { string str_eip = null; string str_uname = null; string str_msgid = null; string str_uid = null; ulong val_time = 0; MsgType msg_type = MsgType.EN_None; while (true) { JsonTokenType next_type = json_reader.GetNextType(); if (next_type == JsonTokenType.PropertyName) { // key の取得 string str_key = json_reader.GetString(); // value の読み込み if (str_key == "time") { if (json_reader.GetNextType() != JsonTokenType.Number) { throw new Exception("!!! JSON のパースに失敗しました。"); } val_time = json_reader.GetUInt64(); continue; } if (json_reader.GetNextType() != JsonTokenType.String) { continue; } string str_value = json_reader.GetString(); if (str_key == "encip") { str_eip = str_value; } else if (str_key == "name") { str_uname = str_value; } else if (str_key == "id") { str_msgid = str_value; } else if (str_key == "uid") { str_uid = str_value; } else if (str_key == "type") { if (str_value == "enter") { msg_type = MsgType.EN_Enter; } else if (str_value == "exit") { msg_type = MsgType.EN_Exit; } } continue; } else if (next_type == JsonTokenType.EndObject) { break; } throw new Exception("!!! JSON のパースに失敗しました。"); } // ms_time_latest の更新 if (val_time > ms_time_latest) { ms_time_latest = val_time; } // msb_to_appear_AI_talk のチェック if (val_time > ms_time_for_AI_talk) { /* * MainForm.WriteStatus($"val_time -> {val_time}\r\n"); * MainForm.WriteStatus($"ms_time_for_AI_talk -> {ms_time_for_AI_talk}\r\n"); * if (str_msgid != null) * { MainForm.WriteStatus($"str_msgid -> {str_msgid}\r\n"); } */ if (ms_str_Uid_AI_talked != null && str_uid != null && str_uid == ms_str_Uid_AI_talked) { msb_to_appear_AI_talk = true; } ms_time_for_AI_talk = val_time; } if (msg_type == MsgType.EN_None) { return; } // 以下では、msg_type は EN_Enter or EN_Exit if (str_eip == null || str_uname == null || str_msgid == null || val_time == 0) { throw new Exception("!!! JSON のパースに失敗しました。"); } int eidx = msa_eip.IndexOf(str_eip); List <string> unames_this_session = null; bool b_disp_new_user = false; if (eidx < 0) { // Chk_NextUser() で検出できなかった eip ユーザの場合、ここにくる // bot がホストであれば、ここには来ないはず?(bot がゲストのときも考慮) msa_eip.Add(str_eip); unames_this_session = NewStringList(str_uname); msa_unames_this_session.Add(unames_this_session); b_disp_new_user = true; msab_disp_new_user.Add(true); eidx = msa_eip.Count - 1; } else { unames_this_session = msa_unames_this_session[eidx]; if (unames_this_session.IndexOf(str_uname) < 0) { unames_this_session.Add(str_uname); } b_disp_new_user = msab_disp_new_user[eidx]; } if (msg_type == MsgType.EN_Enter) { if (val_time < ms_time_for_msgid) { return; } if (MsgID_Chkr.IsNew_MsgID(str_msgid) == false) { return; } // str_msgid は、まだ未処理の msg であることに留意 // Enter メッセージの処理(再入室ユーザ、多窓ユーザの処理を行う) if (b_disp_new_user) { ms_ret_sb.Append("新規検出"); msab_disp_new_user[eidx] = false; //「新規検出」は表示したため、フラグを下ろしておく } else { ms_ret_sb.Append("---再入室者---"); } if (UInfo_onRoom.IsMultiUser(str_eip)) { ms_ret_sb.Append("★★★多窓ユーザ★★★"); } ms_ret_sb.Append($" [{str_uname}] / [{string.Join(", ", unames_this_session)}]\r\n\t{str_eip}\r\n\r\n"); // UInfo_onRoom に m_unames_this_session の情報を付加する UInfo_onRoom.Set_unames_this_session_by_enter_msg(str_eip, unames_this_session); } else { // Exit メッセージの処理(Exit であるため、多窓ユーザかどうかの判定はしない) // ExitEip_onTalks のチェックは、ms_time_for_msgid に関わらず必要なことに注意 int eidx_EUser = ExitEip_onTalks.Regist(str_eip, str_uname); if (val_time < ms_time_for_msgid) { return; } if (MsgID_Chkr.IsNew_MsgID(str_msgid) == false) { return; } ms_ret_sb.Append($"退室者 [{string.Join(", ", ExitEip_onTalks.GetUnames(eidx_EUser))}] / " + $"[{string.Join(", ", unames_this_session)}]\r\n" + $"\t{str_eip}\r\n\r\n"); } ms_time_for_msgid = val_time; }
// ------------------------------------------------------------------------------------ // ポジションを JsonTokenType.StartObject にした状態でコールすること // JsonTokenType.EndObject のポジションでリターンされる static void Chk_NextUser(ref JSON_Reader json_reader) { var uencip = new Uencip(); var uid = new Uid(); string str_uname = null; // user 情報の取得 while (true) { JsonTokenType next_type = json_reader.GetNextType(); if (next_type == JsonTokenType.PropertyName) { // key の取得 string str_key = json_reader.GetString(); // value の読み込み if (json_reader.GetNextType() != JsonTokenType.String) { continue; } string str_value = json_reader.GetString(); if (str_key == "name") { str_uname = str_value; } else if (str_key == "id") { uid.m_str_uid = str_value; } else if (str_key == "encip") { uencip.m_str_encip = str_value; } continue; } else if (next_type == JsonTokenType.EndObject) { if (str_uname == null || uid.m_str_uid == null) { throw new Exception("!!! JSON のパースに失敗しました。"); } // ホストの場合、str_encip == null となる if (uencip.m_str_encip == null) { return; } break; } throw new Exception("!!! JSON のパースに失敗しました。"); } // encip の調査 int eidx = msa_eip.IndexOf(uencip.m_str_encip); if (eidx < 0) { // 現セッションで新規登録の eip msa_eip.Add(uencip.m_str_encip); msa_unames_this_session.Add(NewStringList(str_uname)); msab_disp_new_user.Add(true); } else { // 現セッションで登録済みの eip // 新規の uname であれば、記録しておく var unames = msa_unames_this_session[eidx]; if (unames.IndexOf(str_uname) < 0) { unames.Add(str_uname); } } UInfo_onRoom.Attend(ref uid, str_uname, ref uencip); }
public static StringBuilder Anlz_RoomJSON(byte[] buf_utf8) { // ------------------------------------------------------------ // users の解析 var json_reader = new JSON_Reader(buf_utf8); json_reader.Search_users_key(); UInfo_onRoom.Clear_AttendFlag(); // Remove_Absent() の準備 JsonTokenType type_lead = json_reader.GetNextType(); if (type_lead == JsonTokenType.StartObject) { // users がオブジェクト型の場合の処理 while (true) { JsonTokenType next_type = json_reader.GetNextType(); if (next_type == JsonTokenType.EndObject) { break; } if (next_type != JsonTokenType.PropertyName) { throw new Exception("!!! JSON のパースに失敗しました。"); } if (json_reader.GetNextType() != JsonTokenType.StartObject) { throw new Exception("!!! JSON のパースに失敗しました。"); } Chk_NextUser(ref json_reader); } } else { if (type_lead != JsonTokenType.StartArray) { throw new Exception("!!! JSON のパースに失敗しました。"); } // users が配列型の場合の処理 while (true) { JsonTokenType next_type = json_reader.GetNextType(); if (next_type == JsonTokenType.EndArray) { break; } if (next_type != JsonTokenType.StartObject) { throw new Exception("!!! JSON のパースに失敗しました。"); } Chk_NextUser(ref json_reader); } } UInfo_onRoom.Remove_Absent(); // ここで多窓のチェックも行う // ------------------------------------------------------------ // talks の解析 json_reader.Search_talks_key(); // JsonTokenType.StartArray の位置に設定される // Remove_disappeared() のための準備 MsgID_Chkr.Clear_OnTalksFlag(); ExitEip_onTalks.Clear_OnTalksFlag(); ms_ret_sb.Clear(); // 入室、退室の情報記録用 while (true) { JsonTokenType next_type = json_reader.GetNextType(); if (next_type == JsonTokenType.EndArray) { break; } if (next_type != JsonTokenType.StartObject) { throw new Exception("!!! JSON のパースに失敗しました。"); } Chk_NextTalk(ref json_reader); } MsgID_Chkr.Remove_disappeared(); ExitEip_onTalks.Remove_disappeared(); return(ms_ret_sb); }