cocos2d-cli 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cocos2d-cli",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes",
5
5
  "main": "bin/cocos2d-cli.js",
6
6
  "bin": {
@@ -6,7 +6,7 @@ const fs = require('fs');
6
6
  const path = require('path');
7
7
  const { CCNode, CCScene, CCSceneAsset, CCCanvas, CCWidget, CCCamera } = require('../lib/cc');
8
8
  const { buildTree } = require('../lib/node-utils');
9
- const { loadScriptMap } = require('../lib/fire-utils');
9
+ const { loadScriptMap, createSceneMeta, saveMetaFile } = require('../lib/fire-utils');
10
10
  const { generateUUID, generateCompressedUUID } = require('../lib/utils');
11
11
  const { fromJSON } = require('../lib/json-parser');
12
12
 
@@ -168,6 +168,11 @@ function run(args) {
168
168
  // 保存
169
169
  const data = asset.toJSON();
170
170
  fs.writeFileSync(outputPath, JSON.stringify(data, null, 2), 'utf8');
171
+
172
+ // 生成并保存 meta 文件(如果不存在)
173
+ if (!uuid) {
174
+ saveMetaFile(outputPath, createSceneMeta(scene._id));
175
+ }
171
176
 
172
177
  // 输出 tree
173
178
  const scriptMap = loadScriptMap(outputPath);
@@ -8,7 +8,7 @@ const { outputError } = require('../lib/utils');
8
8
  const { buildTree } = require('../lib/node-utils');
9
9
  const { createPrefab } = require('../lib/templates');
10
10
  const { CCPrefab, CCPrefabInfo } = require('../lib/cc');
11
- const { loadScriptMap } = require('../lib/fire-utils');
11
+ const { loadScriptMap, createPrefabMeta, saveMetaFile } = require('../lib/fire-utils');
12
12
  const { fromJSON } = require('../lib/json-parser');
13
13
 
14
14
  /**
@@ -60,6 +60,9 @@ function run(args) {
60
60
  const data = prefab.toJSON();
61
61
  fs.writeFileSync(outputPath, JSON.stringify(data, null, 2), 'utf8');
62
62
 
63
+ // 生成并保存 meta 文件
64
+ saveMetaFile(outputPath, createPrefabMeta());
65
+
63
66
  const scriptMap = loadScriptMap(outputPath);
64
67
  console.log(buildTree(data, scriptMap, 1).trim());
65
68
  return;
@@ -93,6 +96,9 @@ function run(args) {
93
96
 
94
97
  const data = prefab.toJSON();
95
98
  fs.writeFileSync(outputPath, JSON.stringify(data, null, 2), 'utf8');
99
+
100
+ // 生成并保存 meta 文件
101
+ saveMetaFile(outputPath, createPrefabMeta());
96
102
 
97
103
  const scriptMap = loadScriptMap(outputPath);
98
104
  console.log(buildTree(data, scriptMap, 1).trim());
@@ -5,6 +5,7 @@
5
5
 
6
6
  const fs = require('fs');
7
7
  const path = require('path');
8
+ const crypto = require('crypto');
8
9
 
9
10
  /**
10
11
  * 检测是否为预制体文件
@@ -277,6 +278,72 @@ function getPrefabRootIndex(data) {
277
278
  return 1;
278
279
  }
279
280
 
281
+ /**
282
+ * 生成 UUID
283
+ */
284
+ function generateUUID() {
285
+ return crypto.randomUUID();
286
+ }
287
+
288
+ /**
289
+ * 生成预制体的 meta 对象
290
+ * @param {string} uuid - 可选的 UUID,不传则自动生成
291
+ * @returns {object}
292
+ */
293
+ function createPrefabMeta(uuid) {
294
+ return {
295
+ ver: '1.3.2',
296
+ uuid: uuid || generateUUID(),
297
+ importer: 'prefab',
298
+ optimizationPolicy: 'AUTO',
299
+ asyncLoadAssets: false,
300
+ readonly: false,
301
+ subMetas: {}
302
+ };
303
+ }
304
+
305
+ /**
306
+ * 生成场景的 meta 对象
307
+ * @param {string} uuid - 可选的 UUID,不传则自动生成
308
+ * @returns {object}
309
+ */
310
+ function createSceneMeta(uuid) {
311
+ return {
312
+ ver: '1.3.2',
313
+ uuid: uuid || generateUUID(),
314
+ importer: 'scene',
315
+ asyncLoadAssets: false,
316
+ autoReleaseAssets: false,
317
+ subMetas: {}
318
+ };
319
+ }
320
+
321
+ /**
322
+ * 保存 meta 文件
323
+ * @param {string} filePath - 资源文件路径(.prefab 或 .fire)
324
+ * @param {object} meta - meta 对象
325
+ */
326
+ function saveMetaFile(filePath, meta) {
327
+ const metaPath = filePath + '.meta';
328
+ fs.writeFileSync(metaPath, JSON.stringify(meta, null, 2), 'utf8');
329
+ return metaPath;
330
+ }
331
+
332
+ /**
333
+ * 加载 meta 文件
334
+ * @param {string} filePath - 资源文件路径
335
+ * @returns {object|null}
336
+ */
337
+ function loadMetaFile(filePath) {
338
+ const metaPath = filePath + '.meta';
339
+ try {
340
+ if (fs.existsSync(metaPath)) {
341
+ return JSON.parse(fs.readFileSync(metaPath, 'utf8'));
342
+ }
343
+ } catch (e) {}
344
+ return null;
345
+ }
346
+
280
347
  module.exports = {
281
348
  // 文件操作
282
349
  loadScene,
@@ -293,6 +360,13 @@ module.exports = {
293
360
  installPlugin,
294
361
  checkPluginStatus,
295
362
 
363
+ // Meta 文件管理
364
+ generateUUID,
365
+ createPrefabMeta,
366
+ createSceneMeta,
367
+ saveMetaFile,
368
+ loadMetaFile,
369
+
296
370
  // 工具函数
297
371
  loadScriptMap,
298
372
  generateFileId,
@@ -1,72 +0,0 @@
1
- [
2
- {
3
- "__type__": "cc.Prefab",
4
- "_name": "",
5
- "_objFlags": 0,
6
- "_native": "",
7
- "data": {
8
- "__id__": 1
9
- },
10
- "optimizationPolicy": 0,
11
- "asyncLoadAssets": false,
12
- "readonly": false
13
- },
14
- {
15
- "__type__": "cc.Node",
16
- "_name": "RootNode",
17
- "_objFlags": 0,
18
- "_parent": null,
19
- "_children": [],
20
- "_active": true,
21
- "_components": [],
22
- "_prefab": {
23
- "__id__": 2
24
- },
25
- "_opacity": 255,
26
- "_color": {
27
- "__type__": "cc.Color",
28
- "r": 255,
29
- "g": 255,
30
- "b": 255,
31
- "a": 255
32
- },
33
- "_contentSize": {
34
- "__type__": "cc.Size",
35
- "width": 0,
36
- "height": 0
37
- },
38
- "_anchorPoint": {
39
- "__type__": "cc.Vec2",
40
- "x": 0.5,
41
- "y": 0.5
42
- },
43
- "_trs": {
44
- "__type__": "TypedArray",
45
- "ctor": "Float64Array",
46
- "array": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
47
- },
48
- "_eulerAngles": {
49
- "__type__": "cc.Vec3",
50
- "x": 0,
51
- "y": 0,
52
- "z": 0
53
- },
54
- "_skewX": 0,
55
- "_skewY": 0,
56
- "_is3DNode": false,
57
- "_groupIndex": 0,
58
- "groupIndex": 0,
59
- "_id": ""
60
- },
61
- {
62
- "__type__": "cc.PrefabInfo",
63
- "root": {
64
- "__id__": 1
65
- },
66
- "asset": {
67
- "__id__": 0
68
- },
69
- "fileId": "",
70
- "sync": false
71
- }
72
- ]
@@ -1,241 +0,0 @@
1
- [
2
- {
3
- "__type__": "cc.SceneAsset",
4
- "_name": "",
5
- "_objFlags": 0,
6
- "_native": "",
7
- "scene": {
8
- "__id__": 1
9
- }
10
- },
11
- {
12
- "__type__": "cc.Scene",
13
- "_objFlags": 0,
14
- "_parent": null,
15
- "_children": [
16
- {
17
- "__id__": 2
18
- }
19
- ],
20
- "_active": true,
21
- "_components": [],
22
- "_prefab": null,
23
- "_opacity": 255,
24
- "_color": {
25
- "__type__": "cc.Color",
26
- "r": 255,
27
- "g": 255,
28
- "b": 255,
29
- "a": 255
30
- },
31
- "_contentSize": {
32
- "__type__": "cc.Size",
33
- "width": 0,
34
- "height": 0
35
- },
36
- "_anchorPoint": {
37
- "__type__": "cc.Vec2",
38
- "x": 0,
39
- "y": 0
40
- },
41
- "_trs": {
42
- "__type__": "TypedArray",
43
- "ctor": "Float64Array",
44
- "array": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
45
- },
46
- "_is3DNode": true,
47
- "_groupIndex": 0,
48
- "groupIndex": 0,
49
- "autoReleaseAssets": false,
50
- "_id": ""
51
- },
52
- {
53
- "__type__": "cc.Node",
54
- "_name": "Canvas",
55
- "_objFlags": 0,
56
- "_parent": {
57
- "__id__": 1
58
- },
59
- "_children": [
60
- {
61
- "__id__": 3
62
- }
63
- ],
64
- "_active": true,
65
- "_components": [
66
- {
67
- "__id__": 5
68
- },
69
- {
70
- "__id__": 6
71
- }
72
- ],
73
- "_prefab": null,
74
- "_opacity": 255,
75
- "_color": {
76
- "__type__": "cc.Color",
77
- "r": 255,
78
- "g": 255,
79
- "b": 255,
80
- "a": 255
81
- },
82
- "_contentSize": {
83
- "__type__": "cc.Size",
84
- "width": 960,
85
- "height": 640
86
- },
87
- "_anchorPoint": {
88
- "__type__": "cc.Vec2",
89
- "x": 0.5,
90
- "y": 0.5
91
- },
92
- "_trs": {
93
- "__type__": "TypedArray",
94
- "ctor": "Float64Array",
95
- "array": [480, 320, 0, 0, 0, 0, 1, 1, 1, 1]
96
- },
97
- "_eulerAngles": {
98
- "__type__": "cc.Vec3",
99
- "x": 0,
100
- "y": 0,
101
- "z": 0
102
- },
103
- "_skewX": 0,
104
- "_skewY": 0,
105
- "_is3DNode": false,
106
- "_groupIndex": 0,
107
- "groupIndex": 0,
108
- "_id": ""
109
- },
110
- {
111
- "__type__": "cc.Node",
112
- "_name": "Main Camera",
113
- "_objFlags": 0,
114
- "_parent": {
115
- "__id__": 2
116
- },
117
- "_children": [],
118
- "_active": true,
119
- "_components": [
120
- {
121
- "__id__": 4
122
- }
123
- ],
124
- "_prefab": null,
125
- "_opacity": 255,
126
- "_color": {
127
- "__type__": "cc.Color",
128
- "r": 255,
129
- "g": 255,
130
- "b": 255,
131
- "a": 255
132
- },
133
- "_contentSize": {
134
- "__type__": "cc.Size",
135
- "width": 0,
136
- "height": 0
137
- },
138
- "_anchorPoint": {
139
- "__type__": "cc.Vec2",
140
- "x": 0.5,
141
- "y": 0.5
142
- },
143
- "_trs": {
144
- "__type__": "TypedArray",
145
- "ctor": "Float64Array",
146
- "array": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
147
- },
148
- "_eulerAngles": {
149
- "__type__": "cc.Vec3",
150
- "x": 0,
151
- "y": 0,
152
- "z": 0
153
- },
154
- "_skewX": 0,
155
- "_skewY": 0,
156
- "_is3DNode": false,
157
- "_groupIndex": 0,
158
- "groupIndex": 0,
159
- "_id": ""
160
- },
161
- {
162
- "__type__": "cc.Camera",
163
- "_name": "",
164
- "_objFlags": 0,
165
- "node": {
166
- "__id__": 3
167
- },
168
- "_enabled": true,
169
- "_cullingMask": 4294967295,
170
- "_clearFlags": 7,
171
- "_backgroundColor": {
172
- "__type__": "cc.Color",
173
- "r": 0,
174
- "g": 0,
175
- "b": 0,
176
- "a": 255
177
- },
178
- "_depth": -1,
179
- "_zoomRatio": 1,
180
- "_targetTexture": null,
181
- "_fov": 60,
182
- "_orthoSize": 10,
183
- "_nearClip": 1,
184
- "_farClip": 4096,
185
- "_ortho": true,
186
- "_rect": {
187
- "__type__": "cc.Rect",
188
- "x": 0,
189
- "y": 0,
190
- "width": 1,
191
- "height": 1
192
- },
193
- "_renderStages": 1,
194
- "_alignWithScreen": true,
195
- "_id": ""
196
- },
197
- {
198
- "__type__": "cc.Canvas",
199
- "_name": "",
200
- "_objFlags": 0,
201
- "node": {
202
- "__id__": 2
203
- },
204
- "_enabled": true,
205
- "_designResolution": {
206
- "__type__": "cc.Size",
207
- "width": 960,
208
- "height": 640
209
- },
210
- "_fitWidth": false,
211
- "_fitHeight": true,
212
- "_id": ""
213
- },
214
- {
215
- "__type__": "cc.Widget",
216
- "_name": "",
217
- "_objFlags": 0,
218
- "node": {
219
- "__id__": 2
220
- },
221
- "_enabled": true,
222
- "alignMode": 1,
223
- "_target": null,
224
- "_alignFlags": 45,
225
- "_left": 0,
226
- "_right": 0,
227
- "_top": 0,
228
- "_bottom": 0,
229
- "_verticalCenter": 0,
230
- "_horizontalCenter": 0,
231
- "_isAbsLeft": true,
232
- "_isAbsRight": true,
233
- "_isAbsTop": true,
234
- "_isAbsBottom": true,
235
- "_isAbsHorizontalCenter": true,
236
- "_isAbsVerticalCenter": true,
237
- "_originalWidth": 0,
238
- "_originalHeight": 0,
239
- "_id": ""
240
- }
241
- ]