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.
- 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 +115 -122
- package/{src → dist/src}/lib/cc/CCCamera.js +83 -93
- package/{src → dist/src}/lib/cc/CCCanvas.js +49 -54
- package/{src → dist/src}/lib/cc/CCColor.js +30 -32
- package/{src → dist/src}/lib/cc/CCComponent.js +39 -60
- package/{src → dist/src}/lib/cc/CCLabel.js +139 -146
- package/{src → dist/src}/lib/cc/CCNode.js +190 -256
- package/{src → dist/src}/lib/cc/CCObject.js +19 -23
- package/{src → dist/src}/lib/cc/CCPrefab.js +219 -242
- package/{src → dist/src}/lib/cc/CCRect.js +30 -32
- package/{src → dist/src}/lib/cc/CCRichText.js +38 -44
- package/{src → dist/src}/lib/cc/CCScene.js +32 -42
- package/dist/src/lib/cc/CCSceneAsset.js +242 -0
- package/{src → dist/src}/lib/cc/CCSize.js +22 -26
- package/{src → dist/src}/lib/cc/CCSprite.js +82 -94
- package/{src → dist/src}/lib/cc/CCTrs.js +49 -74
- package/{src → dist/src}/lib/cc/CCVec2.js +22 -26
- package/{src → dist/src}/lib/cc/CCVec3.js +26 -29
- package/{src → dist/src}/lib/cc/CCWidget.js +94 -98
- 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 +242 -285
- 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,122 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this._N$
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
addClickEvent(component, handler, target = null) {
|
|
66
|
-
this.clickEvents.push({
|
|
67
|
-
target: target,
|
|
68
|
-
component: component,
|
|
69
|
-
handler: handler
|
|
70
|
-
});
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
_N$
|
|
101
|
-
|
|
102
|
-
_N$
|
|
103
|
-
|
|
104
|
-
_N$
|
|
105
|
-
_N$
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
_N$
|
|
111
|
-
_N$
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
_N$target: this._N$target,
|
|
117
|
-
_id: this._id
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = CCButton;
|
|
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;
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this.__type__ = 'cc.Button';
|
|
29
|
+
this._normalMaterial = null;
|
|
30
|
+
this._grayMaterial = null;
|
|
31
|
+
this.duration = 0.1;
|
|
32
|
+
this.zoomScale = 1.2;
|
|
33
|
+
this.clickEvents = [];
|
|
34
|
+
this._N$interactable = true;
|
|
35
|
+
this._N$enableAutoGrayEffect = false;
|
|
36
|
+
this._N$transition = 3;
|
|
37
|
+
this.transition = 3;
|
|
38
|
+
this._N$normalColor = new CCColor();
|
|
39
|
+
this._N$pressedColor = new CCColor(200, 200, 200, 255);
|
|
40
|
+
this.pressedColor = new CCColor(200, 200, 200, 255);
|
|
41
|
+
this._N$hoverColor = new CCColor();
|
|
42
|
+
this.hoverColor = new CCColor();
|
|
43
|
+
this._N$disabledColor = new CCColor(120, 120, 120, 200);
|
|
44
|
+
this._N$normalSprite = null;
|
|
45
|
+
this._N$pressedSprite = null;
|
|
46
|
+
this.pressedSprite = null;
|
|
47
|
+
this._N$hoverSprite = null;
|
|
48
|
+
this.hoverSprite = null;
|
|
49
|
+
this._N$disabledSprite = null;
|
|
50
|
+
this._N$target = null;
|
|
51
|
+
}
|
|
52
|
+
setZoomScale(scale) {
|
|
53
|
+
this.zoomScale = scale;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
setTransition(type) {
|
|
57
|
+
this._N$transition = type;
|
|
58
|
+
this.transition = type;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
setNormalSprite(uuid) {
|
|
62
|
+
this._N$normalSprite = { __uuid__: uuid };
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
addClickEvent(component, handler, target = null) {
|
|
66
|
+
this.clickEvents.push({
|
|
67
|
+
target: target,
|
|
68
|
+
component: component,
|
|
69
|
+
handler: handler
|
|
70
|
+
});
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
toPanelJSON() {
|
|
74
|
+
const TRANSITION = ['NONE', 'COLOR', 'SPRITE', 'SCALE'];
|
|
75
|
+
return {
|
|
76
|
+
...super.getProp(),
|
|
77
|
+
interactable: this._N$interactable,
|
|
78
|
+
transition: TRANSITION[this._N$transition] || this._N$transition,
|
|
79
|
+
zoomScale: this.zoomScale,
|
|
80
|
+
duration: this.duration
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
toJSON() {
|
|
84
|
+
return {
|
|
85
|
+
__type__: this.__type__,
|
|
86
|
+
_name: this._name,
|
|
87
|
+
_objFlags: this._objFlags,
|
|
88
|
+
node: this.node,
|
|
89
|
+
_enabled: this._enabled,
|
|
90
|
+
_normalMaterial: this._normalMaterial,
|
|
91
|
+
_grayMaterial: this._grayMaterial,
|
|
92
|
+
duration: this.duration,
|
|
93
|
+
zoomScale: this.zoomScale,
|
|
94
|
+
clickEvents: this.clickEvents,
|
|
95
|
+
_N$interactable: this._N$interactable,
|
|
96
|
+
_N$enableAutoGrayEffect: this._N$enableAutoGrayEffect,
|
|
97
|
+
_N$transition: this._N$transition,
|
|
98
|
+
transition: this.transition,
|
|
99
|
+
_N$normalColor: this._N$normalColor.toJSON(),
|
|
100
|
+
_N$pressedColor: this._N$pressedColor.toJSON(),
|
|
101
|
+
pressedColor: this.pressedColor.toJSON(),
|
|
102
|
+
_N$hoverColor: this._N$hoverColor.toJSON(),
|
|
103
|
+
hoverColor: this.hoverColor.toJSON(),
|
|
104
|
+
_N$disabledColor: this._N$disabledColor.toJSON(),
|
|
105
|
+
_N$normalSprite: this._N$normalSprite,
|
|
106
|
+
_N$pressedSprite: this._N$pressedSprite,
|
|
107
|
+
pressedSprite: this.pressedSprite,
|
|
108
|
+
_N$hoverSprite: this._N$hoverSprite,
|
|
109
|
+
hoverSprite: this.hoverSprite,
|
|
110
|
+
_N$disabledSprite: this._N$disabledSprite,
|
|
111
|
+
_N$target: this._N$target,
|
|
112
|
+
_id: this._id
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|