public static bool Patch_JsonConvert(string str, ref OutputNode __result)
 {
     if (str.StartsWith("[JSON", StringComparison.CurrentCultureIgnoreCase))
     {
         try
         {
             string jsonStr;
             if (str.StartsWith("[JSONFILE", StringComparison.CurrentCultureIgnoreCase))
             {
                 var array = Game.Resource.LoadBytes(str.Substring(10)); // remove [JSONFILE]
                 jsonStr = Encoding.UTF8.GetString(array);
             }
             else
             {
                 jsonStr = str.Substring(6);           // remove [JSON]
             }
             jsonStr = GlobalLib.ReplaceText(jsonStr); // preprocess
             Console.WriteLine("parse json: " + jsonStr);
             __result = ModJson.FromJsonMod <OutputNode>(jsonStr);
         }
         catch (Exception e)
         {
             Debug.LogError(e);
             Debug.LogError("解析Json错误" + str);
             throw;
         }
         return(false);
     }
     return(true);
 }
Example #2
0
        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);
                }
            }
        }