cocos2d-cli 1.6.5 → 2.1.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 +115 -122
  16. package/{src → dist/src}/lib/cc/CCCamera.js +83 -93
  17. package/{src → dist/src}/lib/cc/CCCanvas.js +49 -54
  18. package/{src → dist/src}/lib/cc/CCColor.js +30 -32
  19. package/{src → dist/src}/lib/cc/CCComponent.js +39 -60
  20. package/{src → dist/src}/lib/cc/CCLabel.js +139 -146
  21. package/{src → dist/src}/lib/cc/CCNode.js +190 -256
  22. package/{src → dist/src}/lib/cc/CCObject.js +19 -23
  23. package/{src → dist/src}/lib/cc/CCPrefab.js +219 -242
  24. package/{src → dist/src}/lib/cc/CCRect.js +30 -32
  25. package/{src → dist/src}/lib/cc/CCRichText.js +38 -44
  26. package/{src → dist/src}/lib/cc/CCScene.js +32 -42
  27. package/dist/src/lib/cc/CCSceneAsset.js +242 -0
  28. package/{src → dist/src}/lib/cc/CCSize.js +22 -26
  29. package/{src → dist/src}/lib/cc/CCSprite.js +82 -94
  30. package/{src → dist/src}/lib/cc/CCTrs.js +49 -74
  31. package/{src → dist/src}/lib/cc/CCVec2.js +22 -26
  32. package/{src → dist/src}/lib/cc/CCVec3.js +26 -29
  33. package/{src → dist/src}/lib/cc/CCWidget.js +94 -98
  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 +242 -285
  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,26 +1,22 @@
1
- /**
2
- * Cocos Creator 二维向量类
3
- */
4
- class CCVec2 {
5
- constructor(x = 0, y = 0) {
6
- this.__type__ = 'cc.Vec2';
7
- this.x = x;
8
- this.y = y;
9
- }
10
-
11
- set(x, y) {
12
- this.x = x;
13
- this.y = y;
14
- return this;
15
- }
16
-
17
- toJSON() {
18
- return {
19
- __type__: this.__type__,
20
- x: this.x,
21
- y: this.y
22
- };
23
- }
24
- }
25
-
26
- module.exports = CCVec2;
1
+ export default class CCVec2 {
2
+ __type__;
3
+ x;
4
+ y;
5
+ constructor(x = 0, y = 0) {
6
+ this.__type__ = 'cc.Vec2';
7
+ this.x = x;
8
+ this.y = y;
9
+ }
10
+ set(x, y) {
11
+ this.x = x;
12
+ this.y = y;
13
+ return this;
14
+ }
15
+ toJSON() {
16
+ return {
17
+ __type__: this.__type__,
18
+ x: this.x,
19
+ y: this.y
20
+ };
21
+ }
22
+ }
@@ -1,29 +1,26 @@
1
- /**
2
- * Cocos Creator 三维向量类
3
- */
4
- class CCVec3 {
5
- constructor(x = 0, y = 0, z = 0) {
6
- this.__type__ = 'cc.Vec3';
7
- this.x = x;
8
- this.y = y;
9
- this.z = z;
10
- }
11
-
12
- set(x, y, z = 0) {
13
- this.x = x;
14
- this.y = y;
15
- this.z = z;
16
- return this;
17
- }
18
-
19
- toJSON() {
20
- return {
21
- __type__: this.__type__,
22
- x: this.x,
23
- y: this.y,
24
- z: this.z
25
- };
26
- }
27
- }
28
-
29
- module.exports = CCVec3;
1
+ export default class CCVec3 {
2
+ __type__;
3
+ x;
4
+ y;
5
+ z;
6
+ constructor(x = 0, y = 0, z = 0) {
7
+ this.__type__ = 'cc.Vec3';
8
+ this.x = x;
9
+ this.y = y;
10
+ this.z = z;
11
+ }
12
+ set(x, y, z = 0) {
13
+ this.x = x;
14
+ this.y = y;
15
+ this.z = z;
16
+ return this;
17
+ }
18
+ toJSON() {
19
+ return {
20
+ __type__: this.__type__,
21
+ x: this.x,
22
+ y: this.y,
23
+ z: this.z
24
+ };
25
+ }
26
+ }
@@ -1,98 +1,94 @@
1
- const CCComponent = require('./CCComponent');
2
-
3
- /**
4
- * Cocos Creator Widget 组件
5
- */
6
- class CCWidget extends CCComponent {
7
- constructor() {
8
- super();
9
- this.__type__ = 'cc.Widget';
10
-
11
- this.alignMode = 1;
12
- this._target = null;
13
- this._alignFlags = 45;
14
- this._left = 0;
15
- this._right = 0;
16
- this._top = 0;
17
- this._bottom = 0;
18
- this._verticalCenter = 0;
19
- this._horizontalCenter = 0;
20
- this._isAbsLeft = true;
21
- this._isAbsRight = true;
22
- this._isAbsTop = true;
23
- this._isAbsBottom = true;
24
- this._isAbsHorizontalCenter = true;
25
- this._isAbsVerticalCenter = true;
26
- this._originalWidth = 0;
27
- this._originalHeight = 0;
28
- }
29
-
30
- /**
31
- * 设置对齐标志
32
- * 45 = 左 + 右 + 上 + 下 (全对齐)
33
- */
34
- setAlignFlags(flags) {
35
- this._alignFlags = flags;
36
- return this;
37
- }
38
-
39
- /**
40
- * 设置边距
41
- */
42
- setMargins(left, right, top, bottom) {
43
- this._left = left;
44
- this._right = right;
45
- this._top = top;
46
- this._bottom = bottom;
47
- return this;
48
- }
49
-
50
- /**
51
- * 转换为属性面板显示格式
52
- */
53
- toPanelJSON() {
54
- return {
55
- ...super.toPanelJSON(),
56
- top: this._top,
57
- bottom: this._bottom,
58
- left: this._left,
59
- right: this._right,
60
- horizontalCenter: this._horizontalCenter,
61
- verticalCenter: this._verticalCenter,
62
- isAbsLeft: this._isAbsLeft,
63
- isAbsRight: this._isAbsRight,
64
- isAbsTop: this._isAbsTop,
65
- isAbsBottom: this._isAbsBottom
66
- };
67
- }
68
-
69
- toJSON() {
70
- return {
71
- __type__: this.__type__,
72
- _name: this._name,
73
- _objFlags: this._objFlags,
74
- node: this.node,
75
- _enabled: this._enabled,
76
- alignMode: this.alignMode,
77
- _target: this._target,
78
- _alignFlags: this._alignFlags,
79
- _left: this._left,
80
- _right: this._right,
81
- _top: this._top,
82
- _bottom: this._bottom,
83
- _verticalCenter: this._verticalCenter,
84
- _horizontalCenter: this._horizontalCenter,
85
- _isAbsLeft: this._isAbsLeft,
86
- _isAbsRight: this._isAbsRight,
87
- _isAbsTop: this._isAbsTop,
88
- _isAbsBottom: this._isAbsBottom,
89
- _isAbsHorizontalCenter: this._isAbsHorizontalCenter,
90
- _isAbsVerticalCenter: this._isAbsVerticalCenter,
91
- _originalWidth: this._originalWidth,
92
- _originalHeight: this._originalHeight,
93
- _id: this._id
94
- };
95
- }
96
- }
97
-
98
- module.exports = CCWidget;
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;
20
+ constructor() {
21
+ super();
22
+ this.__type__ = 'cc.Widget';
23
+ this.alignMode = 1;
24
+ this._target = null;
25
+ this._alignFlags = 45;
26
+ this._left = 0;
27
+ this._right = 0;
28
+ this._top = 0;
29
+ this._bottom = 0;
30
+ this._verticalCenter = 0;
31
+ this._horizontalCenter = 0;
32
+ this._isAbsLeft = true;
33
+ this._isAbsRight = true;
34
+ this._isAbsTop = true;
35
+ this._isAbsBottom = true;
36
+ this._isAbsHorizontalCenter = true;
37
+ this._isAbsVerticalCenter = true;
38
+ this._originalWidth = 0;
39
+ this._originalHeight = 0;
40
+ }
41
+ setAlignFlags(flags) {
42
+ this._alignFlags = flags;
43
+ return this;
44
+ }
45
+ setMargins(left, right, top, bottom) {
46
+ this._left = left;
47
+ this._right = right;
48
+ this._top = top;
49
+ this._bottom = bottom;
50
+ return this;
51
+ }
52
+ toPanelJSON() {
53
+ return {
54
+ ...super.getProp(),
55
+ top: this._top,
56
+ bottom: this._bottom,
57
+ left: this._left,
58
+ right: this._right,
59
+ horizontalCenter: this._horizontalCenter,
60
+ verticalCenter: this._verticalCenter,
61
+ isAbsLeft: this._isAbsLeft,
62
+ isAbsRight: this._isAbsRight,
63
+ isAbsTop: this._isAbsTop,
64
+ isAbsBottom: this._isAbsBottom
65
+ };
66
+ }
67
+ toJSON() {
68
+ return {
69
+ __type__: this.__type__,
70
+ _name: this._name,
71
+ _objFlags: this._objFlags,
72
+ node: this.node,
73
+ _enabled: this._enabled,
74
+ alignMode: this.alignMode,
75
+ _target: this._target,
76
+ _alignFlags: this._alignFlags,
77
+ _left: this._left,
78
+ _right: this._right,
79
+ _top: this._top,
80
+ _bottom: this._bottom,
81
+ _verticalCenter: this._verticalCenter,
82
+ _horizontalCenter: this._horizontalCenter,
83
+ _isAbsLeft: this._isAbsLeft,
84
+ _isAbsRight: this._isAbsRight,
85
+ _isAbsTop: this._isAbsTop,
86
+ _isAbsBottom: this._isAbsBottom,
87
+ _isAbsHorizontalCenter: this._isAbsHorizontalCenter,
88
+ _isAbsVerticalCenter: this._isAbsVerticalCenter,
89
+ _originalWidth: this._originalWidth,
90
+ _originalHeight: this._originalHeight,
91
+ _id: this._id
92
+ };
93
+ }
94
+ }
@@ -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
+ }