【回滚】考虑到 cfg table的DataList必须按照配置定义的顺序。如果改成data_json2格式,顺序就无法确定了。回滚上个版本的修改。
parent
15d1e0b07e
commit
02481f03e1
|
|
@ -1,4 +1,5 @@
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Types;
|
using Luban.Job.Common.Types;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -16,38 +17,10 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
|
|
||||||
public override void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
public override void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
var keyType = type.Type.KeyType;
|
|
||||||
if (keyType is not TString
|
|
||||||
&& keyType is not TInt
|
|
||||||
&& keyType is not TLong)
|
|
||||||
{
|
|
||||||
throw new Exception($"data_json2格式只支持key为int,long,string类型的map");
|
|
||||||
}
|
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
foreach (var d in type.Datas)
|
foreach (var d in type.Datas)
|
||||||
{
|
{
|
||||||
switch (d.Key)
|
x.WritePropertyName(d.Key.Apply(ToJsonPropertyNameVisitor.Ins));
|
||||||
{
|
|
||||||
case DString ds:
|
|
||||||
{
|
|
||||||
x.WritePropertyName(ds.Value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DInt di:
|
|
||||||
{
|
|
||||||
x.WritePropertyName(di.Value.ToString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DLong dl:
|
|
||||||
{
|
|
||||||
x.WritePropertyName(dl.Value.ToString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"data_json2格式只支持key为int,long,string类型的map");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
d.Value.Apply(this, ass, x);
|
d.Value.Apply(this, ass, x);
|
||||||
}
|
}
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Luban.Job.Cfg
|
||||||
[Option("output_data_json_monolithic_file", Required = false, HelpText = "output monolithic json file")]
|
[Option("output_data_json_monolithic_file", Required = false, HelpText = "output monolithic json file")]
|
||||||
public string OutputDataJsonMonolithicFile { get; set; }
|
public string OutputDataJsonMonolithicFile { get; set; }
|
||||||
|
|
||||||
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_json,code_cs_unity_json,code_lua_bin,code_java_bin,code_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json_monolithic,data_resources . can be multi")]
|
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_json,code_cs_unity_json,code_lua_bin,code_java_bin,code_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_resources . can be multi")]
|
||||||
public string GenType { get; set; }
|
public string GenType { get; set; }
|
||||||
|
|
||||||
[Option('s', "service", Required = true, HelpText = "service")]
|
[Option('s', "service", Required = true, HelpText = "service")]
|
||||||
|
|
@ -126,7 +126,8 @@ namespace Luban.Job.Cfg
|
||||||
switch (genType)
|
switch (genType)
|
||||||
{
|
{
|
||||||
case "data_bin": return "bin";
|
case "data_bin": return "bin";
|
||||||
case "data_json": return "json";
|
case "data_json":
|
||||||
|
case "data_json2": return "json";
|
||||||
case "data_lua": return "lua";
|
case "data_lua": return "lua";
|
||||||
default: throw new Exception($"not support output data type:{genType}");
|
default: throw new Exception($"not support output data type:{genType}");
|
||||||
}
|
}
|
||||||
|
|
@ -167,8 +168,7 @@ namespace Luban.Job.Cfg
|
||||||
errMsg = "--outputcodedir missing";
|
errMsg = "--outputcodedir missing";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<string> dataGenTypes = genTypes.Where(t => t.StartsWith("data_", StringComparison.Ordinal)).ToList();
|
if (genTypes.Any(t => t.StartsWith("data_", StringComparison.Ordinal)))
|
||||||
if (dataGenTypes.Count > 0)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(inputDataDir))
|
if (string.IsNullOrWhiteSpace(inputDataDir))
|
||||||
{
|
{
|
||||||
|
|
@ -384,6 +384,7 @@ namespace Luban.Job.Cfg
|
||||||
}
|
}
|
||||||
case "data_bin":
|
case "data_bin":
|
||||||
case "data_json":
|
case "data_json":
|
||||||
|
case "data_json2":
|
||||||
case "data_lua":
|
case "data_lua":
|
||||||
{
|
{
|
||||||
await CheckLoadCfgDataAsync();
|
await CheckLoadCfgDataAsync();
|
||||||
|
|
@ -786,7 +787,7 @@ namespace {ctx.TopModule}
|
||||||
{
|
{
|
||||||
allJsonTask.Add(Task.Run(() =>
|
allJsonTask.Add(Task.Run(() =>
|
||||||
{
|
{
|
||||||
return (string)DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json");
|
return (string)DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json2");
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
using Luban.Job.Common.Types;
|
||||||
|
using Luban.Job.Common.TypeVisitors;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
{
|
||||||
|
class CsStringDeserialize : ITypeFuncVisitor<string, string, string>
|
||||||
|
{
|
||||||
|
public static CsStringDeserialize Ins { get; } = new();
|
||||||
|
|
||||||
|
public string Accept(TBool type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = bool.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TByte type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = byte.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TShort type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = short.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFshort type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = short.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TInt type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = int.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFint type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = int.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TLong type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = long.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFlong type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = long.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFloat type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = float.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TDouble type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = double.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TEnum type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = ({type.Apply(CsDefineTypeName.Ins)})int.Parse({strName});";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TString type, string strName, string varName)
|
||||||
|
{
|
||||||
|
return $"{varName} = {strName};";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TBytes type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TText type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TBean type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TArray type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TList type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TSet type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TMap type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TVector2 type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TVector3 type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TVector4 type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TDateTime type, string strName, string varName)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue