@holtjs/stage 0.8.0 → 0.9.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/CHANGELOG.md +17 -0
- package/dist/display-C_NPwPrE.js +1945 -0
- package/dist/{game-D46nY-B2.js → game-C-yXzyAX.js} +25 -15
- package/dist/{game-CEa0m4eX.d.ts → game-DnJYRLZP.d.ts} +5 -1
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +99 -15
- package/dist/lighting.js +602 -98
- package/dist/projection.d.ts +47 -14
- package/dist/projection.js +200 -4
- package/dist/{renderer-webgpu-BXU-ZDIp.js → renderer-webgpu-BZ3J971y.js} +43 -1925
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +1 -1
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/package.json +1 -1
- package/skills/stage/SKILL.md +9 -6
- package/skills/stage/references/subpaths.md +10 -10
|
@@ -0,0 +1,1945 @@
|
|
|
1
|
+
import { _ as rgbToCss, a as EventEmitter, m as createMatrix2D, p as WHITE_RGB, r as BlendModes, s as HEX_MASK, u as TintModes } from "./types-CXsCvp1p.js";
|
|
2
|
+
// src/display.ts
|
|
3
|
+
var DisplayList = class {
|
|
4
|
+
list = [];
|
|
5
|
+
depthDirty = false;
|
|
6
|
+
add(obj) {
|
|
7
|
+
if (obj.parentContainer) obj.parentContainer.remove(obj);
|
|
8
|
+
if (this.list.indexOf(obj) < 0) {
|
|
9
|
+
this.list.push(obj);
|
|
10
|
+
this.depthDirty = true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
remove(obj) {
|
|
14
|
+
const i = this.list.indexOf(obj);
|
|
15
|
+
if (i >= 0) this.list.splice(i, 1);
|
|
16
|
+
}
|
|
17
|
+
markDepthDirty() {
|
|
18
|
+
this.depthDirty = true;
|
|
19
|
+
}
|
|
20
|
+
sorted() {
|
|
21
|
+
if (this.depthDirty) {
|
|
22
|
+
this.depthDirty = false;
|
|
23
|
+
this.list.sort((a, b) => a.depth - b.depth);
|
|
24
|
+
}
|
|
25
|
+
return this.list;
|
|
26
|
+
}
|
|
27
|
+
clear() {
|
|
28
|
+
this.list.length = 0;
|
|
29
|
+
this.depthDirty = false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var DisplayObject = class extends EventEmitter {
|
|
33
|
+
scene;
|
|
34
|
+
type;
|
|
35
|
+
active = true;
|
|
36
|
+
visible = true;
|
|
37
|
+
x = 0;
|
|
38
|
+
y = 0;
|
|
39
|
+
scaleX = 1;
|
|
40
|
+
scaleY = 1;
|
|
41
|
+
rotation = 0;
|
|
42
|
+
skewX = 0;
|
|
43
|
+
skewY = 0;
|
|
44
|
+
alpha = 1;
|
|
45
|
+
depth = 0;
|
|
46
|
+
_zIndex = 0;
|
|
47
|
+
trackId = null;
|
|
48
|
+
alt = null;
|
|
49
|
+
role = null;
|
|
50
|
+
surface = null;
|
|
51
|
+
originX = .5;
|
|
52
|
+
originY = .5;
|
|
53
|
+
width = 0;
|
|
54
|
+
height = 0;
|
|
55
|
+
flipX = false;
|
|
56
|
+
flipY = false;
|
|
57
|
+
blendMode = BlendModes.NORMAL;
|
|
58
|
+
scrollFactorX = 1;
|
|
59
|
+
scrollFactorY = 1;
|
|
60
|
+
parentContainer = null;
|
|
61
|
+
customOrigin = false;
|
|
62
|
+
_displayOriginX = 0;
|
|
63
|
+
_displayOriginY = 0;
|
|
64
|
+
disposers = null;
|
|
65
|
+
constructor(scene, type) {
|
|
66
|
+
super();
|
|
67
|
+
this.scene = scene;
|
|
68
|
+
this.type = type;
|
|
69
|
+
scene._trackNodeCreated?.();
|
|
70
|
+
}
|
|
71
|
+
/** Number of pending LIFO teardown callbacks registered on this node via `onDispose()`. */
|
|
72
|
+
get disposerCount() {
|
|
73
|
+
return this.disposers ? this.disposers.length : 0;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Register a cleanup callback (signal unsubscribe, timer/listener removal, texture ref release) that automatically
|
|
77
|
+
* runs in strict LIFO order with error isolation when this node or any ancestor `Container` is destroyed.
|
|
78
|
+
*/
|
|
79
|
+
onDispose(fn) {
|
|
80
|
+
if (!this.active) {
|
|
81
|
+
try {
|
|
82
|
+
fn();
|
|
83
|
+
} catch (err) {
|
|
84
|
+
this.scene._trackDisposerError?.(err);
|
|
85
|
+
}
|
|
86
|
+
return () => {};
|
|
87
|
+
}
|
|
88
|
+
(this.disposers ?? (this.disposers = [])).push(fn);
|
|
89
|
+
let cancelled = false;
|
|
90
|
+
return () => {
|
|
91
|
+
if (cancelled || !this.disposers) return;
|
|
92
|
+
cancelled = true;
|
|
93
|
+
const idx = this.disposers.lastIndexOf(fn);
|
|
94
|
+
if (idx >= 0) this.disposers.splice(idx, 1);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
get displayOriginX() {
|
|
98
|
+
return this.customOrigin ? this._displayOriginX : this.width * this.originX;
|
|
99
|
+
}
|
|
100
|
+
get displayOriginY() {
|
|
101
|
+
return this.customOrigin ? this._displayOriginY : this.height * this.originY;
|
|
102
|
+
}
|
|
103
|
+
get displayWidth() {
|
|
104
|
+
return Math.abs(this.width * this.scaleX);
|
|
105
|
+
}
|
|
106
|
+
get displayHeight() {
|
|
107
|
+
return Math.abs(this.height * this.scaleY);
|
|
108
|
+
}
|
|
109
|
+
setPosition(x, y = x) {
|
|
110
|
+
this.x = x;
|
|
111
|
+
this.y = y;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
setScale(sx, sy = sx) {
|
|
115
|
+
this.scaleX = sx;
|
|
116
|
+
this.scaleY = sy;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
setRotation(rad) {
|
|
120
|
+
this.rotation = rad;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
setAngle(deg) {
|
|
124
|
+
this.rotation = deg * Math.PI / 180;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/** Set 2D angular shear in radians (`skewX` tilts the Y axis, `skewY` tilts the X axis; completes full 6-DOF affine `Matrix2D`). */
|
|
128
|
+
setSkew(sx, sy = 0) {
|
|
129
|
+
this.skewX = sx;
|
|
130
|
+
this.skewY = sy;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
setAlpha(a) {
|
|
134
|
+
this.alpha = a;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
setDepth(d) {
|
|
138
|
+
if (this.depth !== d) {
|
|
139
|
+
this.depth = d;
|
|
140
|
+
if (!this.parentContainer) this.scene._displayList.markDepthDirty();
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
get zIndex() {
|
|
145
|
+
return this._zIndex;
|
|
146
|
+
}
|
|
147
|
+
set zIndex(z) {
|
|
148
|
+
if (this._zIndex !== z) {
|
|
149
|
+
this._zIndex = z;
|
|
150
|
+
if (this.parentContainer) this.parentContainer._markZDirty(z !== 0);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Native container-local stacking order (0 by default; sorted stably when any sibling has non-zero zIndex). */
|
|
154
|
+
setZIndex(z) {
|
|
155
|
+
if (this._zIndex !== z) {
|
|
156
|
+
this._zIndex = z;
|
|
157
|
+
if (this.parentContainer) this.parentContainer._markZDirty(z !== 0);
|
|
158
|
+
else this.setDepth(z);
|
|
159
|
+
}
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
/** Attach a stable, privacy-safe telemetry/automation identifier (never user text or PII). */
|
|
163
|
+
setTrackId(id) {
|
|
164
|
+
this.trackId = id;
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
/** Attach a concise semantic description for accessibility mirrors and scene snapshots. */
|
|
168
|
+
setAlt(alt) {
|
|
169
|
+
this.alt = alt;
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
/** Attach a semantic role token (e.g. `button`, `toggle`, `panel`, `tab`, `canvas-entity`). */
|
|
173
|
+
setRole(role) {
|
|
174
|
+
this.role = role;
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
/** Attach an owning surface/panel identifier (e.g. `hud`, `settings`, `poker`). */
|
|
178
|
+
setSurface(surface) {
|
|
179
|
+
this.surface = surface;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
/** Batch-assign semantic metadata (`trackId`, `alt`, `role`, `surface`) on this scene-graph node. */
|
|
183
|
+
setSemantics(s) {
|
|
184
|
+
if (s.trackId !== void 0) this.trackId = s.trackId;
|
|
185
|
+
if (s.alt !== void 0) this.alt = s.alt;
|
|
186
|
+
if (s.role !== void 0) this.role = s.role;
|
|
187
|
+
if (s.surface !== void 0) this.surface = s.surface;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
setVisible(v) {
|
|
191
|
+
this.visible = Boolean(v);
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
setOrigin(ox = .5, oy = ox) {
|
|
195
|
+
this.originX = ox;
|
|
196
|
+
this.originY = oy;
|
|
197
|
+
this.customOrigin = false;
|
|
198
|
+
this._displayOriginX = this.width * ox;
|
|
199
|
+
this._displayOriginY = this.height * oy;
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
setDisplayOrigin(dx, dy = dx) {
|
|
203
|
+
this.customOrigin = true;
|
|
204
|
+
this._displayOriginX = dx;
|
|
205
|
+
this._displayOriginY = dy;
|
|
206
|
+
this.originX = this.width ? dx / this.width : 0;
|
|
207
|
+
this.originY = this.height ? dy / this.height : 0;
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
setDisplaySize(w, h) {
|
|
211
|
+
this.scaleX = this.width ? w / this.width : 1;
|
|
212
|
+
this.scaleY = this.height ? h / this.height : 1;
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
setSize(w, h) {
|
|
216
|
+
this.width = w;
|
|
217
|
+
this.height = h;
|
|
218
|
+
if (!this.customOrigin) {
|
|
219
|
+
this._displayOriginX = w * this.originX;
|
|
220
|
+
this._displayOriginY = h * this.originY;
|
|
221
|
+
}
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
setFlipX(b) {
|
|
225
|
+
this.flipX = !!b;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
setFlipY(b) {
|
|
229
|
+
this.flipY = !!b;
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
setBlendMode(mode) {
|
|
233
|
+
this.blendMode = mode;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
setScrollFactor(x, y = x) {
|
|
237
|
+
this.scrollFactorX = x;
|
|
238
|
+
this.scrollFactorY = y;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
removeFromDisplayList() {
|
|
242
|
+
if (this.parentContainer) this.parentContainer.remove(this);
|
|
243
|
+
else this.scene._displayList.remove(this);
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
/** Compute world-space affine transform matrix (matching Phaser's `getWorldTransformMatrix`). */
|
|
247
|
+
getWorldTransformMatrix(out = createMatrix2D(), _temp) {
|
|
248
|
+
const chain = [];
|
|
249
|
+
for (let cur = this; cur; cur = cur.parentContainer) chain.push(cur);
|
|
250
|
+
let a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0;
|
|
251
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
252
|
+
const n = chain[i];
|
|
253
|
+
const sx = n.scaleX, sy = n.scaleY, r = n.rotation, skx = n.skewX, sky = n.skewY;
|
|
254
|
+
let la, lb, lc, ld;
|
|
255
|
+
if (skx === 0 && sky === 0) {
|
|
256
|
+
if (r === 0) {
|
|
257
|
+
la = sx;
|
|
258
|
+
lb = 0;
|
|
259
|
+
lc = 0;
|
|
260
|
+
ld = sy;
|
|
261
|
+
} else {
|
|
262
|
+
const cs = Math.cos(r), sn = Math.sin(r);
|
|
263
|
+
la = cs * sx;
|
|
264
|
+
lb = sn * sx;
|
|
265
|
+
lc = -sn * sy;
|
|
266
|
+
ld = cs * sy;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
la = Math.cos(r + sky) * sx;
|
|
270
|
+
lb = Math.sin(r + sky) * sx;
|
|
271
|
+
lc = -Math.sin(r - skx) * sy;
|
|
272
|
+
ld = Math.cos(r - skx) * sy;
|
|
273
|
+
}
|
|
274
|
+
const na = a * la + c * lb;
|
|
275
|
+
const nb = b * la + d * lb;
|
|
276
|
+
const nc = a * lc + c * ld;
|
|
277
|
+
const nd = b * lc + d * ld;
|
|
278
|
+
const ntx = a * n.x + c * n.y + tx;
|
|
279
|
+
const nty = b * n.x + d * n.y + ty;
|
|
280
|
+
a = na;
|
|
281
|
+
b = nb;
|
|
282
|
+
c = nc;
|
|
283
|
+
d = nd;
|
|
284
|
+
tx = ntx;
|
|
285
|
+
ty = nty;
|
|
286
|
+
}
|
|
287
|
+
out.a = a;
|
|
288
|
+
out.b = b;
|
|
289
|
+
out.c = c;
|
|
290
|
+
out.d = d;
|
|
291
|
+
out.tx = tx;
|
|
292
|
+
out.ty = ty;
|
|
293
|
+
out.scaleX = Math.hypot(a, b);
|
|
294
|
+
out.scaleY = Math.hypot(c, d);
|
|
295
|
+
return out;
|
|
296
|
+
}
|
|
297
|
+
/** World-space axis-aligned bounding box. */
|
|
298
|
+
getBounds() {
|
|
299
|
+
const m = this.getWorldTransformMatrix();
|
|
300
|
+
const ox = this.displayOriginX, oy = this.displayOriginY;
|
|
301
|
+
const x0 = -ox, y0 = -oy, x1 = this.width - ox, y1 = this.height - oy;
|
|
302
|
+
const px0 = m.a * x0 + m.c * y0 + m.tx, py0 = m.b * x0 + m.d * y0 + m.ty;
|
|
303
|
+
const px1 = m.a * x1 + m.c * y0 + m.tx, py1 = m.b * x1 + m.d * y0 + m.ty;
|
|
304
|
+
const px2 = m.a * x1 + m.c * y1 + m.tx, py2 = m.b * x1 + m.d * y1 + m.ty;
|
|
305
|
+
const px3 = m.a * x0 + m.c * y1 + m.tx, py3 = m.b * x0 + m.d * y1 + m.ty;
|
|
306
|
+
const left = Math.min(px0, px1, px2, px3);
|
|
307
|
+
const right = Math.max(px0, px1, px2, px3);
|
|
308
|
+
const top = Math.min(py0, py1, py2, py3);
|
|
309
|
+
const bottom = Math.max(py0, py1, py2, py3);
|
|
310
|
+
return {
|
|
311
|
+
x: left,
|
|
312
|
+
y: top,
|
|
313
|
+
width: right - left,
|
|
314
|
+
height: bottom - top,
|
|
315
|
+
left,
|
|
316
|
+
right,
|
|
317
|
+
top,
|
|
318
|
+
bottom
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
destroy(_fromScene) {
|
|
322
|
+
if (!this.active) return;
|
|
323
|
+
this.active = false;
|
|
324
|
+
this.visible = false;
|
|
325
|
+
const list = this.disposers;
|
|
326
|
+
this.disposers = null;
|
|
327
|
+
if (list && list.length > 0) {
|
|
328
|
+
for (let i = list.length - 1; i >= 0; i--) try {
|
|
329
|
+
list[i]();
|
|
330
|
+
this.scene._trackDisposerRan?.();
|
|
331
|
+
} catch (err) {
|
|
332
|
+
this.scene._trackDisposerError?.(err);
|
|
333
|
+
}
|
|
334
|
+
list.length = 0;
|
|
335
|
+
}
|
|
336
|
+
this.scene._trackNodeDestroyed?.();
|
|
337
|
+
this.emit("destroy", this);
|
|
338
|
+
this.removeAllListeners();
|
|
339
|
+
this.removeFromDisplayList();
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var ImageObject = class extends DisplayObject {
|
|
343
|
+
texture;
|
|
344
|
+
frame;
|
|
345
|
+
tint = WHITE_RGB;
|
|
346
|
+
isTinted = false;
|
|
347
|
+
tintMode = TintModes.MULTIPLY;
|
|
348
|
+
/** Enable GPU Sharp-Bilinear Pixel-Art AA (crisp square pixels at integer scales, uniform strokes at non-integer scales). */
|
|
349
|
+
pixelAA = false;
|
|
350
|
+
isCropped = false;
|
|
351
|
+
cropX = 0;
|
|
352
|
+
cropY = 0;
|
|
353
|
+
cropW = 0;
|
|
354
|
+
cropH = 0;
|
|
355
|
+
customRenderNodes = {};
|
|
356
|
+
constructor(scene, x, y, key, frame, nodeType = "Image") {
|
|
357
|
+
super(scene, nodeType);
|
|
358
|
+
this.x = x;
|
|
359
|
+
this.y = y;
|
|
360
|
+
this.texture = scene.textures.get(key);
|
|
361
|
+
this.frame = this.texture.get(frame);
|
|
362
|
+
this.width = this.frame.width;
|
|
363
|
+
this.height = this.frame.height;
|
|
364
|
+
this._syncFrameOrigin();
|
|
365
|
+
}
|
|
366
|
+
get displayOriginX() {
|
|
367
|
+
if (!this.customOrigin && this.frame?.customPivot) return this.frame.pixelPivotX;
|
|
368
|
+
return super.displayOriginX;
|
|
369
|
+
}
|
|
370
|
+
get displayOriginY() {
|
|
371
|
+
if (!this.customOrigin && this.frame?.customPivot) return this.frame.pixelPivotY;
|
|
372
|
+
return super.displayOriginY;
|
|
373
|
+
}
|
|
374
|
+
_syncFrameOrigin() {
|
|
375
|
+
if (!this.customOrigin) {
|
|
376
|
+
if (this.frame.customPivot) {
|
|
377
|
+
this._displayOriginX = this.frame.pixelPivotX;
|
|
378
|
+
this._displayOriginY = this.frame.pixelPivotY;
|
|
379
|
+
this.originX = this.width > 0 ? this._displayOriginX / this.width : .5;
|
|
380
|
+
this.originY = this.height > 0 ? this._displayOriginY / this.height : .5;
|
|
381
|
+
} else {
|
|
382
|
+
this._displayOriginX = this.width * this.originX;
|
|
383
|
+
this._displayOriginY = this.height * this.originY;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/** Clear any manual `setOrigin()` override so per-frame baked pivots (`ax/ay` or `pivotX/pivotY`) drive alignment automatically. */
|
|
388
|
+
useFramePivot() {
|
|
389
|
+
this.customOrigin = false;
|
|
390
|
+
this._syncFrameOrigin();
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
setTexture(key, frame) {
|
|
394
|
+
this.texture = this.scene.textures.get(key);
|
|
395
|
+
return this.setFrame(frame ?? "__BASE");
|
|
396
|
+
}
|
|
397
|
+
setFrame(frame) {
|
|
398
|
+
this.frame = this.texture.get(frame);
|
|
399
|
+
this.width = this.frame.width;
|
|
400
|
+
this.height = this.frame.height;
|
|
401
|
+
this._syncFrameOrigin();
|
|
402
|
+
return this;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Compute the exact transformed coordinates of a named per-frame pixel socket (e.g. `'hand'`, `'head'`, `'emissive'`)
|
|
406
|
+
* accounting for trimmed `displayOrigin`, `flipX`/`flipY`, `scaleX`/`scaleY`, `rotation`, and ancestor `Container`s.
|
|
407
|
+
*/
|
|
408
|
+
getAnchor(name, space = "parent", out = {
|
|
409
|
+
x: 0,
|
|
410
|
+
y: 0
|
|
411
|
+
}) {
|
|
412
|
+
const raw = this.frame?.getAnchor(name);
|
|
413
|
+
if (!raw) return null;
|
|
414
|
+
const ox = this._displayOriginX;
|
|
415
|
+
const oy = this._displayOriginY;
|
|
416
|
+
const pivotMirrored = this.frame.customPivot && !this.customOrigin && !this.isCropped;
|
|
417
|
+
const lx = this.flipX ? pivotMirrored ? ox - raw[0] : this.width - ox - raw[0] : raw[0] - ox;
|
|
418
|
+
const ly = this.flipY ? pivotMirrored ? oy - raw[1] : this.height - oy - raw[1] : raw[1] - oy;
|
|
419
|
+
if (space === "local") {
|
|
420
|
+
out.x = lx;
|
|
421
|
+
out.y = ly;
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
let px;
|
|
425
|
+
let py;
|
|
426
|
+
if (this.rotation === 0 && this.skewX === 0 && this.skewY === 0) {
|
|
427
|
+
px = this.x + lx * this.scaleX;
|
|
428
|
+
py = this.y + ly * this.scaleY;
|
|
429
|
+
} else if (this.skewX === 0 && this.skewY === 0) {
|
|
430
|
+
const sx = lx * this.scaleX;
|
|
431
|
+
const sy = ly * this.scaleY;
|
|
432
|
+
const c = Math.cos(this.rotation);
|
|
433
|
+
const s = Math.sin(this.rotation);
|
|
434
|
+
px = this.x + sx * c - sy * s;
|
|
435
|
+
py = this.y + sx * s + sy * c;
|
|
436
|
+
} else {
|
|
437
|
+
const la = Math.cos(this.rotation + this.skewY) * this.scaleX;
|
|
438
|
+
const lb = Math.sin(this.rotation + this.skewY) * this.scaleX;
|
|
439
|
+
const lc = -Math.sin(this.rotation - this.skewX) * this.scaleY;
|
|
440
|
+
const ld = Math.cos(this.rotation - this.skewX) * this.scaleY;
|
|
441
|
+
px = this.x + la * lx + lc * ly;
|
|
442
|
+
py = this.y + lb * lx + ld * ly;
|
|
443
|
+
}
|
|
444
|
+
if (space === "parent" || !this.parentContainer) {
|
|
445
|
+
out.x = px;
|
|
446
|
+
out.y = py;
|
|
447
|
+
return out;
|
|
448
|
+
}
|
|
449
|
+
let cur = this.parentContainer;
|
|
450
|
+
while (cur) {
|
|
451
|
+
if (cur.rotation === 0 && cur.skewX === 0 && cur.skewY === 0) {
|
|
452
|
+
px = cur.x + px * cur.scaleX;
|
|
453
|
+
py = cur.y + py * cur.scaleY;
|
|
454
|
+
} else if (cur.skewX === 0 && cur.skewY === 0) {
|
|
455
|
+
const csx = px * cur.scaleX;
|
|
456
|
+
const csy = py * cur.scaleY;
|
|
457
|
+
const cc = Math.cos(cur.rotation);
|
|
458
|
+
const cs = Math.sin(cur.rotation);
|
|
459
|
+
px = cur.x + csx * cc - csy * cs;
|
|
460
|
+
py = cur.y + csx * cs + csy * cc;
|
|
461
|
+
} else {
|
|
462
|
+
const la = Math.cos(cur.rotation + cur.skewY) * cur.scaleX;
|
|
463
|
+
const lb = Math.sin(cur.rotation + cur.skewY) * cur.scaleX;
|
|
464
|
+
const lc = -Math.sin(cur.rotation - cur.skewX) * cur.scaleY;
|
|
465
|
+
const ld = Math.cos(cur.rotation - cur.skewX) * cur.scaleY;
|
|
466
|
+
const nx = cur.x + la * px + lc * py;
|
|
467
|
+
py = cur.y + lb * px + ld * py;
|
|
468
|
+
px = nx;
|
|
469
|
+
}
|
|
470
|
+
cur = cur.parentContainer;
|
|
471
|
+
}
|
|
472
|
+
out.x = px;
|
|
473
|
+
out.y = py;
|
|
474
|
+
return out;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Read the full transformed 2D pose (`x`, `y`, `rotation`, `zBias`, `hasAngle`) of an oriented socket
|
|
478
|
+
* (`[x, y, angleRad, zBias]` from `@holtjs/craft/three` `charKit.handSocket`), transforming the 2D grip
|
|
479
|
+
* tangent vector through the exact `flip -> scale -> rotate/skew -> parentContainer` Jacobian!
|
|
480
|
+
*/
|
|
481
|
+
getAnchorPose(name, space = "parent", out = {
|
|
482
|
+
x: 0,
|
|
483
|
+
y: 0,
|
|
484
|
+
rotation: 0,
|
|
485
|
+
zBias: 1,
|
|
486
|
+
hasAngle: false
|
|
487
|
+
}) {
|
|
488
|
+
const raw = this.frame?.getAnchor(name);
|
|
489
|
+
if (!raw) return null;
|
|
490
|
+
this.getAnchor(name, space, out);
|
|
491
|
+
const hasAngle = raw.length >= 3 && typeof raw[2] === "number" && Number.isFinite(raw[2]);
|
|
492
|
+
const rawAngle = hasAngle ? raw[2] : 0;
|
|
493
|
+
const zBias = raw.length >= 4 && typeof raw[3] === "number" ? raw[3] >= 0 ? 1 : -1 : 1;
|
|
494
|
+
let dx = Math.cos(rawAngle);
|
|
495
|
+
let dy = Math.sin(rawAngle);
|
|
496
|
+
if (this.flipX) dx = -dx;
|
|
497
|
+
if (this.flipY) dy = -dy;
|
|
498
|
+
if (space !== "local") {
|
|
499
|
+
if (this.skewX === 0 && this.skewY === 0) {
|
|
500
|
+
dx *= this.scaleX;
|
|
501
|
+
dy *= this.scaleY;
|
|
502
|
+
if (this.rotation !== 0) {
|
|
503
|
+
const c = Math.cos(this.rotation);
|
|
504
|
+
const s = Math.sin(this.rotation);
|
|
505
|
+
const rx = dx * c - dy * s;
|
|
506
|
+
dy = dx * s + dy * c;
|
|
507
|
+
dx = rx;
|
|
508
|
+
}
|
|
509
|
+
} else {
|
|
510
|
+
const la = Math.cos(this.rotation + this.skewY) * this.scaleX;
|
|
511
|
+
const lb = Math.sin(this.rotation + this.skewY) * this.scaleX;
|
|
512
|
+
const lc = -Math.sin(this.rotation - this.skewX) * this.scaleY;
|
|
513
|
+
const ld = Math.cos(this.rotation - this.skewX) * this.scaleY;
|
|
514
|
+
const rx = la * dx + lc * dy;
|
|
515
|
+
dy = lb * dx + ld * dy;
|
|
516
|
+
dx = rx;
|
|
517
|
+
}
|
|
518
|
+
if (space === "world") {
|
|
519
|
+
let cur = this.parentContainer;
|
|
520
|
+
while (cur) {
|
|
521
|
+
if (cur.skewX === 0 && cur.skewY === 0) {
|
|
522
|
+
dx *= cur.scaleX;
|
|
523
|
+
dy *= cur.scaleY;
|
|
524
|
+
if (cur.rotation !== 0) {
|
|
525
|
+
const cc = Math.cos(cur.rotation);
|
|
526
|
+
const cs = Math.sin(cur.rotation);
|
|
527
|
+
const rx = dx * cc - dy * cs;
|
|
528
|
+
dy = dx * cs + dy * cc;
|
|
529
|
+
dx = rx;
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
const la = Math.cos(cur.rotation + cur.skewY) * cur.scaleX;
|
|
533
|
+
const lb = Math.sin(cur.rotation + cur.skewY) * cur.scaleX;
|
|
534
|
+
const lc = -Math.sin(cur.rotation - cur.skewX) * cur.scaleY;
|
|
535
|
+
const ld = Math.cos(cur.rotation - cur.skewX) * cur.scaleY;
|
|
536
|
+
const rx = la * dx + lc * dy;
|
|
537
|
+
dy = lb * dx + ld * dy;
|
|
538
|
+
dx = rx;
|
|
539
|
+
}
|
|
540
|
+
cur = cur.parentContainer;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
out.rotation = Math.atan2(dy, dx);
|
|
545
|
+
out.zBias = zBias;
|
|
546
|
+
out.hasAngle = hasAngle;
|
|
547
|
+
return out;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Align an equipped weapon/tool `DisplayObject` (`axe`, `spear`, `torch`, `shield`) to a named socket (`'hand'`) in one call:
|
|
551
|
+
* - Sets `child.x` & `child.y` to the transformed socket position
|
|
552
|
+
* - Rotates `child.rotation` so `restAngle` (default `-Math.PI / 2` = upright sprite) aligns with the socket's projected 2D shaft angle
|
|
553
|
+
* - Mirrors asymmetric blades (`mirrorBlade: true`) across the shaft axis via `O(2)` reflection when aiming left (`cos < 0`) so single-bladed axes never strike backwards!
|
|
554
|
+
* - Applies `zBias` (`+1` in front of body, `-1` behind body) via `child.setZIndex(baseZIndex + zBias)`
|
|
555
|
+
*/
|
|
556
|
+
syncAttachment(child, anchorName, opts = {}) {
|
|
557
|
+
const space = opts.space ?? "parent";
|
|
558
|
+
const pose = this.getAnchorPose(anchorName, space);
|
|
559
|
+
if (!pose) return false;
|
|
560
|
+
child.x = pose.x;
|
|
561
|
+
child.y = pose.y;
|
|
562
|
+
if (pose.hasAngle || opts.restAngle !== void 0 || opts.angleOffset !== void 0) {
|
|
563
|
+
const rest = opts.restAngle ?? -Math.PI * .5;
|
|
564
|
+
const mirror = opts.mirrorBlade !== false;
|
|
565
|
+
const aimLeft = Math.cos(pose.rotation) < -1e-4;
|
|
566
|
+
if (mirror) {
|
|
567
|
+
if (Math.abs(Math.sin(rest)) >= Math.abs(Math.cos(rest))) child.flipX = aimLeft;
|
|
568
|
+
else child.flipY = aimLeft;
|
|
569
|
+
}
|
|
570
|
+
const offset = opts.angleOffset ?? 0;
|
|
571
|
+
child.rotation = pose.rotation - rest + (mirror && aimLeft ? -offset : offset);
|
|
572
|
+
}
|
|
573
|
+
if (opts.baseZIndex !== false) {
|
|
574
|
+
const baseZ = opts.baseZIndex ?? this.zIndex;
|
|
575
|
+
child.setZIndex(baseZ + pose.zBias);
|
|
576
|
+
}
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
setTint(color) {
|
|
580
|
+
this.tint = color & HEX_MASK;
|
|
581
|
+
this.isTinted = true;
|
|
582
|
+
return this;
|
|
583
|
+
}
|
|
584
|
+
setTintMode(mode) {
|
|
585
|
+
this.tintMode = mode;
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
clearTint() {
|
|
589
|
+
this.tint = WHITE_RGB;
|
|
590
|
+
this.isTinted = false;
|
|
591
|
+
this.tintMode = TintModes.MULTIPLY;
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
setPixelAA(on = true) {
|
|
595
|
+
this.pixelAA = Boolean(on);
|
|
596
|
+
return this;
|
|
597
|
+
}
|
|
598
|
+
setCrop(x, y, w, h) {
|
|
599
|
+
if (x === void 0 || y === void 0 || w === void 0 || h === void 0) {
|
|
600
|
+
this.isCropped = false;
|
|
601
|
+
this.cropX = this.cropY = this.cropW = this.cropH = 0;
|
|
602
|
+
} else {
|
|
603
|
+
this.isCropped = true;
|
|
604
|
+
this.cropX = x;
|
|
605
|
+
this.cropY = y;
|
|
606
|
+
this.cropW = Math.max(0, w);
|
|
607
|
+
this.cropH = Math.max(0, h);
|
|
608
|
+
}
|
|
609
|
+
return this;
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* First-class animated 2D / 2.5D sprite (`scene.add.sprite(x, y, key, frame)`).
|
|
614
|
+
* - Automatically aligns per-frame trimmed pivots (`ax/ay`) & transforms named sockets (`getAnchor('hand')`)
|
|
615
|
+
* - Deterministic simulation-stepped clip playback (`play`, `playDirectional`, `stop`, `pause`, `resume`)
|
|
616
|
+
* - Phase-preserving 4/8-directional locomotion (`playDirectional`) aligned with `Camera25D` & `@holtjs/craft`
|
|
617
|
+
* - Exact frame-crossing event callbacks (`onAnimEvent` for `footstep`, `hit`, etc.)
|
|
618
|
+
*/
|
|
619
|
+
var SpriteObject = class extends ImageObject {
|
|
620
|
+
_anim = null;
|
|
621
|
+
_frameIdx = 0;
|
|
622
|
+
_frameElapsedMs = 0;
|
|
623
|
+
_forward = true;
|
|
624
|
+
_repeatsLeft = 0;
|
|
625
|
+
_playing = false;
|
|
626
|
+
_paused = false;
|
|
627
|
+
_timeScale = 1;
|
|
628
|
+
_activeDirBase = null;
|
|
629
|
+
_activeDirIndex = -1;
|
|
630
|
+
_animListeners = /* @__PURE__ */ new Set();
|
|
631
|
+
constructor(scene, x, y, key, frame) {
|
|
632
|
+
super(scene, x, y, key, frame, "Sprite");
|
|
633
|
+
}
|
|
634
|
+
get currentAnim() {
|
|
635
|
+
return this._anim;
|
|
636
|
+
}
|
|
637
|
+
get currentAnimKey() {
|
|
638
|
+
return this._anim?.key ?? null;
|
|
639
|
+
}
|
|
640
|
+
get currentFrameIndex() {
|
|
641
|
+
return this._frameIdx;
|
|
642
|
+
}
|
|
643
|
+
get currentDirection() {
|
|
644
|
+
return this._activeDirIndex;
|
|
645
|
+
}
|
|
646
|
+
get isPlaying() {
|
|
647
|
+
return this._playing && !this._paused;
|
|
648
|
+
}
|
|
649
|
+
get timeScale() {
|
|
650
|
+
return this._timeScale;
|
|
651
|
+
}
|
|
652
|
+
setTimeScale(scale) {
|
|
653
|
+
this._timeScale = Number.isFinite(scale) ? Math.max(0, scale) : 1;
|
|
654
|
+
return this;
|
|
655
|
+
}
|
|
656
|
+
onAnimEvent(fn) {
|
|
657
|
+
this._animListeners.add(fn);
|
|
658
|
+
return () => {
|
|
659
|
+
this._animListeners.delete(fn);
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
/** Normalized progress `[0..1)` through the current forward pass of the active animation. */
|
|
663
|
+
get cycleProgress() {
|
|
664
|
+
const anim = this._anim;
|
|
665
|
+
if (!anim || anim.totalDurationMs <= 0 || anim.frames.length === 0) return 0;
|
|
666
|
+
const cf = anim.frames[this._frameIdx];
|
|
667
|
+
if (!cf) return 0;
|
|
668
|
+
return Math.max(0, Math.min(.999999, (cf.offsetMs + this._frameElapsedMs) / anim.totalDurationMs));
|
|
669
|
+
}
|
|
670
|
+
/** Play a registered animation clip by key (or `StageAnimation` object). Fails fast if `key` does not exist! */
|
|
671
|
+
play(keyOrAnim, opts) {
|
|
672
|
+
const options = typeof opts === "boolean" ? { ignoreIfPlaying: opts } : opts ?? {};
|
|
673
|
+
const nextAnim = this.scene.anims.resolveOrThrow(keyOrAnim);
|
|
674
|
+
if (options.timeScale !== void 0) this.setTimeScale(options.timeScale);
|
|
675
|
+
if (options.ignoreIfPlaying && this._playing && this._anim === nextAnim) return this;
|
|
676
|
+
const prevPhase = options.preservePhase && this._anim ? this.cycleProgress : null;
|
|
677
|
+
this._activeDirBase = null;
|
|
678
|
+
this._anim = nextAnim;
|
|
679
|
+
this._playing = true;
|
|
680
|
+
this._paused = false;
|
|
681
|
+
this._forward = true;
|
|
682
|
+
this._repeatsLeft = options.repeat !== void 0 ? options.repeat : nextAnim.repeat;
|
|
683
|
+
if (prevPhase !== null && nextAnim.frames.length > 0) {
|
|
684
|
+
const targetMs = prevPhase * nextAnim.totalDurationMs;
|
|
685
|
+
let idx = 0;
|
|
686
|
+
while (idx + 1 < nextAnim.frames.length && nextAnim.frames[idx + 1].offsetMs <= targetMs) idx++;
|
|
687
|
+
this._frameIdx = idx;
|
|
688
|
+
this._frameElapsedMs = Math.max(0, targetMs - nextAnim.frames[idx].offsetMs);
|
|
689
|
+
this._applyAnimFrame(idx, false);
|
|
690
|
+
} else {
|
|
691
|
+
const startIdx = Math.max(0, Math.min(nextAnim.frames.length - 1, Math.floor(options.startFrame ?? 0)));
|
|
692
|
+
this._frameIdx = startIdx;
|
|
693
|
+
this._frameElapsedMs = 0;
|
|
694
|
+
this._applyAnimFrame(startIdx, true);
|
|
695
|
+
}
|
|
696
|
+
this.scene._registerAnimatedSprite(this);
|
|
697
|
+
return this;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Play a 4- or 8-directional animation group (e.g. `'survivor/walk'` or `'zombie/attack'`) quantized by
|
|
701
|
+
* world movement angle `headingRad = Math.atan2(vy, vx)` and optional `Camera25D.yaw`!
|
|
702
|
+
*
|
|
703
|
+
* Automatically preserves stride phase when turning between directions of the same clip (`walk/d0 -> walk/d1`)
|
|
704
|
+
* so characters never freeze on frame 0 or stutter mid-step!
|
|
705
|
+
*/
|
|
706
|
+
playDirectional(baseKey, headingRad, opts = {}) {
|
|
707
|
+
const grp = this.scene.anims.resolveDirectionalOrThrow(baseKey);
|
|
708
|
+
const dirs = Math.max(1, grp.directions);
|
|
709
|
+
const step = Math.PI * 2 / dirs;
|
|
710
|
+
const camYaw = opts.cameraYaw ?? 0;
|
|
711
|
+
const atlasYaw = opts.atlasYaw ?? grp.atlasYaw;
|
|
712
|
+
const effective = (Number.isFinite(headingRad) ? headingRad : 0) - camYaw + atlasYaw;
|
|
713
|
+
const dirIdx = (Math.round(effective / step) % dirs + dirs) % dirs;
|
|
714
|
+
const targetAnim = grp.dirClips[dirIdx] ?? grp.dirClips[0];
|
|
715
|
+
const sameBase = this._playing && this._activeDirBase === grp.baseKey;
|
|
716
|
+
this._activeDirIndex = dirIdx;
|
|
717
|
+
if (sameBase && this._anim === targetAnim) {
|
|
718
|
+
if (opts.timeScale !== void 0) this.setTimeScale(opts.timeScale);
|
|
719
|
+
this._activeDirBase = grp.baseKey;
|
|
720
|
+
return this;
|
|
721
|
+
}
|
|
722
|
+
this.play(targetAnim, {
|
|
723
|
+
ignoreIfPlaying: false,
|
|
724
|
+
preservePhase: sameBase ? opts.preservePhase !== false : Boolean(opts.preservePhase),
|
|
725
|
+
timeScale: opts.timeScale,
|
|
726
|
+
repeat: opts.repeat
|
|
727
|
+
});
|
|
728
|
+
this._activeDirBase = grp.baseKey;
|
|
729
|
+
return this;
|
|
730
|
+
}
|
|
731
|
+
pause() {
|
|
732
|
+
this._paused = true;
|
|
733
|
+
return this;
|
|
734
|
+
}
|
|
735
|
+
resume() {
|
|
736
|
+
this._paused = false;
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
stop() {
|
|
740
|
+
this._playing = false;
|
|
741
|
+
this._paused = false;
|
|
742
|
+
this._activeDirBase = null;
|
|
743
|
+
this.scene._unregisterAnimatedSprite(this);
|
|
744
|
+
return this;
|
|
745
|
+
}
|
|
746
|
+
/** Internal deterministic simulation step invoked by `Scene._stepAnimations(dt)`. */
|
|
747
|
+
_stepAnim(deltaMs) {
|
|
748
|
+
if (!this._playing || this._paused || !this._anim) return;
|
|
749
|
+
const scaled = deltaMs * this._timeScale;
|
|
750
|
+
if (scaled <= 0) return;
|
|
751
|
+
const anim = this._anim;
|
|
752
|
+
const frames = anim.frames;
|
|
753
|
+
const n = frames.length;
|
|
754
|
+
if (n === 0) return;
|
|
755
|
+
this._frameElapsedMs += scaled;
|
|
756
|
+
let safety = 0;
|
|
757
|
+
while (this._playing && this._anim === anim && safety++ < 64) {
|
|
758
|
+
const cur = frames[this._frameIdx];
|
|
759
|
+
const dur = Math.max(.001, cur.durationMs);
|
|
760
|
+
if (this._frameElapsedMs < dur) break;
|
|
761
|
+
this._frameElapsedMs -= dur;
|
|
762
|
+
if (n === 1) {
|
|
763
|
+
if (this._repeatsLeft === 0) {
|
|
764
|
+
this._finishAnim(anim);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (this._repeatsLeft > 0) this._repeatsLeft--;
|
|
768
|
+
this._applyAnimFrame(0, true);
|
|
769
|
+
this.emit("animrepeat", anim.key, this);
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
if (this._forward) {
|
|
773
|
+
if (this._frameIdx + 1 < n) {
|
|
774
|
+
this._frameIdx++;
|
|
775
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
776
|
+
} else if (anim.yoyo) {
|
|
777
|
+
this._forward = false;
|
|
778
|
+
this._frameIdx = n - 2;
|
|
779
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
780
|
+
} else if (this._repeatsLeft === 0) {
|
|
781
|
+
this._finishAnim(anim);
|
|
782
|
+
return;
|
|
783
|
+
} else {
|
|
784
|
+
if (this._repeatsLeft > 0) this._repeatsLeft--;
|
|
785
|
+
this._frameIdx = 0;
|
|
786
|
+
this._applyAnimFrame(0, true);
|
|
787
|
+
this.emit("animrepeat", anim.key, this);
|
|
788
|
+
}
|
|
789
|
+
} else if (this._frameIdx - 1 >= 0) {
|
|
790
|
+
this._frameIdx--;
|
|
791
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
792
|
+
} else if (this._repeatsLeft === 0) {
|
|
793
|
+
this._finishAnim(anim);
|
|
794
|
+
return;
|
|
795
|
+
} else {
|
|
796
|
+
if (this._repeatsLeft > 0) this._repeatsLeft--;
|
|
797
|
+
this._forward = true;
|
|
798
|
+
this._frameIdx = Math.min(1, n - 1);
|
|
799
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
800
|
+
this.emit("animrepeat", anim.key, this);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
_applyAnimFrame(index, fireEvents) {
|
|
805
|
+
const anim = this._anim;
|
|
806
|
+
if (!anim) return;
|
|
807
|
+
const cf = anim.frames[index];
|
|
808
|
+
if (!cf) return;
|
|
809
|
+
if (this.texture.key !== cf.textureKey) this.setTexture(cf.textureKey, cf.frameName);
|
|
810
|
+
else this.setFrame(cf.frameName);
|
|
811
|
+
if (fireEvents && cf.events.length > 0) for (let i = 0; i < cf.events.length; i++) {
|
|
812
|
+
const ev = cf.events[i];
|
|
813
|
+
for (const fn of this._animListeners) fn(ev, anim.key, index, cf.frameName);
|
|
814
|
+
this.emit("animevent", ev, anim.key, index, cf.frameName);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
_finishAnim(anim) {
|
|
818
|
+
this._frameElapsedMs = 0;
|
|
819
|
+
this._playing = false;
|
|
820
|
+
this._activeDirBase = null;
|
|
821
|
+
this.scene._unregisterAnimatedSprite(this);
|
|
822
|
+
this.emit("animcomplete", anim.key, this);
|
|
823
|
+
}
|
|
824
|
+
destroy(fromScene) {
|
|
825
|
+
this.scene._unregisterAnimatedSprite(this);
|
|
826
|
+
this._animListeners.clear();
|
|
827
|
+
this._anim = null;
|
|
828
|
+
this._playing = false;
|
|
829
|
+
super.destroy(fromScene);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
var NineSliceObject = class extends DisplayObject {
|
|
833
|
+
texture;
|
|
834
|
+
frame;
|
|
835
|
+
leftWidth;
|
|
836
|
+
rightWidth;
|
|
837
|
+
topHeight;
|
|
838
|
+
bottomHeight;
|
|
839
|
+
constructor(scene, x, y, key, frame, width, height, left, right, top, bottom) {
|
|
840
|
+
super(scene, "NineSlice");
|
|
841
|
+
this.x = x;
|
|
842
|
+
this.y = y;
|
|
843
|
+
this.texture = scene.textures.get(key);
|
|
844
|
+
this.frame = this.texture.get(frame);
|
|
845
|
+
this.width = width;
|
|
846
|
+
this.height = height;
|
|
847
|
+
this.leftWidth = left;
|
|
848
|
+
this.rightWidth = right;
|
|
849
|
+
this.topHeight = top;
|
|
850
|
+
this.bottomHeight = bottom;
|
|
851
|
+
}
|
|
852
|
+
setTexture(key, frame) {
|
|
853
|
+
this.texture = this.scene.textures.get(key);
|
|
854
|
+
this.frame = this.texture.get(frame);
|
|
855
|
+
return this;
|
|
856
|
+
}
|
|
857
|
+
setFrame(frame) {
|
|
858
|
+
this.frame = this.texture.get(frame);
|
|
859
|
+
return this;
|
|
860
|
+
}
|
|
861
|
+
setSlices(width, height, left, right, top, bottom) {
|
|
862
|
+
this.width = Math.max(0, width);
|
|
863
|
+
this.height = Math.max(0, height);
|
|
864
|
+
this.leftWidth = Math.max(0, left);
|
|
865
|
+
this.rightWidth = Math.max(0, right);
|
|
866
|
+
this.topHeight = Math.max(0, top);
|
|
867
|
+
this.bottomHeight = Math.max(0, bottom);
|
|
868
|
+
return this;
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
var TileSpriteObject = class extends DisplayObject {
|
|
872
|
+
texture;
|
|
873
|
+
frame;
|
|
874
|
+
tilePositionX = 0;
|
|
875
|
+
tilePositionY = 0;
|
|
876
|
+
tint = WHITE_RGB;
|
|
877
|
+
isTinted = false;
|
|
878
|
+
constructor(scene, x, y, width, height, key, frame) {
|
|
879
|
+
super(scene, "TileSprite");
|
|
880
|
+
this.x = x;
|
|
881
|
+
this.y = y;
|
|
882
|
+
this.width = Math.max(0, width);
|
|
883
|
+
this.height = Math.max(0, height);
|
|
884
|
+
this.texture = scene.textures.get(key);
|
|
885
|
+
this.frame = this.texture.get(frame);
|
|
886
|
+
this.texture.source[0].repeat = true;
|
|
887
|
+
}
|
|
888
|
+
setTint(color) {
|
|
889
|
+
this.tint = color & HEX_MASK;
|
|
890
|
+
this.isTinted = true;
|
|
891
|
+
return this;
|
|
892
|
+
}
|
|
893
|
+
clearTint() {
|
|
894
|
+
this.tint = WHITE_RGB;
|
|
895
|
+
this.isTinted = false;
|
|
896
|
+
return this;
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
var RectangleObject = class extends DisplayObject {
|
|
900
|
+
fillColor;
|
|
901
|
+
fillAlpha;
|
|
902
|
+
constructor(scene, x, y, width, height, fillColor = 0, fillAlpha = 1) {
|
|
903
|
+
super(scene, "Rectangle");
|
|
904
|
+
this.x = x;
|
|
905
|
+
this.y = y;
|
|
906
|
+
this.width = width;
|
|
907
|
+
this.height = height;
|
|
908
|
+
this.fillColor = fillColor & HEX_MASK;
|
|
909
|
+
this.fillAlpha = fillAlpha;
|
|
910
|
+
}
|
|
911
|
+
setFillStyle(color, alpha = 1) {
|
|
912
|
+
this.fillColor = color & HEX_MASK;
|
|
913
|
+
this.fillAlpha = alpha;
|
|
914
|
+
return this;
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
/**
|
|
918
|
+
* GPU Signed-Distance-Field (SDF) rounded-rect / border / pill / stepped-pixel panel primitive.
|
|
919
|
+
* Batched by `SdfPanelBatcher` on WebGL with zero texture uploads, and mirrored analytically on Canvas2D.
|
|
920
|
+
*/
|
|
921
|
+
var PanelObject = class extends DisplayObject {
|
|
922
|
+
fillColor;
|
|
923
|
+
fillAlpha;
|
|
924
|
+
borderColor;
|
|
925
|
+
borderAlpha;
|
|
926
|
+
borderWidth;
|
|
927
|
+
radiusTL;
|
|
928
|
+
radiusTR;
|
|
929
|
+
radiusBR;
|
|
930
|
+
radiusBL;
|
|
931
|
+
pixelStep;
|
|
932
|
+
/** Encoded open seam side: `0` = closed, `1` = open left, `-1` = open right. */
|
|
933
|
+
openSide = 0;
|
|
934
|
+
topGlintColor;
|
|
935
|
+
topGlintAlpha;
|
|
936
|
+
topGlintHeight;
|
|
937
|
+
constructor(scene, x, y, width, height, style = {}) {
|
|
938
|
+
super(scene, "Panel");
|
|
939
|
+
this.originX = 0;
|
|
940
|
+
this.originY = 0;
|
|
941
|
+
this.x = x;
|
|
942
|
+
this.y = y;
|
|
943
|
+
this.width = Math.max(0, width);
|
|
944
|
+
this.height = Math.max(0, height);
|
|
945
|
+
this.fillColor = (style.fillColor ?? 0xffffff) & HEX_MASK;
|
|
946
|
+
this.fillAlpha = style.fillAlpha ?? 1;
|
|
947
|
+
this.borderColor = (style.borderColor ?? 0) & HEX_MASK;
|
|
948
|
+
this.borderAlpha = style.borderAlpha ?? 1;
|
|
949
|
+
this.borderWidth = Math.max(0, style.borderWidth ?? 0);
|
|
950
|
+
this.pixelStep = Math.max(0, style.pixelStep ?? 0);
|
|
951
|
+
this.radiusTL = 0;
|
|
952
|
+
this.radiusTR = 0;
|
|
953
|
+
this.radiusBR = 0;
|
|
954
|
+
this.radiusBL = 0;
|
|
955
|
+
this.topGlintColor = (style.topGlintColor ?? 0xffffff) & HEX_MASK;
|
|
956
|
+
this.topGlintAlpha = Math.max(0, Math.min(1, style.topGlintAlpha ?? 0));
|
|
957
|
+
this.topGlintHeight = Math.max(0, style.topGlintHeight ?? 0);
|
|
958
|
+
if (style.radius !== void 0) this.setRadius(style.radius);
|
|
959
|
+
if (style.openSide !== void 0) this.setOpenSide(style.openSide);
|
|
960
|
+
}
|
|
961
|
+
setFillStyle(color, alpha = 1) {
|
|
962
|
+
this.fillColor = color & HEX_MASK;
|
|
963
|
+
this.fillAlpha = alpha;
|
|
964
|
+
return this;
|
|
965
|
+
}
|
|
966
|
+
setBorderStyle(width, color = this.borderColor, alpha = 1) {
|
|
967
|
+
this.borderWidth = Math.max(0, width);
|
|
968
|
+
this.borderColor = color & HEX_MASK;
|
|
969
|
+
this.borderAlpha = alpha;
|
|
970
|
+
return this;
|
|
971
|
+
}
|
|
972
|
+
setRadius(radius) {
|
|
973
|
+
if (typeof radius === "number") {
|
|
974
|
+
const r = Math.max(0, radius);
|
|
975
|
+
this.radiusTL = r;
|
|
976
|
+
this.radiusTR = r;
|
|
977
|
+
this.radiusBR = r;
|
|
978
|
+
this.radiusBL = r;
|
|
979
|
+
} else {
|
|
980
|
+
this.radiusTL = Math.max(0, radius[0] ?? 0);
|
|
981
|
+
this.radiusTR = Math.max(0, radius[1] ?? 0);
|
|
982
|
+
this.radiusBR = Math.max(0, radius[2] ?? 0);
|
|
983
|
+
this.radiusBL = Math.max(0, radius[3] ?? 0);
|
|
984
|
+
}
|
|
985
|
+
return this;
|
|
986
|
+
}
|
|
987
|
+
setPixelStep(step) {
|
|
988
|
+
this.pixelStep = Math.max(0, step);
|
|
989
|
+
return this;
|
|
990
|
+
}
|
|
991
|
+
setOpenSide(side) {
|
|
992
|
+
this.openSide = side === "left" ? 1 : side === "right" ? -1 : 0;
|
|
993
|
+
return this;
|
|
994
|
+
}
|
|
995
|
+
setTopGlint(height, color = this.topGlintColor, alpha = 1) {
|
|
996
|
+
this.topGlintHeight = Math.max(0, height);
|
|
997
|
+
this.topGlintColor = color & HEX_MASK;
|
|
998
|
+
this.topGlintAlpha = Math.max(0, Math.min(1, alpha));
|
|
999
|
+
return this;
|
|
1000
|
+
}
|
|
1001
|
+
setPanelStyle(style) {
|
|
1002
|
+
if (style.fillColor !== void 0) this.fillColor = style.fillColor & HEX_MASK;
|
|
1003
|
+
if (style.fillAlpha !== void 0) this.fillAlpha = style.fillAlpha;
|
|
1004
|
+
if (style.borderColor !== void 0) this.borderColor = style.borderColor & HEX_MASK;
|
|
1005
|
+
if (style.borderAlpha !== void 0) this.borderAlpha = style.borderAlpha;
|
|
1006
|
+
if (style.borderWidth !== void 0) this.borderWidth = Math.max(0, style.borderWidth);
|
|
1007
|
+
if (style.radius !== void 0) this.setRadius(style.radius);
|
|
1008
|
+
if (style.pixelStep !== void 0) this.pixelStep = Math.max(0, style.pixelStep);
|
|
1009
|
+
if (style.openSide !== void 0) this.setOpenSide(style.openSide);
|
|
1010
|
+
if (style.topGlintColor !== void 0) this.topGlintColor = style.topGlintColor & HEX_MASK;
|
|
1011
|
+
if (style.topGlintAlpha !== void 0) this.topGlintAlpha = Math.max(0, Math.min(1, style.topGlintAlpha));
|
|
1012
|
+
if (style.topGlintHeight !== void 0) this.topGlintHeight = Math.max(0, style.topGlintHeight);
|
|
1013
|
+
return this;
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
/**
|
|
1017
|
+
* GPU Multi-channel + True Signed Distance Field (MTSDF) vector icon display object.
|
|
1018
|
+
* Batched by `MsdfIconBatcher` on WebGL with arbitrary tint + optional true-SDF outline, and mirrored via `Path2D`
|
|
1019
|
+
* on Canvas2D. Resolution-independent from 10 px to 256 px across 1x/2x/3x DPR.
|
|
1020
|
+
*/
|
|
1021
|
+
var MsdfIconObject = class extends DisplayObject {
|
|
1022
|
+
texture;
|
|
1023
|
+
u0 = 0;
|
|
1024
|
+
v0 = 0;
|
|
1025
|
+
u1 = 1;
|
|
1026
|
+
v1 = 1;
|
|
1027
|
+
padRatio = 0;
|
|
1028
|
+
rangeUnits = 3.5;
|
|
1029
|
+
viewSize = 24;
|
|
1030
|
+
fillColor;
|
|
1031
|
+
fillAlpha;
|
|
1032
|
+
outlineColor;
|
|
1033
|
+
outlineAlpha;
|
|
1034
|
+
outlineWidth;
|
|
1035
|
+
svgPath;
|
|
1036
|
+
constructor(scene, x, y, size, config = {}) {
|
|
1037
|
+
super(scene, "MsdfIcon");
|
|
1038
|
+
this.originX = 0;
|
|
1039
|
+
this.originY = 0;
|
|
1040
|
+
this.x = x;
|
|
1041
|
+
this.y = y;
|
|
1042
|
+
const s = Math.max(0, size);
|
|
1043
|
+
this.width = s;
|
|
1044
|
+
this.height = s;
|
|
1045
|
+
this.texture = scene.textures.get(config.textureKey ?? "__DEFAULT");
|
|
1046
|
+
this.fillColor = (config.fillColor ?? 0) & HEX_MASK;
|
|
1047
|
+
this.fillAlpha = config.fillAlpha ?? 1;
|
|
1048
|
+
this.outlineColor = (config.outlineColor ?? 0xffffff) & HEX_MASK;
|
|
1049
|
+
this.outlineAlpha = config.outlineAlpha ?? 1;
|
|
1050
|
+
this.outlineWidth = Math.max(0, config.outlineWidth ?? 0);
|
|
1051
|
+
this.svgPath = config.svgPath ?? null;
|
|
1052
|
+
if (config.col !== void 0 && config.row !== void 0) this.setCell(config.col, config.row, config.cols ?? 8, config.rows ?? 4, config.cellSize ?? 32, config.viewSize ?? 24, config.margin ?? 2, config.pxRange ?? 4);
|
|
1053
|
+
}
|
|
1054
|
+
setTexture(key) {
|
|
1055
|
+
this.texture = this.scene.textures.get(key);
|
|
1056
|
+
return this;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Bind an MTSDF atlas cell `(col, row)` with exact half-texel UV inset so bilinear sampling never bleeds from
|
|
1060
|
+
* neighboring cells, while expanding the quad symmetrically to cover the full padded SDF field.
|
|
1061
|
+
*/
|
|
1062
|
+
setCell(col, row, cols = 8, rows = 4, cellSize = 32, viewSize = 24, margin = 2, pxRange = 4) {
|
|
1063
|
+
const atlasW = Math.max(1, cols * cellSize);
|
|
1064
|
+
const atlasH = Math.max(1, rows * cellSize);
|
|
1065
|
+
this.u0 = (col * cellSize + .5) / atlasW;
|
|
1066
|
+
this.v0 = (row * cellSize + .5) / atlasH;
|
|
1067
|
+
this.u1 = ((col + 1) * cellSize - .5) / atlasW;
|
|
1068
|
+
this.v1 = ((row + 1) * cellSize - .5) / atlasH;
|
|
1069
|
+
const unitsPerTexel = (viewSize + margin * 2) / Math.max(1, cellSize);
|
|
1070
|
+
const insetMargin = Math.max(0, margin - .5 * unitsPerTexel);
|
|
1071
|
+
this.viewSize = Math.max(1, viewSize);
|
|
1072
|
+
this.padRatio = insetMargin / this.viewSize;
|
|
1073
|
+
this.rangeUnits = Math.max(.001, pxRange * unitsPerTexel);
|
|
1074
|
+
return this;
|
|
1075
|
+
}
|
|
1076
|
+
setColor(color, alpha = this.fillAlpha) {
|
|
1077
|
+
this.fillColor = color & HEX_MASK;
|
|
1078
|
+
this.fillAlpha = alpha;
|
|
1079
|
+
return this;
|
|
1080
|
+
}
|
|
1081
|
+
setOutline(width, color = this.outlineColor, alpha = this.outlineAlpha) {
|
|
1082
|
+
this.outlineWidth = Math.max(0, width);
|
|
1083
|
+
this.outlineColor = color & HEX_MASK;
|
|
1084
|
+
this.outlineAlpha = alpha;
|
|
1085
|
+
return this;
|
|
1086
|
+
}
|
|
1087
|
+
setSvgPath(path) {
|
|
1088
|
+
this.svgPath = path;
|
|
1089
|
+
return this;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
let sharedMeasureCtx = null;
|
|
1093
|
+
function getMeasureCtx(doc) {
|
|
1094
|
+
if (!sharedMeasureCtx) sharedMeasureCtx = doc.createElement("canvas").getContext("2d");
|
|
1095
|
+
return sharedMeasureCtx;
|
|
1096
|
+
}
|
|
1097
|
+
var TextObject = class extends DisplayObject {
|
|
1098
|
+
text = "";
|
|
1099
|
+
style;
|
|
1100
|
+
lineSpacing = 0;
|
|
1101
|
+
isCropped = false;
|
|
1102
|
+
cropX = 0;
|
|
1103
|
+
cropY = 0;
|
|
1104
|
+
cropW = 0;
|
|
1105
|
+
cropH = 0;
|
|
1106
|
+
frame = {
|
|
1107
|
+
width: 1,
|
|
1108
|
+
height: 1,
|
|
1109
|
+
cutWidth: 1,
|
|
1110
|
+
cutHeight: 1,
|
|
1111
|
+
source: { resolution: 1 }
|
|
1112
|
+
};
|
|
1113
|
+
canvas = null;
|
|
1114
|
+
ctx = null;
|
|
1115
|
+
glTex = null;
|
|
1116
|
+
glTexAllocW = 0;
|
|
1117
|
+
glTexAllocH = 0;
|
|
1118
|
+
glDirty = true;
|
|
1119
|
+
dirty = true;
|
|
1120
|
+
lines = [];
|
|
1121
|
+
ascent = 12;
|
|
1122
|
+
lineH = 16;
|
|
1123
|
+
constructor(scene, x, y, text, style = {}) {
|
|
1124
|
+
super(scene, "Text");
|
|
1125
|
+
this.originX = 0;
|
|
1126
|
+
this.originY = 0;
|
|
1127
|
+
this.x = x;
|
|
1128
|
+
this.y = y;
|
|
1129
|
+
const pad = style.padding;
|
|
1130
|
+
this.style = {
|
|
1131
|
+
fontFamily: style.fontFamily ?? "system-ui, sans-serif",
|
|
1132
|
+
fontSize: typeof style.fontSize === "number" ? `${style.fontSize}px` : style.fontSize ?? "14px",
|
|
1133
|
+
fontStyle: style.fontStyle ?? "",
|
|
1134
|
+
color: style.color ?? rgbToCss(0, 1),
|
|
1135
|
+
stroke: style.stroke ?? "",
|
|
1136
|
+
strokeThickness: style.strokeThickness ?? 0,
|
|
1137
|
+
backgroundColor: style.backgroundColor ?? null,
|
|
1138
|
+
padding: {
|
|
1139
|
+
left: pad?.left ?? pad?.x ?? 0,
|
|
1140
|
+
right: pad?.right ?? pad?.x ?? 0,
|
|
1141
|
+
top: pad?.top ?? pad?.y ?? 0,
|
|
1142
|
+
bottom: pad?.bottom ?? pad?.y ?? 0
|
|
1143
|
+
},
|
|
1144
|
+
align: style.align ?? "left",
|
|
1145
|
+
resolution: style.resolution ?? 1,
|
|
1146
|
+
metrics: style.metrics ?? null
|
|
1147
|
+
};
|
|
1148
|
+
this.lineSpacing = style.lineSpacing ?? 0;
|
|
1149
|
+
this.frame.source.resolution = this.style.resolution;
|
|
1150
|
+
this.setText(text);
|
|
1151
|
+
}
|
|
1152
|
+
cssFont() {
|
|
1153
|
+
const s = this.style;
|
|
1154
|
+
return `${s.fontStyle ? s.fontStyle + " " : ""}${s.fontSize} ${s.fontFamily}`;
|
|
1155
|
+
}
|
|
1156
|
+
recomputeMetrics() {
|
|
1157
|
+
const s = this.style;
|
|
1158
|
+
const res = s.resolution || 1;
|
|
1159
|
+
this.frame.source.resolution = res;
|
|
1160
|
+
if (!this.text) {
|
|
1161
|
+
this.lines = [];
|
|
1162
|
+
this.width = 0;
|
|
1163
|
+
this.height = 0;
|
|
1164
|
+
this.frame.width = this.frame.cutWidth = 1;
|
|
1165
|
+
this.frame.height = this.frame.cutHeight = 1;
|
|
1166
|
+
this.dirty = true;
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
const lines = this.text.split("\n");
|
|
1170
|
+
this.lines = lines;
|
|
1171
|
+
const mctx = getMeasureCtx(this.scene.doc);
|
|
1172
|
+
mctx.font = this.cssFont();
|
|
1173
|
+
let maxW = 0;
|
|
1174
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1175
|
+
const w = mctx.measureText(lines[i]).width;
|
|
1176
|
+
if (w > maxW) maxW = w;
|
|
1177
|
+
}
|
|
1178
|
+
if (s.metrics) {
|
|
1179
|
+
this.ascent = s.metrics.ascent;
|
|
1180
|
+
this.lineH = s.metrics.fontSize;
|
|
1181
|
+
} else {
|
|
1182
|
+
const px = parseFloat(s.fontSize) || 14;
|
|
1183
|
+
mctx.textBaseline = "alphabetic";
|
|
1184
|
+
const tm = mctx.measureText("Mg中");
|
|
1185
|
+
const asc = Math.ceil(tm.fontBoundingBoxAscent ?? tm.actualBoundingBoxAscent ?? px * .85);
|
|
1186
|
+
const desc = Math.ceil(tm.fontBoundingBoxDescent ?? tm.actualBoundingBoxDescent ?? px * .25);
|
|
1187
|
+
this.ascent = asc;
|
|
1188
|
+
this.lineH = asc + desc;
|
|
1189
|
+
}
|
|
1190
|
+
const stroke = s.strokeThickness || 0;
|
|
1191
|
+
const w = Math.ceil(maxW + stroke + s.padding.left + s.padding.right);
|
|
1192
|
+
const h = Math.ceil(lines.length * this.lineH + Math.max(0, lines.length - 1) * this.lineSpacing + stroke + s.padding.top + s.padding.bottom);
|
|
1193
|
+
this.width = w;
|
|
1194
|
+
this.height = h;
|
|
1195
|
+
this.frame.width = this.frame.cutWidth = Math.max(1, Math.ceil(w * res));
|
|
1196
|
+
this.frame.height = this.frame.cutHeight = Math.max(1, Math.ceil(h * res));
|
|
1197
|
+
if (!this.customOrigin) {
|
|
1198
|
+
this._displayOriginX = w * this.originX;
|
|
1199
|
+
this._displayOriginY = h * this.originY;
|
|
1200
|
+
}
|
|
1201
|
+
this.dirty = true;
|
|
1202
|
+
}
|
|
1203
|
+
setText(value) {
|
|
1204
|
+
const next = Array.isArray(value) ? value.join("\n") : String(value ?? "");
|
|
1205
|
+
if (next === this.text && !this.dirty) return this;
|
|
1206
|
+
this.text = next;
|
|
1207
|
+
this.recomputeMetrics();
|
|
1208
|
+
return this;
|
|
1209
|
+
}
|
|
1210
|
+
setStyle(style) {
|
|
1211
|
+
const s = this.style;
|
|
1212
|
+
if (style.fontFamily !== void 0) s.fontFamily = style.fontFamily;
|
|
1213
|
+
if (style.fontSize !== void 0) s.fontSize = typeof style.fontSize === "number" ? `${style.fontSize}px` : style.fontSize;
|
|
1214
|
+
if (style.fontStyle !== void 0) s.fontStyle = style.fontStyle;
|
|
1215
|
+
if (style.color !== void 0) s.color = style.color;
|
|
1216
|
+
if (style.stroke !== void 0) s.stroke = style.stroke;
|
|
1217
|
+
if (style.strokeThickness !== void 0) s.strokeThickness = style.strokeThickness;
|
|
1218
|
+
if (style.backgroundColor !== void 0) s.backgroundColor = style.backgroundColor;
|
|
1219
|
+
if (style.padding !== void 0) {
|
|
1220
|
+
s.padding.left = style.padding.left ?? style.padding.x ?? 0;
|
|
1221
|
+
s.padding.right = style.padding.right ?? style.padding.x ?? 0;
|
|
1222
|
+
s.padding.top = style.padding.top ?? style.padding.y ?? 0;
|
|
1223
|
+
s.padding.bottom = style.padding.bottom ?? style.padding.y ?? 0;
|
|
1224
|
+
}
|
|
1225
|
+
if (style.align !== void 0) s.align = style.align;
|
|
1226
|
+
if (style.resolution !== void 0) s.resolution = style.resolution;
|
|
1227
|
+
if (style.lineSpacing !== void 0) this.lineSpacing = style.lineSpacing;
|
|
1228
|
+
if (style.metrics !== void 0) s.metrics = style.metrics;
|
|
1229
|
+
else if (style.fontSize !== void 0 || style.fontFamily !== void 0 || style.fontStyle !== void 0) s.metrics = null;
|
|
1230
|
+
this.recomputeMetrics();
|
|
1231
|
+
return this;
|
|
1232
|
+
}
|
|
1233
|
+
setColor(color) {
|
|
1234
|
+
if (this.style.color !== color) {
|
|
1235
|
+
this.style.color = color;
|
|
1236
|
+
this.dirty = true;
|
|
1237
|
+
}
|
|
1238
|
+
return this;
|
|
1239
|
+
}
|
|
1240
|
+
setStroke(color, thickness) {
|
|
1241
|
+
this.style.stroke = color;
|
|
1242
|
+
this.style.strokeThickness = thickness;
|
|
1243
|
+
this.recomputeMetrics();
|
|
1244
|
+
return this;
|
|
1245
|
+
}
|
|
1246
|
+
setFontSize(size) {
|
|
1247
|
+
const next = typeof size === "number" ? `${size}px` : size;
|
|
1248
|
+
if (this.style.fontSize !== next) {
|
|
1249
|
+
this.style.fontSize = next;
|
|
1250
|
+
this.style.metrics = null;
|
|
1251
|
+
this.recomputeMetrics();
|
|
1252
|
+
}
|
|
1253
|
+
return this;
|
|
1254
|
+
}
|
|
1255
|
+
setLineSpacing(v) {
|
|
1256
|
+
if (this.lineSpacing !== v) {
|
|
1257
|
+
this.lineSpacing = v;
|
|
1258
|
+
this.recomputeMetrics();
|
|
1259
|
+
}
|
|
1260
|
+
return this;
|
|
1261
|
+
}
|
|
1262
|
+
setAlign(align) {
|
|
1263
|
+
if (this.style.align !== align) {
|
|
1264
|
+
this.style.align = align;
|
|
1265
|
+
this.dirty = true;
|
|
1266
|
+
}
|
|
1267
|
+
return this;
|
|
1268
|
+
}
|
|
1269
|
+
setResolution(res) {
|
|
1270
|
+
const r = res > 0 ? res : 1;
|
|
1271
|
+
if (this.style.resolution !== r) {
|
|
1272
|
+
this.style.resolution = r;
|
|
1273
|
+
this.recomputeMetrics();
|
|
1274
|
+
}
|
|
1275
|
+
return this;
|
|
1276
|
+
}
|
|
1277
|
+
setCrop(x, y, w, h) {
|
|
1278
|
+
if (x === void 0 || y === void 0 || w === void 0 || h === void 0) {
|
|
1279
|
+
this.isCropped = false;
|
|
1280
|
+
this.cropX = this.cropY = this.cropW = this.cropH = 0;
|
|
1281
|
+
} else {
|
|
1282
|
+
this.isCropped = true;
|
|
1283
|
+
this.cropX = x;
|
|
1284
|
+
this.cropY = y;
|
|
1285
|
+
this.cropW = Math.max(0, w);
|
|
1286
|
+
this.cropH = Math.max(0, h);
|
|
1287
|
+
}
|
|
1288
|
+
return this;
|
|
1289
|
+
}
|
|
1290
|
+
/** Lazily paint the 2D backing canvas only when visible & rendered. */
|
|
1291
|
+
ensureCanvas() {
|
|
1292
|
+
if (!this.text || this.width <= 0 || this.height <= 0) return null;
|
|
1293
|
+
if (!this.dirty && this.canvas) return this.canvas;
|
|
1294
|
+
this.dirty = false;
|
|
1295
|
+
const cw = this.frame.width;
|
|
1296
|
+
const ch = this.frame.height;
|
|
1297
|
+
if (!this.canvas) {
|
|
1298
|
+
this.canvas = this.scene.doc.createElement("canvas");
|
|
1299
|
+
this.ctx = this.canvas.getContext("2d", { willReadFrequently: true });
|
|
1300
|
+
}
|
|
1301
|
+
if (!this.ctx) return null;
|
|
1302
|
+
if (this.canvas.width !== cw || this.canvas.height !== ch) {
|
|
1303
|
+
this.canvas.width = cw;
|
|
1304
|
+
this.canvas.height = ch;
|
|
1305
|
+
} else this.ctx.clearRect(0, 0, cw, ch);
|
|
1306
|
+
const g = this.ctx;
|
|
1307
|
+
const s = this.style;
|
|
1308
|
+
const res = s.resolution || 1;
|
|
1309
|
+
const stroke = s.strokeThickness || 0;
|
|
1310
|
+
g.save();
|
|
1311
|
+
g.scale(res, res);
|
|
1312
|
+
if (s.backgroundColor) {
|
|
1313
|
+
g.fillStyle = s.backgroundColor;
|
|
1314
|
+
g.fillRect(0, 0, this.width, this.height);
|
|
1315
|
+
}
|
|
1316
|
+
g.font = this.cssFont();
|
|
1317
|
+
g.textBaseline = "alphabetic";
|
|
1318
|
+
g.textAlign = s.align;
|
|
1319
|
+
g.lineJoin = "round";
|
|
1320
|
+
g.miterLimit = 2;
|
|
1321
|
+
const innerW = this.width - s.padding.left - s.padding.right - stroke;
|
|
1322
|
+
const baseX = s.align === "center" ? s.padding.left + stroke * .5 + innerW * .5 : s.align === "right" ? this.width - s.padding.right - stroke * .5 : s.padding.left + stroke * .5;
|
|
1323
|
+
let baseY = s.padding.top + stroke * .5 + this.ascent;
|
|
1324
|
+
const stepY = this.lineH + this.lineSpacing;
|
|
1325
|
+
for (let i = 0; i < this.lines.length; i++) {
|
|
1326
|
+
const line = this.lines[i];
|
|
1327
|
+
if (stroke > 0 && s.stroke) {
|
|
1328
|
+
g.strokeStyle = s.stroke;
|
|
1329
|
+
g.lineWidth = stroke;
|
|
1330
|
+
g.strokeText(line, baseX, baseY);
|
|
1331
|
+
}
|
|
1332
|
+
g.fillStyle = s.color;
|
|
1333
|
+
g.fillText(line, baseX, baseY);
|
|
1334
|
+
baseY += stepY;
|
|
1335
|
+
}
|
|
1336
|
+
g.restore();
|
|
1337
|
+
this.glDirty = true;
|
|
1338
|
+
return this.canvas;
|
|
1339
|
+
}
|
|
1340
|
+
/** Called by the WebGL2 renderer to obtain/update the cached WebGLTexture for this Text.
|
|
1341
|
+
* Performs zero GL calls on clean frames; when uploading, binds via `onBindSlot0` so renderer state cache stays exact. */
|
|
1342
|
+
ensureGlTexture(gl, onBindSlot0) {
|
|
1343
|
+
const cv = this.ensureCanvas();
|
|
1344
|
+
if (!cv) return null;
|
|
1345
|
+
if (!this.glTex) {
|
|
1346
|
+
this.glTex = gl.createTexture();
|
|
1347
|
+
this.glTexAllocW = 0;
|
|
1348
|
+
this.glTexAllocH = 0;
|
|
1349
|
+
this.glDirty = true;
|
|
1350
|
+
}
|
|
1351
|
+
if (!this.glTex) return null;
|
|
1352
|
+
if (this.glDirty || this.glTexAllocW !== cv.width || this.glTexAllocH !== cv.height) {
|
|
1353
|
+
if (onBindSlot0) onBindSlot0(this.glTex);
|
|
1354
|
+
else {
|
|
1355
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
1356
|
+
gl.bindTexture(gl.TEXTURE_2D, this.glTex);
|
|
1357
|
+
}
|
|
1358
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
1359
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
1360
|
+
if (this.glTexAllocW === cv.width && this.glTexAllocH === cv.height) gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, cv);
|
|
1361
|
+
else {
|
|
1362
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
1363
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
1364
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
1365
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
1366
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, cv);
|
|
1367
|
+
this.glTexAllocW = cv.width;
|
|
1368
|
+
this.glTexAllocH = cv.height;
|
|
1369
|
+
}
|
|
1370
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
1371
|
+
this.glDirty = false;
|
|
1372
|
+
}
|
|
1373
|
+
return this.glTex;
|
|
1374
|
+
}
|
|
1375
|
+
invalidateGl() {
|
|
1376
|
+
this.glTex = null;
|
|
1377
|
+
this.glTexAllocW = 0;
|
|
1378
|
+
this.glTexAllocH = 0;
|
|
1379
|
+
this.glDirty = true;
|
|
1380
|
+
}
|
|
1381
|
+
destroy(fromScene) {
|
|
1382
|
+
if (this.glTex) {
|
|
1383
|
+
try {
|
|
1384
|
+
const gl = this.scene.renderer?.gl;
|
|
1385
|
+
if (gl && !this.scene.renderer.contextLost) gl.deleteTexture(this.glTex);
|
|
1386
|
+
} catch {}
|
|
1387
|
+
this.glTex = null;
|
|
1388
|
+
}
|
|
1389
|
+
this.canvas = null;
|
|
1390
|
+
this.ctx = null;
|
|
1391
|
+
super.destroy(fromScene);
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
var Graphics = class extends DisplayObject {
|
|
1395
|
+
ops = /* @__PURE__ */ new Uint8Array(64);
|
|
1396
|
+
nums = /* @__PURE__ */ new Float64Array(256);
|
|
1397
|
+
opLen = 0;
|
|
1398
|
+
numLen = 0;
|
|
1399
|
+
/** Monotonic geometry revision bumped on every clear/draw op so WebGL can cache static tessellation meshes. */
|
|
1400
|
+
version = 0;
|
|
1401
|
+
/** True when curved SDF-capable primitives (`fillCircle`, `strokeCircle`, `fillRoundedRect`, `strokeRoundedRect`) are recorded. */
|
|
1402
|
+
_hasSdfShapes = false;
|
|
1403
|
+
/** True when arbitrary polygons, lines, arcs, or eccentric ellipses requiring polygon tessellation are recorded. */
|
|
1404
|
+
_hasNonSdfOps = false;
|
|
1405
|
+
/** Renderer-owned tessellated local-space mesh cache (opaque to user code). */
|
|
1406
|
+
_glCache = null;
|
|
1407
|
+
/** Canvas2D retained `Path2D` cache keyed by `version` (opaque to user code). */
|
|
1408
|
+
_c2dCache = null;
|
|
1409
|
+
/** Last filled rectangle bounds (used O(1) by `Pane` and `ScrollList` rect clip masks). */
|
|
1410
|
+
maskRect = null;
|
|
1411
|
+
constructor(scene) {
|
|
1412
|
+
super(scene, "Graphics");
|
|
1413
|
+
this.originX = 0;
|
|
1414
|
+
this.originY = 0;
|
|
1415
|
+
}
|
|
1416
|
+
pushOp(op, nCount) {
|
|
1417
|
+
if (this.opLen >= this.ops.length) {
|
|
1418
|
+
const next = new Uint8Array(this.ops.length * 2);
|
|
1419
|
+
next.set(this.ops);
|
|
1420
|
+
this.ops = next;
|
|
1421
|
+
}
|
|
1422
|
+
const base = this.numLen;
|
|
1423
|
+
if (base + nCount > this.nums.length) {
|
|
1424
|
+
let cap = this.nums.length * 2;
|
|
1425
|
+
while (cap < base + nCount) cap *= 2;
|
|
1426
|
+
const next = new Float64Array(cap);
|
|
1427
|
+
next.set(this.nums);
|
|
1428
|
+
this.nums = next;
|
|
1429
|
+
}
|
|
1430
|
+
this.ops[this.opLen++] = op;
|
|
1431
|
+
this.numLen = base + nCount;
|
|
1432
|
+
this.version++;
|
|
1433
|
+
return base;
|
|
1434
|
+
}
|
|
1435
|
+
clear() {
|
|
1436
|
+
if (this.opLen !== 0 || this.numLen !== 0 || this.maskRect !== null) {
|
|
1437
|
+
this.opLen = 0;
|
|
1438
|
+
this.numLen = 0;
|
|
1439
|
+
this._hasSdfShapes = false;
|
|
1440
|
+
this._hasNonSdfOps = false;
|
|
1441
|
+
this.maskRect = null;
|
|
1442
|
+
this.version++;
|
|
1443
|
+
}
|
|
1444
|
+
return this;
|
|
1445
|
+
}
|
|
1446
|
+
save() {
|
|
1447
|
+
this.pushOp(22, 0);
|
|
1448
|
+
return this;
|
|
1449
|
+
}
|
|
1450
|
+
restore() {
|
|
1451
|
+
this.pushOp(23, 0);
|
|
1452
|
+
return this;
|
|
1453
|
+
}
|
|
1454
|
+
fillStyle(color, alpha = 1) {
|
|
1455
|
+
const i = this.pushOp(1, 2);
|
|
1456
|
+
this.nums[i] = color & HEX_MASK;
|
|
1457
|
+
this.nums[i + 1] = alpha;
|
|
1458
|
+
return this;
|
|
1459
|
+
}
|
|
1460
|
+
lineStyle(lineWidth, color, alpha = 1) {
|
|
1461
|
+
const i = this.pushOp(2, 3);
|
|
1462
|
+
this.nums[i] = lineWidth;
|
|
1463
|
+
this.nums[i + 1] = color & HEX_MASK;
|
|
1464
|
+
this.nums[i + 2] = alpha;
|
|
1465
|
+
return this;
|
|
1466
|
+
}
|
|
1467
|
+
fillRect(x, y, w, h) {
|
|
1468
|
+
const i = this.pushOp(3, 4);
|
|
1469
|
+
this.nums[i] = x;
|
|
1470
|
+
this.nums[i + 1] = y;
|
|
1471
|
+
this.nums[i + 2] = w;
|
|
1472
|
+
this.nums[i + 3] = h;
|
|
1473
|
+
if (!this.maskRect) this.maskRect = {
|
|
1474
|
+
x,
|
|
1475
|
+
y,
|
|
1476
|
+
w,
|
|
1477
|
+
h
|
|
1478
|
+
};
|
|
1479
|
+
else {
|
|
1480
|
+
this.maskRect.x = x;
|
|
1481
|
+
this.maskRect.y = y;
|
|
1482
|
+
this.maskRect.w = w;
|
|
1483
|
+
this.maskRect.h = h;
|
|
1484
|
+
}
|
|
1485
|
+
return this;
|
|
1486
|
+
}
|
|
1487
|
+
strokeRect(x, y, w, h) {
|
|
1488
|
+
const i = this.pushOp(4, 4);
|
|
1489
|
+
this.nums[i] = x;
|
|
1490
|
+
this.nums[i + 1] = y;
|
|
1491
|
+
this.nums[i + 2] = w;
|
|
1492
|
+
this.nums[i + 3] = h;
|
|
1493
|
+
return this;
|
|
1494
|
+
}
|
|
1495
|
+
fillRoundedRect(x, y, w, h, radius = 8) {
|
|
1496
|
+
const r = typeof radius === "number" ? radius : radius.tl ?? radius.tr ?? 8;
|
|
1497
|
+
this._hasSdfShapes = true;
|
|
1498
|
+
const i = this.pushOp(5, 5);
|
|
1499
|
+
this.nums[i] = x;
|
|
1500
|
+
this.nums[i + 1] = y;
|
|
1501
|
+
this.nums[i + 2] = w;
|
|
1502
|
+
this.nums[i + 3] = h;
|
|
1503
|
+
this.nums[i + 4] = r;
|
|
1504
|
+
return this;
|
|
1505
|
+
}
|
|
1506
|
+
strokeRoundedRect(x, y, w, h, radius = 8) {
|
|
1507
|
+
const r = typeof radius === "number" ? radius : radius.tl ?? radius.tr ?? 8;
|
|
1508
|
+
this._hasSdfShapes = true;
|
|
1509
|
+
const i = this.pushOp(6, 5);
|
|
1510
|
+
this.nums[i] = x;
|
|
1511
|
+
this.nums[i + 1] = y;
|
|
1512
|
+
this.nums[i + 2] = w;
|
|
1513
|
+
this.nums[i + 3] = h;
|
|
1514
|
+
this.nums[i + 4] = r;
|
|
1515
|
+
return this;
|
|
1516
|
+
}
|
|
1517
|
+
fillCircle(x, y, r) {
|
|
1518
|
+
this._hasSdfShapes = true;
|
|
1519
|
+
const i = this.pushOp(7, 3);
|
|
1520
|
+
this.nums[i] = x;
|
|
1521
|
+
this.nums[i + 1] = y;
|
|
1522
|
+
this.nums[i + 2] = r;
|
|
1523
|
+
return this;
|
|
1524
|
+
}
|
|
1525
|
+
strokeCircle(x, y, r) {
|
|
1526
|
+
this._hasSdfShapes = true;
|
|
1527
|
+
const i = this.pushOp(8, 3);
|
|
1528
|
+
this.nums[i] = x;
|
|
1529
|
+
this.nums[i + 1] = y;
|
|
1530
|
+
this.nums[i + 2] = r;
|
|
1531
|
+
return this;
|
|
1532
|
+
}
|
|
1533
|
+
fillEllipse(x, y, width, height) {
|
|
1534
|
+
if (Math.abs(width - height) <= 1e-4) this._hasSdfShapes = true;
|
|
1535
|
+
else this._hasNonSdfOps = true;
|
|
1536
|
+
const i = this.pushOp(9, 4);
|
|
1537
|
+
this.nums[i] = x;
|
|
1538
|
+
this.nums[i + 1] = y;
|
|
1539
|
+
this.nums[i + 2] = width;
|
|
1540
|
+
this.nums[i + 3] = height;
|
|
1541
|
+
return this;
|
|
1542
|
+
}
|
|
1543
|
+
strokeEllipse(x, y, width, height) {
|
|
1544
|
+
if (Math.abs(width - height) <= 1e-4) this._hasSdfShapes = true;
|
|
1545
|
+
else this._hasNonSdfOps = true;
|
|
1546
|
+
const i = this.pushOp(10, 4);
|
|
1547
|
+
this.nums[i] = x;
|
|
1548
|
+
this.nums[i + 1] = y;
|
|
1549
|
+
this.nums[i + 2] = width;
|
|
1550
|
+
this.nums[i + 3] = height;
|
|
1551
|
+
return this;
|
|
1552
|
+
}
|
|
1553
|
+
fillTriangle(x0, y0, x1, y1, x2, y2) {
|
|
1554
|
+
this._hasNonSdfOps = true;
|
|
1555
|
+
const i = this.pushOp(11, 6);
|
|
1556
|
+
this.nums[i] = x0;
|
|
1557
|
+
this.nums[i + 1] = y0;
|
|
1558
|
+
this.nums[i + 2] = x1;
|
|
1559
|
+
this.nums[i + 3] = y1;
|
|
1560
|
+
this.nums[i + 4] = x2;
|
|
1561
|
+
this.nums[i + 5] = y2;
|
|
1562
|
+
return this;
|
|
1563
|
+
}
|
|
1564
|
+
strokeTriangle(x0, y0, x1, y1, x2, y2) {
|
|
1565
|
+
this._hasNonSdfOps = true;
|
|
1566
|
+
const i = this.pushOp(12, 6);
|
|
1567
|
+
this.nums[i] = x0;
|
|
1568
|
+
this.nums[i + 1] = y0;
|
|
1569
|
+
this.nums[i + 2] = x1;
|
|
1570
|
+
this.nums[i + 3] = y1;
|
|
1571
|
+
this.nums[i + 4] = x2;
|
|
1572
|
+
this.nums[i + 5] = y2;
|
|
1573
|
+
return this;
|
|
1574
|
+
}
|
|
1575
|
+
lineBetween(x1, y1, x2, y2) {
|
|
1576
|
+
this._hasNonSdfOps = true;
|
|
1577
|
+
const i = this.pushOp(13, 4);
|
|
1578
|
+
this.nums[i] = x1;
|
|
1579
|
+
this.nums[i + 1] = y1;
|
|
1580
|
+
this.nums[i + 2] = x2;
|
|
1581
|
+
this.nums[i + 3] = y2;
|
|
1582
|
+
return this;
|
|
1583
|
+
}
|
|
1584
|
+
beginPath() {
|
|
1585
|
+
this._hasNonSdfOps = true;
|
|
1586
|
+
this.pushOp(14, 0);
|
|
1587
|
+
return this;
|
|
1588
|
+
}
|
|
1589
|
+
moveTo(x, y) {
|
|
1590
|
+
this._hasNonSdfOps = true;
|
|
1591
|
+
const i = this.pushOp(15, 2);
|
|
1592
|
+
this.nums[i] = x;
|
|
1593
|
+
this.nums[i + 1] = y;
|
|
1594
|
+
return this;
|
|
1595
|
+
}
|
|
1596
|
+
lineTo(x, y) {
|
|
1597
|
+
this._hasNonSdfOps = true;
|
|
1598
|
+
const i = this.pushOp(16, 2);
|
|
1599
|
+
this.nums[i] = x;
|
|
1600
|
+
this.nums[i + 1] = y;
|
|
1601
|
+
return this;
|
|
1602
|
+
}
|
|
1603
|
+
arc(x, y, r, startAngle, endAngle, anticlockwise = false) {
|
|
1604
|
+
this._hasNonSdfOps = true;
|
|
1605
|
+
const i = this.pushOp(17, 6);
|
|
1606
|
+
this.nums[i] = x;
|
|
1607
|
+
this.nums[i + 1] = y;
|
|
1608
|
+
this.nums[i + 2] = r;
|
|
1609
|
+
this.nums[i + 3] = startAngle;
|
|
1610
|
+
this.nums[i + 4] = endAngle;
|
|
1611
|
+
this.nums[i + 5] = anticlockwise ? 1 : 0;
|
|
1612
|
+
return this;
|
|
1613
|
+
}
|
|
1614
|
+
slice(x, y, r, startAngle, endAngle, anticlockwise = false) {
|
|
1615
|
+
this._hasNonSdfOps = true;
|
|
1616
|
+
const i = this.pushOp(18, 6);
|
|
1617
|
+
this.nums[i] = x;
|
|
1618
|
+
this.nums[i + 1] = y;
|
|
1619
|
+
this.nums[i + 2] = r;
|
|
1620
|
+
this.nums[i + 3] = startAngle;
|
|
1621
|
+
this.nums[i + 4] = endAngle;
|
|
1622
|
+
this.nums[i + 5] = anticlockwise ? 1 : 0;
|
|
1623
|
+
return this;
|
|
1624
|
+
}
|
|
1625
|
+
closePath() {
|
|
1626
|
+
this.pushOp(19, 0);
|
|
1627
|
+
return this;
|
|
1628
|
+
}
|
|
1629
|
+
fillPath() {
|
|
1630
|
+
this.pushOp(20, 0);
|
|
1631
|
+
return this;
|
|
1632
|
+
}
|
|
1633
|
+
strokePath() {
|
|
1634
|
+
this.pushOp(21, 0);
|
|
1635
|
+
return this;
|
|
1636
|
+
}
|
|
1637
|
+
fill() {
|
|
1638
|
+
return this.fillPath();
|
|
1639
|
+
}
|
|
1640
|
+
stroke() {
|
|
1641
|
+
return this.strokePath();
|
|
1642
|
+
}
|
|
1643
|
+
fillPoints(points, closeShape = false, closePath = false) {
|
|
1644
|
+
if (points.length < 3) return this;
|
|
1645
|
+
this.beginPath();
|
|
1646
|
+
this.moveTo(points[0].x, points[0].y);
|
|
1647
|
+
for (let i = 1; i < points.length; i++) this.lineTo(points[i].x, points[i].y);
|
|
1648
|
+
if (closeShape || closePath) this.closePath();
|
|
1649
|
+
return this.fillPath();
|
|
1650
|
+
}
|
|
1651
|
+
strokePoints(points, closeShape = false, closePath = false) {
|
|
1652
|
+
if (points.length < 2) return this;
|
|
1653
|
+
this.beginPath();
|
|
1654
|
+
this.moveTo(points[0].x, points[0].y);
|
|
1655
|
+
for (let i = 1; i < points.length; i++) this.lineTo(points[i].x, points[i].y);
|
|
1656
|
+
if (closeShape || closePath) this.closePath();
|
|
1657
|
+
return this.strokePath();
|
|
1658
|
+
}
|
|
1659
|
+
createGeometryMask() {
|
|
1660
|
+
return {
|
|
1661
|
+
graphics: this,
|
|
1662
|
+
active: true
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
destroy(fromScene) {
|
|
1666
|
+
this._glCache = null;
|
|
1667
|
+
this._c2dCache = null;
|
|
1668
|
+
super.destroy(fromScene);
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
var BlitterObject = class extends DisplayObject {
|
|
1672
|
+
texture;
|
|
1673
|
+
children = { list: [] };
|
|
1674
|
+
constructor(scene, x, y, key) {
|
|
1675
|
+
super(scene, "Blitter");
|
|
1676
|
+
this.originX = 0;
|
|
1677
|
+
this.originY = 0;
|
|
1678
|
+
this.x = x;
|
|
1679
|
+
this.y = y;
|
|
1680
|
+
this.texture = scene.textures.get(key);
|
|
1681
|
+
}
|
|
1682
|
+
create(x, y, frame) {
|
|
1683
|
+
const bob = {
|
|
1684
|
+
x,
|
|
1685
|
+
y,
|
|
1686
|
+
visible: true,
|
|
1687
|
+
alpha: 1,
|
|
1688
|
+
frame: this.texture.get(frame)
|
|
1689
|
+
};
|
|
1690
|
+
this.children.list.push(bob);
|
|
1691
|
+
return bob;
|
|
1692
|
+
}
|
|
1693
|
+
destroy(fromScene) {
|
|
1694
|
+
this.children.list.length = 0;
|
|
1695
|
+
super.destroy(fromScene);
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
var Container = class extends DisplayObject {
|
|
1699
|
+
list = [];
|
|
1700
|
+
clipMask = null;
|
|
1701
|
+
filters = null;
|
|
1702
|
+
hasZOrder = false;
|
|
1703
|
+
zDirty = false;
|
|
1704
|
+
sortedBuf = null;
|
|
1705
|
+
constructor(scene, x = 0, y = 0, children) {
|
|
1706
|
+
super(scene, "Container");
|
|
1707
|
+
this.originX = 0;
|
|
1708
|
+
this.originY = 0;
|
|
1709
|
+
this.x = x;
|
|
1710
|
+
this.y = y;
|
|
1711
|
+
if (children?.length) this.add(children);
|
|
1712
|
+
}
|
|
1713
|
+
_markZDirty(nonZero) {
|
|
1714
|
+
if (nonZero) this.hasZOrder = true;
|
|
1715
|
+
this.zDirty = true;
|
|
1716
|
+
}
|
|
1717
|
+
/** Children in render order: O(1) direct `list` when all zIndex === 0, else cached stable sort by `zIndex`. */
|
|
1718
|
+
sortedChildren() {
|
|
1719
|
+
if (!this.hasZOrder) return this.list;
|
|
1720
|
+
if (this.zDirty || !this.sortedBuf) {
|
|
1721
|
+
this.zDirty = false;
|
|
1722
|
+
const src = this.list;
|
|
1723
|
+
let anyNonZero = false;
|
|
1724
|
+
for (let i = 0; i < src.length; i++) if (src[i].zIndex !== 0) {
|
|
1725
|
+
anyNonZero = true;
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
if (!anyNonZero) {
|
|
1729
|
+
this.hasZOrder = false;
|
|
1730
|
+
this.sortedBuf = null;
|
|
1731
|
+
return src;
|
|
1732
|
+
}
|
|
1733
|
+
const buf = this.sortedBuf ?? (this.sortedBuf = []);
|
|
1734
|
+
buf.length = src.length;
|
|
1735
|
+
for (let i = 0; i < src.length; i++) buf[i] = src[i];
|
|
1736
|
+
buf.sort((a, b) => a.zIndex - b.zIndex);
|
|
1737
|
+
}
|
|
1738
|
+
return this.sortedBuf;
|
|
1739
|
+
}
|
|
1740
|
+
add(child) {
|
|
1741
|
+
if (Array.isArray(child)) for (let i = 0; i < child.length; i++) this.addOne(child[i]);
|
|
1742
|
+
else if (child) this.addOne(child);
|
|
1743
|
+
return this;
|
|
1744
|
+
}
|
|
1745
|
+
addOne(child) {
|
|
1746
|
+
if (child === this) return;
|
|
1747
|
+
if (child.parentContainer === this) return;
|
|
1748
|
+
if (child.parentContainer) child.parentContainer.remove(child);
|
|
1749
|
+
else this.scene._displayList.remove(child);
|
|
1750
|
+
child.parentContainer = this;
|
|
1751
|
+
this.list.push(child);
|
|
1752
|
+
if (child.zIndex !== 0) this.hasZOrder = true;
|
|
1753
|
+
if (this.hasZOrder) this.zDirty = true;
|
|
1754
|
+
}
|
|
1755
|
+
/** Insert `child` at `index` in `this.list` (clamped to `[0, list.length]`). Moves in-place if already in this container. */
|
|
1756
|
+
addAt(child, index) {
|
|
1757
|
+
if (!child || child === this) return this;
|
|
1758
|
+
const clamped = Math.max(0, Math.min(Math.round(index), this.list.length));
|
|
1759
|
+
if (child.parentContainer === this) return this.moveTo(child, Math.min(clamped, Math.max(0, this.list.length - 1)));
|
|
1760
|
+
if (child.parentContainer) child.parentContainer.remove(child);
|
|
1761
|
+
else this.scene._displayList.remove(child);
|
|
1762
|
+
child.parentContainer = this;
|
|
1763
|
+
this.list.splice(Math.min(clamped, this.list.length), 0, child);
|
|
1764
|
+
if (child.zIndex !== 0) this.hasZOrder = true;
|
|
1765
|
+
if (this.hasZOrder) this.zDirty = true;
|
|
1766
|
+
return this;
|
|
1767
|
+
}
|
|
1768
|
+
/** Move an existing child of this container to `index` in `this.list` (clamped to `[0, list.length - 1]`). */
|
|
1769
|
+
moveTo(child, index) {
|
|
1770
|
+
const cur = this.list.indexOf(child);
|
|
1771
|
+
if (cur < 0) return this;
|
|
1772
|
+
const target = Math.max(0, Math.min(Math.round(index), this.list.length - 1));
|
|
1773
|
+
if (cur === target) return this;
|
|
1774
|
+
this.list.splice(cur, 1);
|
|
1775
|
+
this.list.splice(target, 0, child);
|
|
1776
|
+
if (this.hasZOrder) this.zDirty = true;
|
|
1777
|
+
return this;
|
|
1778
|
+
}
|
|
1779
|
+
remove(child) {
|
|
1780
|
+
const i = this.list.indexOf(child);
|
|
1781
|
+
if (i >= 0) {
|
|
1782
|
+
this.list.splice(i, 1);
|
|
1783
|
+
child.parentContainer = null;
|
|
1784
|
+
if (this.hasZOrder) this.zDirty = true;
|
|
1785
|
+
}
|
|
1786
|
+
return this;
|
|
1787
|
+
}
|
|
1788
|
+
getIndex(child) {
|
|
1789
|
+
return this.list.indexOf(child);
|
|
1790
|
+
}
|
|
1791
|
+
sendToBack(child) {
|
|
1792
|
+
const i = this.list.indexOf(child);
|
|
1793
|
+
if (i > 0) {
|
|
1794
|
+
this.list.splice(i, 1);
|
|
1795
|
+
this.list.unshift(child);
|
|
1796
|
+
if (this.hasZOrder) this.zDirty = true;
|
|
1797
|
+
}
|
|
1798
|
+
return this;
|
|
1799
|
+
}
|
|
1800
|
+
bringToTop(child) {
|
|
1801
|
+
const i = this.list.indexOf(child);
|
|
1802
|
+
if (i >= 0 && i < this.list.length - 1) {
|
|
1803
|
+
this.list.splice(i, 1);
|
|
1804
|
+
this.list.push(child);
|
|
1805
|
+
if (this.hasZOrder) this.zDirty = true;
|
|
1806
|
+
}
|
|
1807
|
+
return this;
|
|
1808
|
+
}
|
|
1809
|
+
setMask(mask) {
|
|
1810
|
+
this.clipMask = mask;
|
|
1811
|
+
return this;
|
|
1812
|
+
}
|
|
1813
|
+
clearMask() {
|
|
1814
|
+
this.clipMask = null;
|
|
1815
|
+
return this;
|
|
1816
|
+
}
|
|
1817
|
+
/** Zero-FBO compatibility hook for `Pane` & `ScrollList` (clips via hardware `gl.SCISSOR_TEST`). */
|
|
1818
|
+
enableFilters() {
|
|
1819
|
+
if (!this.filters) this.filters = { external: { addMask: (maskG) => {
|
|
1820
|
+
const m = {
|
|
1821
|
+
graphics: maskG,
|
|
1822
|
+
active: true
|
|
1823
|
+
};
|
|
1824
|
+
this.clipMask = m;
|
|
1825
|
+
return m;
|
|
1826
|
+
} } };
|
|
1827
|
+
return this;
|
|
1828
|
+
}
|
|
1829
|
+
destroy(destroyChildren = true) {
|
|
1830
|
+
if (!this.active) return;
|
|
1831
|
+
if (destroyChildren) {
|
|
1832
|
+
const snap = this.list.slice();
|
|
1833
|
+
this.list.length = 0;
|
|
1834
|
+
for (let i = snap.length - 1; i >= 0; i--) {
|
|
1835
|
+
snap[i].parentContainer = null;
|
|
1836
|
+
snap[i].destroy(true);
|
|
1837
|
+
}
|
|
1838
|
+
} else {
|
|
1839
|
+
for (let i = 0; i < this.list.length; i++) this.list[i].parentContainer = null;
|
|
1840
|
+
this.list.length = 0;
|
|
1841
|
+
}
|
|
1842
|
+
this.clipMask = null;
|
|
1843
|
+
this.filters = null;
|
|
1844
|
+
this.sortedBuf = null;
|
|
1845
|
+
this.hasZOrder = false;
|
|
1846
|
+
this.zDirty = false;
|
|
1847
|
+
super.destroy(destroyChildren);
|
|
1848
|
+
}
|
|
1849
|
+
};
|
|
1850
|
+
var CustomPassObject = class extends DisplayObject {
|
|
1851
|
+
onRender;
|
|
1852
|
+
restoreState;
|
|
1853
|
+
constructor(scene, onRender, options) {
|
|
1854
|
+
super(scene, "CustomPass");
|
|
1855
|
+
this.onRender = onRender;
|
|
1856
|
+
this.restoreState = options?.restoreState !== false;
|
|
1857
|
+
this._isCrowdInstanced = true;
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
/**
|
|
1861
|
+
* High-throughput SoA instanced sprite/quad batch (`scene.add.instancedBatch(key, maxCount)`).
|
|
1862
|
+
* Consumes `SoaWorld` `Float32Array` columns directly: renders via hardware `drawElementsInstanced`
|
|
1863
|
+
* in WebGL2, instanced storage/vertex buffer in WebGPU, and zero-alloc loop in Canvas2D / Headless Node.
|
|
1864
|
+
*/
|
|
1865
|
+
var InstancedBatchObject = class extends DisplayObject {
|
|
1866
|
+
texture;
|
|
1867
|
+
defaultFrame;
|
|
1868
|
+
maxCount;
|
|
1869
|
+
columns = null;
|
|
1870
|
+
/** Renderer-owned GPU instance buffer cache (opaque to user code). */
|
|
1871
|
+
_gpuCache = null;
|
|
1872
|
+
constructor(scene, key, maxCount = 1024, frame) {
|
|
1873
|
+
super(scene, "InstancedBatch");
|
|
1874
|
+
this.maxCount = Math.max(1, Math.floor(maxCount));
|
|
1875
|
+
this.originX = .5;
|
|
1876
|
+
this.originY = .5;
|
|
1877
|
+
this.setTexture(key, frame);
|
|
1878
|
+
}
|
|
1879
|
+
setTexture(key, frame) {
|
|
1880
|
+
this.texture = this.scene.textures.get(key);
|
|
1881
|
+
this.defaultFrame = this.texture.get(frame);
|
|
1882
|
+
this.width = this.defaultFrame.width;
|
|
1883
|
+
this.height = this.defaultFrame.height;
|
|
1884
|
+
return this;
|
|
1885
|
+
}
|
|
1886
|
+
/** Bind or update the SoA column views read on each render pass (zero copying on caller side). */
|
|
1887
|
+
setColumns(columns) {
|
|
1888
|
+
this.columns = columns;
|
|
1889
|
+
return this;
|
|
1890
|
+
}
|
|
1891
|
+
destroy(fromScene) {
|
|
1892
|
+
if (this._gpuCache && typeof this._gpuCache.destroy === "function") try {
|
|
1893
|
+
this._gpuCache.destroy();
|
|
1894
|
+
} catch {}
|
|
1895
|
+
this._gpuCache = null;
|
|
1896
|
+
this.columns = null;
|
|
1897
|
+
super.destroy(fromScene);
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
/**
|
|
1901
|
+
* Zero-texture GPU analytical SDF shape batch (`scene.add.shapeBatch(maxCount, defaults?)`).
|
|
1902
|
+
* Renders thousands of dynamic circles, rings, pills, capsules, shadows, health bars, or rounded rects
|
|
1903
|
+
* directly from `SoaWorld` `Float32Array` / `Uint32Array` columns — 1 analytical SDF quad (2 tris) per shape
|
|
1904
|
+
* on WebGL2 & WebGPU with zero sprite atlas baking and zero CPU polygon triangulation.
|
|
1905
|
+
*/
|
|
1906
|
+
var ShapeBatchObject = class extends DisplayObject {
|
|
1907
|
+
maxCount;
|
|
1908
|
+
defaultWidth;
|
|
1909
|
+
defaultHeight;
|
|
1910
|
+
defaultRadius;
|
|
1911
|
+
defaultFillColor;
|
|
1912
|
+
defaultFillAlpha;
|
|
1913
|
+
defaultBorderColor;
|
|
1914
|
+
defaultBorderAlpha;
|
|
1915
|
+
defaultBorderWidth;
|
|
1916
|
+
pixelStep;
|
|
1917
|
+
columns = null;
|
|
1918
|
+
constructor(scene, maxCount = 1024, defaults = {}) {
|
|
1919
|
+
super(scene, "ShapeBatch");
|
|
1920
|
+
this.maxCount = Math.max(1, Math.floor(maxCount));
|
|
1921
|
+
this.originX = .5;
|
|
1922
|
+
this.originY = .5;
|
|
1923
|
+
const w = defaults.width ?? 12;
|
|
1924
|
+
const h = defaults.height ?? w;
|
|
1925
|
+
this.defaultWidth = w;
|
|
1926
|
+
this.defaultHeight = h;
|
|
1927
|
+
this.defaultRadius = defaults.radius ?? Math.min(w, h) * .5;
|
|
1928
|
+
this.defaultFillColor = (defaults.fillColor ?? 0xffffff) & HEX_MASK;
|
|
1929
|
+
this.defaultFillAlpha = defaults.fillAlpha ?? 1;
|
|
1930
|
+
this.defaultBorderColor = (defaults.borderColor ?? 0) & HEX_MASK;
|
|
1931
|
+
this.defaultBorderAlpha = defaults.borderAlpha ?? 1;
|
|
1932
|
+
this.defaultBorderWidth = defaults.borderWidth ?? 0;
|
|
1933
|
+
this.pixelStep = defaults.pixelStep ?? 0;
|
|
1934
|
+
}
|
|
1935
|
+
/** Bind or update the SoA column views read on each render pass (zero copying on caller side). */
|
|
1936
|
+
setColumns(columns) {
|
|
1937
|
+
this.columns = columns;
|
|
1938
|
+
return this;
|
|
1939
|
+
}
|
|
1940
|
+
destroy(fromScene) {
|
|
1941
|
+
this.columns = null;
|
|
1942
|
+
super.destroy(fromScene);
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
export { DisplayObject as a, InstancedBatchObject as c, PanelObject as d, RectangleObject as f, TileSpriteObject as g, TextObject as h, DisplayList as i, MsdfIconObject as l, SpriteObject as m, Container as n, Graphics as o, ShapeBatchObject as p, CustomPassObject as r, ImageObject as s, BlitterObject as t, NineSliceObject as u };
|