export-table-pulgin-csharp 1.0.31 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,321 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ExportPlugins = exports.ExportPlugin = exports.export_stuff = void 0;
27
- const export_table_lib_1 = require("export-table-lib");
28
- const fs = __importStar(require("fs-extra"));
29
- function export_stuff(paras) {
30
- let { datas, fields, inject, name, objects, packagename, tables, xxtea, } = paras;
31
- let firstLetterUpper = function (str) {
32
- return str.charAt(0).toUpperCase() + str.slice(1);
33
- };
34
- let firstLetterLower = function (str) {
35
- return str.charAt(0).toLowerCase() + str.slice(1);
36
- };
37
- let convMemberName = function (str) {
38
- return str.split("_").map(s => firstLetterUpper(s)).join("");
39
- };
40
- let convVarName = firstLetterLower;
41
- let RowClass = firstLetterUpper(name);
42
- let initFunc = name + "Init";
43
- let mapfield = fields.find(a => a.type == "key"); //如果是map,则生成对应的map
44
- let mapName = name + "Map";
45
- let getFieldType = function (f) {
46
- let t = f.type;
47
- if (t == "object") {
48
- throw new Error("invalid type <object>");
49
- }
50
- else if (t == "object[]") {
51
- throw new Error("invalid type <object[]>");
52
- }
53
- else if (t == "number") {
54
- return "double";
55
- }
56
- else if (t == "number[]") {
57
- return "double[]";
58
- }
59
- else if (t == "uid") {
60
- return "int";
61
- }
62
- else if (t == "bool") {
63
- return "bool";
64
- }
65
- else if (t == "bool[]") {
66
- return "bool[]";
67
- }
68
- else if (t == "string") {
69
- return "string";
70
- }
71
- else if (t == "string[]") {
72
- return "string[]";
73
- }
74
- else if (t == "fk") {
75
- return "int";
76
- }
77
- else if (t == "fk[]") {
78
- return "int[]";
79
- }
80
- else if (t == "any") {
81
- console.log(f);
82
- throw new Error(`invalid type ${f.name}:<any>`);
83
- }
84
- else if (t == "key") {
85
- return "string";
86
- }
87
- else {
88
- throw new Error(`invalid type ${f.name}:<unkown>`);
89
- }
90
- return t;
91
- };
92
- let getFkFieldType = function (field) {
93
- return tables.find(a => a.name == field.fkTableName).fields.find(a => a.name == field.fkFieldName).type;
94
- };
95
- const genValue = (value, f) => {
96
- let t = f.type;
97
- if (t == "object") {
98
- throw new Error("invalid type <object>");
99
- }
100
- else if (t == "object[]") {
101
- throw new Error("invalid type <object[]>");
102
- }
103
- else if (t == "number") {
104
- return `${value}`;
105
- }
106
- else if (t == "number[]") {
107
- let values = value;
108
- return `new double[]{${values.join(", ")}}`;
109
- }
110
- else if (t == "uid") {
111
- return `${value}`;
112
- }
113
- else if (t == "bool") {
114
- return `${value}`;
115
- }
116
- else if (t == "bool[]") {
117
- let values = value;
118
- return `new bool[]{${values.join(", ")}}`;
119
- }
120
- else if (t == "string") {
121
- return `"${value}"`;
122
- }
123
- else if (t == "string[]") {
124
- let values = value;
125
- return `new string[]{${values.map(v => `"${v}"`).join(", ")}}`;
126
- }
127
- else if (t == "fk") {
128
- return `${value}`;
129
- }
130
- else if (t == "fk[]") {
131
- let values = value;
132
- return `new int[]{${values.join(", ")}}`;
133
- }
134
- else if (t == "any") {
135
- console.log(f);
136
- throw new Error(`invalid type ${f.name}:<any>`);
137
- }
138
- else if (t == "key") {
139
- return `${value}`;
140
- }
141
- throw new Error(`invalid type ${f.name}:<unkown>`);
142
- };
143
- const getTitle = (v) => {
144
- return v.describe.split("\n")[0];
145
- };
146
- const getDescripts = (v) => {
147
- return v.describe.split("\n");
148
- };
149
- let temp = `
150
- using System.Collections.Generic;
151
- using System.Linq;
152
-
153
- namespace MEEC.ExportedConfigs{
154
- public class ${RowClass} {
155
-
156
- public static List<${RowClass}> Configs = new List<${RowClass}>()
157
- {
158
- ${(0, export_table_lib_1.foreach)(datas, data => ` new ${RowClass}(${(0, export_table_lib_1.st)(() => fields.map((f, index) => genValue(data[index], f)).join(", "))}),`)}
159
- };
160
-
161
- public ${RowClass}() { }
162
- public ${RowClass}(${(0, export_table_lib_1.st)(() => fields.map(f => `${getFieldType(f)} ${convVarName(f.name)}`).join(", "))})
163
- {
164
- ${(0, export_table_lib_1.foreach)(fields, f => ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`)}
165
- }
166
-
167
- public virtual ${RowClass} MergeFrom(${RowClass} source)
168
- {
169
- ${(0, export_table_lib_1.foreach)(fields, f => ` this.${convMemberName(f.name)} = source.${convMemberName(f.name)};`)}
170
- return this;
171
- }
172
-
173
- public virtual ${RowClass} Clone()
174
- {
175
- var config = new ${RowClass}();
176
- config.MergeFrom(this);
177
- return config;
178
- }
179
-
180
- ${(0, export_table_lib_1.cmm)( /**生成字段 */)}
181
- ${(0, export_table_lib_1.foreach)(fields, f => `
182
- /// <summary>
183
- ${(0, export_table_lib_1.foreach)(getDescripts(f), line => ` /// ${line}`)}
184
- /// </summary>
185
- public ${getFieldType(f)} ${convMemberName(f.name)};`)}
186
-
187
- ${(0, export_table_lib_1.cmm)( /**生成get字段 */)}
188
- #region get字段
189
- ${(0, export_table_lib_1.foreach)(fields, f => {
190
- if (f.nameOrigin != f.name) {
191
- return ` public ${getFieldType(f)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`;
192
- }
193
- else {
194
- return "";
195
- }
196
- })}
197
- #endregion
198
-
199
- #region uid map
200
- ${(0, export_table_lib_1.foreach)(fields, f => {
201
- if (f.isUnique) {
202
- return `
203
- protected static Dictionary<${getFieldType(f)}, ${RowClass}> _tempDictBy${convMemberName(f.name)};
204
- public static ${RowClass} GetConfigBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
205
- {
206
- if (_tempDictBy${convMemberName(f.name)} == null)
207
- {
208
- _tempDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}>();
209
- Configs.ForEach(c =>
210
- {
211
- _tempDictBy${convMemberName(f.name)}.Add(c.${convMemberName(f.name)}, c);
212
- });
213
- }
214
- return _tempDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
215
- }
216
- `;
217
- }
218
- else if (f.type == "number" || f.type == "string") {
219
- return `
220
- protected static Dictionary<${getFieldType(f)}, ${RowClass}[]> _tempRecordsDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}[]>();
221
- public static ${RowClass}[] GetConfigsBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
222
- {
223
- if (_tempRecordsDictBy${convMemberName(f.name)}.ContainsKey(${convMemberName(f.name)}))
224
- {
225
- return _tempRecordsDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
226
- }
227
- else
228
- {
229
- var records = Configs.Where(c => c.${convMemberName(f.name)} == ${convMemberName(f.name)}).ToArray();
230
- _tempRecordsDictBy${convMemberName(f.name)}.Add(${convMemberName(f.name)}, records);
231
- return records;
232
- }
233
- }
234
- `;
235
- }
236
- else {
237
- return "";
238
- }
239
- })}
240
-
241
- #endregion uid map
242
-
243
- #region 生成fk.get/set
244
- ${(0, export_table_lib_1.foreach)(fields, f => `
245
- ${(0, export_table_lib_1.iff)(f.type == "fk", () => `
246
- ${(0, export_table_lib_1.iff)(getFkFieldType(f).toLowerCase() != "uid", () => `
247
- protected ${convMemberName(f.fkTableName)}[] _fk${convMemberName(f.name)}=null;
248
- /**
249
- * ${f.describe}
250
- **/
251
- public virtual ${convMemberName(f.fkTableName)}[] ${convMemberName(f.name)}DataList{
252
- get{
253
- if(this._fk${convMemberName(f.name)}==null){
254
- if(null==this.${convMemberName(f.name)}){
255
- this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName)}[0];
256
- }else{
257
- this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName)}.FindAll(a=>a.${convMemberName(f.fkFieldName)}!=null && this.${convMemberName(f.name)}==a.${convMemberName(f.fkFieldName)}).ToArray();
258
- }
259
- }
260
- return this._fk${convMemberName(f.name)};
261
- }
262
- }
263
- `).else(() => `
264
- protected ${convMemberName(f.fkTableName)} _fk${convMemberName(f.name)}=null;
265
- /**
266
- * ${f.describe}
267
- **/
268
- public virtual ${convMemberName(f.fkTableName)} ${convMemberName(f.name)}Data{
269
- get{
270
- if(this._fk${convMemberName(f.name)}==null){
271
- this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName)}.Find(a=>a.${convMemberName(f.fkFieldName)}==this.${convMemberName(f.name)});
272
- }
273
- return this._fk${convMemberName(f.name)};
274
- }
275
- }
276
- `)}
277
- `)}
278
- ${(0, export_table_lib_1.iff)(f.type == "fk[]", () => `
279
- protected ${convMemberName(f.fkTableName)}[] _fk${convMemberName(f.name)}=null;
280
- /**
281
- * ${f.describe}
282
- **/
283
- public virtual ${convMemberName(f.fkTableName)}[] ${convMemberName(f.name)}DataList{
284
- get{
285
- if(this._fk${convMemberName(f.name)}==null){
286
- if(null==this.${convMemberName(f.name)}){
287
- this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName)}[0];
288
- }else{
289
- this._fk${convMemberName(f.name)}=MEEC.ExportedConfigs.${convMemberName(f.fkTableName)}.Configs.FindAll(a=>a.${convMemberName(f.fkFieldName)}!=null && this.${convMemberName(f.name)}!.Contains(a.${convMemberName(f.fkFieldName)})).ToArray();
290
- }
291
- }
292
- return this._fk${convMemberName(f.name)};
293
- }
294
- }
295
- `)}
296
- `)}
297
- #endregion 生成fk.get/set
298
- }
299
- }
300
- `;
301
- return temp;
302
- }
303
- exports.export_stuff = export_stuff;
304
- class ExportPlugin extends export_table_lib_1.PluginBase {
305
- constructor() {
306
- super(...arguments);
307
- this.name = "csharp";
308
- this.tags = ["cs"];
309
- }
310
- handleSheet(paras) {
311
- let content = export_stuff(paras);
312
- if (content != null) {
313
- fs.outputFileSync(paras.outFilePath.fullPath, content, "utf-8");
314
- }
315
- return content;
316
- }
317
- }
318
- exports.ExportPlugin = ExportPlugin;
3
+ exports.ExportPlugins = void 0;
4
+ const ExportCSPlugin_1 = require("./ExportCSPlugin");
5
+ const ExportUnityCSJsonPlugin_1 = require("./ExportUnityCSJsonPlugin");
319
6
  exports.ExportPlugins = [
320
- new ExportPlugin(),
7
+ new ExportCSPlugin_1.ExportPlugin(),
8
+ new ExportUnityCSJsonPlugin_1.ExportUJsonPlugin(),
321
9
  ];
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "export-table-pulgin-csharp",
3
- "version": "1.0.31",
3
+ "version": "1.0.34",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "pub": "npm-publish --token=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"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -0,0 +1,295 @@
1
+
2
+ import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, iff } from "export-table-lib"
3
+ import * as fs from "fs-extra"
4
+
5
+ export function export_stuff(paras: HandleSheetParams): string | null {
6
+ let {
7
+ datas,
8
+ fields,
9
+ inject,
10
+ name,
11
+ objects,
12
+ packagename,
13
+ tables,
14
+ xxtea,
15
+ } = paras;
16
+
17
+ let firstLetterUpper = function (str: string) {
18
+ return str.charAt(0).toUpperCase() + str.slice(1);
19
+ };
20
+ let firstLetterLower = function (str: string) {
21
+ return str.charAt(0).toLowerCase() + str.slice(1);
22
+ };
23
+ let convMemberName = function (str: string) {
24
+ return str.split("_").map(s => firstLetterUpper(s)).join("")
25
+ }
26
+ let convVarName = firstLetterLower
27
+
28
+ let RowClass = firstLetterUpper(name)
29
+ let initFunc = name + "Init"
30
+ let mapfield = fields.find(a => a.type == "key")//如果是map,则生成对应的map
31
+ let mapName = name + "Map"
32
+
33
+ let getFieldType = function (f: Field) {
34
+ let t = f.type
35
+ if (t == "object") {
36
+ throw new Error("invalid type <object>")
37
+ } else if (t == "object[]") {
38
+ throw new Error("invalid type <object[]>")
39
+ } else if (t == "number") {
40
+ return "double";
41
+ } else if (t == "number[]") {
42
+ return "double[]";
43
+ } else if (t == "uid") {
44
+ return "int";
45
+ } else if (t == "bool") {
46
+ return "bool";
47
+ } else if (t == "bool[]") {
48
+ return "bool[]";
49
+ } else if (t == "string") {
50
+ return "string";
51
+ } else if (t == "string[]") {
52
+ return "string[]";
53
+ } else if (t == "fk") {
54
+ return "int";
55
+ } else if (t == "fk[]") {
56
+ return "int[]";
57
+ } else if (t == "any") {
58
+ console.log(f)
59
+ throw new Error(`invalid type ${f.name}:<any>`)
60
+ } else if (t == "key") {
61
+ return "string";
62
+ } else {
63
+ throw new Error(`invalid type ${f.name}:<unkown>`)
64
+ }
65
+ return t;
66
+ }
67
+
68
+ let getFkFieldType = function (field: Field) {
69
+ return tables.find(a => a.name == field.fkTableName)!.fields!.find(a => a.name == field.fkFieldName)!.type
70
+ }
71
+
72
+ const genValue = (value: any, f: Field): string => {
73
+ let t = f.type
74
+ if (t == "object") {
75
+ throw new Error("invalid type <object>")
76
+ } else if (t == "object[]") {
77
+ throw new Error("invalid type <object[]>")
78
+ } else if (t == "number") {
79
+ return `${value}`
80
+ } else if (t == "number[]") {
81
+ let values = value as number[]
82
+ return `new double[]{${values.join(", ")}}`
83
+ } else if (t == "uid") {
84
+ return `${value}`
85
+ } else if (t == "bool") {
86
+ return `${value}`
87
+ } else if (t == "bool[]") {
88
+ let values = value as boolean[]
89
+ return `new bool[]{${values.join(", ")}}`
90
+ } else if (t == "string") {
91
+ // return `"${value}"`
92
+ return JSON.stringify(value)
93
+ } else if (t == "string[]") {
94
+ let values = value as string[]
95
+ return `new string[]{${values.map(v => JSON.stringify(v)).join(", ")}}`
96
+ } else if (t == "fk") {
97
+ return `${value}`
98
+ } else if (t == "fk[]") {
99
+ let values = value as number[]
100
+ return `new int[]{${values.join(", ")}}`
101
+ } else if (t == "any") {
102
+ console.log(f)
103
+ throw new Error(`invalid type ${f.name}:<any>`)
104
+ } else if (t == "key") {
105
+ return `${value}`
106
+ }
107
+
108
+ throw new Error(`invalid type ${f.name}:<unkown>`)
109
+ }
110
+
111
+ const getTitle = (v: Field) => {
112
+ return v.describe.split("\n")[0]
113
+ }
114
+
115
+ const getDescripts = (v: Field) => {
116
+ return v.describe.split("\n")
117
+ }
118
+
119
+ let temp = `
120
+ using System.Collections.Generic;
121
+ using System.Linq;
122
+
123
+ namespace MEEC.ExportedConfigs{
124
+ public class ${RowClass} {
125
+
126
+ public static List<${RowClass}> Configs = new List<${RowClass}>()
127
+ {
128
+ ${foreach(datas, data =>
129
+ ` new ${RowClass}(${st(() => fields.map((f, index) => genValue(data[index], f)).join(", "))}),`
130
+ )}
131
+ };
132
+
133
+ public ${RowClass}() { }
134
+ public ${RowClass}(${st(() => fields.map(f => `${getFieldType(f)} ${convVarName(f.name)}`).join(", "))})
135
+ {
136
+ ${foreach(fields, f =>
137
+ ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`
138
+ )}
139
+ }
140
+
141
+ public virtual ${RowClass} MergeFrom(${RowClass} source)
142
+ {
143
+ ${foreach(fields, f =>
144
+ ` this.${convMemberName(f.name)} = source.${convMemberName(f.name)};`
145
+ )}
146
+ return this;
147
+ }
148
+
149
+ public virtual ${RowClass} Clone()
150
+ {
151
+ var config = new ${RowClass}();
152
+ config.MergeFrom(this);
153
+ return config;
154
+ }
155
+
156
+ ${cmm(/**生成字段 */)}
157
+ ${foreach(fields, f => `
158
+ /// <summary>
159
+ ${foreach(getDescripts(f), line =>
160
+ ` /// ${line}`
161
+ )}
162
+ /// </summary>
163
+ public ${getFieldType(f)} ${convMemberName(f.name)};`
164
+ )}
165
+
166
+ ${cmm(/**生成get字段 */)}
167
+ #region get字段
168
+ ${foreach(fields, f => {
169
+ if (f.nameOrigin != f.name) {
170
+ return ` public ${getFieldType(f)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`
171
+ } else {
172
+ return ""
173
+ }
174
+ }
175
+ )}
176
+ #endregion
177
+
178
+ #region uid map
179
+ ${foreach(fields, f => {
180
+ if (f.isUnique) {
181
+ return `
182
+ protected static Dictionary<${getFieldType(f)}, ${RowClass}> _tempDictBy${convMemberName(f.name)};
183
+ public static ${RowClass} GetConfigBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
184
+ {
185
+ if (_tempDictBy${convMemberName(f.name)} == null)
186
+ {
187
+ _tempDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}>();
188
+ Configs.ForEach(c =>
189
+ {
190
+ _tempDictBy${convMemberName(f.name)}.Add(c.${convMemberName(f.name)}, c);
191
+ });
192
+ }
193
+ return _tempDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
194
+ }
195
+ `
196
+ } else if (f.type == "number" || f.type == "string") {
197
+ return `
198
+ protected static Dictionary<${getFieldType(f)}, ${RowClass}[]> _tempRecordsDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}[]>();
199
+ public static ${RowClass}[] GetConfigsBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
200
+ {
201
+ if (_tempRecordsDictBy${convMemberName(f.name)}.ContainsKey(${convMemberName(f.name)}))
202
+ {
203
+ return _tempRecordsDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
204
+ }
205
+ else
206
+ {
207
+ var records = Configs.Where(c => c.${convMemberName(f.name)} == ${convMemberName(f.name)}).ToArray();
208
+ _tempRecordsDictBy${convMemberName(f.name)}.Add(${convMemberName(f.name)}, records);
209
+ return records;
210
+ }
211
+ }
212
+ `
213
+ } else {
214
+ return ""
215
+ }
216
+ }
217
+ )}
218
+
219
+ #endregion uid map
220
+
221
+ #region 生成fk.get/set
222
+ ${foreach(fields, f => `
223
+ ${iff(f.type == "fk", () => `
224
+ ${iff(getFkFieldType(f).toLowerCase() != "uid", () => `
225
+ protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
226
+ /**
227
+ * ${f.describe}
228
+ **/
229
+ public virtual ${convMemberName(f.fkTableName!)}[] ${convMemberName(f.name)}DataList{
230
+ get{
231
+ if(this._fk${convMemberName(f.name)}==null){
232
+ if(null==this.${convMemberName(f.name)}){
233
+ this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName!)}[0];
234
+ }else{
235
+ this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName!)}.FindAll(a=>a.${convMemberName(f.fkFieldName!)}!=null && this.${convMemberName(f.name)}==a.${convMemberName(f.fkFieldName!)}).ToArray();
236
+ }
237
+ }
238
+ return this._fk${convMemberName(f.name)};
239
+ }
240
+ }
241
+ `).else(() => `
242
+ protected ${convMemberName(f.fkTableName!)} _fk${convMemberName(f.name)}=null;
243
+ /**
244
+ * ${f.describe}
245
+ **/
246
+ public virtual ${convMemberName(f.fkTableName!)} ${convMemberName(f.name)}Data{
247
+ get{
248
+ if(this._fk${convMemberName(f.name)}==null){
249
+ this._fk${convMemberName(f.name)}=${convMemberName(f.fkTableName!)}.Find(a=>a.${convMemberName(f.fkFieldName!)}==this.${convMemberName(f.name)});
250
+ }
251
+ return this._fk${convMemberName(f.name)};
252
+ }
253
+ }
254
+ `)}
255
+ `)}
256
+ ${iff(f.type == "fk[]", () => `
257
+ protected ${convMemberName(f.fkTableName!)}[] _fk${convMemberName(f.name)}=null;
258
+ /**
259
+ * ${f.describe}
260
+ **/
261
+ public virtual ${convMemberName(f.fkTableName!)}[] ${convMemberName(f.name)}DataList{
262
+ get{
263
+ if(this._fk${convMemberName(f.name)}==null){
264
+ if(null==this.${convMemberName(f.name)}){
265
+ this._fk${convMemberName(f.name)} = new ${convMemberName(f.fkTableName!)}[0];
266
+ }else{
267
+ this._fk${convMemberName(f.name)}=MEEC.ExportedConfigs.${convMemberName(f.fkTableName!)}.Configs.FindAll(a=>a.${convMemberName(f.fkFieldName!)}!=null && this.${convMemberName(f.name)}!.Contains(a.${convMemberName(f.fkFieldName!)})).ToArray();
268
+ }
269
+ }
270
+ return this._fk${convMemberName(f.name)};
271
+ }
272
+ }
273
+ `)}
274
+ `)}
275
+ #endregion 生成fk.get/set
276
+ }
277
+ }
278
+ `
279
+
280
+ return temp
281
+
282
+ }
283
+
284
+ export class ExportPlugin extends PluginBase {
285
+ name = "csharp"
286
+ tags: string[] = ["cs"]
287
+
288
+ handleSheet(paras: HandleSheetParams) {
289
+ let content = export_stuff(paras)
290
+ if (content != null) {
291
+ fs.outputFileSync(paras.outFilePath.fullPath, content, "utf-8")
292
+ }
293
+ return content
294
+ }
295
+ }
@@ -0,0 +1,54 @@
1
+
2
+ import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, OutFilePath } from "export-table-lib"
3
+ import * as fs from "fs-extra"
4
+
5
+ export function export_stuff(paras: HandleSheetParams): string | null {
6
+ let {
7
+ datas,
8
+ fields,
9
+ name,
10
+ objects,
11
+ } = paras;
12
+
13
+ let mainField: Field = fields.find(f => f.type == "uid") ?? fields[0]
14
+ let jsonString = `
15
+ {
16
+ ${foreach(objects, obj => `
17
+ "${obj[mainField.name]}" : ${JSON.stringify(obj)}
18
+ `, ",\n")}
19
+ }
20
+ `
21
+ // !!!必须开头没有空格
22
+ let temp = `%YAML 1.1
23
+ %TAG !u! tag:unity3d.com,2011:
24
+ --- !u!114 &11400000
25
+ MonoBehaviour:
26
+ m_ObjectHideFlags: 0
27
+ m_CorrespondingSourceObject: {fileID: 0}
28
+ m_PrefabInstance: {fileID: 0}
29
+ m_PrefabAsset: {fileID: 0}
30
+ m_GameObject: {fileID: 0}
31
+ m_Enabled: 1
32
+ m_EditorHideFlags: 0
33
+ m_Script: {fileID: 11500000, guid: 496f60086c072a8479a6e0b948efb5e8, type: 3}
34
+ m_Name: ${name}
35
+ m_EditorClassIdentifier:
36
+ JsonText: ${JSON.stringify(jsonString)}
37
+ `
38
+ return temp
39
+
40
+ }
41
+
42
+ export class ExportUJsonPlugin extends PluginBase {
43
+ name = "ujson"
44
+ tags: string[] = ["ujson"]
45
+
46
+ handleSheet(paras: HandleSheetParams) {
47
+ let content = export_stuff(paras)
48
+ if (content != null) {
49
+ let savePath = new OutFilePath(paras.outPath, paras.table.name, ".asset").fullPath
50
+ fs.outputFileSync(savePath, content, "utf-8")
51
+ }
52
+ return content
53
+ }
54
+ }