public static JsonArrayCollection Explain(object source, JsonArrayCollection existingData, bool saveJson) { JsonArrayCollection data = new JsonArrayCollection(); Contents.Text.Explain.Format textInformationFormat = (Contents.Text.Explain.Format)source; if (textInformationFormat != null && textInformationFormat.Information != null) { Contents.Text.Explain.Information information = textInformationFormat.Information[0]; if (information.Assign != null) { string currentAssign; Type infoType = information.Assign.GetType(); foreach (Contents.Text.Explain.Information innerInformation in textInformationFormat.Information) { JsonObjectCollection savedItem = default(JsonObjectCollection); currentAssign = ""; JsonObjectCollection item = new JsonObjectCollection(); if (infoType == typeof(Contents.Text.Assign.Type2Int)) { Contents.Text.Assign.Type2Int assign = (Contents.Text.Assign.Type2Int)innerInformation.Assign; for (int i = 0; i < assign.Param.Length; i++) { currentAssign += assign.Param[i].ToString(CultureInfo.InvariantCulture); } } else if (infoType == typeof(Contents.Text.Assign.TypeInt)) { Contents.Text.Assign.TypeInt assign = (Contents.Text.Assign.TypeInt)innerInformation.Assign; currentAssign = assign.Param.ToString(CultureInfo.InvariantCulture); } else if (infoType == typeof(Contents.Text.Assign.TypeString)) { Contents.Text.Assign.TypeString assign = (Contents.Text.Assign.TypeString)innerInformation.Assign; currentAssign = assign.Param; } else if (infoType == typeof(Contents.Text.Assign.Type4Int)) { Contents.Text.Assign.Type4Int assign = (Contents.Text.Assign.Type4Int)innerInformation.Assign; for (int i = 0; i < assign.Param.Length; i++) { currentAssign += assign.Param[i].ToString(CultureInfo.InvariantCulture); } } else { Console.Error.WriteLine("New assign format?"); } if (existingData != null) { int Count = existingData.Count; for (int idx = 0; idx < Count; idx++) { if (existingData[idx] != null && existingData[idx]["jp_text"] == innerInformation.Name) { savedItem = (JsonObjectCollection)existingData[idx]; existingData.RemoveAt(idx); break; } } } item["assign"] = currentAssign; item["jp_text"] = innerInformation.Name; item["tr_text"] = ""; item["jp_explain"] = innerInformation.Explain; item["tr_explain"] = ""; if (savedItem != default(JsonObjectCollection)) { if (!String.IsNullOrEmpty(savedItem["tr_text"])) { innerInformation.Name = savedItem["tr_text"]; item["tr_text"] = savedItem["tr_text"]; } if (!String.IsNullOrEmpty(savedItem["tr_explain"])) { innerInformation.Explain = savedItem["tr_explain"]; item["tr_explain"] = savedItem["tr_explain"]; } } if (saveJson) { data.Add(item); } } } } return(data); }
public static JsonArrayCollection PhotonDice(object source, JsonArrayCollection existingData, bool saveJson) { JsonArrayCollection data = new JsonArrayCollection(); Contents.Text.Leisure_PhotonDice_SpeakText.Format diceFormat = (Contents.Text.Leisure_PhotonDice_SpeakText.Format)source; string currentAssign; foreach (Contents.Text.Leisure_PhotonDice_SpeakText.Information information in diceFormat.Information) { JsonObjectCollection savedItem = default(JsonObjectCollection); JsonObjectCollection item = new JsonObjectCollection(); if (information.Assign.GetType() == typeof(Contents.Text.Assign.TypeInt)) { currentAssign = ((Contents.Text.Assign.TypeInt)information.Assign).Param.ToString(CultureInfo.InvariantCulture); } else if (information.Assign.GetType() == typeof(Contents.Text.Assign.Type2Int)) { Contents.Text.Assign.Type2Int assign = (Contents.Text.Assign.Type2Int)information.Assign; currentAssign = ""; for (int i = 0; i < assign.Param.Length; i++) { currentAssign += assign.Param[i].ToString(CultureInfo.InvariantCulture); } } else { currentAssign = ((Contents.Text.Assign.TypeString)information.Assign).Param.Trim(); } if (existingData != null) { int Count = existingData.Count; for (int idx = 0; idx < Count; idx++) { if (existingData[idx] != null && existingData[idx]["assign"] == currentAssign) { savedItem = (JsonObjectCollection)existingData[idx]; existingData.RemoveAt(idx); break; } } } var patterns = new JsonArrayCollection(); var translatedPatterns = new JsonArrayCollection(); foreach (var pattern in information.Pattern) { patterns.Add(pattern); translatedPatterns.Add(""); } item["assign"] = currentAssign; item["jp_patterns"] = patterns; item["tr_patterns"] = translatedPatterns; if (savedItem != default(JsonObjectCollection)) { if (savedItem.ContainsKey("tr_patterns")) { var idx = 0; foreach (var pattern in (JsonArrayCollection)savedItem["tr_patterns"]) { if (!String.IsNullOrEmpty(pattern) && information.Pattern.Length > idx) { information.Pattern[idx] = pattern; } idx++; } item["tr_patterns"] = savedItem["tr_patterns"]; } } if (saveJson) { data.Add(item); } } return(data); }