public static string ToJsonMod <T>(T obj, Type type, bool pritty = false, bool simple = true) { var str = ToJson(obj, type, settingMod, pritty); if (simple) { str = ModOutputNodeConverter.SimplifyTypeName(str); } return(str); }
static void ModExt_AddActions(ActionListener __instance, string s, ref Type __result) { if (__result == null) { if (s.Length > 0) { if (s[0] == '"') { s = s.Trim(new char[] { '"' }); } Console.WriteLine("尝试解析扩展类型 = " + s); Type action = ModOutputNodeConverter.GetNodeType(s); if (action != null) { Console.WriteLine("解析扩展类型成功 = " + s); __result = action; } } } }
public void OnUpdate() { if (!DebugOn.Value) { return; } if (Input.GetKeyDown(NodeDocKey.Value)) { string target = DebugOutDir.Value + "游戏指令(OutputNode)文档.json"; ModOutputNodeConverter.ExportDoc(target); target = DebugOutDir.Value + "txt表格(Item)文档.json"; ItemDocConverter.ExportDoc(target); } if (Input.GetKeyDown(NodeFileKey.Value) && !string.IsNullOrEmpty(NodeContent.Value)) { // OutputNode string target = DebugOutDir.Value + NodeFilePath.Value; OutputNode obj = OutputNodeConvert.Deserialize(NodeContent.Value); var strJsonMod = ModJson.ToJsonMod(obj, typeof(OutputNode), JsonPritty.Value); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); } if (Input.GetKeyDown(MovieFileKey.Value) && !string.IsNullOrEmpty(MovieFileId.Value)) { // movie string source = string.Format(MovieFileType.Value == MovieType.Cinematic ? GameConfig.CinematicPath : GameConfig.SchedulerPath, MovieFileId.Value); string target = string.Format(DebugOutDir.Value + MovieFilePath.Value, MovieFileId.Value); var obj = ModJson.FromJsonResource <ScheduleGraph.Bundle>(source); if (JsonFormat.Value) { var strJsonMod = ModJson.ToJsonMod(obj, typeof(ScheduleGraph.Bundle), JsonPritty.Value); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); // 测试读取并对比重新通过Json构建的是否有差 var obj2 = ModJson.FromJsonMod <ScheduleGraph.Bundle>(strJsonMod); JsonSerializerSettings originalSetting = new JsonSerializerSettings { Converters = new JsonConverter[] { new OutputNodeJsonConverter() } }; string str2 = ModJson.ToJson(obj2, typeof(ScheduleGraph.Bundle), originalSetting, JsonPritty.Value); Console.WriteLine("重构脚本 = " + str2); } else { GlobalLib.ToFile(Game.Resource.LoadString(source), target); } } if (Input.GetKeyDown(BattleFileKey.Value) && !string.IsNullOrEmpty(BattleFileId.Value)) { // battle schedule string source = string.Format(GameConfig.BattleSchedulePath, GameConfig.Language, BattleFileId.Value + ".json"); string target = string.Format(DebugOutDir.Value + BattleFilePath.Value, BattleFileId.Value); if (JsonFormat.Value) { BattleSchedule obj = ModJson.FromJsonResource <BattleSchedule>(source); var strJsonMod = ModJson.ToJsonMod(obj, typeof(BattleSchedule), JsonPritty.Value); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); } else { GlobalLib.ToFile(Game.Resource.LoadString(source), target); } } if (Input.GetKeyDown(BuffFileKey.Value) && !string.IsNullOrEmpty(BuffFileId.Value)) { // buff string source = string.Format(GameConfig.ButtleBufferPath, GameConfig.Language, BuffFileId.Value + ".json"); string target = string.Format(DebugOutDir.Value + BuffFilePath.Value, BuffFileId.Value); if (JsonFormat.Value) { Heluo.Data.Buffer obj = ModJson.FromJsonResource <Heluo.Data.Buffer>(source); var strJsonMod = ModJson.ToJsonMod(obj, typeof(Heluo.Data.Buffer), true); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); } else { GlobalLib.ToFile(Game.Resource.LoadString(source), target); } } }