From 8977b5c4c3a2dbc7e5238f04541e1589116b9530 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 18 Jun 2021 11:19:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E7=BE=8E?= =?UTF-8?q?=E5=8C=96=E7=94=9F=E6=88=90=E7=9A=84c#=E5=92=8Ctypescript=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8A=A0=E8=BD=BD=E4=BB=A3=E7=A0=81=E3=80=82?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=EF=BC=8C=E5=8E=BB=E6=8E=89=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84';'=E5=8F=B7=E5=92=8C=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +- src/Luban.Job.Cfg/Source/Defs/DefField.cs | 2 +- .../Source/Defs/TTypeTemplateExtends.cs | 4 +- .../Source/Generate/CsBinCodeRender.cs | 8 +- .../Source/Generate/CsJsonCodeRender.cs | 8 +- .../Generate/TypeScriptBinCodeRender.cs | 126 ++++++++-------- .../Generate/TypeScriptJsonCodeRender.cs | 134 +++++++++--------- .../TypescriptBinConstructorVisitor.cs | 2 +- ...TypescriptBinUnderingConstructorVisitor.cs | 4 +- .../TypescriptJsonConstructorVisitor.cs | 2 +- ...ypescriptJsonUnderingConstructorVisitor.cs | 54 +++---- 11 files changed, 175 insertions(+), 180 deletions(-) diff --git a/README.md b/README.md index ab3b33d..2927d43 100644 --- a/README.md +++ b/README.md @@ -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 + tolua、xlua - unity + ILRuntime - unity + puerts - unreal + c++ diff --git a/src/Luban.Job.Cfg/Source/Defs/DefField.cs b/src/Luban.Job.Cfg/Source/Defs/DefField.cs index 8a64bdd..46929cd 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefField.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefField.cs @@ -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)}"; } } diff --git a/src/Luban.Job.Cfg/Source/Defs/TTypeTemplateExtends.cs b/src/Luban.Job.Cfg/Source/Defs/TTypeTemplateExtends.cs index 74dde73..e3874bc 100644 --- a/src/Luban.Job.Cfg/Source/Defs/TTypeTemplateExtends.cs +++ b/src/Luban.Job.Cfg/Source/Defs/TTypeTemplateExtends.cs @@ -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})"; } } diff --git a/src/Luban.Job.Cfg/Source/Generate/CsBinCodeRender.cs b/src/Luban.Job.Cfg/Source/Generate/CsBinCodeRender.cs index 392356d..7bbfd70 100644 --- a/src/Luban.Job.Cfg/Source/Generate/CsBinCodeRender.cs +++ b/src/Luban.Job.Cfg/Source/Generate/CsBinCodeRender.cs @@ -71,12 +71,12 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} { } {{~ for field in export_fields ~}} - public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}}; + public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}}; {{~if field.index_field~}} public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>(); {{~end~}} {{~if field.gen_ref~}} - public {{field.cs_ref_validator_define}} + public {{field.cs_ref_validator_define}} {{~end~}} {{~end~}} @@ -90,9 +90,9 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} { {{~if parent_def_type}}base.Resolve(_tables);{{end}} {{~ for field in export_fields ~}} {{~if field.gen_ref~}} - {{cs_ref_validator_resolve field}} + {{cs_ref_validator_resolve field}} {{~else if field.has_recursive_ref~}} - {{cs_recursive_resolve field '_tables'}} + {{cs_recursive_resolve field '_tables'}} {{~end~}} {{~end~}} OnResolveFinish(_tables); diff --git a/src/Luban.Job.Cfg/Source/Generate/CsJsonCodeRender.cs b/src/Luban.Job.Cfg/Source/Generate/CsJsonCodeRender.cs index 833a0b3..8ebd99c 100644 --- a/src/Luban.Job.Cfg/Source/Generate/CsJsonCodeRender.cs +++ b/src/Luban.Job.Cfg/Source/Generate/CsJsonCodeRender.cs @@ -66,12 +66,12 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} { } {{~ for field in export_fields ~}} - public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}}; + public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}}; {{~if field.index_field~}} public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>(); {{~end~}} {{~if field.gen_ref~}} - public {{field.cs_ref_validator_define}} + public {{field.cs_ref_validator_define}} {{~end~}} {{~end~}} @@ -85,9 +85,9 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} { {{~if parent_def_type}}base.Resolve(_tables);{{end}} {{~ for field in export_fields ~}} {{~if field.gen_ref~}} - {{cs_ref_validator_resolve field}} + {{cs_ref_validator_resolve field}} {{~else if field.has_recursive_ref~}} - {{cs_recursive_resolve field '_tables'}} + {{cs_recursive_resolve field '_tables'}} {{~end~}} {{~end~}} OnResolveFinish(_tables); diff --git a/src/Luban.Job.Cfg/Source/Generate/TypeScriptBinCodeRender.cs b/src/Luban.Job.Cfg/Source/Generate/TypeScriptBinCodeRender.cs index de97176..1712586 100644 --- a/src/Luban.Job.Cfg/Source/Generate/TypeScriptBinCodeRender.cs +++ b/src/Luban.Job.Cfg/Source/Generate/TypeScriptBinCodeRender.cs @@ -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,21 +58,21 @@ 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) : void { + resolve(_tables: Map) { {{~if parent_def_type~}} - super.resolve(_tables); + super.resolve(_tables) {{~end~}} {{~ for field in export_fields ~}} {{~if field.gen_ref~}} - {{ts_ref_validator_resolve field}} + {{ts_ref_validator_resolve field}} {{~else if field.has_recursive_ref~}} - {{ts_recursive_resolve field '_tables'}} + {{ts_recursive_resolve field '_tables'}} {{~end~}} {{~end~}} } @@ -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) : void { + resolve(_tables: Map) { 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) : void { + resolve(_tables: Map) { 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) : void { - this._data.resolve(_tables); + resolve(_tables: Map) { + 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(); + constructor(loader: ByteBufLoader) { + let tables = new Map() {{~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~}} } } diff --git a/src/Luban.Job.Cfg/Source/Generate/TypeScriptJsonCodeRender.cs b/src/Luban.Job.Cfg/Source/Generate/TypeScriptJsonCodeRender.cs index 3797c75..4d61b96 100644 --- a/src/Luban.Job.Cfg/Source/Generate/TypeScriptJsonCodeRender.cs +++ b/src/Luban.Job.Cfg/Source/Generate/TypeScriptJsonCodeRender.cs @@ -36,45 +36,45 @@ 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) : void { + resolve(_tables: Map) { {{~if parent_def_type~}} - super.resolve(_tables); + super.resolve(_tables) {{~end~}} {{~ for field in export_fields ~}} {{~if field.gen_ref~}} - {{ts_ref_validator_resolve field}} + {{ts_ref_validator_resolve field}} {{~else if field.has_recursive_ref~}} - {{ts_recursive_resolve field '_tables'}} + {{ts_recursive_resolve field '_tables'}} {{~end~}} {{~end~}} } @@ -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) : void { + resolve(_tables: Map) { 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) : void { + resolve(_tables: Map) { 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) : void { - this._data.resolve(_tables); + resolve(_tables: Map) { + 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(); + constructor(loader: JsonLoader) { + let tables = new Map() {{~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~}} } } diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinConstructorVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinConstructorVisitor.cs index a2a4057..bbb9f01 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinConstructorVisitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinConstructorVisitor.cs @@ -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 { diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinUnderingConstructorVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinUnderingConstructorVisitor.cs index d6ea85f..1cac577 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinUnderingConstructorVisitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptBinUnderingConstructorVisitor.cs @@ -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})"; } } } diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonConstructorVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonConstructorVisitor.cs index e6f88ef..5c94ba3 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonConstructorVisitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonConstructorVisitor.cs @@ -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 { diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonUnderingConstructorVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonUnderingConstructorVisitor.cs index 28ec9b8..5a18ee4 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonUnderingConstructorVisitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/TypescriptJsonUnderingConstructorVisitor.cs @@ -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}"; } } }