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.
- package/data/script_map.json +25 -25
- package/dist/bin/cocos2d-cli.js +64 -0
- package/dist/src/commands/add-component.js +3 -0
- package/dist/src/commands/add.js +3 -0
- package/dist/src/commands/build.js +6 -0
- package/dist/src/commands/create-scene.js +3 -0
- package/dist/src/commands/get.js +3 -0
- package/dist/src/commands/prefab-create.js +109 -0
- package/dist/src/commands/remove-component.js +3 -0
- package/dist/src/commands/remove.js +3 -0
- package/dist/src/commands/screenshot.js +41 -0
- package/dist/src/commands/set-component.js +3 -0
- package/dist/src/commands/set.js +3 -0
- package/dist/src/commands/tree.js +24 -0
- package/{src → dist/src}/lib/cc/CCButton.js +26 -33
- package/{src → dist/src}/lib/cc/CCCamera.js +20 -30
- package/{src → dist/src}/lib/cc/CCCanvas.js +10 -15
- package/{src → dist/src}/lib/cc/CCColor.js +6 -8
- package/{src → dist/src}/lib/cc/CCComponent.js +8 -29
- package/{src → dist/src}/lib/cc/CCLabel.js +44 -51
- package/{src → dist/src}/lib/cc/CCNode.js +52 -118
- package/{src → dist/src}/lib/cc/CCObject.js +4 -8
- package/{src → dist/src}/lib/cc/CCPrefab.js +77 -100
- package/{src → dist/src}/lib/cc/CCRect.js +6 -8
- package/{src → dist/src}/lib/cc/CCRichText.js +10 -16
- package/{src → dist/src}/lib/cc/CCScene.js +3 -13
- package/dist/src/lib/cc/CCSceneAsset.js +242 -0
- package/{src → dist/src}/lib/cc/CCSize.js +4 -8
- package/{src → dist/src}/lib/cc/CCSprite.js +21 -33
- package/{src → dist/src}/lib/cc/CCTrs.js +4 -29
- package/{src → dist/src}/lib/cc/CCVec2.js +4 -8
- package/{src → dist/src}/lib/cc/CCVec3.js +5 -8
- package/{src → dist/src}/lib/cc/CCWidget.js +20 -24
- package/dist/src/lib/fire-utils.js +86 -0
- package/dist/src/lib/json-parser.js +114 -0
- package/dist/src/lib/node-utils.js +131 -0
- package/{src → dist/src}/lib/screenshot-core.js +54 -119
- package/dist/src/lib/templates.js +17 -0
- package/dist/src/lib/utils.js +81 -0
- package/package.json +40 -33
- package/bin/cocos2d-cli.js +0 -152
- package/src/commands/add-component.js +0 -112
- package/src/commands/add.js +0 -177
- package/src/commands/build.js +0 -78
- package/src/commands/create-scene.js +0 -181
- package/src/commands/get.js +0 -108
- package/src/commands/prefab-create.js +0 -111
- package/src/commands/remove-component.js +0 -111
- package/src/commands/remove.js +0 -99
- package/src/commands/screenshot.js +0 -108
- package/src/commands/set-component.js +0 -119
- package/src/commands/set.js +0 -107
- package/src/commands/tree.js +0 -29
- package/src/lib/cc/CCSceneAsset.js +0 -303
- package/src/lib/cc/index.js +0 -42
- package/src/lib/fire-utils.js +0 -374
- package/src/lib/json-parser.js +0 -185
- package/src/lib/node-utils.js +0 -395
- package/src/lib/screenshot/favicon.ico +0 -0
- package/src/lib/screenshot/index.html +0 -30
- package/src/lib/templates.js +0 -49
- package/src/lib/utils.js +0 -202
package/data/script_map.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
{
|
|
2
|
-
"01e12Vix3xPZaV9rG8NNMhT": "CharacterAnimation",
|
|
3
|
-
"0c1120T6UNNk5mllwLCpN0/": "GameScene",
|
|
4
|
-
"0c5a3bepqdAUZOCSqDOe7tX": "StageManager",
|
|
5
|
-
"166a2V/C3pMsLYQh5Cfhh0M": "Tile",
|
|
6
|
-
"1777aIKiDVM2ayJgXQsFRbc": "InfoNode",
|
|
7
|
-
"2000bQ16aVPOowsYmWzQHBl": "TilemapCamera",
|
|
8
|
-
"25dfekurxJEpa4v3Hll7c7S": "PlayerController",
|
|
9
|
-
"2a19dBOCe1GUpzKNfMsQQR7": "Pathfinder",
|
|
10
|
-
"329ecFYmkpK+ZTeUQlUmyHq": "MapCharacter",
|
|
11
|
-
"36c13QGxrxExoOv5anzjyRj": "EventManager",
|
|
12
|
-
"394e4Gg6E1Dh6AedkHAFZH+": "index",
|
|
13
|
-
"3cc7eQO1TZPTYTHr3v/2h1L": "SceneScript",
|
|
14
|
-
"42cc8kWoTtFHqEMb8ClTUBk": "GameExpressionEvaluator",
|
|
15
|
-
"7541bC/enRKeocYItojXgyK": "Gamepiece",
|
|
16
|
-
"781adeySrdN27K4uANiWTCT": "MinimapRenderer",
|
|
17
|
-
"9701aXPPNhO2IJ1bgr/25pJ": "PlayerManager",
|
|
18
|
-
"a4e62KPZVNEbZO1mvkzyOQt": "FilmEffect",
|
|
19
|
-
"a4ff8dbnCJNsLLBFaNYXrQp": "Player",
|
|
20
|
-
"a89e2IVZx5Bn50oCifRT+GC": "Gameboard",
|
|
21
|
-
"c4069o+d29NprrTzmS9V1Mb": "ResourceManager",
|
|
22
|
-
"e0920R8VWpPOpxr0VnPlCqA": "GamepieceRegistry",
|
|
23
|
-
"e24c1oXqIpLvqqgMFn+zl3A": "Tilemap",
|
|
24
|
-
"f07feXxRJVMj7Vg6tTtIi+T": "index"
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"01e12Vix3xPZaV9rG8NNMhT": "CharacterAnimation",
|
|
3
|
+
"0c1120T6UNNk5mllwLCpN0/": "GameScene",
|
|
4
|
+
"0c5a3bepqdAUZOCSqDOe7tX": "StageManager",
|
|
5
|
+
"166a2V/C3pMsLYQh5Cfhh0M": "Tile",
|
|
6
|
+
"1777aIKiDVM2ayJgXQsFRbc": "InfoNode",
|
|
7
|
+
"2000bQ16aVPOowsYmWzQHBl": "TilemapCamera",
|
|
8
|
+
"25dfekurxJEpa4v3Hll7c7S": "PlayerController",
|
|
9
|
+
"2a19dBOCe1GUpzKNfMsQQR7": "Pathfinder",
|
|
10
|
+
"329ecFYmkpK+ZTeUQlUmyHq": "MapCharacter",
|
|
11
|
+
"36c13QGxrxExoOv5anzjyRj": "EventManager",
|
|
12
|
+
"394e4Gg6E1Dh6AedkHAFZH+": "index",
|
|
13
|
+
"3cc7eQO1TZPTYTHr3v/2h1L": "SceneScript",
|
|
14
|
+
"42cc8kWoTtFHqEMb8ClTUBk": "GameExpressionEvaluator",
|
|
15
|
+
"7541bC/enRKeocYItojXgyK": "Gamepiece",
|
|
16
|
+
"781adeySrdN27K4uANiWTCT": "MinimapRenderer",
|
|
17
|
+
"9701aXPPNhO2IJ1bgr/25pJ": "PlayerManager",
|
|
18
|
+
"a4e62KPZVNEbZO1mvkzyOQt": "FilmEffect",
|
|
19
|
+
"a4ff8dbnCJNsLLBFaNYXrQp": "Player",
|
|
20
|
+
"a89e2IVZx5Bn50oCifRT+GC": "Gameboard",
|
|
21
|
+
"c4069o+d29NprrTzmS9V1Mb": "ResourceManager",
|
|
22
|
+
"e0920R8VWpPOpxr0VnPlCqA": "GamepieceRegistry",
|
|
23
|
+
"e24c1oXqIpLvqqgMFn+zl3A": "Tilemap",
|
|
24
|
+
"f07feXxRJVMj7Vg6tTtIi+T": "index"
|
|
25
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
const commands = {
|
|
7
|
+
tree: '../src/commands/tree.js',
|
|
8
|
+
get: '../src/commands/get.js',
|
|
9
|
+
set: '../src/commands/set.js',
|
|
10
|
+
'set-component': '../src/commands/set-component.js',
|
|
11
|
+
add: '../src/commands/add.js',
|
|
12
|
+
'add-component': '../src/commands/add-component.js',
|
|
13
|
+
'remove-component': '../src/commands/remove-component.js',
|
|
14
|
+
'remove': '../src/commands/remove.js',
|
|
15
|
+
build: '../src/commands/build.js',
|
|
16
|
+
'create-prefab': '../src/commands/prefab-create.js',
|
|
17
|
+
'create-scene': '../src/commands/create-scene.js',
|
|
18
|
+
'screenshot': '../src/commands/screenshot.js'
|
|
19
|
+
};
|
|
20
|
+
function showHelp() {
|
|
21
|
+
console.log(`
|
|
22
|
+
Cocos Creator CLI - 场景/预制体操作工具集
|
|
23
|
+
|
|
24
|
+
用法:
|
|
25
|
+
cocos2d-cli <command> [options]
|
|
26
|
+
|
|
27
|
+
命令:
|
|
28
|
+
tree <场景.fire | 预制体.prefab> 查看节点树
|
|
29
|
+
get <场景.fire | 预制体.prefab> <节点路径> [属性名|组件类型] 获取节点或组件属性
|
|
30
|
+
set <场景.fire | 预制体.prefab> <节点路径> <属性名> <值> 修改节点属性
|
|
31
|
+
set-component <文件> <节点路径> <组件类型> <属性名> <值> 修改组件属性
|
|
32
|
+
add <场景.fire | 预制体.prefab> <父节点路径> <名称> 添加节点
|
|
33
|
+
add-component <文件> <节点路径> <类型> 给节点添加组件
|
|
34
|
+
remove-component <文件> <节点路径> <类型> 删除节点组件
|
|
35
|
+
remove <文件> <节点路径> 删除节点
|
|
36
|
+
build <项目目录> 构建组件映射
|
|
37
|
+
create-prefab [JSON文件路径] <输出.prefab> 创建预制体
|
|
38
|
+
create-scene [JSON文件路径] <输出.fire> 创建场景
|
|
39
|
+
screenshot <json文件> [选项] 渲染JSON并截图
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
const args = process.argv.slice(2);
|
|
43
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h' || args[0] === 'help') {
|
|
44
|
+
showHelp();
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
const commandName = args[0];
|
|
48
|
+
const commandPath = commands[commandName];
|
|
49
|
+
if (!commandPath) {
|
|
50
|
+
console.error(`未知命令: ${commandName}`);
|
|
51
|
+
console.error('运行 cocos2d-cli --help 查看可用命令');
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
async function main() {
|
|
55
|
+
try {
|
|
56
|
+
const command = await import(commandPath);
|
|
57
|
+
await command.run(args.slice(1));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error(`命令执行失败: ${err.message}`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
main();
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import { CCPrefab } from '../lib/cc/CCPrefab.js';
|
|
3
|
+
import CCNode from '../lib/cc/CCNode.js';
|
|
4
|
+
import CCCanvas from '../lib/cc/CCCanvas.js';
|
|
5
|
+
import CCWidget from '../lib/cc/CCWidget.js';
|
|
6
|
+
import CCSprite from '../lib/cc/CCSprite.js';
|
|
7
|
+
import CCLabel from '../lib/cc/CCLabel.js';
|
|
8
|
+
import CCButton from '../lib/cc/CCButton.js';
|
|
9
|
+
function createNodeFromJSON(json) {
|
|
10
|
+
const node = new CCNode(json.name || 'Node');
|
|
11
|
+
if (json.x !== undefined)
|
|
12
|
+
node.x = json.x;
|
|
13
|
+
if (json.y !== undefined)
|
|
14
|
+
node.y = json.y;
|
|
15
|
+
if (json.width !== undefined)
|
|
16
|
+
node.width = json.width;
|
|
17
|
+
if (json.height !== undefined)
|
|
18
|
+
node.height = json.height;
|
|
19
|
+
if (json.anchorX !== undefined)
|
|
20
|
+
node.anchorX = json.anchorX;
|
|
21
|
+
if (json.anchorY !== undefined)
|
|
22
|
+
node.anchorY = json.anchorY;
|
|
23
|
+
if (json.color !== undefined) {
|
|
24
|
+
const color = hexToRgb(json.color);
|
|
25
|
+
if (color)
|
|
26
|
+
node.setColor(color.r, color.g, color.b);
|
|
27
|
+
}
|
|
28
|
+
if (json.active !== undefined)
|
|
29
|
+
node._active = json.active;
|
|
30
|
+
if (json.components) {
|
|
31
|
+
for (const comp of json.components) {
|
|
32
|
+
let component = null;
|
|
33
|
+
if (typeof comp === 'string') {
|
|
34
|
+
component = createComponent(comp);
|
|
35
|
+
}
|
|
36
|
+
else if (comp.type) {
|
|
37
|
+
component = createComponent(comp.type, comp);
|
|
38
|
+
}
|
|
39
|
+
if (component) {
|
|
40
|
+
component.node = node;
|
|
41
|
+
node._components.push(component);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (json.children) {
|
|
46
|
+
for (const childJson of json.children) {
|
|
47
|
+
const childNode = createNodeFromJSON(childJson);
|
|
48
|
+
childNode._parent = node;
|
|
49
|
+
node._children.push(childNode);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return node;
|
|
53
|
+
}
|
|
54
|
+
function createComponent(type, config) {
|
|
55
|
+
switch (type.toLowerCase()) {
|
|
56
|
+
case 'sprite':
|
|
57
|
+
return new CCSprite();
|
|
58
|
+
case 'label':
|
|
59
|
+
const label = new CCLabel();
|
|
60
|
+
if (config) {
|
|
61
|
+
if (config.string)
|
|
62
|
+
label.setString(config.string);
|
|
63
|
+
if (config.fontSize)
|
|
64
|
+
label._fontSize = config.fontSize;
|
|
65
|
+
if (config.horizontalAlign) {
|
|
66
|
+
const alignMap = { left: 0, center: 1, right: 2 };
|
|
67
|
+
label._N$horizontalAlign = alignMap[config.horizontalAlign] ?? 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return label;
|
|
71
|
+
case 'button':
|
|
72
|
+
return new CCButton();
|
|
73
|
+
case 'canvas':
|
|
74
|
+
return new CCCanvas();
|
|
75
|
+
case 'widget':
|
|
76
|
+
return new CCWidget();
|
|
77
|
+
default:
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function hexToRgb(hex) {
|
|
82
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
83
|
+
return result ? {
|
|
84
|
+
r: parseInt(result[1], 16),
|
|
85
|
+
g: parseInt(result[2], 16),
|
|
86
|
+
b: parseInt(result[3], 16)
|
|
87
|
+
} : null;
|
|
88
|
+
}
|
|
89
|
+
export function run(args) {
|
|
90
|
+
const jsonPath = args[0];
|
|
91
|
+
const outputPath = args[1] || 'output.prefab';
|
|
92
|
+
if (!jsonPath) {
|
|
93
|
+
console.log(JSON.stringify({ error: '用法: cocos2d-cli create-prefab <json文件> [输出.prefab]' }));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const jsonContent = fs.readFileSync(jsonPath, 'utf8');
|
|
98
|
+
const jsonData = JSON.parse(jsonContent);
|
|
99
|
+
const rootNode = createNodeFromJSON(jsonData);
|
|
100
|
+
const prefab = new CCPrefab();
|
|
101
|
+
prefab.setRoot(rootNode);
|
|
102
|
+
const prefabData = prefab.toJSON();
|
|
103
|
+
fs.writeFileSync(outputPath, JSON.stringify(prefabData, null, 2), 'utf8');
|
|
104
|
+
console.log(JSON.stringify({ success: true, outputPath }));
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { takeScreenshot } from '../lib/screenshot-core.js';
|
|
3
|
+
export async function run(args) {
|
|
4
|
+
const jsonFilePath = args[0];
|
|
5
|
+
if (!jsonFilePath) {
|
|
6
|
+
console.log(JSON.stringify({ error: '用法: cocos2d-cli screenshot <json文件> [--width <宽度>] [--height <高度>] [--output <输出路径>]' }));
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
let width = 750;
|
|
10
|
+
let height = 1334;
|
|
11
|
+
let outputPath = path.join(process.cwd(), `screenshot-${Date.now()}.png`);
|
|
12
|
+
for (let i = 1; i < args.length; i++) {
|
|
13
|
+
const arg = args[i];
|
|
14
|
+
if (arg === '--width' && args[i + 1]) {
|
|
15
|
+
width = parseInt(args[i + 1]);
|
|
16
|
+
i++;
|
|
17
|
+
}
|
|
18
|
+
else if (arg === '--height' && args[i + 1]) {
|
|
19
|
+
height = parseInt(args[i + 1]);
|
|
20
|
+
i++;
|
|
21
|
+
}
|
|
22
|
+
else if (arg === '--output' && args[i + 1]) {
|
|
23
|
+
outputPath = args[i + 1];
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const { screenshotPath, logs } = await takeScreenshot({
|
|
29
|
+
jsonPath: jsonFilePath,
|
|
30
|
+
viewport: { width, height },
|
|
31
|
+
outputDir: path.dirname(outputPath),
|
|
32
|
+
fullPage: true,
|
|
33
|
+
timeout: 30000,
|
|
34
|
+
waitTime: 1000
|
|
35
|
+
});
|
|
36
|
+
console.log(JSON.stringify({ success: true, outputPath: screenshotPath }));
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { loadScene, loadScriptMap, isPrefab } from '../lib/fire-utils.js';
|
|
2
|
+
import { buildTree } from '../lib/node-utils.js';
|
|
3
|
+
export function run(args) {
|
|
4
|
+
const filePath = args[0];
|
|
5
|
+
if (!filePath) {
|
|
6
|
+
console.log(JSON.stringify({ error: '用法: cocos2d-cli tree <场景.fire | 预制体.prefab>' }));
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const data = loadScene(filePath);
|
|
11
|
+
if (!data || data.length === 0) {
|
|
12
|
+
console.log(JSON.stringify({ error: '文件为空或格式错误' }));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const scriptMap = loadScriptMap(filePath);
|
|
16
|
+
const prefab = isPrefab(data);
|
|
17
|
+
const startIndex = prefab ? 0 : 1;
|
|
18
|
+
const tree = buildTree(data, scriptMap, startIndex);
|
|
19
|
+
console.log(tree ? tree.trim() : '{}');
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import CCComponent from './CCComponent.js';
|
|
2
|
+
import CCColor from './CCColor.js';
|
|
3
|
+
export default class CCButton extends CCComponent {
|
|
4
|
+
_normalMaterial;
|
|
5
|
+
_grayMaterial;
|
|
6
|
+
duration;
|
|
7
|
+
zoomScale;
|
|
8
|
+
clickEvents;
|
|
9
|
+
_N$interactable;
|
|
10
|
+
_N$enableAutoGrayEffect;
|
|
11
|
+
_N$transition;
|
|
12
|
+
transition;
|
|
13
|
+
_N$normalColor;
|
|
14
|
+
_N$pressedColor;
|
|
15
|
+
pressedColor;
|
|
16
|
+
_N$hoverColor;
|
|
17
|
+
hoverColor;
|
|
18
|
+
_N$disabledColor;
|
|
19
|
+
_N$normalSprite;
|
|
20
|
+
_N$pressedSprite;
|
|
21
|
+
pressedSprite;
|
|
22
|
+
_N$hoverSprite;
|
|
23
|
+
hoverSprite;
|
|
24
|
+
_N$disabledSprite;
|
|
25
|
+
_N$target;
|
|
8
26
|
constructor() {
|
|
9
27
|
super();
|
|
10
28
|
this.__type__ = 'cc.Button';
|
|
11
|
-
|
|
12
29
|
this._normalMaterial = null;
|
|
13
30
|
this._grayMaterial = null;
|
|
14
31
|
this.duration = 0.1;
|
|
@@ -32,36 +49,19 @@ class CCButton extends CCComponent {
|
|
|
32
49
|
this._N$disabledSprite = null;
|
|
33
50
|
this._N$target = null;
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 设置缩放
|
|
38
|
-
*/
|
|
39
52
|
setZoomScale(scale) {
|
|
40
53
|
this.zoomScale = scale;
|
|
41
54
|
return this;
|
|
42
55
|
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 设置过渡类型
|
|
46
|
-
* 0: NONE, 1: COLOR, 2: SPRITE, 3: SCALE
|
|
47
|
-
*/
|
|
48
56
|
setTransition(type) {
|
|
49
57
|
this._N$transition = type;
|
|
50
58
|
this.transition = type;
|
|
51
59
|
return this;
|
|
52
60
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 设置正常精灵
|
|
56
|
-
*/
|
|
57
61
|
setNormalSprite(uuid) {
|
|
58
62
|
this._N$normalSprite = { __uuid__: uuid };
|
|
59
63
|
return this;
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 设置点击事件
|
|
64
|
-
*/
|
|
65
65
|
addClickEvent(component, handler, target = null) {
|
|
66
66
|
this.clickEvents.push({
|
|
67
67
|
target: target,
|
|
@@ -70,21 +70,16 @@ class CCButton extends CCComponent {
|
|
|
70
70
|
});
|
|
71
71
|
return this;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 转换为属性面板显示格式
|
|
76
|
-
*/
|
|
77
73
|
toPanelJSON() {
|
|
78
74
|
const TRANSITION = ['NONE', 'COLOR', 'SPRITE', 'SCALE'];
|
|
79
75
|
return {
|
|
80
|
-
...super.
|
|
76
|
+
...super.getProp(),
|
|
81
77
|
interactable: this._N$interactable,
|
|
82
78
|
transition: TRANSITION[this._N$transition] || this._N$transition,
|
|
83
79
|
zoomScale: this.zoomScale,
|
|
84
80
|
duration: this.duration
|
|
85
81
|
};
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
toJSON() {
|
|
89
84
|
return {
|
|
90
85
|
__type__: this.__type__,
|
|
@@ -118,5 +113,3 @@ class CCButton extends CCComponent {
|
|
|
118
113
|
};
|
|
119
114
|
}
|
|
120
115
|
}
|
|
121
|
-
|
|
122
|
-
module.exports = CCButton;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import CCComponent from './CCComponent.js';
|
|
2
|
+
import CCColor from './CCColor.js';
|
|
3
|
+
import CCRect from './CCRect.js';
|
|
4
|
+
export default class CCCamera extends CCComponent {
|
|
5
|
+
_cullingMask;
|
|
6
|
+
_clearFlags;
|
|
7
|
+
_backgroundColor;
|
|
8
|
+
_depth;
|
|
9
|
+
_zoomRatio;
|
|
10
|
+
_targetTexture;
|
|
11
|
+
_fov;
|
|
12
|
+
_orthoSize;
|
|
13
|
+
_nearClip;
|
|
14
|
+
_farClip;
|
|
15
|
+
_ortho;
|
|
16
|
+
_rect;
|
|
17
|
+
_renderStages;
|
|
18
|
+
_alignWithScreen;
|
|
9
19
|
constructor() {
|
|
10
20
|
super();
|
|
11
21
|
this.__type__ = 'cc.Camera';
|
|
12
|
-
|
|
13
22
|
this._cullingMask = 4294967295;
|
|
14
23
|
this._clearFlags = 7;
|
|
15
24
|
this._backgroundColor = new CCColor(0, 0, 0, 255);
|
|
@@ -25,45 +34,28 @@ class CCCamera extends CCComponent {
|
|
|
25
34
|
this._renderStages = 1;
|
|
26
35
|
this._alignWithScreen = true;
|
|
27
36
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 设置正交大小
|
|
31
|
-
*/
|
|
32
37
|
setOrthoSize(size) {
|
|
33
38
|
this._orthoSize = size;
|
|
34
39
|
return this;
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 设置深度
|
|
39
|
-
*/
|
|
40
41
|
setDepth(depth) {
|
|
41
42
|
this._depth = depth;
|
|
42
43
|
return this;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 设置背景颜色
|
|
47
|
-
*/
|
|
48
45
|
setBackgroundColor(r, g, b, a = 255) {
|
|
49
46
|
this._backgroundColor.set(r, g, b, a);
|
|
50
47
|
return this;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 转换为属性面板显示格式
|
|
55
|
-
*/
|
|
56
49
|
toPanelJSON() {
|
|
57
50
|
return {
|
|
58
|
-
...super.
|
|
51
|
+
...super.getProp(),
|
|
59
52
|
depth: this._depth,
|
|
60
53
|
zoomRatio: this._zoomRatio,
|
|
61
54
|
ortho: this._ortho,
|
|
62
55
|
orthoSize: this._orthoSize,
|
|
63
|
-
backgroundColor: this._backgroundColor ? `#${this._backgroundColor.r.toString(16).padStart(2,'0')}${this._backgroundColor.g.toString(16).padStart(2,'0')}${this._backgroundColor.b.toString(16).padStart(2,'0')}` : '#000000'
|
|
56
|
+
backgroundColor: this._backgroundColor ? `#${this._backgroundColor.r.toString(16).padStart(2, '0')}${this._backgroundColor.g.toString(16).padStart(2, '0')}${this._backgroundColor.b.toString(16).padStart(2, '0')}` : '#000000'
|
|
64
57
|
};
|
|
65
58
|
}
|
|
66
|
-
|
|
67
59
|
toJSON() {
|
|
68
60
|
return {
|
|
69
61
|
__type__: this.__type__,
|
|
@@ -89,5 +81,3 @@ class CCCamera extends CCComponent {
|
|
|
89
81
|
};
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
|
-
|
|
93
|
-
module.exports = CCCamera;
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class CCCanvas extends CCComponent {
|
|
1
|
+
import CCComponent from './CCComponent.js';
|
|
2
|
+
import CCSize from './CCSize.js';
|
|
3
|
+
export default class CCCanvas extends CCComponent {
|
|
4
|
+
_designResolution;
|
|
5
|
+
_fitWidth;
|
|
6
|
+
_fitHeight;
|
|
8
7
|
constructor() {
|
|
9
8
|
super();
|
|
10
9
|
this.__type__ = 'cc.Canvas';
|
|
11
|
-
|
|
12
10
|
this._designResolution = new CCSize(960, 640);
|
|
13
11
|
this._fitWidth = false;
|
|
14
12
|
this._fitHeight = true;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
setProp(props) {
|
|
18
15
|
super.setProp(props);
|
|
19
16
|
if (props.designResolution) {
|
|
20
17
|
this._designResolution = new CCSize(props.designResolution.width, props.designResolution.height);
|
|
21
18
|
}
|
|
22
|
-
if (props.fitWidth !== undefined)
|
|
23
|
-
|
|
19
|
+
if (props.fitWidth !== undefined)
|
|
20
|
+
this._fitWidth = props.fitWidth;
|
|
21
|
+
if (props.fitHeight !== undefined)
|
|
22
|
+
this._fitHeight = props.fitHeight;
|
|
24
23
|
return this;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
getProp() {
|
|
28
26
|
return {
|
|
29
27
|
...super.getProp(),
|
|
@@ -35,7 +33,6 @@ class CCCanvas extends CCComponent {
|
|
|
35
33
|
fitHeight: this._fitHeight
|
|
36
34
|
};
|
|
37
35
|
}
|
|
38
|
-
|
|
39
36
|
toJSON() {
|
|
40
37
|
return {
|
|
41
38
|
__type__: this.__type__,
|
|
@@ -50,5 +47,3 @@ class CCCanvas extends CCComponent {
|
|
|
50
47
|
};
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
module.exports = CCCanvas;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export default class CCColor {
|
|
2
|
+
__type__;
|
|
3
|
+
r;
|
|
4
|
+
g;
|
|
5
|
+
b;
|
|
6
|
+
a;
|
|
5
7
|
constructor(r = 255, g = 255, b = 255, a = 255) {
|
|
6
8
|
this.__type__ = 'cc.Color';
|
|
7
9
|
this.r = r;
|
|
@@ -9,7 +11,6 @@ class CCColor {
|
|
|
9
11
|
this.b = b;
|
|
10
12
|
this.a = a;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
14
|
set(r, g, b, a = 255) {
|
|
14
15
|
this.r = r;
|
|
15
16
|
this.g = g;
|
|
@@ -17,7 +18,6 @@ class CCColor {
|
|
|
17
18
|
this.a = a;
|
|
18
19
|
return this;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
21
|
toJSON() {
|
|
22
22
|
return {
|
|
23
23
|
__type__: this.__type__,
|
|
@@ -28,5 +28,3 @@ class CCColor {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
module.exports = CCColor;
|