From 533ab56f86c8af542a0d410a67fdcbd1abbde19a Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 3 Sep 2021 12:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96typescript=20=E5=8F=AF=E7=A9=BA=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E7=9A=84=E5=AE=9A=E4=B9=89=EF=BC=8C=E7=94=B1=20xxx=3F:yyy=20?= =?UTF-8?q?=E6=94=B9=E6=88=90=20xxx:yyy|undefined=20=E3=80=90=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E3=80=91=E6=96=B0=E5=A2=9E=20code=5Ftypescript=5Fedit?= =?UTF-8?q?or=5Fjson=20=E4=B8=80=E4=B8=AA=E7=94=A8=E4=BA=8Eweb=E7=9A=84?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=80=A7=E7=94=9F=E6=88=90=E6=96=B9=E6=A1=88?= =?UTF-8?q?=20=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98=E5=8C=96=20typ?= =?UTF-8?q?escript=20Vector{2,3,4}=E5=8A=A0=E8=BD=BDjson=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82=20json['x']=E6=94=B9=E6=88=90json.x=20?= =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98=E5=8C=96=20typesc?= =?UTF-8?q?ript=20=E6=A0=BC=E5=BC=8F=E5=8F=8A=E8=A7=A3=E5=86=B3=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E7=BC=96=E8=AF=91=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/Defs/DefField.cs | 2 +- .../TypescriptEditorCodeJsonRender.cs | 95 ++++++++++++ src/Luban.Job.Cfg/Source/JobController.cs | 2 +- src/Luban.Job.Common/Source/GenArgsBase.cs | 31 ++-- ...pescriptDefineTypeNameUnderlyingVisitor.cs | 142 ++++++++++++++++++ .../TypescriptDefineTypeNameVisitor.cs | 134 +---------------- src/Luban.Job.Db/Source/JobController.cs | 2 +- src/Luban.Job.Proto/Source/JobController.cs | 2 +- src/Luban.Server/Luban.Server.csproj | 9 ++ .../config/typescript_editor_json/bean.tpl | 50 ++++++ .../config/typescript_editor_json/enum.tpl | 25 +++ .../config/typescript_editor_json/table.tpl | 54 +++++++ .../Templates/config/typescript_json/bean.tpl | 8 +- .../config/typescript_json/vectors.tpl | 18 +-- 14 files changed, 409 insertions(+), 165 deletions(-) create mode 100644 src/Luban.Job.Cfg/Source/Generate/TypescriptEditorCodeJsonRender.cs create mode 100644 src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameUnderlyingVisitor.cs create mode 100644 src/Luban.Server/Templates/config/typescript_editor_json/bean.tpl create mode 100644 src/Luban.Server/Templates/config/typescript_editor_json/enum.tpl create mode 100644 src/Luban.Server/Templates/config/typescript_editor_json/table.tpl diff --git a/src/Luban.Job.Cfg/Source/Defs/DefField.cs b/src/Luban.Job.Cfg/Source/Defs/DefField.cs index c194871..d2d3b1f 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefField.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefField.cs @@ -105,7 +105,7 @@ namespace Luban.Job.Cfg.Defs get { var table = Assembly.GetCfgTable(Ref.FirstTable); - return $"{TsRefVarName} : {table.ValueTType.Apply(TypescriptDefineTypeNameVisitor.Ins)}{(IsNullable ? " | undefined" : " = undefined!")}"; + return $"{TsRefVarName} : {table.ValueTType.Apply(TypescriptDefineTypeNameVisitor.Ins)}{(IsNullable ? "" : " = undefined!")}"; } } diff --git a/src/Luban.Job.Cfg/Source/Generate/TypescriptEditorCodeJsonRender.cs b/src/Luban.Job.Cfg/Source/Generate/TypescriptEditorCodeJsonRender.cs new file mode 100644 index 0000000..c6308ba --- /dev/null +++ b/src/Luban.Job.Cfg/Source/Generate/TypescriptEditorCodeJsonRender.cs @@ -0,0 +1,95 @@ +using Luban.Common.Protos; +using Luban.Job.Cfg.Defs; +using Luban.Job.Common; +using Luban.Job.Common.Defs; +using Luban.Job.Common.Utils; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Luban.Job.Cfg.Generate +{ + [Render("code_typescript_editor_json")] + class TypescriptEditorCodeJsonRender : TypescriptCodeRenderBase + { + public override void Render(GenContext ctx) + { + string genType = ctx.GenType; + var args = ctx.GenArgs; + ctx.Render = this; + ctx.Lan = RenderFileUtil.GetLanguage(genType); + + var lines = new List(10000); + Action> preContent = (fileContent) => + { + fileContent.Add(StringTemplateUtil.GetTemplateString("config/typescript_json/vectors")); + + fileContent.Add(@$"export namespace {ctx.TopModule} {{"); + }; + + Action> postContent = (fileContent) => + { + fileContent.Add("}\n"); // end of topmodule + }; + + GenerateCode(ctx, "Types.ts", lines, preContent, postContent); + } + + protected void GenerateCode(GenContext ctx, string outputFile, List fileContent, Action> preContent, Action> postContent) + { + ctx.Tasks.Add(Task.Run(() => + { + fileContent.Add(FileHeaderUtil.GetAutoGenerationHeader(ctx.Lan)); + + preContent?.Invoke(fileContent); + + foreach (var c in ctx.Assembly.Types.Values) + { + switch (c) + { + case DefConst: + case DefEnum: + case DefBean: + case DefTable: + { + fileContent.Add(ctx.Render.RenderAny(c)); + break; + } + } + } + postContent?.Invoke(fileContent); + + var file = outputFile; + var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join('\n', fileContent)); + ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); + })); + } + + public override string Render(DefEnum e) + { + var template = StringTemplateUtil.GetTemplate("config/typescript_editor_json/enum"); + var result = template.RenderCode(e); + + return result; + } + + public override string Render(DefBean b) + { + var template = StringTemplateUtil.GetTemplate("config/typescript_editor_json/bean"); + var result = template.RenderCode(b); + return result; + } + + public override string Render(DefTable p) + { + var template = StringTemplateUtil.GetTemplate("config/typescript_editor_json/table"); + var result = template.RenderCode(p); + return result; + } + + public override string RenderService(string name, string module, List tables) + { + throw new NotSupportedException(); + } + } +} diff --git a/src/Luban.Job.Cfg/Source/JobController.cs b/src/Luban.Job.Cfg/Source/JobController.cs index de7d65b..e2fce31 100644 --- a/src/Luban.Job.Cfg/Source/JobController.cs +++ b/src/Luban.Job.Cfg/Source/JobController.cs @@ -94,7 +94,7 @@ namespace Luban.Job.Cfg return false; } - if (!options.ValidateTypescriptRequire(options.GenType, ref errMsg)) + if (options.GenType.Contains("typescript_bin") && !options.ValidateTypescriptRequire(options.GenType, ref errMsg)) { return false; } diff --git a/src/Luban.Job.Common/Source/GenArgsBase.cs b/src/Luban.Job.Common/Source/GenArgsBase.cs index 56fc32e..4ca1f09 100644 --- a/src/Luban.Job.Common/Source/GenArgsBase.cs +++ b/src/Luban.Job.Common/Source/GenArgsBase.cs @@ -37,24 +37,21 @@ namespace Luban.Job.Common public bool ValidateTypescriptRequire(string genType, ref string errMsg) { - if (genType.Contains("typescript")) + if (!string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath) && !string.IsNullOrWhiteSpace(this.TypescriptBrightPackageName)) { - if (!string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath) && !string.IsNullOrWhiteSpace(this.TypescriptBrightPackageName)) - { - errMsg = "can't use options --typescript_bright_require_path and --typescript_bright_package_name at the same time"; - return false; - } - bool hasBrightPathOrPacakge = !string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath) || !string.IsNullOrWhiteSpace(this.TypescriptBrightPackageName); - if (!this.UsePuertsByteBuf && !hasBrightPathOrPacakge) - { - errMsg = "while --use_puerts_bytebuf is false, should provide option --typescript_bright_require_path or --typescript_bright_package_name"; - return false; - } - if (!this.EmbedBrightTypes && !hasBrightPathOrPacakge) - { - errMsg = "while --embed_bright_types is false, should provide option --typescript_bright_require_path or --typescript_bright_package_name"; - return false; - } + errMsg = "can't use options --typescript_bright_require_path and --typescript_bright_package_name at the same time"; + return false; + } + bool hasBrightPathOrPacakge = !string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath) || !string.IsNullOrWhiteSpace(this.TypescriptBrightPackageName); + if (!this.UsePuertsByteBuf && !hasBrightPathOrPacakge) + { + errMsg = "while --use_puerts_bytebuf is false, should provide option --typescript_bright_require_path or --typescript_bright_package_name"; + return false; + } + if (!this.EmbedBrightTypes && !hasBrightPathOrPacakge) + { + errMsg = "while --embed_bright_types is false, should provide option --typescript_bright_require_path or --typescript_bright_package_name"; + return false; } return true; } diff --git a/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameUnderlyingVisitor.cs b/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameUnderlyingVisitor.cs new file mode 100644 index 0000000..638f503 --- /dev/null +++ b/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameUnderlyingVisitor.cs @@ -0,0 +1,142 @@ +using Luban.Job.Common.Types; + +namespace Luban.Job.Common.TypeVisitors +{ + public class TypescriptDefineTypeNameUnderlyingVisitor : ITypeFuncVisitor + { + public static TypescriptDefineTypeNameUnderlyingVisitor Ins { get; } = new(); + + public string Accept(TBool type) + { + return "boolean"; + } + + public string Accept(TByte type) + { + return "number"; + } + + public string Accept(TShort type) + { + return "number"; + } + + public string Accept(TFshort type) + { + return "number"; + } + + public string Accept(TInt type) + { + return "number"; + } + + public string Accept(TFint type) + { + return "number"; + } + + public string Accept(TLong type) + { + return type.IsBigInt ? "bigint" : "number"; + } + + public string Accept(TFlong type) + { + return "bigint"; + } + + public string Accept(TFloat type) + { + return "number"; + } + + public string Accept(TDouble type) + { + return "number"; + } + + public string Accept(TEnum type) + { + return type.DefineEnum.FullName; + } + + public string Accept(TString type) + { + return "string"; + } + + public string Accept(TBytes type) + { + return "Uint8Array"; + } + + public string Accept(TText type) + { + return "string"; + } + + public string Accept(TBean type) + { + return type.Bean.FullName; + } + + + private string GetArrayType(TType elementType) + { + switch (elementType) + { + case TByte _: return "Uint8Array"; + case TShort _: + case TFshort _: return "Int16Array"; + case TInt _: + case TFint _: return "Int32Array"; + case TLong _: + case TFlong _: return "Int64Array"; + case TFloat _: return "Float32Array"; + case TDouble _: return "Float64Array"; + default: return $"{elementType.Apply(this)}[]"; + } + } + + public virtual string Accept(TArray type) + { + return GetArrayType(type.ElementType); + } + + public virtual string Accept(TList type) + { + return $"{type.ElementType.Apply(this)}[]"; + } + + public virtual string Accept(TSet type) + { + return $"Set<{type.ElementType.Apply(this)}>"; + } + + public virtual string Accept(TMap type) + { + return $"Map<{type.KeyType.Apply(this)}, {type.ValueType.Apply(this)}>"; + } + + public string Accept(TVector2 type) + { + return "Vector2"; + } + + public string Accept(TVector3 type) + { + return "Vector3"; + } + + public string Accept(TVector4 type) + { + return "Vector4"; + } + + public string Accept(TDateTime type) + { + return "number"; + } + } +} diff --git a/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameVisitor.cs b/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameVisitor.cs index 68462ad..11e1f22 100644 --- a/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameVisitor.cs +++ b/src/Luban.Job.Common/Source/TypeVisitors/TypescriptDefineTypeNameVisitor.cs @@ -2,141 +2,13 @@ using Luban.Job.Common.Types; namespace Luban.Job.Common.TypeVisitors { - public class TypescriptDefineTypeNameVisitor : ITypeFuncVisitor + public class TypescriptDefineTypeNameVisitor : DecoratorFuncVisitor { public static TypescriptDefineTypeNameVisitor Ins { get; } = new TypescriptDefineTypeNameVisitor(); - public string Accept(TBool type) + public override string DoAccept(TType type) { - return "boolean"; - } - - public string Accept(TByte type) - { - return "number"; - } - - public string Accept(TShort type) - { - return "number"; - } - - public string Accept(TFshort type) - { - return "number"; - } - - public string Accept(TInt type) - { - return "number"; - } - - public string Accept(TFint type) - { - return "number"; - } - - public string Accept(TLong type) - { - return type.IsBigInt ? "bigint" : "number"; - } - - public string Accept(TFlong type) - { - return "bigint"; - } - - public string Accept(TFloat type) - { - return "number"; - } - - public string Accept(TDouble type) - { - return "number"; - } - - public string Accept(TEnum type) - { - return type.DefineEnum.FullName; - } - - public string Accept(TString type) - { - return "string"; - } - - public string Accept(TBytes type) - { - return "Uint8Array"; - } - - public string Accept(TText type) - { - return "string"; - } - - public string Accept(TBean type) - { - return type.Bean.FullName; - } - - - private string GetArrayType(TType elementType) - { - switch (elementType) - { - case TByte _: return "Uint8Array"; - case TShort _: - case TFshort _: return "Int16Array"; - case TInt _: - case TFint _: return "Int32Array"; - case TLong _: - case TFlong _: return "Int64Array"; - case TFloat _: return "Float32Array"; - case TDouble _: return "Float64Array"; - default: return $"{elementType.Apply(this)}[]"; - } - } - - public virtual string Accept(TArray type) - { - return GetArrayType(type.ElementType); - } - - public virtual string Accept(TList type) - { - return $"{type.ElementType.Apply(this)}[]"; - } - - public virtual string Accept(TSet type) - { - return $"Set<{type.ElementType.Apply(this)}>"; - } - - public virtual string Accept(TMap type) - { - return $"Map<{type.KeyType.Apply(this)}, {type.ValueType.Apply(this)}>"; - } - - public string Accept(TVector2 type) - { - return "Vector2"; - } - - public string Accept(TVector3 type) - { - return "Vector3"; - } - - public string Accept(TVector4 type) - { - return "Vector4"; - } - - public string Accept(TDateTime type) - { - return "number"; + return type.IsNullable ? $"{type.Apply(TypescriptDefineTypeNameUnderlyingVisitor.Ins)}|undefined" : type.Apply(TypescriptDefineTypeNameUnderlyingVisitor.Ins); } } } diff --git a/src/Luban.Job.Db/Source/JobController.cs b/src/Luban.Job.Db/Source/JobController.cs index 948a5e7..9859214 100644 --- a/src/Luban.Job.Db/Source/JobController.cs +++ b/src/Luban.Job.Db/Source/JobController.cs @@ -47,7 +47,7 @@ namespace Luban.Job.Db { return false; } - if (!options.ValidateTypescriptRequire(options.GenType, ref errMsg)) + if (options.GenType.Contains("typescript") && !options.ValidateTypescriptRequire(options.GenType, ref errMsg)) { return false; } diff --git a/src/Luban.Job.Proto/Source/JobController.cs b/src/Luban.Job.Proto/Source/JobController.cs index f87ffa2..ceef506 100644 --- a/src/Luban.Job.Proto/Source/JobController.cs +++ b/src/Luban.Job.Proto/Source/JobController.cs @@ -54,7 +54,7 @@ namespace Luban.Job.Proto { return false; } - if (!options.ValidateTypescriptRequire(options.GenType, ref errMsg)) + if (options.GenType.Contains("typescript") && !options.ValidateTypescriptRequire(options.GenType, ref errMsg)) { return false; } diff --git a/src/Luban.Server/Luban.Server.csproj b/src/Luban.Server/Luban.Server.csproj index 3348f16..7bcc7fb 100644 --- a/src/Luban.Server/Luban.Server.csproj +++ b/src/Luban.Server/Luban.Server.csproj @@ -187,6 +187,15 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/src/Luban.Server/Templates/config/typescript_editor_json/bean.tpl b/src/Luban.Server/Templates/config/typescript_editor_json/bean.tpl new file mode 100644 index 0000000..69ecfc8 --- /dev/null +++ b/src/Luban.Server/Templates/config/typescript_editor_json/bean.tpl @@ -0,0 +1,50 @@ + +{{ + name = x.name + parent_def_type = x.parent_def_type + export_fields = x.export_fields + hierarchy_export_fields = x.hierarchy_export_fields +}} + +{{x.typescript_namespace_begin}} +{{~if x.comment != '' ~}} +/** + * {{x.comment}} + */ +{{~end~}} +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}}{ + switch (_json_.__type__) { + {{~ for child in x.hierarchy_not_abstract_children~}} + case '{{child.name}}': return new {{child.full_name}}(_json_) + {{~end~}} + default: throw new Error() + } + } +{{~end~}} + + constructor(_json_: any) { + {{~if parent_def_type~}} + super(_json_) + {{~end~}} + {{~ for field in export_fields ~}} + {{~if !field.ctype.is_nullable~}} + if (_json_.{{field.name}} === undefined) { throw new Error() } + {{~end~}} + {{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}} + {{~end~}} + } + + {{~ for field in export_fields ~}} +{{~if field.comment != '' ~}} + /** + * {{field.comment}} + */ +{{~end~}} + {{field.ts_style_name}}: {{ts_define_type field.ctype}} + {{~end~}} + +} + +{{x.typescript_namespace_end}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/typescript_editor_json/enum.tpl b/src/Luban.Server/Templates/config/typescript_editor_json/enum.tpl new file mode 100644 index 0000000..c644b10 --- /dev/null +++ b/src/Luban.Server/Templates/config/typescript_editor_json/enum.tpl @@ -0,0 +1,25 @@ + +{{x.typescript_namespace_begin}} +{{~if x.comment != '' ~}} +/** + * {{x.comment}} + */ +{{~end~}} +export class {{x.name}} { + readonly id: number + readonly name: string + readonly alias: string + readonly comment: string + constructor(id: number, name: string, alias: string, comment: string) { + this.id = id + this.name = name + this.alias= alias + this.comment = comment + } + + {{~for item in x.items ~}} + static readonly {{item.name}} = new {{x.name}}({{item.int_value}}, `{{item.name}}`, `{{item.alias}}`, `{{item.comment}}`) + {{~end~}} +} + +{{x.typescript_namespace_end}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/typescript_editor_json/table.tpl b/src/Luban.Server/Templates/config/typescript_editor_json/table.tpl new file mode 100644 index 0000000..cca8a05 --- /dev/null +++ b/src/Luban.Server/Templates/config/typescript_editor_json/table.tpl @@ -0,0 +1,54 @@ +{{ + name = x.name + key_type = x.key_ttype + key_type1 = x.key_ttype1 + key_type2 = x.key_ttype2 + value_type = x.value_ttype +}} +{{x.typescript_namespace_begin}} +{{~if x.comment != '' ~}} +/** + * {{x.comment}} + */ +{{~end~}} +export class {{name}}{ + {{~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 = [] + for(var _json2_ of _json_) { + 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) + } + } + + 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}} | undefined { return this._dataMap.get(key); } + + {{~else~}} + + 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; } + + {{~ for field in value_type.bean.hierarchy_export_fields ~}} +{{~if field.comment != '' ~}} + /** + * {{field.comment}} + */ +{{~end~}} + get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; } + {{~end~}} + {{end}} +} +{{x.typescript_namespace_end}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/typescript_json/bean.tpl b/src/Luban.Server/Templates/config/typescript_json/bean.tpl index e2e02b1..7ce0d1e 100644 --- a/src/Luban.Server/Templates/config/typescript_json/bean.tpl +++ b/src/Luban.Server/Templates/config/typescript_json/bean.tpl @@ -12,9 +12,9 @@ * {{x.comment}} */ {{~end~}} -export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} { +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__) { {{~ for child in x.hierarchy_not_abstract_children~}} case '{{child.name}}': return new {{child.full_name}}(_json_) @@ -30,7 +30,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def {{~end~}} {{~ for field in export_fields ~}} {{~if !field.ctype.is_nullable~}} - if (_json_.{{field.name}} == undefined) { throw new Error() } + if (_json_.{{field.name}} === undefined) { throw new Error() } {{~end~}} {{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}} {{~end~}} @@ -42,7 +42,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def * {{field.comment}} */ {{~end~}} - readonly {{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}} + readonly {{field.ts_style_name}}: {{ts_define_type field.ctype}} {{~if field.gen_ref~}} {{field.ts_ref_validator_define}} {{~end~}} diff --git a/src/Luban.Server/Templates/config/typescript_json/vectors.tpl b/src/Luban.Server/Templates/config/typescript_json/vectors.tpl index 5b0db58..f3ed8be 100644 --- a/src/Luban.Server/Templates/config/typescript_json/vectors.tpl +++ b/src/Luban.Server/Templates/config/typescript_json/vectors.tpl @@ -1,8 +1,8 @@ export class Vector2 { static deserializeFromJson(json: any): Vector2 { - let x = json['x'] - let y = json['y'] + let x = json.x + let y = json.y if (x == null || y == null) { throw new Error() } @@ -19,9 +19,9 @@ export class Vector2 { export class Vector3 { static deserializeFromJson(json: any): Vector3 { - let x = json['x'] - let y = json['y'] - let z = json['z'] + let x = json.x + let y = json.y + let z = json.z if (x == null || y == null || z == null) { throw new Error() } @@ -41,10 +41,10 @@ export class Vector3 { export class Vector4 { static deserializeFromJson(json: any): Vector4 { - let x = json['x'] - let y = json['y'] - let z = json['z'] - let w = json['w'] + let x = json.x + let y = json.y + let z = json.z + let w = json.w if (x == null || y == null || z == null || w == null) { throw new Error() }