public static JSONNode JsonSerialize <T>(this T obj) { var objStr = JsonConvert.SerializeObject(obj, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); PandaLogger.LogToFile(objStr); var json = JSON.DeserializeString(objStr); return(json); }
public static Dictionary <string, List <string> > GetJSONSettingPaths(string fileType) { Dictionary <string, List <string> > retval = new Dictionary <string, List <string> >(); try { foreach (var info in GameLoader.AllModInfos) { if (info.Value.TryGetAs(GameLoader.NAMESPACE + ".jsonFiles", out JSONNode jsonFilles)) { foreach (var jsonNode in jsonFilles.LoopArray()) { if (jsonNode.TryGetAs("fileType", out string jsonFileType)) { if (jsonFileType == fileType) { if (jsonNode.TryGetAs("relativePath", out string itemsPath)) { if (!retval.ContainsKey(info.Key)) { retval.Add(info.Key, new List <string>()); } retval[info.Key].Add(itemsPath); PandaLogger.LogToFile("Getting json configurations {0} from file {1}", fileType, info.Key); } else { PandaLogger.Log(ChatColor.red, "Unable to read relativePath for fileType {0} from file {1}", itemsPath, info.Key); } } } else { PandaLogger.Log(ChatColor.red, "Unable to read fileType from file {0}", info.Key); } } } } } catch (Exception ex) { PandaLogger.LogError(ex); } return(retval); }