comparison Resources/CodeGeneration/template.in.ts @ 495:6405435480ae bgo-commands-codegen

Fixed template to add dump capabilities + started work on an integrated TS/WASM test
author bgo-osimis
date Sat, 23 Feb 2019 14:14:32 +0100
parents fc17251477d6
children ce49eae4c887
comparison
equal deleted inserted replaced
494:fc17251477d6 495:6405435480ae
48 {% for key in struct['fields']%}{% if NeedsTsConstruction(enums,CanonToTs(struct['fields'][key])) %} this.{{key}} = new {{CanonToTs(struct['fields'][key])}}(); 48 {% for key in struct['fields']%}{% if NeedsTsConstruction(enums,CanonToTs(struct['fields'][key])) %} this.{{key}} = new {{CanonToTs(struct['fields'][key])}}();
49 {% endif %}{% endfor %} } 49 {% endif %}{% endfor %} }
50 50
51 public StoneSerialize(): string { 51 public StoneSerialize(): string {
52 let container: object = {}; 52 let container: object = {};
53 container['type'] = '{{rWholootName}}.{{struct['name']}}'; 53 container['type'] = '{{rootName}}.{{struct['name']}}';
54 container['value'] = this; 54 container['value'] = this;
55 return JSON.stringify(container); 55 return JSON.stringify(container);
56 } 56 }
57 57
58 public static StoneDeserialize(valueStr: string) : {{struct['name']}} 58 public static StoneDeserialize(valueStr: string) : {{struct['name']}}
64 } 64 }
65 } 65 }
66 66
67 {% endfor %} 67 {% endfor %}
68 68
69 export interface IDispatcher { 69 export interface IHandler {
70 {% for struct in structs%} Handle{{struct['name']}}(value: {{struct['name']}}): boolean; 70 {% for struct in structs%} Handle{{struct['name']}}(value: {{struct['name']}}): boolean;
71 {% endfor %} 71 {% endfor %}
72 }; 72 };
73 73
74 /** Service function for StoneDispatchToHandler */ 74 /** Service function for StoneDispatchToHandler */
75 export function StoneDispatchJsonToHandler( 75 export function StoneDispatchJsonToHandler(
76 jsonValue: any, dispatcher: IDispatcher): boolean 76 jsonValue: any, handler: IHandler): boolean
77 { 77 {
78 StoneCheckSerializedValueTypeGeneric(jsonValue); 78 StoneCheckSerializedValueTypeGeneric(jsonValue);
79 let type: string = jsonValue["type"]; 79 let type: string = jsonValue["type"];
80 if (type == "") 80 if (type == "")
81 { 81 {
83 throw new Error("Caught empty type while dispatching"); 83 throw new Error("Caught empty type while dispatching");
84 } 84 }
85 {% for struct in structs%} else if (type == "{{rootName}}.{{struct['name']}}") 85 {% for struct in structs%} else if (type == "{{rootName}}.{{struct['name']}}")
86 { 86 {
87 let value = jsonValue["value"] as {{struct['name']}}; 87 let value = jsonValue["value"] as {{struct['name']}};
88 return dispatcher.Handle{{struct['name']}}(value); 88 return handler.Handle{{struct['name']}}(value);
89 } 89 }
90 {% endfor %} 90 {% endfor %}
91 else 91 else
92 { 92 {
93 return false; 93 return false;
94 } 94 }
95 } 95 }
96 96
97 /** Takes a serialized type and passes this to the dispatcher */ 97 /** Takes a serialized type and passes this to the handler */
98 export function StoneDispatchToHandler( 98 export function StoneDispatchToHandler(
99 strValue: string, dispatcher: IDispatcher): boolean 99 strValue: string, handler: IHandler): boolean
100 { 100 {
101 // console.//log("+------------------------------------------------+"); 101 // console.//log("+------------------------------------------------+");
102 // console.//log("| StoneDispatchToHandler |"); 102 // console.//log("| StoneDispatchToHandler |");
103 // console.//log("+------------------------------------------------+"); 103 // console.//log("+------------------------------------------------+");
104 // console.//log("strValue = "); 104 // console.//log("strValue = ");
105 // console.//log(strValue); 105 // console.//log(strValue);
106 let jsonValue: any = JSON.parse(strValue) 106 let jsonValue: any = JSON.parse(strValue)
107 return StoneDispatchJsonToHandler(jsonValue, dispatcher); 107 return StoneDispatchJsonToHandler(jsonValue, handler);
108 } 108 }