pixifact 0.11.2 → 0.13.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.
|
@@ -46,6 +46,10 @@ class CompileContext {
|
|
|
46
46
|
this.#lines.push(`export function ${functionName}(root: Group${this.#hasEvents() ? `, ${actionsParameter}: Record<string, () => void> = {}` : ''}) {`);
|
|
47
47
|
this.#lines.push(' const __pixifactNodes: Record<string, Container> = {};');
|
|
48
48
|
this.#lines.push(' const __pixifactSlots: Record<string, Container> = {};');
|
|
49
|
+
if (this.options.registrationPath) {
|
|
50
|
+
this.#lines.push(" const __pixifactSceneSource = Symbol.for('pixifact.scene.source');");
|
|
51
|
+
this.#recordSource('root', null);
|
|
52
|
+
}
|
|
49
53
|
this.#applyRootProps();
|
|
50
54
|
for (const [index, child] of this.template.children.entries()) {
|
|
51
55
|
this.#compileNode(child, 'root', actionsParameter, String(index));
|
|
@@ -219,6 +223,7 @@ class CompileContext {
|
|
|
219
223
|
const variable = node.id || this.#anonymousName(node.type);
|
|
220
224
|
const locator = compilerSceneNodeLocator(node, path);
|
|
221
225
|
this.#lines.push(` const ${variable} = ${this.#constructPixiNode(node)};`);
|
|
226
|
+
this.#recordSource(variable, locator);
|
|
222
227
|
this.#applyNodeId(variable, node.id);
|
|
223
228
|
this.#applyPixiProps(variable, node.props, false, undefined, node.type);
|
|
224
229
|
this.#applyParentSorting(parent, node.props);
|
|
@@ -234,6 +239,7 @@ class CompileContext {
|
|
|
234
239
|
const constructorName = this.#sceneConstructorName(node);
|
|
235
240
|
const constructorArgs = this.#sceneInstanceConstructorArgs(variable, node);
|
|
236
241
|
this.#lines.push(` const ${variable} = new ${constructorName}(${constructorArgs});`);
|
|
242
|
+
this.#recordSource(variable, locator, true);
|
|
237
243
|
this.#applyPixiProps(variable, node.props, true, node);
|
|
238
244
|
for (const [name, action] of Object.entries(node.events)) {
|
|
239
245
|
this.#runtimeImports.add('connectSceneEvent');
|
|
@@ -260,6 +266,7 @@ class CompileContext {
|
|
|
260
266
|
const constructorName = this.#sceneConstructorName(node);
|
|
261
267
|
const constructorArgs = this.#sceneInstanceConstructorArgs(variable, node);
|
|
262
268
|
this.#lines.push(` const ${variable} = new ${constructorName}(${constructorArgs});`);
|
|
269
|
+
this.#recordSource(variable, locator, true);
|
|
263
270
|
this.#applyPixiProps(variable, node.props, true, node);
|
|
264
271
|
for (const [name, action] of Object.entries(node.events)) {
|
|
265
272
|
this.#runtimeImports.add('connectSceneEvent');
|
|
@@ -278,6 +285,7 @@ class CompileContext {
|
|
|
278
285
|
const variable = node.id || this.#anonymousName(node.type);
|
|
279
286
|
const locator = compilerSceneNodeLocator(node, path);
|
|
280
287
|
this.#lines.push(` const ${variable} = ${this.#constructPixiNode(node)};`);
|
|
288
|
+
this.#recordSource(variable, locator);
|
|
281
289
|
this.#applyNodeId(variable, node.id);
|
|
282
290
|
this.#applyPixiProps(variable, node.props, false, undefined, node.type);
|
|
283
291
|
this.#lines.push(` __pixifactNodes[${JSON.stringify(locator)}] = ${variable};`);
|
|
@@ -596,6 +604,12 @@ class CompileContext {
|
|
|
596
604
|
this.#lines.push(` ${variable}.label = ${JSON.stringify(id)};`);
|
|
597
605
|
}
|
|
598
606
|
}
|
|
607
|
+
#recordSource(variable, locator, instance = false) {
|
|
608
|
+
if (!this.options.registrationPath)
|
|
609
|
+
return;
|
|
610
|
+
const symbol = instance ? "Symbol.for('pixifact.scene.instanceSource')" : '__pixifactSceneSource';
|
|
611
|
+
this.#lines.push(` Reflect.set(${variable}, ${symbol}, { scenePath: ${JSON.stringify(this.options.registrationPath)}, locator: ${JSON.stringify(locator)} });`);
|
|
612
|
+
}
|
|
599
613
|
#applyParentSorting(parent, props) {
|
|
600
614
|
if (props.zIndex !== undefined) {
|
|
601
615
|
this.#lines.push(` ${parent}.sortableChildren = true;`);
|
package/dist/project/index.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { type PixifactViewportConfig } from '../viewport.js';
|
|
2
2
|
export declare const pixifactProjectConfigFileName = "pixifact.project.json";
|
|
3
|
-
export interface PixifactProjectRunConfig {
|
|
4
|
-
command: string;
|
|
5
|
-
args: string[];
|
|
6
|
-
cwd: string;
|
|
7
|
-
url?: string;
|
|
8
|
-
}
|
|
9
3
|
export interface PixifactProjectResolution {
|
|
10
4
|
width: number;
|
|
11
5
|
height: number;
|
|
@@ -18,7 +12,6 @@ export interface PixifactProjectConfig {
|
|
|
18
12
|
scenes: Record<string, string>;
|
|
19
13
|
resourcePacks?: string[];
|
|
20
14
|
remoteResourcePacks?: Record<string, string>;
|
|
21
|
-
run?: PixifactProjectRunConfig;
|
|
22
15
|
}
|
|
23
16
|
export type PixifactProjectViewport = PixifactViewportConfig;
|
|
24
17
|
export interface PixifactProjectSummary {
|
|
@@ -28,7 +21,6 @@ export interface PixifactProjectSummary {
|
|
|
28
21
|
scenes: Record<string, string>;
|
|
29
22
|
resourcePacks?: string[];
|
|
30
23
|
remoteResourcePacks?: Record<string, string>;
|
|
31
|
-
run?: PixifactProjectRunConfig;
|
|
32
24
|
}
|
|
33
25
|
export declare const defaultPixifactProjectResolution: PixifactProjectResolution;
|
|
34
26
|
export declare const defaultPixifactProjectViewport: PixifactProjectViewport;
|
package/dist/project/index.js
CHANGED
|
@@ -42,13 +42,6 @@ function normalizeProjectPath(value, name) {
|
|
|
42
42
|
}
|
|
43
43
|
return input;
|
|
44
44
|
}
|
|
45
|
-
function normalizeRunCwd(value) {
|
|
46
|
-
const input = assertString(value, 'run.cwd').replaceAll('\\', '/');
|
|
47
|
-
if (input === '.') {
|
|
48
|
-
return input;
|
|
49
|
-
}
|
|
50
|
-
return normalizeProjectPath(input, 'run.cwd');
|
|
51
|
-
}
|
|
52
45
|
function parseScenes(value) {
|
|
53
46
|
const scenes = assertRecord(value, 'scenes');
|
|
54
47
|
return Object.fromEntries(Object.entries(scenes).map(([key, scenePath]) => [
|
|
@@ -82,21 +75,6 @@ function parseViewport(value) {
|
|
|
82
75
|
function isPixifactViewportMode(value) {
|
|
83
76
|
return pixifactViewportModes.includes(value);
|
|
84
77
|
}
|
|
85
|
-
function parseRun(value) {
|
|
86
|
-
if (value === undefined) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
const run = assertRecord(value, 'run');
|
|
90
|
-
if (!Array.isArray(run.args) || !run.args.every((arg) => typeof arg === 'string')) {
|
|
91
|
-
throw new Error('run.args must be an array of strings.');
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
command: assertString(run.command, 'run.command'),
|
|
95
|
-
args: run.args,
|
|
96
|
-
cwd: normalizeRunCwd(run.cwd),
|
|
97
|
-
...(run.url === undefined ? {} : { url: assertString(run.url, 'run.url') }),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
78
|
function parseResourcePacks(value) {
|
|
101
79
|
if (value === undefined) {
|
|
102
80
|
return undefined;
|
|
@@ -161,7 +139,6 @@ export function parsePixifactProjectConfig(value) {
|
|
|
161
139
|
scenes: parseScenes(config.scenes),
|
|
162
140
|
...(resourcePacks === undefined ? {} : { resourcePacks }),
|
|
163
141
|
...(remoteResourcePacks === undefined ? {} : { remoteResourcePacks }),
|
|
164
|
-
run: parseRun(config.run),
|
|
165
142
|
};
|
|
166
143
|
}
|
|
167
144
|
export function summarizePixifactProjectConfig(config) {
|
|
@@ -172,6 +149,5 @@ export function summarizePixifactProjectConfig(config) {
|
|
|
172
149
|
scenes: config.scenes,
|
|
173
150
|
...(config.resourcePacks === undefined ? {} : { resourcePacks: config.resourcePacks }),
|
|
174
151
|
...(config.remoteResourcePacks === undefined ? {} : { remoteResourcePacks: config.remoteResourcePacks }),
|
|
175
|
-
...(config.run === undefined ? {} : { run: config.run }),
|
|
176
152
|
};
|
|
177
153
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { BitmapText, Graphics,
|
|
1
|
+
import { BitmapText, Graphics, RenderTexture, Sprite, Text, } from 'pixi.js';
|
|
2
2
|
const maxRetainedLogs = 500;
|
|
3
|
+
const sceneSourceKey = Symbol.for('pixifact.scene.source');
|
|
4
|
+
const sceneInstanceSourceKey = Symbol.for('pixifact.scene.instanceSource');
|
|
3
5
|
const runtimeRequestEvent = 'pixifact:runtime:request';
|
|
4
6
|
const runtimeResponseEvent = 'pixifact:runtime:response';
|
|
5
7
|
const runtimeAnnounceEvent = 'pixifact:runtime:announce';
|
|
@@ -14,6 +16,14 @@ function boundsSnapshot(bounds) {
|
|
|
14
16
|
height: bounds.height,
|
|
15
17
|
};
|
|
16
18
|
}
|
|
19
|
+
function sourceSnapshot(node) {
|
|
20
|
+
const source = Reflect.get(node, sceneSourceKey);
|
|
21
|
+
const instanceSource = Reflect.get(node, sceneInstanceSourceKey);
|
|
22
|
+
return {
|
|
23
|
+
...(source ? { source } : {}),
|
|
24
|
+
...(instanceSource ? { instanceSource } : {}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
17
27
|
function basicNodeSnapshot(node, childIndex) {
|
|
18
28
|
return {
|
|
19
29
|
uid: node.uid,
|
|
@@ -28,6 +38,7 @@ function basicNodeSnapshot(node, childIndex) {
|
|
|
28
38
|
renderable: node.renderable,
|
|
29
39
|
zIndex: node.zIndex,
|
|
30
40
|
eventMode: node.eventMode ?? null,
|
|
41
|
+
...sourceSnapshot(node),
|
|
31
42
|
children: node.children.map((child, index) => basicNodeSnapshot(child, index)),
|
|
32
43
|
};
|
|
33
44
|
}
|
|
@@ -109,6 +120,7 @@ function detailedNodeSnapshot(node) {
|
|
|
109
120
|
blendMode: String(node.blendMode),
|
|
110
121
|
eventMode: node.eventMode ?? null,
|
|
111
122
|
cursor: node.cursor === undefined ? null : String(node.cursor),
|
|
123
|
+
...sourceSnapshot(node),
|
|
112
124
|
...(specific ? { specific } : {}),
|
|
113
125
|
};
|
|
114
126
|
}
|
|
@@ -306,19 +318,25 @@ export function createPixifactRuntimeClient(options) {
|
|
|
306
318
|
async function captureScreenshot(currentApp) {
|
|
307
319
|
const width = Math.max(1, Math.floor(currentApp.screen.width));
|
|
308
320
|
const height = Math.max(1, Math.floor(currentApp.screen.height));
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
321
|
+
const target = RenderTexture.create({ width, height, resolution: 1 });
|
|
322
|
+
try {
|
|
323
|
+
currentApp.stage.updateLocalTransform();
|
|
324
|
+
currentApp.renderer.render({
|
|
325
|
+
container: currentApp.stage,
|
|
326
|
+
transform: currentApp.stage.localTransform,
|
|
327
|
+
target,
|
|
328
|
+
clearColor: currentApp.renderer.background.colorRgba,
|
|
329
|
+
});
|
|
330
|
+
return {
|
|
331
|
+
runtimeId: options.runtimeId,
|
|
332
|
+
width,
|
|
333
|
+
height,
|
|
334
|
+
dataUrl: await currentApp.renderer.extract.base64(target),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
target.destroy(true);
|
|
339
|
+
}
|
|
322
340
|
}
|
|
323
341
|
async function handleRequest(request) {
|
|
324
342
|
if (request.type === 'logs') {
|