cocos2d-cli 1.6.5 → 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/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 +221 -285
- package/dist/src/lib/templates.js +17 -0
- package/dist/src/lib/utils.js +81 -0
- package/package.json +13 -6
- 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
|
@@ -1,285 +1,221 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
text
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
await
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
addLog('info',
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const errorText = failure ? failure.errorText : 'Unknown error';
|
|
223
|
-
addLog('requestfailed', request.url(), { error: errorText });
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// 加载页面
|
|
227
|
-
addLog('info', 'Loading Page');
|
|
228
|
-
const pageUrl = config.debugBounds
|
|
229
|
-
? `${serverUrl}/index.html?debugBounds=true`
|
|
230
|
-
: `${serverUrl}/index.html`;
|
|
231
|
-
await page.goto(pageUrl, {
|
|
232
|
-
waitUntil: 'networkidle',
|
|
233
|
-
timeout: config.timeout
|
|
234
|
-
});
|
|
235
|
-
addLog('info', 'Page loaded');
|
|
236
|
-
|
|
237
|
-
// 等待渲染
|
|
238
|
-
addLog('info', 'Waiting for Render');
|
|
239
|
-
await page.waitForTimeout(config.waitTime);
|
|
240
|
-
addLog('info', 'Wait complete');
|
|
241
|
-
|
|
242
|
-
// 截图
|
|
243
|
-
addLog('info', 'Taking Screenshot');
|
|
244
|
-
await page.screenshot({
|
|
245
|
-
path: screenshotPath,
|
|
246
|
-
fullPage: config.fullPage
|
|
247
|
-
});
|
|
248
|
-
addLog('info', `Screenshot saved: ${screenshotPath}`);
|
|
249
|
-
addLog('info', 'Done');
|
|
250
|
-
|
|
251
|
-
return { screenshotPath, logs };
|
|
252
|
-
|
|
253
|
-
} catch (error) {
|
|
254
|
-
addLog('error', error.message);
|
|
255
|
-
try {
|
|
256
|
-
logDir = path.join(config.outputDir, `screenshot-logs-${Date.now()}`);
|
|
257
|
-
await fs.mkdir(logDir, { recursive: true });
|
|
258
|
-
await fs.writeFile(
|
|
259
|
-
path.join(logDir, 'logs.json'),
|
|
260
|
-
JSON.stringify({
|
|
261
|
-
error: error.message,
|
|
262
|
-
jsonPath: config.jsonPath,
|
|
263
|
-
outputDir: config.outputDir,
|
|
264
|
-
viewport: config.viewport,
|
|
265
|
-
fullPage: config.fullPage,
|
|
266
|
-
debugBounds: config.debugBounds,
|
|
267
|
-
timeout: config.timeout,
|
|
268
|
-
waitTime: config.waitTime,
|
|
269
|
-
screenshotPath,
|
|
270
|
-
logs
|
|
271
|
-
}, null, 2),
|
|
272
|
-
'utf8'
|
|
273
|
-
);
|
|
274
|
-
} catch (_) {}
|
|
275
|
-
error.logDir = logDir;
|
|
276
|
-
throw error;
|
|
277
|
-
} finally {
|
|
278
|
-
// 清理资源
|
|
279
|
-
if (browser) await browser.close().catch(() => {});
|
|
280
|
-
if (server) server.close();
|
|
281
|
-
if (tempDir) await removeDir(tempDir, logs);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
module.exports = { takeScreenshot };
|
|
1
|
+
import { chromium } from 'playwright';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as http from 'http';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const DEFAULT_CONFIG = {
|
|
8
|
+
outputDir: process.cwd(),
|
|
9
|
+
viewport: { width: 750, height: 1334 },
|
|
10
|
+
fullPage: true,
|
|
11
|
+
debugBounds: false,
|
|
12
|
+
timeout: 30000,
|
|
13
|
+
waitTime: 1000
|
|
14
|
+
};
|
|
15
|
+
function getAssetsDir() {
|
|
16
|
+
const projectRoot = process.cwd();
|
|
17
|
+
return path.join(projectRoot, 'src', 'lib', 'screenshot');
|
|
18
|
+
}
|
|
19
|
+
async function createTempWorkDir() {
|
|
20
|
+
const tempBase = process.env.TEMP || process.env.TMP || '/tmp';
|
|
21
|
+
const timestamp = Date.now();
|
|
22
|
+
const tempDir = path.join(tempBase, `cocos2d-screenshot-${timestamp}`);
|
|
23
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
24
|
+
return tempDir;
|
|
25
|
+
}
|
|
26
|
+
async function copyBuiltInAssets(tempDir, logs) {
|
|
27
|
+
const assetsDir = getAssetsDir();
|
|
28
|
+
const assets = ['index.html', 'favicon.ico'];
|
|
29
|
+
for (const asset of assets) {
|
|
30
|
+
const src = path.join(assetsDir, asset);
|
|
31
|
+
const dest = path.join(tempDir, asset);
|
|
32
|
+
try {
|
|
33
|
+
await fs.copyFile(src, dest);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
logs.push({
|
|
37
|
+
timestamp: new Date().toISOString(),
|
|
38
|
+
type: 'warning',
|
|
39
|
+
text: `Could not copy ${asset}: ${err.message}`
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function startServer(staticDir, logs) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const server = http.createServer(async (req, res) => {
|
|
47
|
+
try {
|
|
48
|
+
const reqUrl = new URL(req.url || '/', `http://${req.headers.host}`);
|
|
49
|
+
let filePath = path.join(staticDir, reqUrl.pathname);
|
|
50
|
+
if (reqUrl.pathname === '/') {
|
|
51
|
+
filePath = path.join(staticDir, 'index.html');
|
|
52
|
+
}
|
|
53
|
+
const data = await fs.readFile(filePath);
|
|
54
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
55
|
+
const contentTypes = {
|
|
56
|
+
'.html': 'text/html',
|
|
57
|
+
'.htm': 'text/html',
|
|
58
|
+
'.json': 'application/json',
|
|
59
|
+
'.js': 'application/javascript',
|
|
60
|
+
'.mjs': 'application/javascript',
|
|
61
|
+
'.css': 'text/css',
|
|
62
|
+
'.png': 'image/png',
|
|
63
|
+
'.jpg': 'image/jpeg',
|
|
64
|
+
'.jpeg': 'image/jpeg',
|
|
65
|
+
'.gif': 'image/gif',
|
|
66
|
+
'.svg': 'image/svg+xml',
|
|
67
|
+
'.ico': 'image/x-icon',
|
|
68
|
+
'.txt': 'text/plain',
|
|
69
|
+
'.xml': 'application/xml'
|
|
70
|
+
};
|
|
71
|
+
res.writeHead(200, {
|
|
72
|
+
'Content-Type': contentTypes[ext] || 'application/octet-stream',
|
|
73
|
+
'Access-Control-Allow-Origin': '*'
|
|
74
|
+
});
|
|
75
|
+
res.end(data);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (err.code === 'ENOENT') {
|
|
79
|
+
res.writeHead(404);
|
|
80
|
+
res.end();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
logs.push({
|
|
84
|
+
timestamp: new Date().toISOString(),
|
|
85
|
+
type: 'server-error',
|
|
86
|
+
text: `${req.url}: ${err.message}`
|
|
87
|
+
});
|
|
88
|
+
res.writeHead(500);
|
|
89
|
+
res.end();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
server.listen(0, '127.0.0.1', () => resolve(server));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function removeDir(dirPath, logs) {
|
|
97
|
+
try {
|
|
98
|
+
await fs.rm(dirPath, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (logs) {
|
|
102
|
+
logs.push({
|
|
103
|
+
timestamp: new Date().toISOString(),
|
|
104
|
+
type: 'warning',
|
|
105
|
+
text: `Could not remove temp dir: ${err.message}`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function takeScreenshot(userConfig = {}) {
|
|
111
|
+
const config = { ...DEFAULT_CONFIG, ...userConfig };
|
|
112
|
+
if (!config.jsonPath) {
|
|
113
|
+
throw new Error('JSON file path is required');
|
|
114
|
+
}
|
|
115
|
+
let server = null;
|
|
116
|
+
let browser = null;
|
|
117
|
+
let tempDir = null;
|
|
118
|
+
const logs = [];
|
|
119
|
+
let screenshotPath = null;
|
|
120
|
+
let logDir = null;
|
|
121
|
+
const addLog = (type, text, extra = {}) => {
|
|
122
|
+
logs.push({
|
|
123
|
+
timestamp: new Date().toISOString(),
|
|
124
|
+
type,
|
|
125
|
+
text,
|
|
126
|
+
...extra
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
try {
|
|
130
|
+
const timestamp = Date.now();
|
|
131
|
+
try {
|
|
132
|
+
await fs.access(config.jsonPath);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new Error(`JSON file not found: ${config.jsonPath}`);
|
|
136
|
+
}
|
|
137
|
+
await fs.mkdir(config.outputDir, { recursive: true });
|
|
138
|
+
tempDir = await createTempWorkDir();
|
|
139
|
+
addLog('info', `Temp dir: ${tempDir}`);
|
|
140
|
+
await copyBuiltInAssets(tempDir, logs);
|
|
141
|
+
const destJsonPath = path.join(tempDir, 'data.json');
|
|
142
|
+
await fs.copyFile(config.jsonPath, destJsonPath);
|
|
143
|
+
addLog('info', `JSON: ${config.jsonPath}`);
|
|
144
|
+
screenshotPath = path.join(config.outputDir, `screenshot-${timestamp}.png`);
|
|
145
|
+
addLog('info', 'Starting Server');
|
|
146
|
+
server = await startServer(tempDir, logs);
|
|
147
|
+
const address = server.address();
|
|
148
|
+
const serverUrl = `http://127.0.0.1:${address.port}`;
|
|
149
|
+
addLog('info', `Server: ${serverUrl}`);
|
|
150
|
+
addLog('info', 'Launching Browser');
|
|
151
|
+
browser = await chromium.launch({
|
|
152
|
+
headless: true
|
|
153
|
+
});
|
|
154
|
+
addLog('info', 'Browser launched');
|
|
155
|
+
const page = await browser.newPage({
|
|
156
|
+
viewport: config.viewport
|
|
157
|
+
});
|
|
158
|
+
page.on('console', (msg) => {
|
|
159
|
+
const text = msg.text();
|
|
160
|
+
addLog(msg.type(), text);
|
|
161
|
+
});
|
|
162
|
+
page.on('pageerror', (error) => {
|
|
163
|
+
addLog('pageerror', error.message);
|
|
164
|
+
});
|
|
165
|
+
page.on('requestfailed', (request) => {
|
|
166
|
+
const failure = request.failure();
|
|
167
|
+
const errorText = failure ? failure.errorText : 'Unknown error';
|
|
168
|
+
addLog('requestfailed', request.url(), { error: errorText });
|
|
169
|
+
});
|
|
170
|
+
addLog('info', 'Loading Page');
|
|
171
|
+
const pageUrl = config.debugBounds
|
|
172
|
+
? `${serverUrl}/index.html?debugBounds=true`
|
|
173
|
+
: `${serverUrl}/index.html`;
|
|
174
|
+
await page.goto(pageUrl, {
|
|
175
|
+
waitUntil: 'networkidle',
|
|
176
|
+
timeout: config.timeout
|
|
177
|
+
});
|
|
178
|
+
addLog('info', 'Page loaded');
|
|
179
|
+
addLog('info', 'Waiting for Render');
|
|
180
|
+
await page.waitForTimeout(config.waitTime);
|
|
181
|
+
addLog('info', 'Wait complete');
|
|
182
|
+
addLog('info', 'Taking Screenshot');
|
|
183
|
+
await page.screenshot({
|
|
184
|
+
path: screenshotPath,
|
|
185
|
+
fullPage: config.fullPage
|
|
186
|
+
});
|
|
187
|
+
addLog('info', `Screenshot saved: ${screenshotPath}`);
|
|
188
|
+
addLog('info', 'Done');
|
|
189
|
+
return { screenshotPath, logs };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
addLog('error', error.message);
|
|
193
|
+
try {
|
|
194
|
+
logDir = path.join(config.outputDir, `screenshot-logs-${Date.now()}`);
|
|
195
|
+
await fs.mkdir(logDir, { recursive: true });
|
|
196
|
+
await fs.writeFile(path.join(logDir, 'logs.json'), JSON.stringify({
|
|
197
|
+
error: error.message,
|
|
198
|
+
jsonPath: config.jsonPath,
|
|
199
|
+
outputDir: config.outputDir,
|
|
200
|
+
viewport: config.viewport,
|
|
201
|
+
fullPage: config.fullPage,
|
|
202
|
+
debugBounds: config.debugBounds,
|
|
203
|
+
timeout: config.timeout,
|
|
204
|
+
waitTime: config.waitTime,
|
|
205
|
+
screenshotPath,
|
|
206
|
+
logs
|
|
207
|
+
}, null, 2), 'utf8');
|
|
208
|
+
}
|
|
209
|
+
catch (_) { }
|
|
210
|
+
error.logDir = logDir;
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
if (browser)
|
|
215
|
+
await browser.close().catch(() => { });
|
|
216
|
+
if (server)
|
|
217
|
+
server.close();
|
|
218
|
+
if (tempDir)
|
|
219
|
+
await removeDir(tempDir, logs);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import CCNode from './cc/CCNode.js';
|
|
2
|
+
import CCScene from './cc/CCScene.js';
|
|
3
|
+
import CCSceneAsset from './cc/CCSceneAsset.js';
|
|
4
|
+
import { CCPrefab, CCPrefabInfo } from './cc/CCPrefab.js';
|
|
5
|
+
export function createPrefab(name = 'Prefab') {
|
|
6
|
+
const prefab = new CCPrefab();
|
|
7
|
+
const root = new CCNode(name);
|
|
8
|
+
prefab.setRoot(root);
|
|
9
|
+
return prefab;
|
|
10
|
+
}
|
|
11
|
+
export function createScene(name = 'NewScene') {
|
|
12
|
+
const asset = new CCSceneAsset();
|
|
13
|
+
const scene = new CCScene(name);
|
|
14
|
+
asset._scene = scene;
|
|
15
|
+
return asset;
|
|
16
|
+
}
|
|
17
|
+
export { CCNode, CCScene, CCSceneAsset, CCPrefab, CCPrefabInfo };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
export function parseColor(color) {
|
|
3
|
+
if (!color)
|
|
4
|
+
return null;
|
|
5
|
+
if (color.startsWith('#')) {
|
|
6
|
+
const hex = color.slice(1);
|
|
7
|
+
if (hex.length === 6 || hex.length === 8) {
|
|
8
|
+
return {
|
|
9
|
+
r: parseInt(hex.slice(0, 2), 16),
|
|
10
|
+
g: parseInt(hex.slice(2, 4), 16),
|
|
11
|
+
b: parseInt(hex.slice(4, 6), 16),
|
|
12
|
+
a: hex.length === 8 ? parseInt(hex.slice(6, 8), 16) : 255
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const rgbMatch = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
|
|
17
|
+
if (rgbMatch) {
|
|
18
|
+
return {
|
|
19
|
+
r: parseInt(rgbMatch[1]),
|
|
20
|
+
g: parseInt(rgbMatch[2]),
|
|
21
|
+
b: parseInt(rgbMatch[3]),
|
|
22
|
+
a: rgbMatch[4] ? Math.round(parseFloat(rgbMatch[4]) * 255) : 255
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export function parseColorToCcColor(color) {
|
|
28
|
+
const parsed = parseColor(color);
|
|
29
|
+
if (!parsed)
|
|
30
|
+
return null;
|
|
31
|
+
return { __type__: 'cc.Color', ...parsed };
|
|
32
|
+
}
|
|
33
|
+
export function colorToHex(r, g, b, a = 255) {
|
|
34
|
+
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}${a !== 255 ? a.toString(16).padStart(2, '0') : ''}`;
|
|
35
|
+
}
|
|
36
|
+
export function generateUUID() {
|
|
37
|
+
return crypto.randomUUID().replace(/-/g, '');
|
|
38
|
+
}
|
|
39
|
+
export function compressUUID(uuid) {
|
|
40
|
+
const hex = uuid.replace(/-/g, '');
|
|
41
|
+
const bytes = Buffer.from(hex, 'hex');
|
|
42
|
+
return bytes.toString('base64url').slice(0, 22);
|
|
43
|
+
}
|
|
44
|
+
export function generateCompressedUUID() {
|
|
45
|
+
return compressUUID(generateUUID());
|
|
46
|
+
}
|
|
47
|
+
export function generateId() {
|
|
48
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
49
|
+
let result = '';
|
|
50
|
+
for (let i = 0; i < 22; i++) {
|
|
51
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
export function parseOptions(args) {
|
|
56
|
+
const options = {};
|
|
57
|
+
for (let i = 0; i < args.length; i++) {
|
|
58
|
+
const arg = args[i];
|
|
59
|
+
if (arg.startsWith('--')) {
|
|
60
|
+
const key = arg.slice(2);
|
|
61
|
+
const nextArg = args[i + 1];
|
|
62
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
63
|
+
options[key] = nextArg;
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
options[key] = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
export function outputJson(data) {
|
|
74
|
+
console.log(JSON.stringify(data, null, 2));
|
|
75
|
+
}
|
|
76
|
+
export function outputError(message) {
|
|
77
|
+
console.log(JSON.stringify({ error: message }));
|
|
78
|
+
}
|
|
79
|
+
export function outputSuccess(message) {
|
|
80
|
+
console.log(JSON.stringify({ success: message }));
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cocos2d-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/bin/cocos2d-cli.js",
|
|
6
7
|
"bin": {
|
|
7
|
-
"cocos2d-cli": "bin/cocos2d-cli.js"
|
|
8
|
+
"cocos2d-cli": "dist/bin/cocos2d-cli.js"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
|
-
"
|
|
11
|
-
"src",
|
|
11
|
+
"dist",
|
|
12
12
|
"data"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"watch": "tsc --watch",
|
|
17
|
+
"prepare": "npm run build",
|
|
15
18
|
"test": "echo \"No tests specified\" && exit 1"
|
|
16
19
|
},
|
|
17
20
|
"keywords": [
|
|
@@ -25,9 +28,13 @@
|
|
|
25
28
|
"author": "",
|
|
26
29
|
"license": "MIT",
|
|
27
30
|
"engines": {
|
|
28
|
-
"node": ">=
|
|
31
|
+
"node": ">=18.0.0"
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
31
34
|
"playwright": "^1.58.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.15.17",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
32
39
|
}
|
|
33
40
|
}
|