export-table-pulgin-csharp 1.1.65 → 1.1.67

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ExportCSPlugin.d.ts","sourceRoot":"","sources":["../src/ExportCSPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAA0B,MAAM,kBAAkB,CAAA;AAM1H,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAqTpE;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC3C,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAS;IAEvB,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAOpC"}
1
+ {"version":3,"file":"ExportCSPlugin.d.ts","sourceRoot":"","sources":["../src/ExportCSPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAA0B,MAAM,kBAAkB,CAAA;AAM1H,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA4TpE;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC3C,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAS;IAEvB,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAOpC"}
@@ -116,7 +116,7 @@ function export_stuff(paras) {
116
116
  convert.push(`{"${k}","${value[k].toString()}"}`);
117
117
  }
118
118
  ;
119
- return `new Dictionary<string,string>(){${convert}}`;
119
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
120
120
  }
121
121
  else if (t == "object[]") {
122
122
  let values = value;
@@ -127,7 +127,7 @@ function export_stuff(paras) {
127
127
  convert.push(`{"${k}","${val[k].toString()}"}`);
128
128
  }
129
129
  ;
130
- return `new Dictionary<string,string>(){${convert}}`;
130
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
131
131
  })}}`;
132
132
  }
133
133
  else if (t == "number" || t == "int" || t == "long") {
@@ -241,35 +241,42 @@ ${(0, export_table_lib_1.foreach)(fields, f => {
241
241
  #region uid map
242
242
  ${(0, export_table_lib_1.foreach)(fields, f => {
243
243
  if (f.isUnique) {
244
+ let memberName = convMemberName(f.name);
245
+ let tempDictByMemberName = `_tempDictBy${memberName}`;
246
+ let memberType = getFieldType(f);
244
247
  return `
245
- protected static Dictionary<${getFieldType(f)}, ${RowClass}> _tempDictBy${convMemberName(f.name)};
246
- public static ${RowClass} GetConfigBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
248
+ protected static Dictionary<${memberType}, ${RowClass}> ${tempDictByMemberName};
249
+ public static ${RowClass} GetConfigBy${memberName}(${memberType} ${memberName})
247
250
  {
248
- if (_tempDictBy${convMemberName(f.name)} == null)
251
+ if (${tempDictByMemberName} == null)
249
252
  {
250
- _tempDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}>();
251
- Configs.ForEach(c =>
253
+ ${tempDictByMemberName} = new Dictionary<${memberType}, ${RowClass}>(Configs.Count);
254
+ for(var i = 0; i < Configs.Count; i++)
252
255
  {
253
- _tempDictBy${convMemberName(f.name)}.Add(c.${convMemberName(f.name)}, c);
254
- });
256
+ var c = Configs[i];
257
+ ${tempDictByMemberName}.Add(c.${memberName}, c);
258
+ }
255
259
  }
256
- return _tempDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
260
+ return ${tempDictByMemberName}.GetValueOrDefault(${memberName});
257
261
  }
258
262
  `;
259
263
  }
260
264
  else if (f.type == "number" || f.type == "int" || f.type == "long" || f.type == "string") {
265
+ let memberName = convMemberName(f.name);
266
+ let tempRecordsDictByMemberName = `_tempRecordsDictBy${memberName}`;
267
+ let memberType = getFieldType(f);
261
268
  return `
262
- protected static Dictionary<${getFieldType(f)}, ${RowClass}[]> _tempRecordsDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}[]>();
263
- public static ${RowClass}[] GetConfigsBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
269
+ protected static Dictionary<${memberType}, ${RowClass}[]> ${tempRecordsDictByMemberName} = new Dictionary<${memberType}, ${RowClass}[]>(Configs.Count);
270
+ public static ${RowClass}[] GetConfigsBy${memberName}(${memberType} ${memberName})
264
271
  {
265
- if (_tempRecordsDictBy${convMemberName(f.name)}.ContainsKey(${convMemberName(f.name)}))
272
+ if (${tempRecordsDictByMemberName}.ContainsKey(${memberName}))
266
273
  {
267
- return _tempRecordsDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
274
+ return ${tempRecordsDictByMemberName}.GetValueOrDefault(${memberName});
268
275
  }
269
276
  else
270
277
  {
271
- var records = Configs.Where(c => c.${convMemberName(f.name)} == ${convMemberName(f.name)}).ToArray();
272
- _tempRecordsDictBy${convMemberName(f.name)}.Add(${convMemberName(f.name)}, records);
278
+ var records = Configs.Where(c => c.${memberName} == ${memberName});//.ToArray();
279
+ ${tempRecordsDictByMemberName}.Add(${memberName}, records);
273
280
  return records;
274
281
  }
275
282
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ExportUnityCSJsonPlugin.d.ts","sourceRoot":"","sources":["../src/ExportUnityCSJsonPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAe,MAAM,kBAAkB,CAAA;AAMlI,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA+CnE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAgFzE;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;CAsB3C"}
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;AAIxJ,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CA+CnE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAgFzE;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;CAsB3C"}
@@ -26,9 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ExportUJsonPlugin = exports.exportUJsonLoader = exports.exportUJson = void 0;
27
27
  const export_table_lib_1 = require("export-table-lib");
28
28
  const fs = __importStar(require("fs-extra"));
29
- let firstLetterUpper = function (str) {
30
- return str.charAt(0).toUpperCase() + str.slice(1);
31
- };
29
+ let firstLetterUpper = export_table_lib_1.makeFirstLetterUpper;
32
30
  function exportUJson(paras) {
33
31
  let { datas, fields, name, objects, table, } = paras;
34
32
  let firstLetterLower = function (str) {
@@ -72,71 +70,71 @@ function exportUJsonLoader(paras) {
72
70
  let RowClass = firstLetterUpper(name);
73
71
  var fullName = `${table.workbookName}-${name}`;
74
72
  // !!!必须开头没有空格
75
- let temp = `
76
- using UnityEngine.AddressableAssets;
77
- using System.Threading.Tasks;
78
- using UnityEngine;
79
- using lang.json;
80
-
81
- namespace MEEC.ExportedConfigs
82
- {
83
- public partial class ${RowClass}
84
- {
85
- #if UNITY_EDITOR && ENABLE_CONFIG_LOG
86
- static ${RowClass}()
87
- {
88
- Debug.Log("ReferConfig-${RowClass}");
89
- }
90
- #endif
91
- public static async Task Load()
92
- {
93
- var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
94
- var configJson =
95
- #if UNITY_EDITOR
96
- Application.isPlaying ? await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task
97
- : UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
98
- #else
99
- await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task;
100
- #endif
101
- if (configJson != null)
102
- {
103
- var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
104
- var configs = ${RowClass}.Configs;
105
- configs.Clear();
106
- configs.AddRange(jsonObjs);
107
- }
108
- else
109
- {
110
- Debug.LogError($"配表资源缺失: {loadUrl}");
111
- }
112
- }
113
-
114
- #if UNITY_EDITOR
115
- public static void LoadInEditor()
116
- {
117
- if (Application.isPlaying)
118
- {
119
- var tip = $"cannot load ${RowClass}[] with LoadInEditor at runtime";
120
- Debug.LogError(tip);
121
- throw new System.Exception(tip);
122
- }
123
- var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
124
- var configJson = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
125
- if (configJson != null)
126
- {
127
- var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
128
- var configs = ${RowClass}.Configs;
129
- configs.Clear();
130
- configs.AddRange(jsonObjs);
131
- }
132
- else
133
- {
134
- Debug.LogError($"配表资源缺失: {loadUrl}");
135
- }
136
- }
137
- #endif
138
- }
139
- }
73
+ let temp = `
74
+ using UnityEngine.AddressableAssets;
75
+ using System.Threading.Tasks;
76
+ using UnityEngine;
77
+ using lang.json;
78
+
79
+ namespace MEEC.ExportedConfigs
80
+ {
81
+ public partial class ${RowClass}
82
+ {
83
+ #if UNITY_EDITOR && ENABLE_CONFIG_LOG
84
+ static ${RowClass}()
85
+ {
86
+ Debug.Log("ReferConfig-${RowClass}");
87
+ }
88
+ #endif
89
+ public static async Task Load()
90
+ {
91
+ var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
92
+ var configJson =
93
+ #if UNITY_EDITOR
94
+ Application.isPlaying ? await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task
95
+ : UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
96
+ #else
97
+ await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task;
98
+ #endif
99
+ if (configJson != null)
100
+ {
101
+ var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
102
+ var configs = ${RowClass}.Configs;
103
+ configs.Clear();
104
+ configs.AddRange(jsonObjs);
105
+ }
106
+ else
107
+ {
108
+ Debug.LogError($"配表资源缺失: {loadUrl}");
109
+ }
110
+ }
111
+
112
+ #if UNITY_EDITOR
113
+ public static void LoadInEditor()
114
+ {
115
+ if (Application.isPlaying)
116
+ {
117
+ var tip = $"cannot load ${RowClass}[] with LoadInEditor at runtime";
118
+ Debug.LogError(tip);
119
+ throw new System.Exception(tip);
120
+ }
121
+ var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
122
+ var configJson = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
123
+ if (configJson != null)
124
+ {
125
+ var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
126
+ var configs = ${RowClass}.Configs;
127
+ configs.Clear();
128
+ configs.AddRange(jsonObjs);
129
+ }
130
+ else
131
+ {
132
+ Debug.LogError($"配表资源缺失: {loadUrl}");
133
+ }
134
+ }
135
+ #endif
136
+ }
137
+ }
140
138
  `;
141
139
  return temp;
142
140
  }
@@ -167,22 +165,22 @@ class ExportUJsonPlugin extends export_table_lib_1.PluginBase {
167
165
  }
168
166
  handleBatch(paras) {
169
167
  var tables = paras.tables;
170
- var temp = `
171
- using System;
172
- using System.Collections.Generic;
173
- using System.Threading.Tasks;
174
-
175
- namespace MEEC.ExportedConfigs
176
- {
177
- public static class DefaultConfigLoader{
178
- public static IEnumerable<Func<Task>> Load(){
179
- ${(0, export_table_lib_1.foreach)(tables, (table) => `
180
- yield return ${firstLetterUpper(table.name)}.Load;
181
- `)}
182
- yield break;
183
- }
184
- }
185
- }
168
+ var temp = `
169
+ using System;
170
+ using System.Collections.Generic;
171
+ using System.Threading.Tasks;
172
+
173
+ namespace MEEC.ExportedConfigs
174
+ {
175
+ public static class DefaultConfigLoader{
176
+ public static IEnumerable<Func<Task>> Load(){
177
+ ${(0, export_table_lib_1.foreach)(tables, (table) => `
178
+ yield return ${firstLetterUpper(table.name)}.Load;
179
+ `)}
180
+ yield break;
181
+ }
182
+ }
183
+ }
186
184
  `;
187
185
  let savePath = paras.outPath + "/DefaultConfigLoader.cs";
188
186
  fs.outputFileSync(savePath, temp, "utf-8");
@@ -0,0 +1,8 @@
1
+ import { HandleSheetParams, PluginBase, HandleBatchParams } from "export-table-lib";
2
+ export declare class ExportUJsonPluginV1 extends PluginBase {
3
+ name: string;
4
+ tags: string[];
5
+ handleSheet(paras: HandleSheetParams): string | null;
6
+ handleBatch(paras: HandleBatchParams): void;
7
+ }
8
+ //# sourceMappingURL=ExportUnityCSJsonPluginV1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExportUnityCSJsonPluginV1.d.ts","sourceRoot":"","sources":["../src/ExportUnityCSJsonPluginV1.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAAE,iBAAiB,EAAqC,MAAM,kBAAkB,CAAA;AAgGxJ,qBAAa,mBAAoB,SAAQ,UAAU;IAClD,IAAI,SAAW;IACf,IAAI,EAAE,MAAM,EAAE,CAAa;IAE3B,WAAW,CAAC,KAAK,EAAE,iBAAiB;IAmBpC,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;CAsB3C"}
@@ -0,0 +1,149 @@
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.ExportUJsonPluginV1 = void 0;
27
+ const export_table_lib_1 = require("export-table-lib");
28
+ const fs = __importStar(require("fs-extra"));
29
+ let firstLetterUpper = export_table_lib_1.makeFirstLetterUpper;
30
+ function exportUJson(paras) {
31
+ let { datas, fields, name, objects, table, } = paras;
32
+ let firstLetterLower = function (str) {
33
+ return str.charAt(0).toLowerCase() + str.slice(1);
34
+ };
35
+ let convMemberName = function (str) {
36
+ return str.split("_").map(s => firstLetterUpper(s)).join("");
37
+ };
38
+ var fullName = `${table.workbookName}-${name}`;
39
+ let jsonString = JSON.stringify(objects.map(obj => {
40
+ var newObj = Object.create(null);
41
+ Object.keys(obj).forEach(key => {
42
+ var newKey = convMemberName(key);
43
+ newObj[newKey] = obj[key];
44
+ });
45
+ return newObj;
46
+ }));
47
+ // !!!必须开头没有空格
48
+ let temp = `%YAML 1.1
49
+ %TAG !u! tag:unity3d.com,2011:
50
+ --- !u!114 &11400000
51
+ MonoBehaviour:
52
+ m_ObjectHideFlags: 0
53
+ m_CorrespondingSourceObject: {fileID: 0}
54
+ m_PrefabInstance: {fileID: 0}
55
+ m_PrefabAsset: {fileID: 0}
56
+ m_GameObject: {fileID: 0}
57
+ m_Enabled: 1
58
+ m_EditorHideFlags: 0
59
+ m_Script: {fileID: 11500000, guid: 496f60086c072a8479a6e0b948efb5e8, type: 3}
60
+ m_Name: ${fullName}
61
+ m_EditorClassIdentifier:
62
+ JsonText: ${JSON.stringify(jsonString)}
63
+ `;
64
+ return temp;
65
+ }
66
+ function exportUJsonLoader(paras) {
67
+ let { datas, fields, name, objects, table, } = paras;
68
+ let RowClass = firstLetterUpper(name);
69
+ var fullName = `${table.workbookName}-${name}`;
70
+ // !!!必须开头没有空格
71
+ let temp = `
72
+ using lang.json;
73
+ using UnityEngine.AddressableAssets;
74
+ using System.Threading.Tasks;
75
+ using UnityEngine;
76
+
77
+ namespace MEEC.ExportedConfigs
78
+ {
79
+ public partial class ${RowClass}
80
+ {
81
+ public static async Task Load()
82
+ {
83
+ var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.asset";
84
+ var configJson = await Addressables.LoadAssetAsync<ExcelConfigJson>(loadUrl).Task;
85
+ if (configJson != null)
86
+ {
87
+ var jsonObjs = JSON.parse<${RowClass}[]>(configJson.JsonText);
88
+ var configs = ${RowClass}.Configs;
89
+ configs.Clear();
90
+ configs.AddRange(jsonObjs);
91
+ }
92
+ else
93
+ {
94
+ Debug.LogError($"配表资源缺失: {loadUrl}");
95
+ }
96
+ }
97
+ }
98
+ }
99
+ `;
100
+ return temp;
101
+ }
102
+ class ExportUJsonPluginV1 extends export_table_lib_1.PluginBase {
103
+ constructor() {
104
+ super(...arguments);
105
+ this.name = "ujson1";
106
+ this.tags = ["ujson1"];
107
+ }
108
+ handleSheet(paras) {
109
+ var fullName = `${paras.table.workbookName}-${paras.name}`;
110
+ {
111
+ let content1 = exportUJsonLoader(paras);
112
+ if (content1 != null) {
113
+ let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, "Loader.cs").fullPath;
114
+ fs.outputFileSync(savePath, content1, "utf-8");
115
+ }
116
+ }
117
+ {
118
+ let content2 = exportUJson(paras);
119
+ if (content2 != null) {
120
+ let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, ".asset").fullPath;
121
+ fs.outputFileSync(savePath, content2, "utf-8");
122
+ }
123
+ return content2;
124
+ }
125
+ }
126
+ handleBatch(paras) {
127
+ var tables = paras.tables;
128
+ var temp = `
129
+ using System;
130
+ using System.Collections.Generic;
131
+ using System.Threading.Tasks;
132
+
133
+ namespace MEEC.ExportedConfigs
134
+ {
135
+ public static class DefaultConfigLoader{
136
+ public static IEnumerable<Func<Task>> Load(){
137
+ ${(0, export_table_lib_1.foreach)(tables, (table) => `
138
+ yield return ${firstLetterUpper(table.name)}.Load;
139
+ `)}
140
+ yield break;
141
+ }
142
+ }
143
+ }
144
+ `;
145
+ let savePath = paras.outPath + "/DefaultConfigLoader.cs";
146
+ fs.outputFileSync(savePath, temp, "utf-8");
147
+ }
148
+ }
149
+ exports.ExportUJsonPluginV1 = ExportUJsonPluginV1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "export-table-pulgin-csharp",
3
- "version": "1.1.65",
3
+ "version": "1.1.67",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -90,7 +90,7 @@ export function export_stuff(paras: HandleSheetParams): string | null {
90
90
  for (let k in value) {
91
91
  convert.push(`{"${k}","${(value as any)[k].toString()}"}`);
92
92
  };
93
- return `new Dictionary<string,string>(){${convert}}`;
93
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
94
94
  } else if (t == "object[]") {
95
95
  let values = value as object[];
96
96
  //throw new Error("invalid type <object[]>")
@@ -99,7 +99,7 @@ export function export_stuff(paras: HandleSheetParams): string | null {
99
99
  for (let k in val) {
100
100
  convert.push(`{"${k}","${(val as any)[k].toString()}"}`);
101
101
  };
102
- return `new Dictionary<string,string>(){${convert}}`;
102
+ return `new Dictionary<string,string>(${convert.length}){${convert}}`;
103
103
  })}}`
104
104
  } else if (t == "number" || t == "int" || t == "long") {
105
105
  return `${value}`
@@ -213,34 +213,41 @@ ${foreach(fields, f => {
213
213
  #region uid map
214
214
  ${foreach(fields, f => {
215
215
  if (f.isUnique) {
216
+ let memberName = convMemberName(f.name);
217
+ let tempDictByMemberName = `_tempDictBy${memberName}`;
218
+ let memberType = getFieldType(f);
216
219
  return `
217
- protected static Dictionary<${getFieldType(f)}, ${RowClass}> _tempDictBy${convMemberName(f.name)};
218
- public static ${RowClass} GetConfigBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
220
+ protected static Dictionary<${memberType}, ${RowClass}> ${tempDictByMemberName};
221
+ public static ${RowClass} GetConfigBy${memberName}(${memberType} ${memberName})
219
222
  {
220
- if (_tempDictBy${convMemberName(f.name)} == null)
223
+ if (${tempDictByMemberName} == null)
221
224
  {
222
- _tempDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}>();
223
- Configs.ForEach(c =>
225
+ ${tempDictByMemberName} = new Dictionary<${memberType}, ${RowClass}>(Configs.Count);
226
+ for(var i = 0; i < Configs.Count; i++)
224
227
  {
225
- _tempDictBy${convMemberName(f.name)}.Add(c.${convMemberName(f.name)}, c);
226
- });
228
+ var c = Configs[i];
229
+ ${tempDictByMemberName}.Add(c.${memberName}, c);
230
+ }
227
231
  }
228
- return _tempDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
232
+ return ${tempDictByMemberName}.GetValueOrDefault(${memberName});
229
233
  }
230
234
  `
231
235
  } else if (f.type == "number" || f.type == "int" || f.type == "long" || f.type == "string") {
236
+ let memberName = convMemberName(f.name);
237
+ let tempRecordsDictByMemberName = `_tempRecordsDictBy${memberName}`;
238
+ let memberType = getFieldType(f);
232
239
  return `
233
- protected static Dictionary<${getFieldType(f)}, ${RowClass}[]> _tempRecordsDictBy${convMemberName(f.name)} = new Dictionary<${getFieldType(f)}, ${RowClass}[]>();
234
- public static ${RowClass}[] GetConfigsBy${convMemberName(f.name)}(${getFieldType(f)} ${convMemberName(f.name)})
240
+ protected static Dictionary<${memberType}, ${RowClass}[]> ${tempRecordsDictByMemberName} = new Dictionary<${memberType}, ${RowClass}[]>(Configs.Count);
241
+ public static ${RowClass}[] GetConfigsBy${memberName}(${memberType} ${memberName})
235
242
  {
236
- if (_tempRecordsDictBy${convMemberName(f.name)}.ContainsKey(${convMemberName(f.name)}))
243
+ if (${tempRecordsDictByMemberName}.ContainsKey(${memberName}))
237
244
  {
238
- return _tempRecordsDictBy${convMemberName(f.name)}.GetValueOrDefault(${convMemberName(f.name)});
245
+ return ${tempRecordsDictByMemberName}.GetValueOrDefault(${memberName});
239
246
  }
240
247
  else
241
248
  {
242
- var records = Configs.Where(c => c.${convMemberName(f.name)} == ${convMemberName(f.name)}).ToArray();
243
- _tempRecordsDictBy${convMemberName(f.name)}.Add(${convMemberName(f.name)}, records);
249
+ var records = Configs.Where(c => c.${memberName} == ${memberName});//.ToArray();
250
+ ${tempRecordsDictByMemberName}.Add(${memberName}, records);
244
251
  return records;
245
252
  }
246
253
  }
@@ -1,184 +1,182 @@
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
- let firstLetterUpper = function (str: string) {
6
- return str.charAt(0).toUpperCase() + str.slice(1);
7
- };
8
- export function exportUJson(paras: HandleSheetParams): string | null {
9
- let {
10
- datas,
11
- fields,
12
- name,
13
- objects,
14
- table,
15
- } = paras;
16
-
17
- let firstLetterLower = function (str: string) {
18
- return str.charAt(0).toLowerCase() + str.slice(1);
19
- };
20
- let convMemberName = function (str: string) {
21
- return str.split("_").map(s => firstLetterUpper(s)).join("")
22
- }
23
-
24
- var fullName = `${table.workbookName}-${name}`
25
- let jsonString = JSON.stringify(objects.map(obj => {
26
- var newObj = Object.create(null);
27
- Object.keys(obj).forEach(key => {
28
- var newKey = convMemberName(key);
29
- newObj[newKey] = obj[key];
30
- })
31
- return newObj
32
- }));
33
-
34
- return jsonString;
35
-
36
- // // !!!必须开头没有空格
37
- // let temp = `%YAML 1.1
38
- // %TAG !u! tag:unity3d.com,2011:
39
- // --- !u!114 &11400000
40
- // MonoBehaviour:
41
- // m_ObjectHideFlags: 0
42
- // m_CorrespondingSourceObject: {fileID: 0}
43
- // m_PrefabInstance: {fileID: 0}
44
- // m_PrefabAsset: {fileID: 0}
45
- // m_GameObject: {fileID: 0}
46
- // m_Enabled: 1
47
- // m_EditorHideFlags: 0
48
- // m_Script: {fileID: 11500000, guid: 496f60086c072a8479a6e0b948efb5e8, type: 3}
49
- // m_Name: ${fullName}
50
- // m_EditorClassIdentifier:
51
- // JsonText: ${JSON.stringify(jsonString)}
52
- // `
53
- // return temp
54
-
55
- }
56
-
57
- export function exportUJsonLoader(paras: HandleSheetParams): string | null {
58
- let {
59
- datas,
60
- fields,
61
- name,
62
- objects,
63
- table,
64
- } = paras;
65
-
66
- let RowClass = firstLetterUpper(name)
67
- var fullName = `${table.workbookName}-${name}`
68
- // !!!必须开头没有空格
69
- let temp = `
70
- using UnityEngine.AddressableAssets;
71
- using System.Threading.Tasks;
72
- using UnityEngine;
73
- using lang.json;
74
-
75
- namespace MEEC.ExportedConfigs
76
- {
77
- public partial class ${RowClass}
78
- {
79
- #if UNITY_EDITOR && ENABLE_CONFIG_LOG
80
- static ${RowClass}()
81
- {
82
- Debug.Log("ReferConfig-${RowClass}");
83
- }
84
- #endif
85
- public static async Task Load()
86
- {
87
- var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
88
- var configJson =
89
- #if UNITY_EDITOR
90
- Application.isPlaying ? await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task
91
- : UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
92
- #else
93
- await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task;
94
- #endif
95
- if (configJson != null)
96
- {
97
- var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
98
- var configs = ${RowClass}.Configs;
99
- configs.Clear();
100
- configs.AddRange(jsonObjs);
101
- }
102
- else
103
- {
104
- Debug.LogError($"配表资源缺失: {loadUrl}");
105
- }
106
- }
107
-
108
- #if UNITY_EDITOR
109
- public static void LoadInEditor()
110
- {
111
- if (Application.isPlaying)
112
- {
113
- var tip = $"cannot load ${RowClass}[] with LoadInEditor at runtime";
114
- Debug.LogError(tip);
115
- throw new System.Exception(tip);
116
- }
117
- var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
118
- var configJson = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
119
- if (configJson != null)
120
- {
121
- var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
122
- var configs = ${RowClass}.Configs;
123
- configs.Clear();
124
- configs.AddRange(jsonObjs);
125
- }
126
- else
127
- {
128
- Debug.LogError($"配表资源缺失: {loadUrl}");
129
- }
130
- }
131
- #endif
132
- }
133
- }
134
- `
135
- return temp
136
-
137
- }
138
-
139
- export class ExportUJsonPlugin extends PluginBase {
140
- name = "ujson"
141
- tags: string[] = ["ujson"]
142
-
143
- handleSheet(paras: HandleSheetParams) {
144
- var fullName = `${paras.table.workbookName}-${paras.name}`
145
- {
146
- let content1 = exportUJsonLoader(paras)
147
- if (content1 != null) {
148
- let savePath = new OutFilePath(paras.outPath, fullName, "Loader.cs").fullPath
149
- fs.outputFileSync(savePath, content1, "utf-8")
150
- }
151
- }
152
- {
153
- let content2 = exportUJson(paras)
154
- if (content2 != null) {
155
- let savePath = new OutFilePath(paras.outPath, fullName, ".json").fullPath
156
- fs.outputFileSync(savePath, content2, "utf-8")
157
- }
158
- return content2
159
- }
160
- }
161
-
162
- handleBatch(paras: HandleBatchParams): void {
163
- var tables = paras.tables;
164
- var temp = `
165
- using System;
166
- using System.Collections.Generic;
167
- using System.Threading.Tasks;
168
-
169
- namespace MEEC.ExportedConfigs
170
- {
171
- public static class DefaultConfigLoader{
172
- public static IEnumerable<Func<Task>> Load(){
173
- ${foreach(tables, (table) => `
174
- yield return ${firstLetterUpper(table.name)}.Load;
175
- `)}
176
- yield break;
177
- }
178
- }
179
- }
180
- `
181
- let savePath = paras.outPath + "/DefaultConfigLoader.cs";
182
- fs.outputFileSync(savePath, temp, "utf-8");
183
- }
184
- }
1
+
2
+ import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, OutFilePath, makeFirstLetterUpper } from "export-table-lib"
3
+ import * as fs from "fs-extra"
4
+
5
+ let firstLetterUpper = makeFirstLetterUpper;
6
+ export function exportUJson(paras: HandleSheetParams): string | null {
7
+ let {
8
+ datas,
9
+ fields,
10
+ name,
11
+ objects,
12
+ table,
13
+ } = paras;
14
+
15
+ let firstLetterLower = function (str: string) {
16
+ return str.charAt(0).toLowerCase() + str.slice(1);
17
+ };
18
+ let convMemberName = function (str: string) {
19
+ return str.split("_").map(s => firstLetterUpper(s)).join("")
20
+ }
21
+
22
+ var fullName = `${table.workbookName}-${name}`
23
+ let jsonString = JSON.stringify(objects.map(obj => {
24
+ var newObj = Object.create(null);
25
+ Object.keys(obj).forEach(key => {
26
+ var newKey = convMemberName(key);
27
+ newObj[newKey] = obj[key];
28
+ })
29
+ return newObj
30
+ }));
31
+
32
+ return jsonString;
33
+
34
+ // // !!!必须开头没有空格
35
+ // let temp = `%YAML 1.1
36
+ // %TAG !u! tag:unity3d.com,2011:
37
+ // --- !u!114 &11400000
38
+ // MonoBehaviour:
39
+ // m_ObjectHideFlags: 0
40
+ // m_CorrespondingSourceObject: {fileID: 0}
41
+ // m_PrefabInstance: {fileID: 0}
42
+ // m_PrefabAsset: {fileID: 0}
43
+ // m_GameObject: {fileID: 0}
44
+ // m_Enabled: 1
45
+ // m_EditorHideFlags: 0
46
+ // m_Script: {fileID: 11500000, guid: 496f60086c072a8479a6e0b948efb5e8, type: 3}
47
+ // m_Name: ${fullName}
48
+ // m_EditorClassIdentifier:
49
+ // JsonText: ${JSON.stringify(jsonString)}
50
+ // `
51
+ // return temp
52
+
53
+ }
54
+
55
+ export function exportUJsonLoader(paras: HandleSheetParams): string | null {
56
+ let {
57
+ datas,
58
+ fields,
59
+ name,
60
+ objects,
61
+ table,
62
+ } = paras;
63
+
64
+ let RowClass = firstLetterUpper(name)
65
+ var fullName = `${table.workbookName}-${name}`
66
+ // !!!必须开头没有空格
67
+ let temp = `
68
+ using UnityEngine.AddressableAssets;
69
+ using System.Threading.Tasks;
70
+ using UnityEngine;
71
+ using lang.json;
72
+
73
+ namespace MEEC.ExportedConfigs
74
+ {
75
+ public partial class ${RowClass}
76
+ {
77
+ #if UNITY_EDITOR && ENABLE_CONFIG_LOG
78
+ static ${RowClass}()
79
+ {
80
+ Debug.Log("ReferConfig-${RowClass}");
81
+ }
82
+ #endif
83
+ public static async Task Load()
84
+ {
85
+ var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
86
+ var configJson =
87
+ #if UNITY_EDITOR
88
+ Application.isPlaying ? await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task
89
+ : UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
90
+ #else
91
+ await Addressables.LoadAssetAsync<TextAsset>(loadUrl).Task;
92
+ #endif
93
+ if (configJson != null)
94
+ {
95
+ var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
96
+ var configs = ${RowClass}.Configs;
97
+ configs.Clear();
98
+ configs.AddRange(jsonObjs);
99
+ }
100
+ else
101
+ {
102
+ Debug.LogError($"配表资源缺失: {loadUrl}");
103
+ }
104
+ }
105
+
106
+ #if UNITY_EDITOR
107
+ public static void LoadInEditor()
108
+ {
109
+ if (Application.isPlaying)
110
+ {
111
+ var tip = $"cannot load ${RowClass}[] with LoadInEditor at runtime";
112
+ Debug.LogError(tip);
113
+ throw new System.Exception(tip);
114
+ }
115
+ var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.json";
116
+ var configJson = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(loadUrl);
117
+ if (configJson != null)
118
+ {
119
+ var jsonObjs = JSON.parse<${RowClass}[]>(configJson.text);
120
+ var configs = ${RowClass}.Configs;
121
+ configs.Clear();
122
+ configs.AddRange(jsonObjs);
123
+ }
124
+ else
125
+ {
126
+ Debug.LogError($"配表资源缺失: {loadUrl}");
127
+ }
128
+ }
129
+ #endif
130
+ }
131
+ }
132
+ `
133
+ return temp
134
+
135
+ }
136
+
137
+ export class ExportUJsonPlugin extends PluginBase {
138
+ name = "ujson"
139
+ tags: string[] = ["ujson"]
140
+
141
+ handleSheet(paras: HandleSheetParams) {
142
+ var fullName = `${paras.table.workbookName}-${paras.name}`
143
+ {
144
+ let content1 = exportUJsonLoader(paras)
145
+ if (content1 != null) {
146
+ let savePath = new OutFilePath(paras.outPath, fullName, "Loader.cs").fullPath
147
+ fs.outputFileSync(savePath, content1, "utf-8")
148
+ }
149
+ }
150
+ {
151
+ let content2 = exportUJson(paras)
152
+ if (content2 != null) {
153
+ let savePath = new OutFilePath(paras.outPath, fullName, ".json").fullPath
154
+ fs.outputFileSync(savePath, content2, "utf-8")
155
+ }
156
+ return content2
157
+ }
158
+ }
159
+
160
+ handleBatch(paras: HandleBatchParams): void {
161
+ var tables = paras.tables;
162
+ var temp = `
163
+ using System;
164
+ using System.Collections.Generic;
165
+ using System.Threading.Tasks;
166
+
167
+ namespace MEEC.ExportedConfigs
168
+ {
169
+ public static class DefaultConfigLoader{
170
+ public static IEnumerable<Func<Task>> Load(){
171
+ ${foreach(tables, (table) => `
172
+ yield return ${firstLetterUpper(table.name)}.Load;
173
+ `)}
174
+ yield break;
175
+ }
176
+ }
177
+ }
178
+ `
179
+ let savePath = paras.outPath + "/DefaultConfigLoader.cs";
180
+ fs.outputFileSync(savePath, temp, "utf-8");
181
+ }
182
+ }
@@ -0,0 +1,143 @@
1
+
2
+ import { cmm, HandleSheetParams, Field, foreach, IPlugin, st, PluginBase, HandleBatchParams, OutFilePath, makeFirstLetterUpper } from "export-table-lib"
3
+ import * as fs from "fs-extra"
4
+
5
+ let firstLetterUpper = makeFirstLetterUpper;
6
+ function exportUJson(paras: HandleSheetParams): string | null {
7
+ let {
8
+ datas,
9
+ fields,
10
+ name,
11
+ objects,
12
+ table,
13
+ } = paras;
14
+
15
+ let firstLetterLower = function (str: string) {
16
+ return str.charAt(0).toLowerCase() + str.slice(1);
17
+ };
18
+ let convMemberName = function (str: string) {
19
+ return str.split("_").map(s => firstLetterUpper(s)).join("")
20
+ }
21
+
22
+ var fullName = `${table.workbookName}-${name}`
23
+ let jsonString = JSON.stringify(objects.map(obj => {
24
+ var newObj = Object.create(null);
25
+ Object.keys(obj).forEach(key => {
26
+ var newKey = convMemberName(key);
27
+ newObj[newKey] = obj[key];
28
+ })
29
+ return newObj
30
+ }));
31
+
32
+ // !!!必须开头没有空格
33
+ let temp = `%YAML 1.1
34
+ %TAG !u! tag:unity3d.com,2011:
35
+ --- !u!114 &11400000
36
+ MonoBehaviour:
37
+ m_ObjectHideFlags: 0
38
+ m_CorrespondingSourceObject: {fileID: 0}
39
+ m_PrefabInstance: {fileID: 0}
40
+ m_PrefabAsset: {fileID: 0}
41
+ m_GameObject: {fileID: 0}
42
+ m_Enabled: 1
43
+ m_EditorHideFlags: 0
44
+ m_Script: {fileID: 11500000, guid: 496f60086c072a8479a6e0b948efb5e8, type: 3}
45
+ m_Name: ${fullName}
46
+ m_EditorClassIdentifier:
47
+ JsonText: ${JSON.stringify(jsonString)}
48
+ `
49
+ return temp
50
+
51
+ }
52
+
53
+ function exportUJsonLoader(paras: HandleSheetParams): string | null {
54
+ let {
55
+ datas,
56
+ fields,
57
+ name,
58
+ objects,
59
+ table,
60
+ } = paras;
61
+
62
+ let RowClass = firstLetterUpper(name)
63
+ var fullName = `${table.workbookName}-${name}`
64
+ // !!!必须开头没有空格
65
+ let temp = `
66
+ using lang.json;
67
+ using UnityEngine.AddressableAssets;
68
+ using System.Threading.Tasks;
69
+ using UnityEngine;
70
+
71
+ namespace MEEC.ExportedConfigs
72
+ {
73
+ public partial class ${RowClass}
74
+ {
75
+ public static async Task Load()
76
+ {
77
+ var loadUrl="Assets/Bundles/GameConfigs/Auto/${fullName}.asset";
78
+ var configJson = await Addressables.LoadAssetAsync<ExcelConfigJson>(loadUrl).Task;
79
+ if (configJson != null)
80
+ {
81
+ var jsonObjs = JSON.parse<${RowClass}[]>(configJson.JsonText);
82
+ var configs = ${RowClass}.Configs;
83
+ configs.Clear();
84
+ configs.AddRange(jsonObjs);
85
+ }
86
+ else
87
+ {
88
+ Debug.LogError($"配表资源缺失: {loadUrl}");
89
+ }
90
+ }
91
+ }
92
+ }
93
+ `
94
+ return temp
95
+
96
+ }
97
+
98
+ export class ExportUJsonPluginV1 extends PluginBase {
99
+ name = "ujson1"
100
+ tags: string[] = ["ujson1"]
101
+
102
+ handleSheet(paras: HandleSheetParams) {
103
+ var fullName = `${paras.table.workbookName}-${paras.name}`
104
+ {
105
+ let content1 = exportUJsonLoader(paras)
106
+ if (content1 != null) {
107
+ let savePath = new OutFilePath(paras.outPath, fullName, "Loader.cs").fullPath
108
+ fs.outputFileSync(savePath, content1, "utf-8")
109
+ }
110
+ }
111
+ {
112
+ let content2 = exportUJson(paras)
113
+ if (content2 != null) {
114
+ let savePath = new OutFilePath(paras.outPath, fullName, ".asset").fullPath
115
+ fs.outputFileSync(savePath, content2, "utf-8")
116
+ }
117
+ return content2
118
+ }
119
+ }
120
+
121
+ handleBatch(paras: HandleBatchParams): void {
122
+ var tables = paras.tables;
123
+ var temp = `
124
+ using System;
125
+ using System.Collections.Generic;
126
+ using System.Threading.Tasks;
127
+
128
+ namespace MEEC.ExportedConfigs
129
+ {
130
+ public static class DefaultConfigLoader{
131
+ public static IEnumerable<Func<Task>> Load(){
132
+ ${foreach(tables, (table) => `
133
+ yield return ${firstLetterUpper(table.name)}.Load;
134
+ `)}
135
+ yield break;
136
+ }
137
+ }
138
+ }
139
+ `
140
+ let savePath = paras.outPath + "/DefaultConfigLoader.cs";
141
+ fs.outputFileSync(savePath, temp, "utf-8");
142
+ }
143
+ }
package/test/testCS.bat CHANGED
@@ -1 +1 @@
1
- node E:\DATA\Projects\netease\quicktable\export-table\dist\launch.js export src dist --tags csharp:cs --libs E:\DATA\Projects\netease\quicktable %*
1
+ node E:\DATA\Projects\netease\quicktable\export-table\dist\launch.js export src dist --tags csharp:cs --libs E:\DATA\Projects\netease\quicktable %*
@@ -1 +1 @@
1
- node E:\DATA\Projects\netease\quicktable\export-table\dist\launch.js export src dist --tags csharp:ujson --libs E:\DATA\Projects\netease\quicktable %*
1
+ node E:\DATA\Projects\netease\quicktable\export-table\dist\launch.js export src dist --tags csharp:ujson --libs E:\DATA\Projects\netease\quicktable %*