export-table-pulgin-csharp 1.0.13 → 1.0.16

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.
@@ -0,0 +1,9 @@
1
+ import { HandleSheetParams, PluginBase } 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
+ }
8
+ export declare const ExportPlugins: ExportPlugin[];
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AAGrH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAiKpE;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC3C,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAS;IAEvB,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAOpC;AAED,eAAO,MAAM,aAAa,gBAEzB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,204 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ExportPlugins = exports.ExportPlugin = exports.export_stuff = void 0;
27
+ const windy_quicktable_1 = require("windy-quicktable");
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 = firstLetterUpper;
38
+ let convVarName = firstLetterLower;
39
+ let RowClass = firstLetterUpper(name);
40
+ let initFunc = name + "Init";
41
+ let mapfield = fields.find(a => a.type == "key"); //如果是map,则生成对应的map
42
+ let mapName = name + "Map";
43
+ let getFieldType = function (f) {
44
+ let t = f.type;
45
+ if (t == "object") {
46
+ throw new Error("invalid type <object>");
47
+ }
48
+ else if (t == "object[]") {
49
+ throw new Error("invalid type <object[]>");
50
+ }
51
+ else if (t == "number") {
52
+ return "double";
53
+ }
54
+ else if (t == "number[]") {
55
+ return "double[]";
56
+ }
57
+ else if (t == "uid") {
58
+ return "int";
59
+ }
60
+ else if (t == "bool") {
61
+ return "bool";
62
+ }
63
+ else if (t == "bool[]") {
64
+ return "bool[]";
65
+ }
66
+ else if (t == "string") {
67
+ return "string";
68
+ }
69
+ else if (t == "string[]") {
70
+ return "string[]";
71
+ }
72
+ else if (t == "fk") {
73
+ return "int";
74
+ }
75
+ else if (t == "fk[]") {
76
+ return "int[]";
77
+ }
78
+ else if (t == "any") {
79
+ throw new Error(`invalid type ${f.name}:<any>`);
80
+ }
81
+ else if (t == "key") {
82
+ return "string";
83
+ }
84
+ else {
85
+ throw new Error(`invalid type ${f.name}:<unkown>`);
86
+ }
87
+ return t;
88
+ };
89
+ const genValue = (value, f) => {
90
+ let t = f.type;
91
+ if (t == "object") {
92
+ throw new Error("invalid type <object>");
93
+ }
94
+ else if (t == "object[]") {
95
+ throw new Error("invalid type <object[]>");
96
+ }
97
+ else if (t == "number") {
98
+ return `${value}`;
99
+ }
100
+ else if (t == "number[]") {
101
+ let values = value;
102
+ return `new double[]{${values.join(", ")}}`;
103
+ }
104
+ else if (t == "uid") {
105
+ return `${value}`;
106
+ }
107
+ else if (t == "bool") {
108
+ return `${value}`;
109
+ }
110
+ else if (t == "bool[]") {
111
+ let values = value;
112
+ return `new bool[]{${values.join(", ")}}`;
113
+ }
114
+ else if (t == "string") {
115
+ return `"${value}"`;
116
+ }
117
+ else if (t == "string[]") {
118
+ let values = value;
119
+ return `new string[]{${values.map(v => `"${v}"`).join(", ")}}`;
120
+ }
121
+ else if (t == "fk") {
122
+ return `${value}`;
123
+ }
124
+ else if (t == "fk[]") {
125
+ let values = value;
126
+ return `new int[]{${values.join(", ")}}`;
127
+ }
128
+ else if (t == "any") {
129
+ throw new Error(`invalid type ${f.name}:<any>`);
130
+ }
131
+ else if (t == "key") {
132
+ return `${value}`;
133
+ }
134
+ throw new Error(`invalid type ${f.name}:<unkown>`);
135
+ };
136
+ const getTitle = (v) => {
137
+ return v.describe.split("\n")[0];
138
+ };
139
+ const getDescripts = (v) => {
140
+ return v.describe.split("\n");
141
+ };
142
+ let temp = `
143
+ using System.Collections.Generic;
144
+
145
+ public class ${RowClass} {
146
+
147
+ public static List<${RowClass}> Configs = new List<${RowClass}>()
148
+ {
149
+ ${(0, windy_quicktable_1.foreach)(datas, data => ` new ${RowClass}(${(0, windy_quicktable_1.st)(() => fields.map((f, index) => genValue(data[index], f)).join(", "))}),`)}
150
+ };
151
+
152
+ public ${RowClass}() { }
153
+ public ${RowClass}(${(0, windy_quicktable_1.st)(() => fields.map(f => `${getFieldType(f)} ${convVarName(f.name)}`).join(", "))})
154
+ {
155
+ ${(0, windy_quicktable_1.foreach)(fields, f => ` this.${convMemberName(f.name)} = ${convVarName(f.name)};`)}
156
+ }
157
+
158
+ public virtual ${RowClass} MergeFrom(${RowClass} source)
159
+ {
160
+ ${(0, windy_quicktable_1.foreach)(fields, f => ` this.${convMemberName(f.name)} = source.${convMemberName(f.name)};`)}
161
+ return this;
162
+ }
163
+
164
+ public virtual ${RowClass} Clone()
165
+ {
166
+ var config = new ${RowClass}();
167
+ config.MergeFrom(this);
168
+ return config;
169
+ }
170
+
171
+ ${(0, windy_quicktable_1.cmm)( /**生成字段 */)}
172
+ ${(0, windy_quicktable_1.foreach)(fields, f => `
173
+ /// <summary>
174
+ ${(0, windy_quicktable_1.foreach)(getDescripts(f), line => ` /// ${line}`)}
175
+ /// </summary>
176
+ public ${getFieldType(f)} ${convMemberName(f.name)};`)}
177
+
178
+ ${(0, windy_quicktable_1.cmm)( /**生成get字段 */)}
179
+ #region get字段
180
+ ${(0, windy_quicktable_1.foreach)(fields, f => ` public ${getFieldType(f)} ${getTitle(f).replace(" ", "_")} => ${convMemberName(f.name)};`)}
181
+ #endregion
182
+ }
183
+ `;
184
+ return temp;
185
+ }
186
+ exports.export_stuff = export_stuff;
187
+ class ExportPlugin extends windy_quicktable_1.PluginBase {
188
+ constructor() {
189
+ super(...arguments);
190
+ this.name = "csharp";
191
+ this.tags = ["cs"];
192
+ }
193
+ handleSheet(paras) {
194
+ let content = export_stuff(paras);
195
+ if (content != null) {
196
+ fs.outputFileSync(paras.outFilePath.fullPath, content, "utf-8");
197
+ }
198
+ return content;
199
+ }
200
+ }
201
+ exports.ExportPlugin = ExportPlugin;
202
+ exports.ExportPlugins = [
203
+ new ExportPlugin(),
204
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "export-table-pulgin-csharp",
3
- "version": "1.0.13",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,55 @@
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
@@ -0,0 +1,55 @@
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
File without changes