export-table-plugin-csharp 1.1.189
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/.vscode/launch.json +21 -0
- package/bin/Json2LiteDB.exe +0 -0
- package/bin/Json2LiteDB.pdb +0 -0
- package/bin/LiteDB.dll +0 -0
- package/bin/LiteDB.xml +7288 -0
- package/dist/CSParseTool.d.ts +36 -0
- package/dist/CSParseTool.d.ts.map +1 -0
- package/dist/CSParseTool.js +533 -0
- package/dist/CSProtoParser.d.ts +22 -0
- package/dist/CSProtoParser.d.ts.map +1 -0
- package/dist/CSProtoParser.js +171 -0
- package/dist/ExportCSPlugin.d.ts +9 -0
- package/dist/ExportCSPlugin.d.ts.map +1 -0
- package/dist/ExportCSPlugin.js +290 -0
- package/dist/ExportLiteDBCSPlugin.d.ts +8 -0
- package/dist/ExportLiteDBCSPlugin.d.ts.map +1 -0
- package/dist/ExportLiteDBCSPlugin.js +221 -0
- package/dist/ExportLiteDBUnityCSJsonPlugin.d.ts +11 -0
- package/dist/ExportLiteDBUnityCSJsonPlugin.d.ts.map +1 -0
- package/dist/ExportLiteDBUnityCSJsonPlugin.js +190 -0
- package/dist/ExportUnityCSJsonPlugin.d.ts +10 -0
- package/dist/ExportUnityCSJsonPlugin.d.ts.map +1 -0
- package/dist/ExportUnityCSJsonPlugin.js +265 -0
- package/dist/ExportUnityMMPPlugin.d.ts +8 -0
- package/dist/ExportUnityMMPPlugin.d.ts.map +1 -0
- package/dist/ExportUnityMMPPlugin.js +116 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/package.json +24 -0
- package/res/mmp-cs/BitUtils.cs +171 -0
- package/res/mmp-cs/BitUtils.cs.meta +11 -0
- package/res/mmp-cs/WritableValueTuple.cs +40 -0
- package/res/mmp-cs/WritableValueTuple.cs.meta +11 -0
- package/src/CSParseTool.ts +425 -0
- package/src/CSProtoParser.ts +137 -0
- package/src/ExportCSPlugin.ts +321 -0
- package/src/ExportLiteDBCSPlugin.ts +245 -0
- package/src/ExportLiteDBUnityCSJsonPlugin.ts +175 -0
- package/src/ExportUnityCSJsonPlugin.ts +297 -0
- package/src/ExportUnityMMPPlugin.ts +127 -0
- package/src/index.ts +14 -0
- package/test/testCS.bat +1 -0
- package/test/testCSWithProto.bat +1 -0
- package/test/testLiteDB.bat +2 -0
- package/test/testUJson.bat +2 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExportLiteDBCSPlugin = void 0;
|
|
4
|
+
exports.export_stuff = export_stuff;
|
|
5
|
+
const export_table_lib_1 = require("export-table-lib");
|
|
6
|
+
const CSParseTool_1 = require("./CSParseTool");
|
|
7
|
+
function export_stuff(paras) {
|
|
8
|
+
let { datas, fields, inject, name, objects, packagename, tables, xxtea, exportNamespace, moreOptions, } = paras;
|
|
9
|
+
let isSkipExportDefaults = !!(moreOptions?.SkipDefaults ?? false);
|
|
10
|
+
if (CSParseTool_1.isSkipExportDefaults0) {
|
|
11
|
+
isSkipExportDefaults = true;
|
|
12
|
+
}
|
|
13
|
+
let RowClass = (0, CSParseTool_1.firstLetterUpper)(name);
|
|
14
|
+
let initFunc = name + "Init";
|
|
15
|
+
let mapfield = fields.find(a => a.type == "key"); //如果是map,则生成对应的map
|
|
16
|
+
let mapName = name + "Map";
|
|
17
|
+
let temp = `
|
|
18
|
+
using System.Collections.Generic;
|
|
19
|
+
using System.Linq;
|
|
20
|
+
|
|
21
|
+
namespace ${exportNamespace}
|
|
22
|
+
{
|
|
23
|
+
[System.Serializable]
|
|
24
|
+
public partial class ${RowClass}
|
|
25
|
+
{
|
|
26
|
+
|
|
27
|
+
private static List<${RowClass}> _configs;
|
|
28
|
+
|
|
29
|
+
public static List<${RowClass}> Configs
|
|
30
|
+
{
|
|
31
|
+
get
|
|
32
|
+
{
|
|
33
|
+
if (_configs == null)
|
|
34
|
+
{
|
|
35
|
+
_configs = Collection.FindAll().ToList();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return _configs;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public ${RowClass}()
|
|
43
|
+
{
|
|
44
|
+
}
|
|
45
|
+
public ${RowClass}(${(0, export_table_lib_1.st)(() => fields.map(f => `${(0, CSParseTool_1.getFieldType)(f)} ${(0, CSParseTool_1.convVarName)(f.name)}`).join(", "))})
|
|
46
|
+
{
|
|
47
|
+
${(0, export_table_lib_1.foreach)(fields, f => ` this.${(0, CSParseTool_1.convMemberName)(f.name)} = ${(0, CSParseTool_1.convVarName)(f.name)};`)}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public virtual ${RowClass} MergeFrom(${RowClass} source)
|
|
51
|
+
{
|
|
52
|
+
${(0, export_table_lib_1.foreach)(fields, f => ` this.${(0, CSParseTool_1.convMemberName)(f.name)} = source.${(0, CSParseTool_1.convMemberName)(f.name)};`)}
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public virtual ${RowClass} Clone()
|
|
57
|
+
{
|
|
58
|
+
var config = new ${RowClass}();
|
|
59
|
+
config.MergeFrom(this);
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
${(0, export_table_lib_1.cmm)( /**生成字段 */)}
|
|
64
|
+
${(0, export_table_lib_1.foreach)(fields, f => `
|
|
65
|
+
/// <summary>
|
|
66
|
+
${(0, export_table_lib_1.foreach)((0, CSParseTool_1.getDescripts)(f), line => ` /// ${line}`)}
|
|
67
|
+
/// </summary>
|
|
68
|
+
public ${(0, CSParseTool_1.getFieldType)(f)} ${(0, CSParseTool_1.convMemberName)(f.name)};
|
|
69
|
+
|
|
70
|
+
${(0, export_table_lib_1.iff)(f.rawType.startsWith("@"), () => `
|
|
71
|
+
/// <summary>
|
|
72
|
+
${(0, export_table_lib_1.foreach)((0, CSParseTool_1.getDescripts)(f), line => ` /// ${line}`)}
|
|
73
|
+
/// </summary>
|
|
74
|
+
${(0, CSParseTool_1.convTupleArrayTypeDefine)(f)}`)}`)}
|
|
75
|
+
|
|
76
|
+
${(0, export_table_lib_1.cmm)( /**生成get字段 */)}
|
|
77
|
+
#region get字段
|
|
78
|
+
${(0, export_table_lib_1.foreach)(fields, f => {
|
|
79
|
+
if (f.nameOrigin != f.name) {
|
|
80
|
+
return ` public ${(0, CSParseTool_1.getFieldType)(f)} ${(0, CSParseTool_1.getTitle)(f).replace(" ", "_")} => ${(0, CSParseTool_1.convMemberName)(f.name)};`;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return "";
|
|
84
|
+
}
|
|
85
|
+
})}
|
|
86
|
+
#endregion
|
|
87
|
+
|
|
88
|
+
#region uid map
|
|
89
|
+
${(0, export_table_lib_1.foreach)(fields, f => {
|
|
90
|
+
if (f.isUnique) {
|
|
91
|
+
let memberName = (0, CSParseTool_1.convMemberName)(f.name);
|
|
92
|
+
let paraName = (0, CSParseTool_1.convVarName)(memberName);
|
|
93
|
+
let tempDictByMemberName = `TempDictBy${memberName}`;
|
|
94
|
+
let memberType = (0, CSParseTool_1.getFieldType)(f);
|
|
95
|
+
return `
|
|
96
|
+
protected static Dictionary<${memberType}, ${RowClass}> ${tempDictByMemberName};
|
|
97
|
+
public static ${RowClass} GetConfigBy${memberName}(${memberType} ${paraName})
|
|
98
|
+
{
|
|
99
|
+
if (${tempDictByMemberName} == null)
|
|
100
|
+
{
|
|
101
|
+
${tempDictByMemberName} = new Dictionary<${memberType}, ${RowClass}>(Configs.Count);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (${tempDictByMemberName}.TryGetValue(${paraName}, out var result))
|
|
105
|
+
{
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
result = Collection.FindOne(record => record.${memberName} == ${paraName});
|
|
110
|
+
${tempDictByMemberName}.Add(${paraName}, result);
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
else if (f.type == "number" || f.type == "float" || f.type == "int" || f.type == "long" || f.type == "string") {
|
|
116
|
+
let memberName = (0, CSParseTool_1.convMemberName)(f.name);
|
|
117
|
+
let paraName = (0, CSParseTool_1.convVarName)(memberName);
|
|
118
|
+
let tempRecordsDictByMemberName = `TempRecordsDictBy${memberName}`;
|
|
119
|
+
let memberType = (0, CSParseTool_1.getFieldType)(f);
|
|
120
|
+
return `
|
|
121
|
+
protected static Dictionary<${memberType}, ${RowClass}[]> ${tempRecordsDictByMemberName};
|
|
122
|
+
public static ${RowClass}[] GetConfigsBy${memberName}(${memberType} ${paraName})
|
|
123
|
+
{
|
|
124
|
+
if (${tempRecordsDictByMemberName} != null && ${tempRecordsDictByMemberName}.TryGetValue(${paraName},out var retValue))
|
|
125
|
+
{
|
|
126
|
+
return retValue;
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
{
|
|
130
|
+
if (${tempRecordsDictByMemberName} == null)
|
|
131
|
+
{
|
|
132
|
+
${tempRecordsDictByMemberName} = new Dictionary<${memberType}, ${RowClass}[]>(Configs.Count);
|
|
133
|
+
}
|
|
134
|
+
var records = Collection.Find(c => c.${memberName} == ${paraName}).ToArray();
|
|
135
|
+
${tempRecordsDictByMemberName}.Add(${paraName}, records);
|
|
136
|
+
return records;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
})}
|
|
145
|
+
|
|
146
|
+
#endregion uid map
|
|
147
|
+
|
|
148
|
+
#region 生成fk.get/set
|
|
149
|
+
${(0, export_table_lib_1.foreach)(fields, f => `
|
|
150
|
+
${(0, export_table_lib_1.iff)(f.type == "fk", () => `
|
|
151
|
+
${(0, export_table_lib_1.iff)((0, CSParseTool_1.getFkFieldType)(tables, f).toLowerCase() != "uid", () => `
|
|
152
|
+
protected ${(0, CSParseTool_1.convMemberName)(f.fkTableName)}[] _fk${(0, CSParseTool_1.convMemberName)(f.name)}=null;
|
|
153
|
+
/**
|
|
154
|
+
* ${f.describe}
|
|
155
|
+
**/
|
|
156
|
+
public virtual ${(0, CSParseTool_1.convMemberName)(f.fkTableName)}[] ${(0, CSParseTool_1.convMemberName)(f.name)}DataList{
|
|
157
|
+
get{
|
|
158
|
+
if(this._fk${(0, CSParseTool_1.convMemberName)(f.name)}==null){
|
|
159
|
+
if(null==this.${(0, CSParseTool_1.convMemberName)(f.name)}){
|
|
160
|
+
this._fk${(0, CSParseTool_1.convMemberName)(f.name)} = new ${(0, CSParseTool_1.convMemberName)(f.fkTableName)}[0];
|
|
161
|
+
}else{
|
|
162
|
+
this._fk${(0, CSParseTool_1.convMemberName)(f.name)}=${(0, CSParseTool_1.convMemberName)(f.fkTableName)}.Configs.FindAll(a=>a.${(0, CSParseTool_1.convMemberName)(f.fkFieldName)}!=null && this.${(0, CSParseTool_1.convMemberName)(f.name)}==a.${(0, CSParseTool_1.convMemberName)(f.fkFieldName)}).ToArray();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return this._fk${(0, CSParseTool_1.convMemberName)(f.name)};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
`).else(() => `
|
|
169
|
+
protected ${(0, CSParseTool_1.convMemberName)(f.fkTableName)} _fk${(0, CSParseTool_1.convMemberName)(f.name)}=null;
|
|
170
|
+
/**
|
|
171
|
+
* ${f.describe}
|
|
172
|
+
**/
|
|
173
|
+
public virtual ${(0, CSParseTool_1.convMemberName)(f.fkTableName)} ${(0, CSParseTool_1.convMemberName)(f.name)}Data{
|
|
174
|
+
get{
|
|
175
|
+
if(this._fk${(0, CSParseTool_1.convMemberName)(f.name)}==null){
|
|
176
|
+
this._fk${(0, CSParseTool_1.convMemberName)(f.name)}=${(0, CSParseTool_1.convMemberName)(f.fkTableName)}.Configs.Find(a=>a.${(0, CSParseTool_1.convMemberName)(f.fkFieldName)}==this.${(0, CSParseTool_1.convMemberName)(f.name)});
|
|
177
|
+
}
|
|
178
|
+
return this._fk${(0, CSParseTool_1.convMemberName)(f.name)};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
`)}
|
|
182
|
+
`)}
|
|
183
|
+
${(0, export_table_lib_1.iff)(f.type == "fk[]", () => `
|
|
184
|
+
protected ${(0, CSParseTool_1.convMemberName)(f.fkTableName)}[] _fk${(0, CSParseTool_1.convMemberName)(f.name)}=null;
|
|
185
|
+
/**
|
|
186
|
+
* ${f.describe}
|
|
187
|
+
**/
|
|
188
|
+
public virtual ${(0, CSParseTool_1.convMemberName)(f.fkTableName)}[] ${(0, CSParseTool_1.convMemberName)(f.name)}DataList{
|
|
189
|
+
get{
|
|
190
|
+
if(this._fk${(0, CSParseTool_1.convMemberName)(f.name)}==null){
|
|
191
|
+
if(null==this.${(0, CSParseTool_1.convMemberName)(f.name)}){
|
|
192
|
+
this._fk${(0, CSParseTool_1.convMemberName)(f.name)} = new ${(0, CSParseTool_1.convMemberName)(f.fkTableName)}[0];
|
|
193
|
+
}else{
|
|
194
|
+
this._fk${(0, CSParseTool_1.convMemberName)(f.name)}=${exportNamespace}.${(0, CSParseTool_1.convMemberName)(f.fkTableName)}.Configs.FindAll(a=>a.${(0, CSParseTool_1.convMemberName)(f.fkFieldName)}!=null && this.${(0, CSParseTool_1.convMemberName)(f.name)}!.Contains(a.${(0, CSParseTool_1.convMemberName)(f.fkFieldName)})).ToArray();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return this._fk${(0, CSParseTool_1.convMemberName)(f.name)};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
`)}
|
|
201
|
+
`)}
|
|
202
|
+
#endregion 生成fk.get/set
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
`;
|
|
206
|
+
return temp;
|
|
207
|
+
}
|
|
208
|
+
class ExportLiteDBCSPlugin extends export_table_lib_1.PluginBase {
|
|
209
|
+
name = "litedbcs";
|
|
210
|
+
tags = ["litedbcs"];
|
|
211
|
+
handleSheet(paras) {
|
|
212
|
+
let content = export_stuff(paras);
|
|
213
|
+
if (content != null) {
|
|
214
|
+
var fullName = `${paras.table.workbookName}-${paras.name}`;
|
|
215
|
+
let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, ".cs").fullPath;
|
|
216
|
+
(0, CSParseTool_1.outputFileSync)(savePath, content, "utf-8");
|
|
217
|
+
}
|
|
218
|
+
return content;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.ExportLiteDBCSPlugin = ExportLiteDBCSPlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HandleSheetParams, PluginBase, HandleBatchParams } from "export-table-lib";
|
|
2
|
+
export declare function exportUJsonLoader(paras: HandleSheetParams): string | null;
|
|
3
|
+
export declare function RemoveJsonFiles(savePaths2: string[]): Promise<void>;
|
|
4
|
+
export declare function ConvJson2LiteDB(litedbpath: string, savePaths: string[]): Promise<void>;
|
|
5
|
+
export declare class ExportLiteDBUJsonPlugin extends PluginBase {
|
|
6
|
+
name: string;
|
|
7
|
+
tags: string[];
|
|
8
|
+
handleSheet(paras: HandleSheetParams): string | null;
|
|
9
|
+
handleBatch(paras: HandleBatchParams): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ExportLiteDBUnityCSJsonPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportLiteDBUnityCSJsonPlugin.d.ts","sourceRoot":"","sources":["../src/ExportLiteDBUnityCSJsonPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAqC,MAAM,kBAAkB,CAAA;AASxJ,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAiDzE;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,iBAczD;AACD,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,iBAmB5E;AAED,qBAAa,uBAAwB,SAAQ,UAAU;IACtD,IAAI,SAAgB;IACpB,IAAI,EAAE,MAAM,EAAE,CAAkB;IAEhC,WAAW,CAAC,KAAK,EAAE,iBAAiB;IAoB9B,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAqD1C"}
|
|
@@ -0,0 +1,190 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ExportLiteDBUJsonPlugin = void 0;
|
|
40
|
+
exports.exportUJsonLoader = exportUJsonLoader;
|
|
41
|
+
exports.RemoveJsonFiles = RemoveJsonFiles;
|
|
42
|
+
exports.ConvJson2LiteDB = ConvJson2LiteDB;
|
|
43
|
+
const export_table_lib_1 = require("export-table-lib");
|
|
44
|
+
const fs = __importStar(require("fs-extra"));
|
|
45
|
+
const CSParseTool_1 = require("./CSParseTool");
|
|
46
|
+
const path_1 = __importDefault(require("path"));
|
|
47
|
+
const cp = __importStar(require("child_process"));
|
|
48
|
+
const ExportUnityCSJsonPlugin_1 = require("./ExportUnityCSJsonPlugin");
|
|
49
|
+
var isSkipIndexLoader0 = process.argv.findIndex(v => v == "--SkipIndexLoader") >= 0;
|
|
50
|
+
function exportUJsonLoader(paras) {
|
|
51
|
+
let { datas, fields, name, objects, table, exportNamespace, } = paras;
|
|
52
|
+
let useJsonToolNamesapce = (0, CSParseTool_1.GetUsingJsonToolNamespace)();
|
|
53
|
+
let RowClass = (0, CSParseTool_1.firstLetterUpper)(name);
|
|
54
|
+
var fullName = `${table.workbookName}-${name}`;
|
|
55
|
+
// !!!必须开头没有空格
|
|
56
|
+
let temp = `
|
|
57
|
+
using System.Threading.Tasks;
|
|
58
|
+
using LiteDB;
|
|
59
|
+
using UnityEngine;
|
|
60
|
+
${useJsonToolNamesapce}
|
|
61
|
+
|
|
62
|
+
namespace ${exportNamespace}
|
|
63
|
+
{
|
|
64
|
+
public partial class ${RowClass}
|
|
65
|
+
{
|
|
66
|
+
protected static LiteDatabase Database;
|
|
67
|
+
protected static ILiteCollection<${RowClass}> Collection;
|
|
68
|
+
public const string CollKey = "${fullName.replace("-", "_")}";
|
|
69
|
+
public static Task Load()
|
|
70
|
+
{
|
|
71
|
+
#if UNITY_EDITOR && ENABLE_CONFIG_LOG
|
|
72
|
+
Debug.Log("ReferConfig-${RowClass}");
|
|
73
|
+
#endif
|
|
74
|
+
var key = CollKey;
|
|
75
|
+
var ldb = SharedLiteDB.Database;
|
|
76
|
+
Database = ldb;
|
|
77
|
+
if (!ldb.CollectionExists(key))
|
|
78
|
+
{
|
|
79
|
+
Debug.LogError($"配表资源缺失: {key}");
|
|
80
|
+
}
|
|
81
|
+
Collection = ldb.GetCollection<${RowClass}>(key);
|
|
82
|
+
|
|
83
|
+
return Task.CompletedTask;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
return temp;
|
|
89
|
+
}
|
|
90
|
+
async function RemoveJsonFiles(savePaths2) {
|
|
91
|
+
let deleteTasks = savePaths2.map(async (savePath2) => {
|
|
92
|
+
console.log(`delete file: ${savePath2}`);
|
|
93
|
+
try {
|
|
94
|
+
if (fs.existsSync(savePath2)) {
|
|
95
|
+
fs.removeSync(savePath2);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (ex) {
|
|
99
|
+
console.error(`error: cannot delete file ${savePath2}`);
|
|
100
|
+
console.error(ex);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
await Promise.all(deleteTasks);
|
|
104
|
+
}
|
|
105
|
+
async function ConvJson2LiteDB(litedbpath, savePaths) {
|
|
106
|
+
if (litedbpath != null && litedbpath != "") {
|
|
107
|
+
let modulePath = require.resolve(".");
|
|
108
|
+
let binPath = path_1.default.resolve(modulePath, "../../bin/Json2LiteDB.exe");
|
|
109
|
+
// let dbPath = path.resolve("../../../GameClient/Assets/Bundles/GameConfigs/Auto/MainConfig.db.bytes");
|
|
110
|
+
// let dbPath = path.resolve(litedbpath)
|
|
111
|
+
let savePaths2 = savePaths.map(savePath => path_1.default.resolve(savePath));
|
|
112
|
+
let cmdParas = savePaths2.concat();
|
|
113
|
+
cmdParas.unshift(litedbpath);
|
|
114
|
+
let cmdParasLine = cmdParas.join(" ");
|
|
115
|
+
let cmdline = `${binPath} ${cmdParasLine}`;
|
|
116
|
+
console.log("execute-cmdline: " + cmdline);
|
|
117
|
+
var output = cp.spawnSync(binPath, cmdParas);
|
|
118
|
+
console.log(output.output.toString());
|
|
119
|
+
RemoveJsonFiles(savePaths2);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.log(`no litedbpath given, skip conv database`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class ExportLiteDBUJsonPlugin extends export_table_lib_1.PluginBase {
|
|
126
|
+
name = "litedbujson";
|
|
127
|
+
tags = ["litedbujson"];
|
|
128
|
+
handleSheet(paras) {
|
|
129
|
+
var fullName = `${paras.table.workbookName}-${paras.name}`;
|
|
130
|
+
{
|
|
131
|
+
let content1 = exportUJsonLoader(paras);
|
|
132
|
+
if (content1 != null) {
|
|
133
|
+
let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, "Loader.cs").fullPath;
|
|
134
|
+
(0, CSParseTool_1.outputFileSync)(savePath, content1, "utf-8");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
{
|
|
138
|
+
let content2 = (0, ExportUnityCSJsonPlugin_1.exportUJson)(paras);
|
|
139
|
+
if (content2 != null) {
|
|
140
|
+
let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, ".json").fullPath;
|
|
141
|
+
(0, CSParseTool_1.outputFileSync)(savePath, content2, "utf-8");
|
|
142
|
+
}
|
|
143
|
+
return content2;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async handleBatch(paras) {
|
|
147
|
+
let { moreOptions, tables, exportNamespace, } = paras;
|
|
148
|
+
let isSkipIndexLoader = moreOptions?.SkipIndexLoader ?? false;
|
|
149
|
+
if (isSkipIndexLoader0) {
|
|
150
|
+
isSkipIndexLoader = true;
|
|
151
|
+
}
|
|
152
|
+
if (isSkipIndexLoader) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
var temp = `
|
|
156
|
+
using System;
|
|
157
|
+
using System.Collections.Generic;
|
|
158
|
+
using System.Threading.Tasks;
|
|
159
|
+
|
|
160
|
+
namespace ${exportNamespace}
|
|
161
|
+
{
|
|
162
|
+
public static class DefaultConfigLoader{
|
|
163
|
+
public static IEnumerable<Func<Task>> Load(){
|
|
164
|
+
${(0, export_table_lib_1.foreach)(tables.sort((ta, tb) => ta.name.localeCompare(tb.name)), (table) => `
|
|
165
|
+
yield return ${(0, CSParseTool_1.firstLetterUpper)(table.name)}.Load;
|
|
166
|
+
`)}
|
|
167
|
+
yield break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
let savePath = paras.outPath + "/DefaultConfigLoader.cs";
|
|
173
|
+
(0, CSParseTool_1.outputFileSync)(savePath, temp, "utf-8");
|
|
174
|
+
// var options = new program.Command().option("--litedbpath <string>").parse(process.argv).allowUnknownOption(true).opts()
|
|
175
|
+
// let litedbpath = options["litedbpath"]
|
|
176
|
+
let litedbpathIndex = process.argv.indexOf("--litedbpath");
|
|
177
|
+
let litedbpath = "";
|
|
178
|
+
if (litedbpathIndex >= 0) {
|
|
179
|
+
litedbpath = process.argv[litedbpathIndex + 1];
|
|
180
|
+
}
|
|
181
|
+
console.log(`litedbpath: ${litedbpath}`);
|
|
182
|
+
let cmdParas = tables.map(table => {
|
|
183
|
+
var fullName = `${table.workbookName}-${table.name}`;
|
|
184
|
+
let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, ".json").fullPath;
|
|
185
|
+
return savePath;
|
|
186
|
+
});
|
|
187
|
+
await ConvJson2LiteDB(litedbpath, cmdParas);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.ExportLiteDBUJsonPlugin = ExportLiteDBUJsonPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HandleSheetParams, PluginBase, HandleBatchParams } from "export-table-lib";
|
|
2
|
+
export declare function exportUJson(paras: HandleSheetParams): string | null;
|
|
3
|
+
export declare function exportUJsonLoader(paras: HandleSheetParams): string | null;
|
|
4
|
+
export declare class ExportUJsonPlugin extends PluginBase {
|
|
5
|
+
name: string;
|
|
6
|
+
tags: string[];
|
|
7
|
+
handleSheet(paras: HandleSheetParams): string | null;
|
|
8
|
+
handleBatch(paras: HandleBatchParams): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ExportUnityCSJsonPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportUnityCSJsonPlugin.d.ts","sourceRoot":"","sources":["../src/ExportUnityCSJsonPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAqC,MAAM,kBAAkB,CAAA;AAQxJ,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA+DnE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAyJzE;AAED,qBAAa,iBAAkB,SAAQ,UAAU;IAChD,IAAI,SAAU;IACd,IAAI,EAAE,MAAM,EAAE,CAAY;IAE1B,WAAW,CAAC,KAAK,EAAE,iBAAiB;IAmBpC,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;CA4C3C"}
|