【优化】美化生成的c#和typescript 配置加载代码。对齐,去掉不必要的';'号和空格

main
walon 2021-06-18 11:19:31 +08:00
parent 19dce48383
commit 8977b5c4c3
11 changed files with 175 additions and 180 deletions

View File

@ -48,13 +48,14 @@ Luban适合有以下需求的开发者
- 强大的数据校验能力。支持内建数据格式检查支持ref表引用检查策划不用担心填错id支持path资源检查策划不用担心填错资源路径
- 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了。
- 支持多种常见数据表模式。 one(单例表)、map常规key-value表、bmap(双键表)
- 支持时间本地化。datetime类型数据会根据指定的timezone转换为目标地区该时刻的UTC时间方便程序使用。
- 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力。
- 支持res资源标记。可以一键导出配置中引用的所有资源列表(icon,ui,assetbundle等等)
- 生成代码良好模块化。
- **支持文本静态本地化。导出时所有text类型数据正确替换为最终的本地化字符串。**
- **支持main + branches 数据合并。在基础数据上,施加差分数据,生成最终完整数据,适用于制作有细微不同的多地区的配置数据。**
- **[TODO] 支持文本动态本地化。运行时动态切换所有text类型数据为目标本地化字符串。**
- **本地化支持**
- 支持时间本地化。datetime类型数据会根据指定的timezone转换为目标地区该时刻的UTC时间方便程序使用。
- **支持文本静态本地化。导出时所有text类型数据正确替换为最终的本地化字符串。**
- [TODO] 支持文本动态本地化。运行时动态切换所有text类型数据为目标本地化字符串。
- **支持 main + patches 数据合并。在基础数据上,施加差分数据,生成最终完整数据,适用于制作有细微不同的多地区的配置数据。**
- 支持主流的游戏开发语言
- c++ (11+)
- c# (.net framework 4+. dotnet core 3+)
@ -65,7 +66,7 @@ Luban适合有以下需求的开发者
- python (2.7+ 及 3.0+)
- 支持主流引擎和平台
- unity + c#
- unity + tolua,xlua
- unity + toluaxlua
- unity + ILRuntime
- unity + puerts
- unreal + c++

View File

@ -94,7 +94,7 @@ namespace Luban.Job.Cfg.Defs
get
{
var table = Assembly.GetCfgTable(Ref.FirstTable);
return $"{TsRefVarName} : {table.ValueTType.Apply(TypescriptDefineTypeName.Ins)};";
return $"{TsRefVarName} : {table.ValueTType.Apply(TypescriptDefineTypeName.Ins)}";
}
}

View File

@ -121,11 +121,11 @@ namespace Luban.Job.Cfg.Defs
var table = field.Assembly.GetCfgTable(field.Ref.FirstTable);
if (field.IsNullable)
{
return $"this.{refVarName} = {name} != null ? (_tables.get('{tableName}') as {table.FullName}).get({name}) : null;";
return $"this.{refVarName} = {name} != null ? (_tables.get('{tableName}') as {table.FullName}).get({name}) : null";
}
else
{
return $"this.{refVarName} = (_tables.get('{tableName}') as {table.FullName}).get({name});";
return $"this.{refVarName} = (_tables.get('{tableName}') as {table.FullName}).get({name})";
}
}

View File

@ -36,21 +36,21 @@ namespace Luban.Job.Cfg.Generate
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
{{~if x.is_abstract_type~}}
static constructorFrom(_buf_ : Bright.Serialization.ByteBuf) : {{name}} {
static constructorFrom(_buf_: Bright.Serialization.ByteBuf): {{name}} {
switch (_buf_.ReadInt())
{
case 0 : return null;
case 0: return null
{{~ for child in x.hierarchy_not_abstract_children~}}
case {{child.id}}: return new {{child.full_name}}(_buf_);
case {{child.id}}: return new {{child.full_name}}(_buf_)
{{~end~}}
default: throw new Error();
default: throw new Error()
}
}
{{~end~}}
constructor(_buf_ : Bright.Serialization.ByteBuf) {
constructor(_buf_: Bright.Serialization.ByteBuf) {
{{~if parent_def_type~}}
super(_buf_);
super(_buf_)
{{~end~}}
{{~ for field in export_fields ~}}
{{ts_bin_constructor ('this.' + field.ts_style_name) '_buf_' field.ctype}}
@ -58,15 +58,15 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
}
{{~ for field in export_fields ~}}
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}};
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
{{~if field.gen_ref~}}
{{field.ts_ref_validator_define}}
{{~end~}}
{{~end~}}
resolve(_tables : Map<string, any>) : void {
resolve(_tables: Map<string, any>) {
{{~if parent_def_type~}}
super.resolve(_tables);
super.resolve(_tables)
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_ref~}}
@ -100,91 +100,91 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
{{x.typescript_namespace_begin}}
export class {{name}}{
{{~ if x.is_two_key_map_table ~}}
private _dataListMap : Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>;
private _dataMapMap : Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>;
private _dataList : {{ts_define_type value_type}}[];
private _dataListMap: Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>
private _dataMapMap: Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>
private _dataList: {{ts_define_type value_type}}[]
constructor(_buf_ : Bright.Serialization.ByteBuf) {
this._dataListMap = new Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>();
this._dataMapMap = new Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>();
this._dataList = [];
constructor(_buf_: Bright.Serialization.ByteBuf) {
this._dataListMap = new Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>()
this._dataMapMap = new Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>()
this._dataList = []
for(let n = _buf_.ReadInt(); n > 0 ; n--) {
let _v : {{ts_define_type value_type}};
let _v: {{ts_define_type value_type}}
{{ts_bin_constructor '_v' '_buf_' value_type}}
this._dataList.push(_v);
var _key = _v.{{x.index_field1.ts_style_name}};
let list : {{ts_define_type value_type}}[] = this._dataListMap.get(_key);
this._dataList.push(_v)
var _key = _v.{{x.index_field1.ts_style_name}}
let list: {{ts_define_type value_type}}[] = this._dataListMap.get(_key)
if (list == null) {
list = [];
this._dataListMap.set(_key, list);
list = []
this._dataListMap.set(_key, list)
}
list.push(_v);
list.push(_v)
let map : Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}> = this._dataMapMap.get(_key);
let map: Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}> = this._dataMapMap.get(_key)
if (map == null) {
map = new Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>();
this._dataMapMap.set(_key, map);
map = new Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>()
this._dataMapMap.set(_key, map)
}
map.set(_v.{{x.index_field2.ts_style_name}}, _v);
map.set(_v.{{x.index_field2.ts_style_name}}, _v)
}
}
getDataListMap() : Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]> { return this._dataListMap; }
getDataMapMap() : Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>> { return this._dataMapMap; }
getDataList() : {{ts_define_type value_type}}[] { return this._dataList; }
getDataListMap(): Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]> { return this._dataListMap }
getDataMapMap(): Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>> { return this._dataMapMap }
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
get(key1 : {{ts_define_type key_type1}}, key2 : {{ts_define_type key_type2}}) : {{ts_define_type value_type}} { return this._dataMapMap.get(key1).get(key2); }
get(key1: {{ts_define_type key_type1}}, key2: {{ts_define_type key_type2}}): {{ts_define_type value_type}} { return this._dataMapMap.get(key1).get(key2) }
resolve(_tables : Map<string, any>) : void {
resolve(_tables: Map<string, any>) {
for(var v of this._dataList) {
v.resolve(_tables);
v.resolve(_tables)
}
}
{{~else if x.is_map_table ~}}
private _dataMap : Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>;
private _dataList : {{ts_define_type value_type}}[];
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
private _dataList: {{ts_define_type value_type}}[]
constructor(_buf_ : Bright.Serialization.ByteBuf) {
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>();
this._dataList = [];
constructor(_buf_: Bright.Serialization.ByteBuf) {
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
this._dataList = []
for(let n = _buf_.ReadInt() ; n > 0 ; n--) {
let _v : {{ts_define_type value_type}};
let _v: {{ts_define_type value_type}}
{{ts_bin_constructor '_v' '_buf_' value_type}}
this._dataList.push(_v);
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v);
this._dataList.push(_v)
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
}
}
getDataMap() : Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
getDataList() : {{ts_define_type value_type}}[] { return this._dataList; }
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap }
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
get(key : {{ts_define_type key_type}}) : {{ts_define_type value_type}} { return this._dataMap.get(key); }
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} { return this._dataMap.get(key) }
resolve(_tables : Map<string, any>) : void {
resolve(_tables: Map<string, any>) {
for(var v of this._dataList) {
v.resolve(_tables);
v.resolve(_tables)
}
}
{{~else~}}
private _data : {{ts_define_type value_type}};
private _data: {{ts_define_type value_type}}
constructor(_buf_ : Bright.Serialization.ByteBuf) {
if (_buf_.ReadInt() != 1) throw new Error('table mode=one, but size != 1');
constructor(_buf_: Bright.Serialization.ByteBuf) {
if (_buf_.ReadInt() != 1) throw new Error('table mode=one, but size != 1')
{{ts_bin_constructor 'this._data' '_buf_' value_type}}
}
getData() : {{ts_define_type value_type}} { return this._data; }
getData(): {{ts_define_type value_type}} { return this._data }
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
get {{field.ts_style_name}}() : {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; }
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}} }
{{~end~}}
resolve(_tables : Map<string, any>) : void {
this._data.resolve(_tables);
resolve(_tables: Map<string, any>) {
this._data.resolve(_tables)
}
{{end}}
@ -208,23 +208,23 @@ export class {{name}}{
}}
type ByteBufLoader = (file : string) => Bright.Serialization.ByteBuf
type ByteBufLoader = (file: string) => Bright.Serialization.ByteBuf
export class {{name}} {
{{~ for table in tables ~}}
private _{{table.name}} : {{table.full_name}};
get {{table.name}}() : {{table.full_name}} { return this._{{table.name}};}
private _{{table.name}}: {{table.full_name}}
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}}}
{{~end~}}
constructor(loader : ByteBufLoader) {
let tables = new Map<string, any>();
constructor(loader: ByteBufLoader) {
let tables = new Map<string, any>()
{{~for table in tables ~}}
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'));
tables.set('{{table.full_name}}', this._{{table.name}});
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
tables.set('{{table.full_name}}', this._{{table.name}})
{{~end~}}
{{~ for table in tables ~}}
this._{{table.name}}.resolve(tables);
this._{{table.name}}.resolve(tables)
{{~end~}}
}
}

View File

@ -36,39 +36,39 @@ namespace Luban.Job.Cfg.Generate
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
{{~if x.is_abstract_type~}}
static constructorFrom(_json_ : any) : {{name}} {
static constructorFrom(_json_: any): {{name}} {
switch (_json_.__type__) {
case null : return null;
case null: return null
{{~ for child in x.hierarchy_not_abstract_children~}}
case '{{child.name}}': return new {{child.full_name}}(_json_);
case '{{child.name}}': return new {{child.full_name}}(_json_)
{{~end~}}
default: throw new Error();
default: throw new Error()
}
}
{{~end~}}
constructor(_json_ : any) {
constructor(_json_: any) {
{{~if parent_def_type~}}
super(_json_);
super(_json_)
{{~end~}}
{{~ for field in export_fields ~}}
{{~if !field.ctype.is_nullable~}}
if (_json_.{{field.name}} == null) { throw new Error(); }
if (_json_.{{field.name}} == null) { throw new Error() }
{{~end~}}
{{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}}
{{~end~}}
}
{{~ for field in export_fields ~}}
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}};
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
{{~if field.gen_ref~}}
{{field.ts_ref_validator_define}}
{{~end~}}
{{~end~}}
resolve(_tables : Map<string, any>) : void {
resolve(_tables: Map<string, any>) {
{{~if parent_def_type~}}
super.resolve(_tables);
super.resolve(_tables)
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_ref~}}
@ -102,91 +102,85 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
{{x.typescript_namespace_begin}}
export class {{name}}{
{{~ if x.is_two_key_map_table ~}}
private _dataListMap : Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>;
private _dataMapMap : Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>;
private _dataList : {{ts_define_type value_type}}[];
constructor(_json_ : any) {
this._dataListMap = new Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>();
this._dataMapMap = new Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>();
this._dataList = [];
private _dataListMap: Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>
private _dataMapMap: Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>
private _dataList: {{ts_define_type value_type}}[]
constructor(_json_: any) {
this._dataListMap = new Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]>()
this._dataMapMap = new Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>>()
this._dataList = []
for(var _json2_ of _json_) {
let _v : {{ts_define_type value_type}};
let _v: {{ts_define_type value_type}}
{{ts_json_constructor '_v' '_json2_' value_type}}
this._dataList.push(_v);
var _key = _v.{{x.index_field1.ts_style_name}};
let list : {{ts_define_type value_type}}[] = this._dataListMap.get(_key);
this._dataList.push(_v)
var _key = _v.{{x.index_field1.ts_style_name}}
let list: {{ts_define_type value_type}}[] = this._dataListMap.get(_key)
if (list == null) {
list = [];
this._dataListMap.set(_key, list);
list = []
this._dataListMap.set(_key, list)
}
list.push(_v);
let map : Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}> = this._dataMapMap.get(_key);
list.push(_v)
let map: Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}> = this._dataMapMap.get(_key)
if (map == null) {
map = new Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>();
this._dataMapMap.set(_key, map);
map = new Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>()
this._dataMapMap.set(_key, map)
}
map.set(_v.{{x.index_field2.ts_style_name}}, _v);
map.set(_v.{{x.index_field2.ts_style_name}}, _v)
}
}
getDataListMap() : Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]> { return this._dataListMap; }
getDataMapMap() : Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>> { return this._dataMapMap; }
getDataList() : {{ts_define_type value_type}}[] { return this._dataList; }
getDataListMap(): Map<{{ts_define_type key_type1}}, {{ts_define_type value_type}}[]> { return this._dataListMap; }
getDataMapMap(): Map<{{ts_define_type key_type1}}, Map<{{ts_define_type key_type2}}, {{ts_define_type value_type}}>> { return this._dataMapMap; }
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
get(key1 : {{ts_define_type key_type1}}, key2 : {{ts_define_type key_type2}}) : {{ts_define_type value_type}} { return this._dataMapMap.get(key1).get(key2); }
get(key1: {{ts_define_type key_type1}}, key2: {{ts_define_type key_type2}}): {{ts_define_type value_type}} { return this._dataMapMap.get(key1).get(key2); }
resolve(_tables : Map<string, any>) : void {
resolve(_tables: Map<string, any>) {
for(var v of this._dataList) {
v.resolve(_tables);
v.resolve(_tables)
}
}
{{~else if x.is_map_table ~}}
private _dataMap : Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>;
private _dataList : {{ts_define_type value_type}}[];
constructor(_json_ : any) {
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>();
this._dataList = [];
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
private _dataList: {{ts_define_type value_type}}[]
constructor(_json_: any) {
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
this._dataList = []
for(var _json2_ of _json_) {
let _v : {{ts_define_type value_type}};
let _v: {{ts_define_type value_type}}
{{ts_json_constructor '_v' '_json2_' value_type}}
this._dataList.push(_v);
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v);
this._dataList.push(_v)
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
}
}
getDataMap() : Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
getDataList() : {{ts_define_type value_type}}[] { return this._dataList; }
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
get(key : {{ts_define_type key_type}}) : {{ts_define_type value_type}} { return this._dataMap.get(key); }
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} { return this._dataMap.get(key); }
resolve(_tables : Map<string, any>) : void {
resolve(_tables: Map<string, any>) {
for(var v of this._dataList) {
v.resolve(_tables);
v.resolve(_tables)
}
}
{{~else~}}
private _data : {{ts_define_type value_type}};
constructor(_json_ : any) {
if (_json_.length != 1) throw new Error('table mode=one, but size != 1');
private _data: {{ts_define_type value_type}}
constructor(_json_: any) {
if (_json_.length != 1) throw new Error('table mode=one, but size != 1')
{{ts_json_constructor 'this._data' '_json_[0]' value_type}}
}
getData() : {{ts_define_type value_type}} { return this._data; }
getData(): {{ts_define_type value_type}} { return this._data; }
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
get {{field.ts_style_name}}() : {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; }
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; }
{{~end~}}
resolve(_tables : Map<string, any>) : void {
this._data.resolve(_tables);
resolve(_tables: Map<string, any>) {
this._data.resolve(_tables)
}
{{end}}
@ -210,23 +204,23 @@ export class {{name}}{
}}
type JsonLoader = (file : string) => any
type JsonLoader = (file: string) => any
export class {{name}} {
{{~ for table in tables ~}}
private _{{table.name}} : {{table.full_name}};
get {{table.name}}() : {{table.full_name}} { return this._{{table.name}};}
private _{{table.name}}: {{table.full_name}}
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}};}
{{~end~}}
constructor(loader : JsonLoader) {
let tables = new Map<string, any>();
constructor(loader: JsonLoader) {
let tables = new Map<string, any>()
{{~for table in tables ~}}
this._{{table.name}} = new {{table.full_name}}(loader('{{table.json_output_data_file}}'));
tables.set('{{table.full_name}}', this._{{table.name}});
this._{{table.name}} = new {{table.full_name}}(loader('{{table.json_output_data_file}}'))
tables.set('{{table.full_name}}', this._{{table.name}})
{{~end~}}
{{~ for table in tables ~}}
this._{{table.name}}.resolve(tables);
this._{{table.name}}.resolve(tables)
{{~end~}}
}
}

View File

@ -11,7 +11,7 @@ namespace Luban.Job.Common.TypeVisitors
{
if (type.IsNullable)
{
return $"if({byteBufName}.ReadBool()) {{ {type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName)} }} else {{ {fieldName} = null; }}";
return $"if({byteBufName}.ReadBool()) {{ {type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName)} }} else {{ {fieldName} = null }}";
}
else
{

View File

@ -11,11 +11,11 @@ namespace Luban.Job.Common.TypeVisitors
{
if (type.Bean.IsAbstractType)
{
return $"{fieldName} = {type.Bean.FullName}.constructorFrom({bufVarName});";
return $"{fieldName} = {type.Bean.FullName}.constructorFrom({bufVarName})";
}
else
{
return $"{fieldName} = new {type.Bean.FullName}({bufVarName});";
return $"{fieldName} = new {type.Bean.FullName}({bufVarName})";
}
}
}

View File

@ -11,7 +11,7 @@ namespace Luban.Job.Cfg.TypeVisitors
{
if (type.IsNullable)
{
return $"if({jsonFieldName} != null) {{ {type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, jsonFieldName, fieldName)} }} else {{ {fieldName} = null; }}";
return $"if({jsonFieldName} != null) {{ {type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, jsonFieldName, fieldName)} }} else {{ {fieldName} = null }}";
}
else
{

View File

@ -9,83 +9,83 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TBool type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TByte type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TShort type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFshort type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TInt type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFint type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TLong type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFlong type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFloat type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TDouble type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TEnum type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TString type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TBytes type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TText type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TBean type, string jsonVarName, string fieldName)
{
if (type.Bean.IsAbstractType)
{
return $"{fieldName} = {type.Bean.FullName}.constructorFrom({jsonVarName});";
return $"{fieldName} = {type.Bean.FullName}.constructorFrom({jsonVarName})";
}
else
{
return $"{fieldName} = new {type.Bean.FullName}({jsonVarName});";
return $"{fieldName} = new {type.Bean.FullName}({jsonVarName})";
}
}
@ -93,11 +93,11 @@ namespace Luban.Job.Cfg.TypeVisitors
{
if (type.Apply(SimpleJsonTypeVisitor.Ins))
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
else
{
return $"{{ {fieldName} = []; for(let _ele of {jsonVarName}) {{ let _e :{type.ElementType.Apply(TypescriptDefineTypeName.Ins)};{type.ElementType.Apply(this, "_ele", "_e")} {fieldName}.push(_e);}}}}";
return $"{{ {fieldName} = []; for(let _ele of {jsonVarName}) {{ let _e :{type.ElementType.Apply(TypescriptDefineTypeName.Ins)}; {type.ElementType.Apply(this, "_ele", "_e")}; {fieldName}.push(_e);}}}}";
}
}
@ -105,11 +105,11 @@ namespace Luban.Job.Cfg.TypeVisitors
{
if (type.Apply(SimpleJsonTypeVisitor.Ins))
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
else
{
return $"{{ {fieldName} = []; for(let _ele of {jsonVarName}) {{ let _e : {type.ElementType.Apply(TypescriptDefineTypeName.Ins)};{type.ElementType.Apply(this, "_ele", "_e")} {fieldName}.push(_e);}}}}";
return $"{{ {fieldName} = []; for(let _ele of {jsonVarName}) {{ let _e : {type.ElementType.Apply(TypescriptDefineTypeName.Ins)}; {type.ElementType.Apply(this, "_ele", "_e")}; {fieldName}.push(_e);}}}}";
}
}
@ -117,38 +117,38 @@ namespace Luban.Job.Cfg.TypeVisitors
{
if (type.Apply(SimpleJsonTypeVisitor.Ins))
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
else
{
return $"{{ {fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(var _ele of {jsonVarName}) {{ let _e:{type.ElementType.Apply(TypescriptDefineTypeName.Ins)};{type.ElementType.Apply(this, "_ele", "_e")} {fieldName}.add(_e);}}}}";
return $"{{ {fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(var _ele of {jsonVarName}) {{ let _e:{type.ElementType.Apply(TypescriptDefineTypeName.Ins)}; {type.ElementType.Apply(this, "_ele", "_e")}; {fieldName}.add(_e);}}}}";
}
}
public string Accept(TMap type, string jsonVarName, string fieldName)
{
return $"{fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(var _entry_ of {jsonVarName}) {{ let _k:{type.KeyType.Apply(TypescriptDefineTypeName.Ins)}; {type.KeyType.Apply(this, "_entry_[0]", "_k")} let _v:{type.ValueType.Apply(TypescriptDefineTypeName.Ins)}; {type.ValueType.Apply(this, "_entry_[1]", "_v")} {fieldName}.set(_k, _v); }}";
return $"{fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(var _entry_ of {jsonVarName}) {{ let _k:{type.KeyType.Apply(TypescriptDefineTypeName.Ins)}; {type.KeyType.Apply(this, "_entry_[0]", "_k")} let _v:{type.ValueType.Apply(TypescriptDefineTypeName.Ins)}; {type.ValueType.Apply(this, "_entry_[1]", "_v")}; {fieldName}.set(_k, _v); }}";
}
public string Accept(TVector2 type, string jsonVarName, string fieldName)
{
return $"{fieldName} = Vector2.from({jsonVarName});";
return $"{fieldName} = Vector2.from({jsonVarName})";
}
public string Accept(TVector3 type, string jsonVarName, string fieldName)
{
return $"{fieldName} = Vector3.from({jsonVarName});";
return $"{fieldName} = Vector3.from({jsonVarName})";
}
public string Accept(TVector4 type, string jsonVarName, string fieldName)
{
return $"{fieldName} = Vector4.from({jsonVarName});";
return $"{fieldName} = Vector4.from({jsonVarName})";
}
public string Accept(TDateTime type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName};";
return $"{fieldName} = {jsonVarName}";
}
}
}