cocos2d-cli 1.6.3 → 1.6.5
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/bin/cocos2d-cli.js +152 -152
- package/data/script_map.json +25 -25
- package/package.json +33 -33
- package/src/commands/add-component.js +112 -112
- package/src/commands/add.js +177 -177
- package/src/commands/build.js +78 -78
- package/src/commands/create-scene.js +181 -181
- package/src/commands/get.js +108 -108
- package/src/commands/prefab-create.js +110 -110
- package/src/commands/remove-component.js +110 -110
- package/src/commands/remove.js +99 -99
- package/src/commands/screenshot.js +108 -103
- package/src/commands/set-component.js +119 -119
- package/src/commands/set.js +107 -107
- package/src/commands/tree.js +28 -28
- package/src/lib/cc/CCButton.js +122 -122
- package/src/lib/cc/CCCamera.js +93 -93
- package/src/lib/cc/CCCanvas.js +54 -54
- package/src/lib/cc/CCColor.js +32 -32
- package/src/lib/cc/CCComponent.js +60 -60
- package/src/lib/cc/CCLabel.js +146 -146
- package/src/lib/cc/CCNode.js +255 -255
- package/src/lib/cc/CCObject.js +23 -23
- package/src/lib/cc/CCPrefab.js +242 -242
- package/src/lib/cc/CCRect.js +32 -32
- package/src/lib/cc/CCRichText.js +44 -44
- package/src/lib/cc/CCScene.js +42 -42
- package/src/lib/cc/CCSceneAsset.js +302 -302
- package/src/lib/cc/CCSize.js +26 -26
- package/src/lib/cc/CCSprite.js +94 -94
- package/src/lib/cc/CCTrs.js +74 -74
- package/src/lib/cc/CCVec2.js +26 -26
- package/src/lib/cc/CCVec3.js +29 -29
- package/src/lib/cc/CCWidget.js +98 -98
- package/src/lib/cc/index.js +42 -42
- package/src/lib/fire-utils.js +373 -373
- package/src/lib/json-parser.js +185 -185
- package/src/lib/node-utils.js +395 -395
- package/src/lib/screenshot/index.html +29 -29
- package/src/lib/screenshot-core.js +285 -286
- package/src/lib/templates.js +49 -49
- package/src/lib/utils.js +202 -202
package/src/lib/cc/CCPrefab.js
CHANGED
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
const CCObject = require('./CCObject');
|
|
2
|
-
const { generateFileId } = require('../fire-utils');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Cocos Creator 预制体类(只是元数据头,不管理节点树)
|
|
6
|
-
*/
|
|
7
|
-
class CCPrefab extends CCObject {
|
|
8
|
-
constructor() {
|
|
9
|
-
super('');
|
|
10
|
-
this.__type__ = 'cc.Prefab';
|
|
11
|
-
|
|
12
|
-
this._native = '';
|
|
13
|
-
this._root = null; // 根节点引用
|
|
14
|
-
this.optimizationPolicy = 0;
|
|
15
|
-
this.asyncLoadAssets = false;
|
|
16
|
-
this.readonly = false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setRoot(node) {
|
|
20
|
-
this._root = node;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 从 JSON 解析
|
|
26
|
-
*/
|
|
27
|
-
static fromJSON(json) {
|
|
28
|
-
const prefab = new CCPrefab();
|
|
29
|
-
const objects = [];
|
|
30
|
-
|
|
31
|
-
// 第一遍:创建所有对象
|
|
32
|
-
json.forEach((item, index) => {
|
|
33
|
-
objects[index] = createObject(item);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// 第二遍:建立引用关系
|
|
37
|
-
json.forEach((item, index) => {
|
|
38
|
-
setupReferences(objects[index], item, objects);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
prefab._root = objects[1];
|
|
42
|
-
return prefab;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 序列化为 JSON
|
|
47
|
-
* 顺序:Prefab头 → 节点树(节点 → 子节点们+PrefabInfo → 组件 → PrefabInfo) → 根PrefabInfo
|
|
48
|
-
*/
|
|
49
|
-
toJSON() {
|
|
50
|
-
const result = [];
|
|
51
|
-
const indexMap = new Map();
|
|
52
|
-
|
|
53
|
-
// 0: Prefab 头
|
|
54
|
-
indexMap.set(this, 0);
|
|
55
|
-
result.push({
|
|
56
|
-
__type__: 'cc.Prefab',
|
|
57
|
-
_name: '',
|
|
58
|
-
_objFlags: 0,
|
|
59
|
-
_native: '',
|
|
60
|
-
data: null, // 后面填充
|
|
61
|
-
optimizationPolicy: this.optimizationPolicy,
|
|
62
|
-
asyncLoadAssets: this.asyncLoadAssets,
|
|
63
|
-
readonly: this.readonly
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// 递归处理节点
|
|
67
|
-
const processNode = (node, isRoot = false) => {
|
|
68
|
-
if (!node) return;
|
|
69
|
-
|
|
70
|
-
// 添加节点
|
|
71
|
-
indexMap.set(node, result.length);
|
|
72
|
-
result.push(null); // 占位
|
|
73
|
-
|
|
74
|
-
// 递归处理子节点(每个子节点处理完会带上它的 PrefabInfo)
|
|
75
|
-
if (node._children) {
|
|
76
|
-
node._children.forEach(child => processNode(child, false));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 添加组件
|
|
80
|
-
if (node._components) {
|
|
81
|
-
node._components.forEach(comp => {
|
|
82
|
-
indexMap.set(comp, result.length);
|
|
83
|
-
result.push(componentToJSON(comp, indexMap));
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 生成节点 JSON
|
|
88
|
-
result[indexMap.get(node)] = {
|
|
89
|
-
__type__: 'cc.Node',
|
|
90
|
-
_name: node._name,
|
|
91
|
-
_objFlags: node._objFlags,
|
|
92
|
-
_parent: node._parent ? { __id__: indexMap.get(node._parent) } : null,
|
|
93
|
-
_children: (node._children || []).map(c => ({ __id__: indexMap.get(c) })),
|
|
94
|
-
_active: node._active,
|
|
95
|
-
_components: (node._components || []).map(c => ({ __id__: indexMap.get(c) })),
|
|
96
|
-
_prefab: null, // 后面填充
|
|
97
|
-
_opacity: node._opacity,
|
|
98
|
-
_color: node._color.toJSON(),
|
|
99
|
-
_contentSize: node._contentSize.toJSON(),
|
|
100
|
-
_anchorPoint: node._anchorPoint.toJSON(),
|
|
101
|
-
_trs: node._trs.toJSON(),
|
|
102
|
-
_eulerAngles: node._eulerAngles.toJSON(),
|
|
103
|
-
_skewX: node._skewX,
|
|
104
|
-
_skewY: node._skewY,
|
|
105
|
-
_is3DNode: node._is3DNode,
|
|
106
|
-
_groupIndex: node._groupIndex,
|
|
107
|
-
groupIndex: node.groupIndex,
|
|
108
|
-
_id: node._id || ''
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// 非根节点:立即添加 PrefabInfo
|
|
112
|
-
if (!isRoot) {
|
|
113
|
-
const infoIdx = result.length;
|
|
114
|
-
result.push({
|
|
115
|
-
__type__: 'cc.PrefabInfo',
|
|
116
|
-
root: { __id__: indexMap.get(this._root) },
|
|
117
|
-
asset: { __id__: 0 },
|
|
118
|
-
fileId: generateFileId(),
|
|
119
|
-
sync: false
|
|
120
|
-
});
|
|
121
|
-
result[indexMap.get(node)]._prefab = { __id__: infoIdx };
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// 处理根节点
|
|
126
|
-
processNode(this._root, true);
|
|
127
|
-
|
|
128
|
-
// 填充 Prefab 头的 data
|
|
129
|
-
result[0].data = { __id__: indexMap.get(this._root) };
|
|
130
|
-
|
|
131
|
-
// 最后添加根节点的 PrefabInfo
|
|
132
|
-
if (this._root) {
|
|
133
|
-
const infoIdx = result.length;
|
|
134
|
-
result.push({
|
|
135
|
-
__type__: 'cc.PrefabInfo',
|
|
136
|
-
root: { __id__: indexMap.get(this._root) },
|
|
137
|
-
asset: { __id__: 0 },
|
|
138
|
-
fileId: '',
|
|
139
|
-
sync: false
|
|
140
|
-
});
|
|
141
|
-
result[indexMap.get(this._root)]._prefab = { __id__: infoIdx };
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function componentToJSON(comp, indexMap) {
|
|
149
|
-
const json = {
|
|
150
|
-
__type__: comp.__type__,
|
|
151
|
-
_name: comp._name || '',
|
|
152
|
-
_objFlags: comp._objFlags || 0,
|
|
153
|
-
node: { __id__: indexMap.get(comp.node) },
|
|
154
|
-
_enabled: comp._enabled !== false
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// 其他属性
|
|
158
|
-
for (const key of Object.keys(comp)) {
|
|
159
|
-
if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
|
|
160
|
-
const val = comp[key];
|
|
161
|
-
if (val === undefined) continue;
|
|
162
|
-
json[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// _id 放最后
|
|
166
|
-
json._id = comp._id || '';
|
|
167
|
-
|
|
168
|
-
return json;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function createObject(item) {
|
|
172
|
-
const type = item.__type__;
|
|
173
|
-
|
|
174
|
-
if (type === 'cc.Prefab') return null; // 跳过,由 CCPrefab.fromJSON 处理
|
|
175
|
-
if (type === 'cc.PrefabInfo') return new CCPrefabInfo();
|
|
176
|
-
|
|
177
|
-
if (type === 'cc.Node') {
|
|
178
|
-
const CCNode = require('./CCNode');
|
|
179
|
-
const node = new CCNode(item._name || 'Node');
|
|
180
|
-
node._id = item._id || '';
|
|
181
|
-
copyNodeProps(node, item);
|
|
182
|
-
return node;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// 组件
|
|
186
|
-
const comp = { __type__: type };
|
|
187
|
-
for (const key of Object.keys(item)) {
|
|
188
|
-
if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
|
|
189
|
-
comp[key] = item[key];
|
|
190
|
-
}
|
|
191
|
-
return comp;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function copyNodeProps(node, item) {
|
|
195
|
-
if (item._active !== undefined) node._active = item._active;
|
|
196
|
-
if (item._opacity !== undefined) node._opacity = item._opacity;
|
|
197
|
-
if (item._is3DNode !== undefined) node._is3DNode = item._is3DNode;
|
|
198
|
-
if (item._groupIndex !== undefined) node._groupIndex = item._groupIndex;
|
|
199
|
-
if (item.groupIndex !== undefined) node.groupIndex = item.groupIndex;
|
|
200
|
-
if (item._skewX !== undefined) node._skewX = item._skewX;
|
|
201
|
-
if (item._skewY !== undefined) node._skewY = item._skewY;
|
|
202
|
-
|
|
203
|
-
if (item._color) node._color.set(item._color.r, item._color.g, item._color.b, item._color.a);
|
|
204
|
-
if (item._contentSize) node._contentSize.set(item._contentSize.width, item._contentSize.height);
|
|
205
|
-
if (item._anchorPoint) node._anchorPoint.set(item._anchorPoint.x, item._anchorPoint.y);
|
|
206
|
-
if (item._trs?.array) item._trs.array.forEach((v, i) => node._trs.array[i] = v);
|
|
207
|
-
if (item._eulerAngles) node._eulerAngles.set(item._eulerAngles.x, item._eulerAngles.y, item._eulerAngles.z);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function setupReferences(obj, item, objects) {
|
|
211
|
-
if (!obj) return;
|
|
212
|
-
|
|
213
|
-
if (obj.__type__ === 'cc.Node') {
|
|
214
|
-
if (item._parent) obj._parent = objects[item._parent.__id__];
|
|
215
|
-
if (item._children) obj._children = item._children.map(c => objects[c.__id__]).filter(Boolean);
|
|
216
|
-
if (item._components) {
|
|
217
|
-
obj._components = item._components.map(c => objects[c.__id__]).filter(Boolean);
|
|
218
|
-
obj._components.forEach(c => { if (c) c.node = obj; });
|
|
219
|
-
}
|
|
220
|
-
if (item._prefab) obj._prefab = objects[item._prefab.__id__];
|
|
221
|
-
} else if (obj.__type__ === 'cc.PrefabInfo') {
|
|
222
|
-
if (item.root) obj.root = objects[item.root.__id__];
|
|
223
|
-
if (item.asset) obj.asset = objects[item.asset.__id__];
|
|
224
|
-
obj.fileId = item.fileId || '';
|
|
225
|
-
obj.sync = item.sync || false;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* 预制体信息类
|
|
231
|
-
*/
|
|
232
|
-
class CCPrefabInfo {
|
|
233
|
-
constructor() {
|
|
234
|
-
this.__type__ = 'cc.PrefabInfo';
|
|
235
|
-
this.root = null;
|
|
236
|
-
this.asset = null;
|
|
237
|
-
this.fileId = '';
|
|
238
|
-
this.sync = false;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
module.exports = { CCPrefab, CCPrefabInfo };
|
|
1
|
+
const CCObject = require('./CCObject');
|
|
2
|
+
const { generateFileId } = require('../fire-utils');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cocos Creator 预制体类(只是元数据头,不管理节点树)
|
|
6
|
+
*/
|
|
7
|
+
class CCPrefab extends CCObject {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('');
|
|
10
|
+
this.__type__ = 'cc.Prefab';
|
|
11
|
+
|
|
12
|
+
this._native = '';
|
|
13
|
+
this._root = null; // 根节点引用
|
|
14
|
+
this.optimizationPolicy = 0;
|
|
15
|
+
this.asyncLoadAssets = false;
|
|
16
|
+
this.readonly = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setRoot(node) {
|
|
20
|
+
this._root = node;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 从 JSON 解析
|
|
26
|
+
*/
|
|
27
|
+
static fromJSON(json) {
|
|
28
|
+
const prefab = new CCPrefab();
|
|
29
|
+
const objects = [];
|
|
30
|
+
|
|
31
|
+
// 第一遍:创建所有对象
|
|
32
|
+
json.forEach((item, index) => {
|
|
33
|
+
objects[index] = createObject(item);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 第二遍:建立引用关系
|
|
37
|
+
json.forEach((item, index) => {
|
|
38
|
+
setupReferences(objects[index], item, objects);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
prefab._root = objects[1];
|
|
42
|
+
return prefab;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 序列化为 JSON
|
|
47
|
+
* 顺序:Prefab头 → 节点树(节点 → 子节点们+PrefabInfo → 组件 → PrefabInfo) → 根PrefabInfo
|
|
48
|
+
*/
|
|
49
|
+
toJSON() {
|
|
50
|
+
const result = [];
|
|
51
|
+
const indexMap = new Map();
|
|
52
|
+
|
|
53
|
+
// 0: Prefab 头
|
|
54
|
+
indexMap.set(this, 0);
|
|
55
|
+
result.push({
|
|
56
|
+
__type__: 'cc.Prefab',
|
|
57
|
+
_name: '',
|
|
58
|
+
_objFlags: 0,
|
|
59
|
+
_native: '',
|
|
60
|
+
data: null, // 后面填充
|
|
61
|
+
optimizationPolicy: this.optimizationPolicy,
|
|
62
|
+
asyncLoadAssets: this.asyncLoadAssets,
|
|
63
|
+
readonly: this.readonly
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// 递归处理节点
|
|
67
|
+
const processNode = (node, isRoot = false) => {
|
|
68
|
+
if (!node) return;
|
|
69
|
+
|
|
70
|
+
// 添加节点
|
|
71
|
+
indexMap.set(node, result.length);
|
|
72
|
+
result.push(null); // 占位
|
|
73
|
+
|
|
74
|
+
// 递归处理子节点(每个子节点处理完会带上它的 PrefabInfo)
|
|
75
|
+
if (node._children) {
|
|
76
|
+
node._children.forEach(child => processNode(child, false));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 添加组件
|
|
80
|
+
if (node._components) {
|
|
81
|
+
node._components.forEach(comp => {
|
|
82
|
+
indexMap.set(comp, result.length);
|
|
83
|
+
result.push(componentToJSON(comp, indexMap));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 生成节点 JSON
|
|
88
|
+
result[indexMap.get(node)] = {
|
|
89
|
+
__type__: 'cc.Node',
|
|
90
|
+
_name: node._name,
|
|
91
|
+
_objFlags: node._objFlags,
|
|
92
|
+
_parent: node._parent ? { __id__: indexMap.get(node._parent) } : null,
|
|
93
|
+
_children: (node._children || []).map(c => ({ __id__: indexMap.get(c) })),
|
|
94
|
+
_active: node._active,
|
|
95
|
+
_components: (node._components || []).map(c => ({ __id__: indexMap.get(c) })),
|
|
96
|
+
_prefab: null, // 后面填充
|
|
97
|
+
_opacity: node._opacity,
|
|
98
|
+
_color: node._color.toJSON(),
|
|
99
|
+
_contentSize: node._contentSize.toJSON(),
|
|
100
|
+
_anchorPoint: node._anchorPoint.toJSON(),
|
|
101
|
+
_trs: node._trs.toJSON(),
|
|
102
|
+
_eulerAngles: node._eulerAngles.toJSON(),
|
|
103
|
+
_skewX: node._skewX,
|
|
104
|
+
_skewY: node._skewY,
|
|
105
|
+
_is3DNode: node._is3DNode,
|
|
106
|
+
_groupIndex: node._groupIndex,
|
|
107
|
+
groupIndex: node.groupIndex,
|
|
108
|
+
_id: node._id || ''
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// 非根节点:立即添加 PrefabInfo
|
|
112
|
+
if (!isRoot) {
|
|
113
|
+
const infoIdx = result.length;
|
|
114
|
+
result.push({
|
|
115
|
+
__type__: 'cc.PrefabInfo',
|
|
116
|
+
root: { __id__: indexMap.get(this._root) },
|
|
117
|
+
asset: { __id__: 0 },
|
|
118
|
+
fileId: generateFileId(),
|
|
119
|
+
sync: false
|
|
120
|
+
});
|
|
121
|
+
result[indexMap.get(node)]._prefab = { __id__: infoIdx };
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// 处理根节点
|
|
126
|
+
processNode(this._root, true);
|
|
127
|
+
|
|
128
|
+
// 填充 Prefab 头的 data
|
|
129
|
+
result[0].data = { __id__: indexMap.get(this._root) };
|
|
130
|
+
|
|
131
|
+
// 最后添加根节点的 PrefabInfo
|
|
132
|
+
if (this._root) {
|
|
133
|
+
const infoIdx = result.length;
|
|
134
|
+
result.push({
|
|
135
|
+
__type__: 'cc.PrefabInfo',
|
|
136
|
+
root: { __id__: indexMap.get(this._root) },
|
|
137
|
+
asset: { __id__: 0 },
|
|
138
|
+
fileId: '',
|
|
139
|
+
sync: false
|
|
140
|
+
});
|
|
141
|
+
result[indexMap.get(this._root)]._prefab = { __id__: infoIdx };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function componentToJSON(comp, indexMap) {
|
|
149
|
+
const json = {
|
|
150
|
+
__type__: comp.__type__,
|
|
151
|
+
_name: comp._name || '',
|
|
152
|
+
_objFlags: comp._objFlags || 0,
|
|
153
|
+
node: { __id__: indexMap.get(comp.node) },
|
|
154
|
+
_enabled: comp._enabled !== false
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// 其他属性
|
|
158
|
+
for (const key of Object.keys(comp)) {
|
|
159
|
+
if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
|
|
160
|
+
const val = comp[key];
|
|
161
|
+
if (val === undefined) continue;
|
|
162
|
+
json[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// _id 放最后
|
|
166
|
+
json._id = comp._id || '';
|
|
167
|
+
|
|
168
|
+
return json;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function createObject(item) {
|
|
172
|
+
const type = item.__type__;
|
|
173
|
+
|
|
174
|
+
if (type === 'cc.Prefab') return null; // 跳过,由 CCPrefab.fromJSON 处理
|
|
175
|
+
if (type === 'cc.PrefabInfo') return new CCPrefabInfo();
|
|
176
|
+
|
|
177
|
+
if (type === 'cc.Node') {
|
|
178
|
+
const CCNode = require('./CCNode');
|
|
179
|
+
const node = new CCNode(item._name || 'Node');
|
|
180
|
+
node._id = item._id || '';
|
|
181
|
+
copyNodeProps(node, item);
|
|
182
|
+
return node;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 组件
|
|
186
|
+
const comp = { __type__: type };
|
|
187
|
+
for (const key of Object.keys(item)) {
|
|
188
|
+
if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
|
|
189
|
+
comp[key] = item[key];
|
|
190
|
+
}
|
|
191
|
+
return comp;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function copyNodeProps(node, item) {
|
|
195
|
+
if (item._active !== undefined) node._active = item._active;
|
|
196
|
+
if (item._opacity !== undefined) node._opacity = item._opacity;
|
|
197
|
+
if (item._is3DNode !== undefined) node._is3DNode = item._is3DNode;
|
|
198
|
+
if (item._groupIndex !== undefined) node._groupIndex = item._groupIndex;
|
|
199
|
+
if (item.groupIndex !== undefined) node.groupIndex = item.groupIndex;
|
|
200
|
+
if (item._skewX !== undefined) node._skewX = item._skewX;
|
|
201
|
+
if (item._skewY !== undefined) node._skewY = item._skewY;
|
|
202
|
+
|
|
203
|
+
if (item._color) node._color.set(item._color.r, item._color.g, item._color.b, item._color.a);
|
|
204
|
+
if (item._contentSize) node._contentSize.set(item._contentSize.width, item._contentSize.height);
|
|
205
|
+
if (item._anchorPoint) node._anchorPoint.set(item._anchorPoint.x, item._anchorPoint.y);
|
|
206
|
+
if (item._trs?.array) item._trs.array.forEach((v, i) => node._trs.array[i] = v);
|
|
207
|
+
if (item._eulerAngles) node._eulerAngles.set(item._eulerAngles.x, item._eulerAngles.y, item._eulerAngles.z);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function setupReferences(obj, item, objects) {
|
|
211
|
+
if (!obj) return;
|
|
212
|
+
|
|
213
|
+
if (obj.__type__ === 'cc.Node') {
|
|
214
|
+
if (item._parent) obj._parent = objects[item._parent.__id__];
|
|
215
|
+
if (item._children) obj._children = item._children.map(c => objects[c.__id__]).filter(Boolean);
|
|
216
|
+
if (item._components) {
|
|
217
|
+
obj._components = item._components.map(c => objects[c.__id__]).filter(Boolean);
|
|
218
|
+
obj._components.forEach(c => { if (c) c.node = obj; });
|
|
219
|
+
}
|
|
220
|
+
if (item._prefab) obj._prefab = objects[item._prefab.__id__];
|
|
221
|
+
} else if (obj.__type__ === 'cc.PrefabInfo') {
|
|
222
|
+
if (item.root) obj.root = objects[item.root.__id__];
|
|
223
|
+
if (item.asset) obj.asset = objects[item.asset.__id__];
|
|
224
|
+
obj.fileId = item.fileId || '';
|
|
225
|
+
obj.sync = item.sync || false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 预制体信息类
|
|
231
|
+
*/
|
|
232
|
+
class CCPrefabInfo {
|
|
233
|
+
constructor() {
|
|
234
|
+
this.__type__ = 'cc.PrefabInfo';
|
|
235
|
+
this.root = null;
|
|
236
|
+
this.asset = null;
|
|
237
|
+
this.fileId = '';
|
|
238
|
+
this.sync = false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
module.exports = { CCPrefab, CCPrefabInfo };
|
package/src/lib/cc/CCRect.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cocos Creator 矩形类
|
|
3
|
-
*/
|
|
4
|
-
class CCRect {
|
|
5
|
-
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
6
|
-
this.__type__ = 'cc.Rect';
|
|
7
|
-
this.x = x;
|
|
8
|
-
this.y = y;
|
|
9
|
-
this.width = width;
|
|
10
|
-
this.height = height;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
set(x, y, width, height) {
|
|
14
|
-
this.x = x;
|
|
15
|
-
this.y = y;
|
|
16
|
-
this.width = width;
|
|
17
|
-
this.height = height;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
toJSON() {
|
|
22
|
-
return {
|
|
23
|
-
__type__: this.__type__,
|
|
24
|
-
x: this.x,
|
|
25
|
-
y: this.y,
|
|
26
|
-
width: this.width,
|
|
27
|
-
height: this.height
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
module.exports = CCRect;
|
|
1
|
+
/**
|
|
2
|
+
* Cocos Creator 矩形类
|
|
3
|
+
*/
|
|
4
|
+
class CCRect {
|
|
5
|
+
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
6
|
+
this.__type__ = 'cc.Rect';
|
|
7
|
+
this.x = x;
|
|
8
|
+
this.y = y;
|
|
9
|
+
this.width = width;
|
|
10
|
+
this.height = height;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
set(x, y, width, height) {
|
|
14
|
+
this.x = x;
|
|
15
|
+
this.y = y;
|
|
16
|
+
this.width = width;
|
|
17
|
+
this.height = height;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
__type__: this.__type__,
|
|
24
|
+
x: this.x,
|
|
25
|
+
y: this.y,
|
|
26
|
+
width: this.width,
|
|
27
|
+
height: this.height
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = CCRect;
|
package/src/lib/cc/CCRichText.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
const CCComponent = require('./CCComponent');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cocos Creator RichText 组件
|
|
5
|
-
* 支持 BBCode 标签语法:
|
|
6
|
-
* <color=#ff0000>红色</color>
|
|
7
|
-
* <size=30>大字</size>
|
|
8
|
-
* <b>加粗</b> <i>斜体</i> <u>下划线</u>
|
|
9
|
-
* <br/> 换行
|
|
10
|
-
*/
|
|
11
|
-
class CCRichText extends CCComponent {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
this.__type__ = 'cc.RichText';
|
|
15
|
-
|
|
16
|
-
this._string = '';
|
|
17
|
-
this._horizontalAlign = 0; // 0=LEFT 1=CENTER 2=RIGHT
|
|
18
|
-
this._fontSize = 40;
|
|
19
|
-
this._maxWidth = 0;
|
|
20
|
-
this._lineHeight = 40;
|
|
21
|
-
this._imageAtlas = null;
|
|
22
|
-
this._handleTouchEvent = true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
toJSON() {
|
|
26
|
-
return {
|
|
27
|
-
__type__: this.__type__,
|
|
28
|
-
_name: this._name,
|
|
29
|
-
_objFlags: this._objFlags,
|
|
30
|
-
node: this.node,
|
|
31
|
-
_enabled: this._enabled,
|
|
32
|
-
_string: this._string,
|
|
33
|
-
_horizontalAlign: this._horizontalAlign,
|
|
34
|
-
_fontSize: this._fontSize,
|
|
35
|
-
_maxWidth: this._maxWidth,
|
|
36
|
-
_lineHeight: this._lineHeight,
|
|
37
|
-
_imageAtlas: this._imageAtlas,
|
|
38
|
-
_handleTouchEvent: this._handleTouchEvent,
|
|
39
|
-
_id: this._id
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = CCRichText;
|
|
1
|
+
const CCComponent = require('./CCComponent');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cocos Creator RichText 组件
|
|
5
|
+
* 支持 BBCode 标签语法:
|
|
6
|
+
* <color=#ff0000>红色</color>
|
|
7
|
+
* <size=30>大字</size>
|
|
8
|
+
* <b>加粗</b> <i>斜体</i> <u>下划线</u>
|
|
9
|
+
* <br/> 换行
|
|
10
|
+
*/
|
|
11
|
+
class CCRichText extends CCComponent {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.__type__ = 'cc.RichText';
|
|
15
|
+
|
|
16
|
+
this._string = '';
|
|
17
|
+
this._horizontalAlign = 0; // 0=LEFT 1=CENTER 2=RIGHT
|
|
18
|
+
this._fontSize = 40;
|
|
19
|
+
this._maxWidth = 0;
|
|
20
|
+
this._lineHeight = 40;
|
|
21
|
+
this._imageAtlas = null;
|
|
22
|
+
this._handleTouchEvent = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
__type__: this.__type__,
|
|
28
|
+
_name: this._name,
|
|
29
|
+
_objFlags: this._objFlags,
|
|
30
|
+
node: this.node,
|
|
31
|
+
_enabled: this._enabled,
|
|
32
|
+
_string: this._string,
|
|
33
|
+
_horizontalAlign: this._horizontalAlign,
|
|
34
|
+
_fontSize: this._fontSize,
|
|
35
|
+
_maxWidth: this._maxWidth,
|
|
36
|
+
_lineHeight: this._lineHeight,
|
|
37
|
+
_imageAtlas: this._imageAtlas,
|
|
38
|
+
_handleTouchEvent: this._handleTouchEvent,
|
|
39
|
+
_id: this._id
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = CCRichText;
|