export-table-pulgin-csharp 1.0.8 → 1.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "export-table-pulgin-csharp",
3
- "version": "1.0.8",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -28,7 +28,8 @@ export function export_stuff(paras: HandleSheetParams): string | null {
28
28
  let mapfield = fields.find(a => a.type == "key")//如果是map,则生成对应的map
29
29
  let mapName = name + "Map"
30
30
 
31
- let getFieldType = function (t: string) {
31
+ let getFieldType = function (f: Field) {
32
+ let t = f.type
32
33
  if (t == "object") {
33
34
  throw new Error("invalid type <object>")
34
35
  } else if (t == "object[]") {
@@ -52,16 +53,17 @@ export function export_stuff(paras: HandleSheetParams): string | null {
52
53
  } else if (t == "fk[]") {
53
54
  return "int[]";
54
55
  } else if (t == "any") {
55
- throw new Error("invalid type <any>")
56
+ throw new Error(`invalid type ${f.name}:<any>`)
56
57
  } else if (t == "key") {
57
58
  return "string";
58
59
  } else {
59
- throw new Error("invalid type <unkown>")
60
+ throw new Error(`invalid type ${f.name}:<unkown>`)
60
61
  }
61
62
  return t;
62
63
  }
63
64
 
64
- const genValue = (value: any, t: string): string => {
65
+ const genValue = (value: any, f: Field): string => {
66
+ let t = f.type
65
67
  if (t == "object") {
66
68
  throw new Error("invalid type <object>")
67
69
  } else if (t == "object[]") {
@@ -113,12 +115,12 @@ public class ${RowClass} {
113
115
  public static List<${RowClass}> Configs = new List<${RowClass}>()
114
116
  {
115
117
  ${foreach(datas, data =>
116
- ` new ${RowClass}(${st(() => fields.map((f, index) => genValue(data[index], f.type)).join(", "))}),`
118
+ ` new ${RowClass}(${st(() => fields.map((f, index) => genValue(data[index], f)).join(", "))}),`
117
119
  )}
118
120
  };
119
121
 
120
122
  public ${RowClass}() { }
121
- public ${RowClass}(${st(() => fields.map(f => `${getFieldType(f.type)} ${convVarName(f.name)}`).join(", "))})
123
+ public ${RowClass}(${st(() => fields.map(f => `${getFieldType(f)} ${convVarName(f.name)}`).join(", "))})
122
124
  {
123
125
  ${foreach(fields, f =>
124
126
  ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`
@@ -147,13 +149,13 @@ ${foreach(getDescripts(f), line =>
147
149
  ` /// ${line}`
148
150
  )}
149
151
  /// </summary>
150
- public ${getFieldType(f.type)} ${convMemberName(f.name)};`
152
+ public ${getFieldType(f)} ${convMemberName(f.name)};`
151
153
  )}
152
154
 
153
155
  ${cmm(/**生成get字段 */)}
154
156
  #region get字段
155
157
  ${foreach(fields, f =>
156
- ` public ${getFieldType(f.type)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`
158
+ ` public ${getFieldType(f)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`
157
159
  )}
158
160
  #endregion
159
161
  }
@@ -170,7 +172,7 @@ export class ExportPlugin extends PluginBase {
170
172
  handleSheet(paras: HandleSheetParams) {
171
173
  let content = export_stuff(paras)
172
174
  if (content != null) {
173
- fs.writeFileSync(paras.outFilePath, content, "utf-8")
175
+ fs.writeFileSync(paras.outFilePath.fullPath, content, "utf-8")
174
176
  }
175
177
  return content
176
178
  }
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { HandleSheetParams, PluginBase, HandleBatchParams } from "windy-quicktable";
2
- export declare function export_stuff(paras: HandleSheetParams): string | null;
3
- export declare class ExportPlugin extends PluginBase {
4
- name: string;
5
- tags: string[];
6
- handleSheet(paras: HandleSheetParams): string | null;
7
- handleBatch(paras: HandleBatchParams): void;
8
- }
9
- export declare const ExportPlugins: ExportPlugin[];
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGrH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA+JpE;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC3C,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAS;IAEvB,WAAW,CAAC,KAAK,EAAE,iBAAiB;IAOpC,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;CAG3C;AAED,eAAO,MAAM,aAAa,gBAEzB,CAAA"}
package/dist/index.js DELETED
@@ -1,201 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.ExportPlugins = exports.ExportPlugin = exports.export_stuff = void 0;
23
- const windy_quicktable_1 = require("windy-quicktable");
24
- const fs = __importStar(require("fs"));
25
- function export_stuff(paras) {
26
- let { datas, fields, inject, name, objects, packagename, tables, xxtea, } = paras;
27
- let firstLetterUpper = function (str) {
28
- return str.charAt(0).toUpperCase() + str.slice(1);
29
- };
30
- let firstLetterLower = function (str) {
31
- return str.charAt(0).toLowerCase() + str.slice(1);
32
- };
33
- let convMemberName = firstLetterUpper;
34
- let convVarName = firstLetterLower;
35
- let RowClass = firstLetterUpper(name);
36
- let initFunc = name + "Init";
37
- let mapfield = fields.find(a => a.type == "key"); //如果是map,则生成对应的map
38
- let mapName = name + "Map";
39
- let getFieldType = function (t) {
40
- if (t == "object") {
41
- throw new Error("invalid type <object>");
42
- }
43
- else if (t == "object[]") {
44
- throw new Error("invalid type <object[]>");
45
- }
46
- else if (t == "number") {
47
- return "double";
48
- }
49
- else if (t == "number[]") {
50
- return "double[]";
51
- }
52
- else if (t == "uid") {
53
- return "int";
54
- }
55
- else if (t == "bool") {
56
- return "bool";
57
- }
58
- else if (t == "bool[]") {
59
- return "bool[]";
60
- }
61
- else if (t == "string") {
62
- return "string";
63
- }
64
- else if (t == "string[]") {
65
- return "string[]";
66
- }
67
- else if (t == "fk") {
68
- return "int";
69
- }
70
- else if (t == "fk[]") {
71
- return "int[]";
72
- }
73
- else if (t == "any") {
74
- throw new Error("invalid type <any>");
75
- }
76
- else if (t == "key") {
77
- return "string";
78
- }
79
- else {
80
- throw new Error("invalid type <unkown>");
81
- }
82
- return t;
83
- };
84
- const genValue = (value, t) => {
85
- if (t == "object") {
86
- throw new Error("invalid type <object>");
87
- }
88
- else if (t == "object[]") {
89
- throw new Error("invalid type <object[]>");
90
- }
91
- else if (t == "number") {
92
- return `${value}`;
93
- }
94
- else if (t == "number[]") {
95
- let values = value;
96
- return `new double[]{${values.join(", ")}}`;
97
- }
98
- else if (t == "uid") {
99
- return `${value}`;
100
- }
101
- else if (t == "bool") {
102
- return `${value}`;
103
- }
104
- else if (t == "bool[]") {
105
- let values = value;
106
- return `new bool[]{${values.join(", ")}}`;
107
- }
108
- else if (t == "string") {
109
- return `"${value}"`;
110
- }
111
- else if (t == "string[]") {
112
- let values = value;
113
- return `new string[]{${values.map(v => `"${v}"`).join(", ")}}`;
114
- }
115
- else if (t == "fk") {
116
- return `${value}`;
117
- }
118
- else if (t == "fk[]") {
119
- let values = value;
120
- return `new int[]{${values.join(", ")}}`;
121
- }
122
- else if (t == "any") {
123
- throw new Error("invalid type <any>");
124
- }
125
- else if (t == "key") {
126
- return `${value}`;
127
- }
128
- throw new Error("invalid type <unkown>");
129
- };
130
- const getTitle = (v) => {
131
- return v.describe.split("\n")[0];
132
- };
133
- const getDescripts = (v) => {
134
- return v.describe.split("\n");
135
- };
136
- let temp = `
137
- using System.Collections.Generic;
138
-
139
- public class ${RowClass} {
140
-
141
- public static List<${RowClass}> Configs = new List<${RowClass}>()
142
- {
143
- ${(0, windy_quicktable_1.foreach)(datas, data => ` new ${RowClass}(${(0, windy_quicktable_1.st)(() => fields.map((f, index) => genValue(data[index], f.type)).join(", "))}),`)}
144
- };
145
-
146
- public ${RowClass}() { }
147
- public ${RowClass}(${(0, windy_quicktable_1.st)(() => fields.map(f => `${getFieldType(f.type)} ${convVarName(f.name)}`).join(", "))})
148
- {
149
- ${(0, windy_quicktable_1.foreach)(fields, f => ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`)}
150
- }
151
-
152
- public virtual ${RowClass} MergeFrom(${RowClass} source)
153
- {
154
- ${(0, windy_quicktable_1.foreach)(fields, f => ` this.${convMemberName(f.name)} = source.${convMemberName(f.name)};`)}
155
- return this;
156
- }
157
-
158
- public virtual ${RowClass} Clone()
159
- {
160
- var config = new ${RowClass}();
161
- config.MergeFrom(this);
162
- return config;
163
- }
164
-
165
- ${(0, windy_quicktable_1.cmm)( /**生成字段 */)}
166
- ${(0, windy_quicktable_1.foreach)(fields, f => `
167
- /// <summary>
168
- ${(0, windy_quicktable_1.foreach)(getDescripts(f), line => ` /// ${line}`)}
169
- /// </summary>
170
- public ${getFieldType(f.type)} ${convMemberName(f.name)};`)}
171
-
172
- ${(0, windy_quicktable_1.cmm)( /**生成get字段 */)}
173
- #region get字段
174
- ${(0, windy_quicktable_1.foreach)(fields, f => ` public ${getFieldType(f.type)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`)}
175
- #endregion
176
- }
177
- `;
178
- return temp;
179
- }
180
- exports.export_stuff = export_stuff;
181
- class ExportPlugin extends windy_quicktable_1.PluginBase {
182
- constructor() {
183
- super(...arguments);
184
- this.name = "csharp";
185
- this.tags = ["cs"];
186
- }
187
- handleSheet(paras) {
188
- let content = export_stuff(paras);
189
- if (content != null) {
190
- fs.writeFileSync(paras.outFilePath, content, "utf-8");
191
- }
192
- return content;
193
- }
194
- handleBatch(paras) {
195
- console.log("lkwej:", paras.workbookManager.dataTables.length);
196
- }
197
- }
198
- exports.ExportPlugin = ExportPlugin;
199
- exports.ExportPlugins = [
200
- new ExportPlugin(),
201
- ];
@@ -1,55 +0,0 @@
1
-
2
- using System.Collections.Generic;
3
-
4
- public class SceneConfig {
5
-
6
- public static List<SceneConfig> Configs = new List<SceneConfig>()
7
- {
8
- new SceneConfig(1, "第1章 格莫拉城", 1000),
9
- new SceneConfig(2, "第2章 纳皮尔乐园", 1200),
10
- };
11
-
12
- public SceneConfig() { }
13
- public SceneConfig(int uid, string sceneId, double outingBaseGold)
14
- {
15
- this.Uid = uid;
16
- this.SceneId = sceneId;
17
- this.OutingBaseGold = outingBaseGold;
18
- }
19
-
20
- public virtual SceneConfig MergeFrom(SceneConfig source)
21
- {
22
- this.Uid = source.Uid;
23
- this.SceneId = source.SceneId;
24
- this.OutingBaseGold = source.OutingBaseGold;
25
- return this;
26
- }
27
-
28
- public virtual SceneConfig Clone()
29
- {
30
- var config = new SceneConfig();
31
- config.MergeFrom(this);
32
- return config;
33
- }
34
-
35
- /// <summary>
36
- /// uid
37
- /// </summary>
38
- public int Uid;
39
-
40
- /// <summary>
41
- /// 场景名
42
- /// </summary>
43
- public string SceneId;
44
-
45
- /// <summary>
46
- /// 出行基础金币收益
47
- /// </summary>
48
- public double OutingBaseGold;
49
-
50
- #region get字段
51
- public int uid => Uid;
52
- public string 场景名 => SceneId;
53
- public double 出行基础金币收益 => OutingBaseGold;
54
- #endregion
55
- }
File without changes
@@ -1,55 +0,0 @@
1
-
2
- using System.Collections.Generic;
3
-
4
- public class SceneConfig {
5
-
6
- public static List<SceneConfig> Configs = new List<SceneConfig>()
7
- {
8
- new SceneConfig(1, "第1章 格莫拉城", 1000),
9
- new SceneConfig(2, "第2章 纳皮尔乐园", 1200),
10
- };
11
-
12
- public SceneConfig() { }
13
- public SceneConfig(int uid, string sceneId, double outingBaseGold)
14
- {
15
- this.Uid = uid;
16
- this.SceneId = sceneId;
17
- this.OutingBaseGold = outingBaseGold;
18
- }
19
-
20
- public virtual SceneConfig MergeFrom(SceneConfig source)
21
- {
22
- this.Uid = source.Uid;
23
- this.SceneId = source.SceneId;
24
- this.OutingBaseGold = source.OutingBaseGold;
25
- return this;
26
- }
27
-
28
- public virtual SceneConfig Clone()
29
- {
30
- var config = new SceneConfig();
31
- config.MergeFrom(this);
32
- return config;
33
- }
34
-
35
- /// <summary>
36
- /// uid
37
- /// </summary>
38
- public int Uid;
39
-
40
- /// <summary>
41
- /// 场景名
42
- /// </summary>
43
- public string SceneId;
44
-
45
- /// <summary>
46
- /// 出行基础金币收益
47
- /// </summary>
48
- public double OutingBaseGold;
49
-
50
- #region get字段
51
- public int uid => Uid;
52
- public string 场景名 => SceneId;
53
- public double 出行基础金币收益 => OutingBaseGold;
54
- #endregion
55
- }
Binary file