cocos2d-cli 1.6.4 → 2.0.0

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.
Files changed (62) hide show
  1. package/data/script_map.json +25 -25
  2. package/dist/bin/cocos2d-cli.js +64 -0
  3. package/dist/src/commands/add-component.js +3 -0
  4. package/dist/src/commands/add.js +3 -0
  5. package/dist/src/commands/build.js +6 -0
  6. package/dist/src/commands/create-scene.js +3 -0
  7. package/dist/src/commands/get.js +3 -0
  8. package/dist/src/commands/prefab-create.js +109 -0
  9. package/dist/src/commands/remove-component.js +3 -0
  10. package/dist/src/commands/remove.js +3 -0
  11. package/dist/src/commands/screenshot.js +41 -0
  12. package/dist/src/commands/set-component.js +3 -0
  13. package/dist/src/commands/set.js +3 -0
  14. package/dist/src/commands/tree.js +24 -0
  15. package/{src → dist/src}/lib/cc/CCButton.js +26 -33
  16. package/{src → dist/src}/lib/cc/CCCamera.js +20 -30
  17. package/{src → dist/src}/lib/cc/CCCanvas.js +10 -15
  18. package/{src → dist/src}/lib/cc/CCColor.js +6 -8
  19. package/{src → dist/src}/lib/cc/CCComponent.js +8 -29
  20. package/{src → dist/src}/lib/cc/CCLabel.js +44 -51
  21. package/{src → dist/src}/lib/cc/CCNode.js +52 -118
  22. package/{src → dist/src}/lib/cc/CCObject.js +4 -8
  23. package/{src → dist/src}/lib/cc/CCPrefab.js +77 -100
  24. package/{src → dist/src}/lib/cc/CCRect.js +6 -8
  25. package/{src → dist/src}/lib/cc/CCRichText.js +10 -16
  26. package/{src → dist/src}/lib/cc/CCScene.js +3 -13
  27. package/dist/src/lib/cc/CCSceneAsset.js +242 -0
  28. package/{src → dist/src}/lib/cc/CCSize.js +4 -8
  29. package/{src → dist/src}/lib/cc/CCSprite.js +21 -33
  30. package/{src → dist/src}/lib/cc/CCTrs.js +4 -29
  31. package/{src → dist/src}/lib/cc/CCVec2.js +4 -8
  32. package/{src → dist/src}/lib/cc/CCVec3.js +5 -8
  33. package/{src → dist/src}/lib/cc/CCWidget.js +20 -24
  34. package/dist/src/lib/fire-utils.js +86 -0
  35. package/dist/src/lib/json-parser.js +114 -0
  36. package/dist/src/lib/node-utils.js +131 -0
  37. package/{src → dist/src}/lib/screenshot-core.js +54 -119
  38. package/dist/src/lib/templates.js +17 -0
  39. package/dist/src/lib/utils.js +81 -0
  40. package/package.json +40 -33
  41. package/bin/cocos2d-cli.js +0 -152
  42. package/src/commands/add-component.js +0 -112
  43. package/src/commands/add.js +0 -177
  44. package/src/commands/build.js +0 -78
  45. package/src/commands/create-scene.js +0 -181
  46. package/src/commands/get.js +0 -108
  47. package/src/commands/prefab-create.js +0 -111
  48. package/src/commands/remove-component.js +0 -111
  49. package/src/commands/remove.js +0 -99
  50. package/src/commands/screenshot.js +0 -108
  51. package/src/commands/set-component.js +0 -119
  52. package/src/commands/set.js +0 -107
  53. package/src/commands/tree.js +0 -29
  54. package/src/lib/cc/CCSceneAsset.js +0 -303
  55. package/src/lib/cc/index.js +0 -42
  56. package/src/lib/fire-utils.js +0 -374
  57. package/src/lib/json-parser.js +0 -185
  58. package/src/lib/node-utils.js +0 -395
  59. package/src/lib/screenshot/favicon.ico +0 -0
  60. package/src/lib/screenshot/index.html +0 -30
  61. package/src/lib/templates.js +0 -49
  62. package/src/lib/utils.js +0 -202
@@ -1,16 +1,22 @@
1
- const CCComponent = require('./CCComponent');
2
- const CCVec2 = require('./CCVec2');
3
-
1
+ import CCComponent from './CCComponent.js';
2
+ import CCVec2 from './CCVec2.js';
4
3
  const default_sprite_splash = 'a23235d1-15db-4b95-8439-a2e005bfff91';
5
-
6
- /**
7
- * Cocos Creator Sprite 组件
8
- */
9
- class CCSprite extends CCComponent {
4
+ export default class CCSprite extends CCComponent {
5
+ _materials;
6
+ _srcBlendFactor;
7
+ _dstBlendFactor;
8
+ _spriteFrame;
9
+ _type;
10
+ _sizeMode;
11
+ _fillType;
12
+ _fillCenter;
13
+ _fillStart;
14
+ _fillRange;
15
+ _isTrimmedMode;
16
+ _atlas;
10
17
  constructor() {
11
18
  super();
12
19
  this.__type__ = 'cc.Sprite';
13
-
14
20
  this._materials = [{ __uuid__: 'eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432' }];
15
21
  this._srcBlendFactor = 770;
16
22
  this._dstBlendFactor = 771;
@@ -23,30 +29,16 @@ class CCSprite extends CCComponent {
23
29
  this._fillRange = 0;
24
30
  this._isTrimmedMode = true;
25
31
  this._atlas = null;
26
-
27
32
  this.setSpriteFrame(default_sprite_splash);
28
33
  }
29
-
30
- /**
31
- * 设置精灵帧
32
- */
33
34
  setSpriteFrame(uuid) {
34
35
  this._spriteFrame = { __uuid__: uuid };
35
36
  return this;
36
37
  }
37
-
38
- /**
39
- * 设置尺寸模式
40
- * 0: CUSTOM, 1: TRIMMED, 2: RAW
41
- */
42
38
  setSizeMode(mode) {
43
39
  this._sizeMode = mode;
44
40
  return this;
45
41
  }
46
-
47
- /**
48
- * 获取属性
49
- */
50
42
  getProp() {
51
43
  const SIZE_MODE = ['CUSTOM', 'RAW', 'TRIMMED'];
52
44
  const SPRITE_TYPE = ['SIMPLE', 'SLICED', 'TILED', 'FILLED', 'MESH'];
@@ -56,17 +48,15 @@ class CCSprite extends CCComponent {
56
48
  trim: this._isTrimmedMode
57
49
  };
58
50
  }
59
-
60
- /**
61
- * 设置属性
62
- */
63
51
  setProp(props) {
64
- if (props.sizeMode !== undefined) this.setSizeMode(props.sizeMode);
65
- if (props.spriteFrame !== undefined) this.setSpriteFrame(props.spriteFrame);
66
- if (props.type !== undefined) this._type = props.type;
52
+ if (props.sizeMode !== undefined)
53
+ this.setSizeMode(props.sizeMode);
54
+ if (props.spriteFrame !== undefined)
55
+ this.setSpriteFrame(props.spriteFrame);
56
+ if (props.type !== undefined)
57
+ this._type = props.type;
67
58
  return this;
68
59
  }
69
-
70
60
  toJSON() {
71
61
  return {
72
62
  __type__: this.__type__,
@@ -90,5 +80,3 @@ class CCSprite extends CCComponent {
90
80
  };
91
81
  }
92
82
  }
93
-
94
- module.exports = CCSprite;
@@ -1,67 +1,44 @@
1
- /**
2
- * Cocos Creator 变换数据类 (TRS = Translation, Rotation, Scale)
3
- * array: [posX, posY, posZ, rotX, rotY, rotZ, rotW, scaleX, scaleY, scaleZ]
4
- */
5
- class CCTrs {
1
+ export default class CCTrs {
2
+ __type__;
3
+ ctor;
4
+ array;
6
5
  constructor() {
7
6
  this.__type__ = 'TypedArray';
8
7
  this.ctor = 'Float64Array';
9
8
  this.array = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1];
10
9
  }
11
-
12
- // Position
13
10
  get x() { return this.array[0]; }
14
11
  set x(v) { this.array[0] = v; }
15
-
16
12
  get y() { return this.array[1]; }
17
13
  set y(v) { this.array[1] = v; }
18
-
19
14
  get z() { return this.array[2]; }
20
15
  set z(v) { this.array[2] = v; }
21
-
22
- // Scale
23
16
  get scaleX() { return this.array[7]; }
24
17
  set scaleX(v) { this.array[7] = v; }
25
-
26
18
  get scaleY() { return this.array[8]; }
27
19
  set scaleY(v) { this.array[8] = v; }
28
-
29
20
  get scaleZ() { return this.array[9]; }
30
21
  set scaleZ(v) { this.array[9] = v; }
31
-
32
- // Rotation (四元数)
33
22
  get rotX() { return this.array[3]; }
34
23
  set rotX(v) { this.array[3] = v; }
35
-
36
24
  get rotY() { return this.array[4]; }
37
25
  set rotY(v) { this.array[4] = v; }
38
-
39
26
  get rotZ() { return this.array[5]; }
40
27
  set rotZ(v) { this.array[5] = v; }
41
-
42
28
  get rotW() { return this.array[6]; }
43
29
  set rotW(v) { this.array[6] = v; }
44
-
45
- /**
46
- * 设置位置
47
- */
48
30
  setPosition(x, y, z = 0) {
49
31
  this.array[0] = x;
50
32
  this.array[1] = y;
51
33
  this.array[2] = z;
52
34
  return this;
53
35
  }
54
-
55
- /**
56
- * 设置缩放
57
- */
58
36
  setScale(x, y = x, z = 1) {
59
37
  this.array[7] = x;
60
38
  this.array[8] = y;
61
39
  this.array[9] = z;
62
40
  return this;
63
41
  }
64
-
65
42
  toJSON() {
66
43
  return {
67
44
  __type__: this.__type__,
@@ -70,5 +47,3 @@ class CCTrs {
70
47
  };
71
48
  }
72
49
  }
73
-
74
- module.exports = CCTrs;
@@ -1,19 +1,17 @@
1
- /**
2
- * Cocos Creator 二维向量类
3
- */
4
- class CCVec2 {
1
+ export default class CCVec2 {
2
+ __type__;
3
+ x;
4
+ y;
5
5
  constructor(x = 0, y = 0) {
6
6
  this.__type__ = 'cc.Vec2';
7
7
  this.x = x;
8
8
  this.y = y;
9
9
  }
10
-
11
10
  set(x, y) {
12
11
  this.x = x;
13
12
  this.y = y;
14
13
  return this;
15
14
  }
16
-
17
15
  toJSON() {
18
16
  return {
19
17
  __type__: this.__type__,
@@ -22,5 +20,3 @@ class CCVec2 {
22
20
  };
23
21
  }
24
22
  }
25
-
26
- module.exports = CCVec2;
@@ -1,21 +1,20 @@
1
- /**
2
- * Cocos Creator 三维向量类
3
- */
4
- class CCVec3 {
1
+ export default class CCVec3 {
2
+ __type__;
3
+ x;
4
+ y;
5
+ z;
5
6
  constructor(x = 0, y = 0, z = 0) {
6
7
  this.__type__ = 'cc.Vec3';
7
8
  this.x = x;
8
9
  this.y = y;
9
10
  this.z = z;
10
11
  }
11
-
12
12
  set(x, y, z = 0) {
13
13
  this.x = x;
14
14
  this.y = y;
15
15
  this.z = z;
16
16
  return this;
17
17
  }
18
-
19
18
  toJSON() {
20
19
  return {
21
20
  __type__: this.__type__,
@@ -25,5 +24,3 @@ class CCVec3 {
25
24
  };
26
25
  }
27
26
  }
28
-
29
- module.exports = CCVec3;
@@ -1,13 +1,25 @@
1
- const CCComponent = require('./CCComponent');
2
-
3
- /**
4
- * Cocos Creator Widget 组件
5
- */
6
- class CCWidget extends CCComponent {
1
+ import CCComponent from './CCComponent.js';
2
+ export default class CCWidget extends CCComponent {
3
+ alignMode;
4
+ _target;
5
+ _alignFlags;
6
+ _left;
7
+ _right;
8
+ _top;
9
+ _bottom;
10
+ _verticalCenter;
11
+ _horizontalCenter;
12
+ _isAbsLeft;
13
+ _isAbsRight;
14
+ _isAbsTop;
15
+ _isAbsBottom;
16
+ _isAbsHorizontalCenter;
17
+ _isAbsVerticalCenter;
18
+ _originalWidth;
19
+ _originalHeight;
7
20
  constructor() {
8
21
  super();
9
22
  this.__type__ = 'cc.Widget';
10
-
11
23
  this.alignMode = 1;
12
24
  this._target = null;
13
25
  this._alignFlags = 45;
@@ -26,19 +38,10 @@ class CCWidget extends CCComponent {
26
38
  this._originalWidth = 0;
27
39
  this._originalHeight = 0;
28
40
  }
29
-
30
- /**
31
- * 设置对齐标志
32
- * 45 = 左 + 右 + 上 + 下 (全对齐)
33
- */
34
41
  setAlignFlags(flags) {
35
42
  this._alignFlags = flags;
36
43
  return this;
37
44
  }
38
-
39
- /**
40
- * 设置边距
41
- */
42
45
  setMargins(left, right, top, bottom) {
43
46
  this._left = left;
44
47
  this._right = right;
@@ -46,13 +49,9 @@ class CCWidget extends CCComponent {
46
49
  this._bottom = bottom;
47
50
  return this;
48
51
  }
49
-
50
- /**
51
- * 转换为属性面板显示格式
52
- */
53
52
  toPanelJSON() {
54
53
  return {
55
- ...super.toPanelJSON(),
54
+ ...super.getProp(),
56
55
  top: this._top,
57
56
  bottom: this._bottom,
58
57
  left: this._left,
@@ -65,7 +64,6 @@ class CCWidget extends CCComponent {
65
64
  isAbsBottom: this._isAbsBottom
66
65
  };
67
66
  }
68
-
69
67
  toJSON() {
70
68
  return {
71
69
  __type__: this.__type__,
@@ -94,5 +92,3 @@ class CCWidget extends CCComponent {
94
92
  };
95
93
  }
96
94
  }
97
-
98
- module.exports = CCWidget;
@@ -0,0 +1,86 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as crypto from 'crypto';
4
+ export function loadScene(filePath) {
5
+ const content = fs.readFileSync(filePath, 'utf-8');
6
+ return JSON.parse(content);
7
+ }
8
+ export function saveScene(filePath, data) {
9
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
10
+ }
11
+ export function isPrefab(data) {
12
+ return data[0]?.__type__ === 'cc.Prefab';
13
+ }
14
+ export function generateUUID() {
15
+ return crypto.randomUUID();
16
+ }
17
+ export function generateFileId() {
18
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
19
+ let result = '';
20
+ for (let i = 0; i < 22; i++) {
21
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
22
+ }
23
+ return result;
24
+ }
25
+ export function createPrefabMeta(uuid) {
26
+ return {
27
+ ver: '1.0.0',
28
+ uuid: uuid,
29
+ optimizationPolicy: 0,
30
+ asyncLoadAssets: false,
31
+ readonly: false
32
+ };
33
+ }
34
+ export function createSceneMeta(uuid) {
35
+ return {
36
+ ver: '1.0.0',
37
+ uuid: uuid
38
+ };
39
+ }
40
+ export function saveMetaFile(filePath, meta) {
41
+ fs.writeFileSync(filePath + '.meta', JSON.stringify(meta, null, 2), 'utf-8');
42
+ }
43
+ export function loadMetaFile(filePath) {
44
+ const metaPath = filePath + '.meta';
45
+ if (!fs.existsSync(metaPath))
46
+ return null;
47
+ const content = fs.readFileSync(metaPath, 'utf-8');
48
+ return JSON.parse(content);
49
+ }
50
+ export function loadScriptMap(filePath) {
51
+ const mapPath = path.join(path.dirname(filePath), '..', 'script_map.json');
52
+ if (!fs.existsSync(mapPath))
53
+ return {};
54
+ const content = fs.readFileSync(mapPath, 'utf-8');
55
+ return JSON.parse(content);
56
+ }
57
+ export function buildMaps(data) {
58
+ const nodeMap = new Map();
59
+ const compMap = new Map();
60
+ data.forEach((item, index) => {
61
+ if (!item)
62
+ return;
63
+ if (item.__type__ === 'cc.Node') {
64
+ nodeMap.set(index, item);
65
+ }
66
+ else if (item.__type__?.includes('cc.')) {
67
+ compMap.set(index, item);
68
+ }
69
+ });
70
+ return { nodeMap, compMap };
71
+ }
72
+ export function findNodeIndex(data, path) {
73
+ return -1;
74
+ }
75
+ export function rebuildReferences(data) {
76
+ }
77
+ export function refreshEditor(scenePath) {
78
+ }
79
+ export function installPlugin() {
80
+ }
81
+ export function checkPluginStatus() {
82
+ return Promise.resolve(false);
83
+ }
84
+ export function getPrefabRootIndex(data) {
85
+ return 1;
86
+ }
@@ -0,0 +1,114 @@
1
+ import CCNode from './cc/CCNode.js';
2
+ import CCCanvas from './cc/CCCanvas.js';
3
+ import CCWidget from './cc/CCWidget.js';
4
+ import CCSprite from './cc/CCSprite.js';
5
+ import CCLabel from './cc/CCLabel.js';
6
+ import CCButton from './cc/CCButton.js';
7
+ import CCCamera from './cc/CCCamera.js';
8
+ import CCRichText from './cc/CCRichText.js';
9
+ import { parseColor } from './utils.js';
10
+ export function fromJSON(json) {
11
+ const nodes = [];
12
+ json.forEach((item, index) => {
13
+ nodes[index] = parseNode(item);
14
+ });
15
+ json.forEach((item, index) => {
16
+ if (item.children && nodes[index]) {
17
+ item.children.forEach((childIdx) => {
18
+ const child = nodes[childIdx];
19
+ const parent = nodes[index];
20
+ if (child && parent) {
21
+ parent.addChild(child);
22
+ }
23
+ });
24
+ }
25
+ });
26
+ return nodes[0];
27
+ }
28
+ export function parseNode(item) {
29
+ const node = new CCNode(item.name || 'Node');
30
+ if (item.x !== undefined || item.y !== undefined) {
31
+ node.setPosition(item.x ?? 0, item.y ?? 0);
32
+ }
33
+ if (item.width !== undefined || item.height !== undefined) {
34
+ node.setContentSize(item.width ?? 100, item.height ?? 100);
35
+ }
36
+ if (item.scaleX !== undefined || item.scaleY !== undefined) {
37
+ node.setScale(item.scaleX ?? 1, item.scaleY ?? 1);
38
+ }
39
+ if (item.rotation !== undefined) {
40
+ node.setRotation(item.rotation);
41
+ }
42
+ if (item.opacity !== undefined) {
43
+ node.setOpacity(item.opacity);
44
+ }
45
+ if (item.color) {
46
+ const c = parseColor(item.color);
47
+ if (c)
48
+ node.setColor(c.r, c.g, c.b, c.a);
49
+ }
50
+ if (item.anchorX !== undefined || item.anchorY !== undefined) {
51
+ node.setAnchorPoint(item.anchorX ?? 0.5, item.anchorY ?? 0.5);
52
+ }
53
+ if (item.active !== undefined) {
54
+ node.setActive(item.active);
55
+ }
56
+ if (item.components) {
57
+ item.components.forEach((comp) => {
58
+ addComponentToNode(node, comp);
59
+ });
60
+ }
61
+ return node;
62
+ }
63
+ function addComponentToNode(node, comp) {
64
+ switch (comp.type) {
65
+ case 'Sprite':
66
+ node.addComponent(new CCSprite());
67
+ break;
68
+ case 'Label':
69
+ const label = new CCLabel();
70
+ if (comp.string)
71
+ label._string = comp.string;
72
+ if (comp.fontSize)
73
+ label._fontSize = comp.fontSize;
74
+ node.addComponent(label);
75
+ break;
76
+ case 'Button':
77
+ node.addComponent(new CCButton());
78
+ break;
79
+ case 'Canvas':
80
+ node.addComponent(new CCCanvas());
81
+ break;
82
+ case 'Widget':
83
+ node.addComponent(new CCWidget());
84
+ break;
85
+ case 'Camera':
86
+ node.addComponent(new CCCamera());
87
+ break;
88
+ case 'RichText':
89
+ node.addComponent(new CCRichText());
90
+ break;
91
+ }
92
+ }
93
+ export function applyNodeProps(node, props) {
94
+ if (props.name !== undefined)
95
+ node._name = props.name;
96
+ if (props.x !== undefined)
97
+ node.x = props.x;
98
+ if (props.y !== undefined)
99
+ node.y = props.y;
100
+ if (props.width !== undefined)
101
+ node.width = props.width;
102
+ if (props.height !== undefined)
103
+ node.height = props.height;
104
+ if (props.scaleX !== undefined)
105
+ node.scaleX = props.scaleX;
106
+ if (props.scaleY !== undefined)
107
+ node.scaleY = props.scaleY;
108
+ if (props.rotation !== undefined)
109
+ node.setRotation(props.rotation);
110
+ if (props.opacity !== undefined)
111
+ node._opacity = props.opacity;
112
+ if (props.active !== undefined)
113
+ node._active = props.active;
114
+ }
@@ -0,0 +1,131 @@
1
+ import { generateId, parseColorToCcColor } from './utils.js';
2
+ export function createNodeData(name) {
3
+ return {
4
+ __type__: 'cc.Node',
5
+ _name: name,
6
+ _objFlags: 0,
7
+ _parent: null,
8
+ _children: [],
9
+ _active: true,
10
+ _components: [],
11
+ _prefab: null,
12
+ _opacity: 255,
13
+ _color: { __type__: 'cc.Color', r: 255, g: 255, b: 255, a: 255 },
14
+ _contentSize: { __type__: 'cc.Size', width: 100, height: 100 },
15
+ _anchorPoint: { __type__: 'cc.Vec2', x: 0.5, y: 0.5 },
16
+ _trs: {
17
+ __type__: 'TypedArray',
18
+ ctor: 'Float64Array',
19
+ array: [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
20
+ },
21
+ _eulerAngles: { __type__: 'cc.Vec3', x: 0, y: 0, z: 0 },
22
+ _skewX: 0,
23
+ _skewY: 0,
24
+ _is3DNode: false,
25
+ _groupIndex: 0,
26
+ groupIndex: 0,
27
+ _id: generateId()
28
+ };
29
+ }
30
+ export function setNodeProperty(node, key, value) {
31
+ if (key === 'x') {
32
+ node._trs.array[0] = parseFloat(value);
33
+ }
34
+ else if (key === 'y') {
35
+ node._trs.array[1] = parseFloat(value);
36
+ }
37
+ else if (key === 'width') {
38
+ node._contentSize.width = parseFloat(value);
39
+ }
40
+ else if (key === 'height') {
41
+ node._contentSize.height = parseFloat(value);
42
+ }
43
+ else if (key === 'scaleX') {
44
+ node._trs.array[7] = parseFloat(value);
45
+ }
46
+ else if (key === 'scaleY') {
47
+ node._trs.array[8] = parseFloat(value);
48
+ }
49
+ else if (key === 'rotation') {
50
+ node._trs.array[5] = parseFloat(value) * Math.PI / 180;
51
+ node._eulerAngles.z = parseFloat(value);
52
+ }
53
+ else if (key === 'opacity') {
54
+ node._opacity = parseInt(value);
55
+ }
56
+ else if (key === 'color') {
57
+ const c = parseColorToCcColor(value);
58
+ if (c)
59
+ node._color = c;
60
+ }
61
+ else if (key === 'anchorX') {
62
+ node._anchorPoint.x = parseFloat(value);
63
+ }
64
+ else if (key === 'anchorY') {
65
+ node._anchorPoint.y = parseFloat(value);
66
+ }
67
+ else if (key === 'name') {
68
+ node._name = value;
69
+ }
70
+ else if (key === 'active') {
71
+ node._active = value === 'true' || value === true;
72
+ }
73
+ }
74
+ export function setNodeProperties(node, props) {
75
+ for (const [key, value] of Object.entries(props)) {
76
+ setNodeProperty(node, key, value);
77
+ }
78
+ }
79
+ export function getNodeState(node) {
80
+ return {
81
+ name: node._name,
82
+ active: node._active,
83
+ x: node._trs?.array?.[0] ?? 0,
84
+ y: node._trs?.array?.[1] ?? 0,
85
+ width: node._contentSize?.width ?? 100,
86
+ height: node._contentSize?.height ?? 100,
87
+ scaleX: node._trs?.array?.[7] ?? 1,
88
+ scaleY: node._trs?.array?.[8] ?? 1,
89
+ rotation: node._eulerAngles?.z ?? 0,
90
+ opacity: node._opacity ?? 255,
91
+ anchorX: node._anchorPoint?.x ?? 0.5,
92
+ anchorY: node._anchorPoint?.y ?? 0.5
93
+ };
94
+ }
95
+ export function collectNodeAndChildren(node) {
96
+ const result = [node];
97
+ if (node._children) {
98
+ node._children.forEach((child) => {
99
+ result.push(...collectNodeAndChildren(child));
100
+ });
101
+ }
102
+ return result;
103
+ }
104
+ export function removeFromParent(node) {
105
+ if (!node._parent)
106
+ return false;
107
+ const idx = node._parent._children.indexOf(node);
108
+ if (idx > -1) {
109
+ node._parent._children.splice(idx, 1);
110
+ node._parent = null;
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ export function deleteNode(node) {
116
+ return removeFromParent(node);
117
+ }
118
+ export function buildTree(data, scriptMap, startIndex) {
119
+ return JSON.stringify(data[startIndex], null, 2);
120
+ }
121
+ export function detectItemType(item) {
122
+ if (!item)
123
+ return 'unknown';
124
+ if (item.__type__ === 'cc.Node')
125
+ return 'node';
126
+ if (item.__type__ === 'cc.Scene')
127
+ return 'scene';
128
+ if (item.__type__?.includes('cc.'))
129
+ return 'component';
130
+ return 'unknown';
131
+ }