From f31172c850c156d58bd53789fc91d2041afa6c2d Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 27 Aug 2021 12:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=87=8D=E6=9E=84=E3=80=91=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E8=AE=A1=E7=AE=97gen=5Ftype=E5=AF=B9=E5=BA=94ELangua?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=EF=BC=8C=E9=87=8D=E6=9E=84=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E7=94=9F=E6=88=90=E6=95=B0=E6=8D=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8E=E7=BC=80=E7=9A=84=E6=96=B9=E5=BC=8F=20=E3=80=90?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=90=8D=E4=B8=BA=20xx=5Fzz=5F=20=E5=8C=85=E5=90=AB=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E7=9A=84=5F=E6=97=B6=EF=BC=8CUpperCaseFirstChar?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E5=90=8D=E5=AD=97=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Common/Source/Utils/TypeUtil.cs | 6 +- src/Luban.Job.Cfg/Source/JobController.cs | 49 ++--------------- src/Luban.Job.Common/Source/ELanguage.cs | 1 + .../Source/Utils/RenderFileUtil.cs | 55 +++++++++++++++++++ 4 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/Luban.Common/Source/Utils/TypeUtil.cs b/src/Luban.Common/Source/Utils/TypeUtil.cs index 6a24e7e..413b7fe 100644 --- a/src/Luban.Common/Source/Utils/TypeUtil.cs +++ b/src/Luban.Common/Source/Utils/TypeUtil.cs @@ -205,12 +205,12 @@ namespace Luban.Common.Utils public static string ToCsStyleName(string orginName) { - return string.Join("", orginName.Split('_').Select(c => UpperCaseFirstChar(c))); + return string.Join("", orginName.Split('_').Where(s => !string.IsNullOrWhiteSpace(s)).Select(c => UpperCaseFirstChar(c))); } public static string ToJavaStyleName(string orginName) { - var words = orginName.Split('_'); + var words = orginName.Split('_').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); var s = new StringBuilder(); s.Append(words[0]); for (int i = 1; i < words.Length; i++) @@ -222,7 +222,7 @@ namespace Luban.Common.Utils public static string ToJavaGetterName(string orginName) { - var words = orginName.Split('_'); + var words = orginName.Split('_').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); var s = new StringBuilder("get"); foreach (var word in words) { diff --git a/src/Luban.Job.Cfg/Source/JobController.cs b/src/Luban.Job.Cfg/Source/JobController.cs index 8810605..9ce508b 100644 --- a/src/Luban.Job.Cfg/Source/JobController.cs +++ b/src/Luban.Job.Cfg/Source/JobController.cs @@ -98,47 +98,6 @@ namespace Luban.Job.Cfg } } - private ELanguage GetLanguage(string genType) - { - switch (genType) - { - case "code_cs_bin": - case "code_cs_json": - case "code_cs_unity_json": return ELanguage.CS; - case "code_java_bin": - case "code_java_json": return ELanguage.JAVA; - case "code_go_bin": - case "code_go_json": return ELanguage.GO; - case "code_cpp_bin": return ELanguage.CPP; - case "code_lua_bin": - case "code_lua_lua": return ELanguage.LUA; - case "code_python3_json": return ELanguage.PYTHON; - case "code_typescript_bin": - case "code_typescript_json": return ELanguage.TYPESCRIPT; - case "code_cpp_ue_editor": - case "code_cpp_ue_bp": return ELanguage.CPP; - case "code_cs_unity_editor": return ELanguage.CS; - default: throw new ArgumentException($"not support output data type:{genType}"); - } - } - - private string GetOutputFileSuffix(string genType) - { - switch (genType) - { - case "data_bin": return "bin"; - case "data_json": - case "data_json2": return "json"; - case "data_lua": return "lua"; - default: throw new Exception($"not support output data type:{genType}"); - } - } - - private string GetOutputFileName(string genType, string fileName) - { - return $"{(genType.EndsWith("lua") ? fileName.Replace('.', '_') : fileName)}.{GetOutputFileSuffix(genType)}"; - } - private static bool TryParseArg(List args, out GenArgs options, out string errMsg) { var helpWriter = new StringWriter(); @@ -475,7 +434,7 @@ namespace Luban.Job.Cfg { string genType = ctx.GenType; ctx.Render = CreateCodeRender(genType); - ctx.Lan = GetLanguage(genType); + ctx.Lan = RenderFileUtil.GetLanguage(genType); foreach (var c in ctx.ExportTypes) { ctx.Tasks.Add(Task.Run(() => @@ -535,7 +494,7 @@ namespace Luban.Job.Cfg string genType = ctx.GenType; var args = ctx.GenArgs; ctx.Render = CreateCodeRender(genType); - ctx.Lan = GetLanguage(genType); + ctx.Lan = RenderFileUtil.GetLanguage(genType); var lines = new List(10000); Action> preContent = (fileContent) => @@ -589,7 +548,7 @@ namespace Luban.Job.Cfg { string genType = ctx.GenType; ctx.Render = CreateCodeRender(genType); - ctx.Lan = GetLanguage(genType); + ctx.Lan = RenderFileUtil.GetLanguage(genType); var lines = new List(10000); static void PreContent(List fileContent) @@ -769,7 +728,7 @@ namespace {ctx.TopModule} { ctx.Tasks.Add(Task.Run(() => { - var file = GetOutputFileName(genType, table.OutputDataFile); + var file = RenderFileUtil.GetOutputFileName(genType, table.OutputDataFile); var records = ctx.Assembly.GetTableExportDataList(table); if (!FileRecordCacheManager.Ins.TryGetRecordOutputData(table, records, genType, out string md5)) { diff --git a/src/Luban.Job.Common/Source/ELanguage.cs b/src/Luban.Job.Common/Source/ELanguage.cs index 46a2dd0..13725cf 100644 --- a/src/Luban.Job.Common/Source/ELanguage.cs +++ b/src/Luban.Job.Common/Source/ELanguage.cs @@ -10,5 +10,6 @@ namespace Luban.Job.Common JS, TYPESCRIPT, PYTHON, + ERLANG, } } diff --git a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs index 2ef0b55..f392592 100644 --- a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Luban.Job.Common.Utils { @@ -84,5 +85,59 @@ namespace Luban.Job.Common.Utils } } } + + private readonly static Dictionary s_name2Lans = new() + { + { "cs", ELanguage.CS }, + { "java", ELanguage.JAVA }, + { "go", ELanguage.GO }, + { "cpp", ELanguage.CPP }, + { "lua", ELanguage.LUA }, + { "python", ELanguage.PYTHON }, + { "typescript", ELanguage.TYPESCRIPT }, + { "javascript", ELanguage.JS }, + { "erlang", ELanguage.ERLANG }, + }; + + public static ELanguage GetLanguage(string genType) + { + foreach (var (name, lan) in s_name2Lans) + { + if (genType.Contains(name)) + { + return lan; + } + } + throw new ArgumentException($"not support output data type:{genType}"); + } + + private readonly static Dictionary s_name2Suxxifx = new() + { + { "json", "json" }, + { "lua", "lua" }, + { "bin", "bin" }, + { "xml", "xml" }, + { "yaml", "yml" }, + { "yml", "yml" }, + { "erlang", "erl" }, + { "erl", "erl" }, + }; + + public static string GetOutputFileSuffix(string genType) + { + foreach (var (name, suffix) in s_name2Suxxifx) + { + if (genType.Contains(name)) + { + return suffix; + } + } + throw new Exception($"not support output data type:{genType}"); + } + + public static string GetOutputFileName(string genType, string fileName) + { + return $"{(genType.EndsWith("lua") ? fileName.Replace('.', '_') : fileName)}.{GetOutputFileSuffix(genType)}"; + } } }