export-table-pulgin-csharp 1.1.65 → 1.1.66

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":"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.66",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -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 %*