@holtjs/stage 0.9.0 → 0.10.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 +14 -0
- package/README.md +12 -11
- package/dist/{anims-ClNi6zZQ.d.ts → anims-xOSYNG79.d.ts} +23 -4
- package/dist/anims.d.ts +1 -1
- package/dist/anims.js +49 -5
- package/dist/{display-C_NPwPrE.js → display-CZb3yen0.js} +273 -56
- package/dist/{game-DnJYRLZP.d.ts → game-BbgtwqyW.d.ts} +76 -14
- package/dist/{game-C-yXzyAX.js → game-CUZbJLbR.js} +83 -7
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/lighting.js +1 -1
- package/dist/projection.d.ts +1 -1
- package/dist/projection.js +7 -1
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/rig2d.d.ts +2 -2
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/llms.txt +12 -11
- package/package.json +1 -1
- package/skills/stage/SKILL.md +9 -6
- package/skills/stage/references/subpaths.md +6 -6
|
@@ -474,9 +474,9 @@ var ImageObject = class extends DisplayObject {
|
|
|
474
474
|
return out;
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
|
-
* Read the full transformed 2D pose (`x`, `y`, `rotation`, `zBias`, `hasAngle`
|
|
478
|
-
*
|
|
479
|
-
*
|
|
477
|
+
* Read the full transformed 2D pose (`x`, `y`, `rotation`, `zBias`, `hasAngle`, plus 2x2 projected basis `ux, uy, vx, vy`
|
|
478
|
+
* when baked via `@holtjs/craft/three` `charKit.handBasisSocket`) transforming tangent/basis vectors through the exact
|
|
479
|
+
* `flip -> scale -> rotate/skew -> parentContainer` Jacobian!
|
|
480
480
|
*/
|
|
481
481
|
getAnchorPose(name, space = "parent", out = {
|
|
482
482
|
x: 0,
|
|
@@ -491,67 +491,78 @@ var ImageObject = class extends DisplayObject {
|
|
|
491
491
|
const hasAngle = raw.length >= 3 && typeof raw[2] === "number" && Number.isFinite(raw[2]);
|
|
492
492
|
const rawAngle = hasAngle ? raw[2] : 0;
|
|
493
493
|
const zBias = raw.length >= 4 && typeof raw[3] === "number" ? raw[3] >= 0 ? 1 : -1 : 1;
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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;
|
|
494
|
+
const hasBasis = raw.length >= 8 && typeof raw[4] === "number" && typeof raw[5] === "number" && typeof raw[6] === "number" && typeof raw[7] === "number";
|
|
495
|
+
const mapVec = (vx0, vy0) => {
|
|
496
|
+
let vx = this.flipX ? -vx0 : vx0;
|
|
497
|
+
let vy = this.flipY ? -vy0 : vy0;
|
|
498
|
+
if (space !== "local") {
|
|
499
|
+
const applyLinear = (n) => {
|
|
500
|
+
if (n.skewX === 0 && n.skewY === 0) {
|
|
501
|
+
vx *= n.scaleX;
|
|
502
|
+
vy *= n.scaleY;
|
|
503
|
+
if (n.rotation !== 0) {
|
|
504
|
+
const c = Math.cos(n.rotation);
|
|
505
|
+
const s = Math.sin(n.rotation);
|
|
506
|
+
const rx = vx * c - vy * s;
|
|
507
|
+
vy = vx * s + vy * c;
|
|
508
|
+
vx = rx;
|
|
530
509
|
}
|
|
531
510
|
} else {
|
|
532
|
-
const la = Math.cos(
|
|
533
|
-
const lb = Math.sin(
|
|
534
|
-
const lc = -Math.sin(
|
|
535
|
-
const ld = Math.cos(
|
|
536
|
-
const rx = la *
|
|
537
|
-
|
|
538
|
-
|
|
511
|
+
const la = Math.cos(n.rotation + n.skewY) * n.scaleX;
|
|
512
|
+
const lb = Math.sin(n.rotation + n.skewY) * n.scaleX;
|
|
513
|
+
const lc = -Math.sin(n.rotation - n.skewX) * n.scaleY;
|
|
514
|
+
const ld = Math.cos(n.rotation - n.skewX) * n.scaleY;
|
|
515
|
+
const rx = la * vx + lc * vy;
|
|
516
|
+
vy = lb * vx + ld * vy;
|
|
517
|
+
vx = rx;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
applyLinear(this);
|
|
521
|
+
if (space === "world") {
|
|
522
|
+
let cur = this.parentContainer;
|
|
523
|
+
while (cur) {
|
|
524
|
+
applyLinear(cur);
|
|
525
|
+
cur = cur.parentContainer;
|
|
539
526
|
}
|
|
540
|
-
cur = cur.parentContainer;
|
|
541
527
|
}
|
|
542
528
|
}
|
|
529
|
+
return [vx, vy];
|
|
530
|
+
};
|
|
531
|
+
if (hasBasis) {
|
|
532
|
+
const [ux, uy] = mapVec(raw[4], raw[5]);
|
|
533
|
+
const [vx, vy] = mapVec(raw[6], raw[7]);
|
|
534
|
+
const uLen = Math.hypot(ux, uy);
|
|
535
|
+
const [dx, dy] = uLen > 1e-6 ? [ux, uy] : mapVec(Math.cos(rawAngle), Math.sin(rawAngle));
|
|
536
|
+
out.rotation = Math.atan2(dy, dx);
|
|
537
|
+
out.zBias = zBias;
|
|
538
|
+
out.hasAngle = true;
|
|
539
|
+
out.hasBasis = true;
|
|
540
|
+
out.ux = ux;
|
|
541
|
+
out.uy = uy;
|
|
542
|
+
out.vx = vx;
|
|
543
|
+
out.vy = vy;
|
|
544
|
+
out.foreshorten = uLen;
|
|
545
|
+
return out;
|
|
543
546
|
}
|
|
547
|
+
const [dx, dy] = mapVec(Math.cos(rawAngle), Math.sin(rawAngle));
|
|
544
548
|
out.rotation = Math.atan2(dy, dx);
|
|
545
549
|
out.zBias = zBias;
|
|
546
550
|
out.hasAngle = hasAngle;
|
|
551
|
+
out.hasBasis = false;
|
|
552
|
+
out.ux = void 0;
|
|
553
|
+
out.uy = void 0;
|
|
554
|
+
out.vx = void 0;
|
|
555
|
+
out.vy = void 0;
|
|
556
|
+
out.foreshorten = void 0;
|
|
547
557
|
return out;
|
|
548
558
|
}
|
|
549
559
|
/**
|
|
550
560
|
* Align an equipped weapon/tool `DisplayObject` (`axe`, `spear`, `torch`, `shield`) to a named socket (`'hand'`) in one call:
|
|
551
|
-
* -
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* -
|
|
561
|
+
* - When the socket provides a 2x2 projected 3D basis (`handBasisSocket`), solves the exact 6-DOF affine matrix
|
|
562
|
+
* (`scaleX`, `scaleY`, `rotation`, `skewY`) capturing shaft perspective foreshortening (`||u|| < 1`), `45°/30°`
|
|
563
|
+
* non-orthogonal isometric blade shear (`u · v != 0`), automatic chirality blade reflection, and per-clip wrist angles (`clipAngles`)!
|
|
564
|
+
* - Falls back cleanly to rigid `rotation` + `O(2)` `mirrorBlade` when given a 4-tuple `[x, y, angleRad, zBias]`.
|
|
565
|
+
* - Applies `zBias` (`+1` in front of body, `-1` behind body) via `child.setZIndex(baseZIndex + zBias)`.
|
|
555
566
|
*/
|
|
556
567
|
syncAttachment(child, anchorName, opts = {}) {
|
|
557
568
|
const space = opts.space ?? "parent";
|
|
@@ -559,7 +570,85 @@ var ImageObject = class extends DisplayObject {
|
|
|
559
570
|
if (!pose) return false;
|
|
560
571
|
child.x = pose.x;
|
|
561
572
|
child.y = pose.y;
|
|
562
|
-
|
|
573
|
+
let activeClip = opts.clip ?? this.frame?.clip ?? null;
|
|
574
|
+
if (!activeClip && "currentAnimKey" in this) {
|
|
575
|
+
const ak = this.currentAnimKey;
|
|
576
|
+
if (ak) {
|
|
577
|
+
const stripped = ak.replace(/\/d\d+$/i, "");
|
|
578
|
+
const slash = stripped.lastIndexOf("/");
|
|
579
|
+
activeClip = slash >= 0 ? stripped.slice(slash + 1) : stripped;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const clipDelta = activeClip && opts.clipAngles && typeof opts.clipAngles[activeClip] === "number" ? opts.clipAngles[activeClip] : 0;
|
|
583
|
+
const totalOffset = (opts.angleOffset ?? 0) + clipDelta;
|
|
584
|
+
const bsx = Array.isArray(opts.baseScale) ? opts.baseScale[0] : typeof opts.baseScale === "number" ? opts.baseScale : 1;
|
|
585
|
+
const bsy = Array.isArray(opts.baseScale) ? opts.baseScale[1] : typeof opts.baseScale === "number" ? opts.baseScale : 1;
|
|
586
|
+
if (pose.hasBasis && opts.affineBasis !== false && pose.ux !== void 0 && pose.uy !== void 0 && pose.vx !== void 0 && pose.vy !== void 0) {
|
|
587
|
+
const rest = opts.restAngle ?? -Math.PI * .5;
|
|
588
|
+
let uxp = pose.ux;
|
|
589
|
+
let uyp = pose.uy;
|
|
590
|
+
let vxp = pose.vx;
|
|
591
|
+
let vyp = pose.vy;
|
|
592
|
+
if (totalOffset !== 0) {
|
|
593
|
+
const cd = Math.cos(totalOffset);
|
|
594
|
+
const sd = Math.sin(totalOffset);
|
|
595
|
+
const nux = cd * uxp + sd * vxp;
|
|
596
|
+
const nuy = cd * uyp + sd * vyp;
|
|
597
|
+
vxp = -sd * uxp + cd * vxp;
|
|
598
|
+
vyp = -sd * uyp + cd * vyp;
|
|
599
|
+
uxp = nux;
|
|
600
|
+
uyp = nuy;
|
|
601
|
+
}
|
|
602
|
+
const minLen = Math.max(.02, opts.minForeshorten ?? .22) * (space === "local" ? 1 : Math.max(1e-4, Math.hypot(this.scaleX, this.scaleY) * Math.SQRT1_2));
|
|
603
|
+
const uLen = Math.hypot(uxp, uyp);
|
|
604
|
+
if (uLen < minLen) {
|
|
605
|
+
if (uLen > 1e-6) {
|
|
606
|
+
const k = minLen / uLen;
|
|
607
|
+
uxp *= k;
|
|
608
|
+
uyp *= k;
|
|
609
|
+
} else {
|
|
610
|
+
uxp = Math.cos(pose.rotation) * minLen;
|
|
611
|
+
uyp = Math.sin(pose.rotation) * minLen;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const vLen = Math.hypot(vxp, vyp);
|
|
615
|
+
if (vLen < minLen) {
|
|
616
|
+
if (vLen > 1e-6) {
|
|
617
|
+
const k = minLen / vLen;
|
|
618
|
+
vxp *= k;
|
|
619
|
+
vyp *= k;
|
|
620
|
+
} else {
|
|
621
|
+
const ua = Math.atan2(uyp, uxp) + Math.PI * .5;
|
|
622
|
+
vxp = Math.cos(ua) * minLen;
|
|
623
|
+
vyp = Math.sin(ua) * minLen;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const uxS = uxp * bsy;
|
|
627
|
+
const uyS = uyp * bsy;
|
|
628
|
+
const vxS = vxp * bsx;
|
|
629
|
+
const vyS = vyp * bsx;
|
|
630
|
+
const s0x = Math.cos(rest);
|
|
631
|
+
const s0y = Math.sin(rest);
|
|
632
|
+
const b0x = -s0y;
|
|
633
|
+
const b0y = s0x;
|
|
634
|
+
const a = uxS * s0x + vxS * b0x;
|
|
635
|
+
const b = uyS * s0x + vyS * b0x;
|
|
636
|
+
const c = uxS * s0y + vxS * b0y;
|
|
637
|
+
const d = uyS * s0y + vyS * b0y;
|
|
638
|
+
const sx = Math.hypot(a, b);
|
|
639
|
+
const len2 = Math.hypot(c, d);
|
|
640
|
+
const det = a * d - b * c;
|
|
641
|
+
const sy = det >= 0 ? len2 : -len2;
|
|
642
|
+
const alpha1 = sx > 1e-8 ? Math.atan2(b, a) : 0;
|
|
643
|
+
const beta = len2 > 1e-8 ? det >= 0 ? Math.atan2(-c, d) : Math.atan2(c, -d) : alpha1;
|
|
644
|
+
if ("flipX" in child) child.flipX = false;
|
|
645
|
+
if ("flipY" in child) child.flipY = false;
|
|
646
|
+
child.scaleX = sx;
|
|
647
|
+
child.scaleY = sy;
|
|
648
|
+
child.rotation = beta;
|
|
649
|
+
child.skewX = 0;
|
|
650
|
+
child.skewY = Math.atan2(Math.sin(alpha1 - beta), Math.cos(alpha1 - beta));
|
|
651
|
+
} else if (pose.hasAngle || opts.restAngle !== void 0 || opts.angleOffset !== void 0 || opts.clipAngles !== void 0) {
|
|
563
652
|
const rest = opts.restAngle ?? -Math.PI * .5;
|
|
564
653
|
const mirror = opts.mirrorBlade !== false;
|
|
565
654
|
const aimLeft = Math.cos(pose.rotation) < -1e-4;
|
|
@@ -567,8 +656,13 @@ var ImageObject = class extends DisplayObject {
|
|
|
567
656
|
if (Math.abs(Math.sin(rest)) >= Math.abs(Math.cos(rest))) child.flipX = aimLeft;
|
|
568
657
|
else child.flipY = aimLeft;
|
|
569
658
|
}
|
|
570
|
-
|
|
571
|
-
|
|
659
|
+
if (opts.baseScale !== void 0) {
|
|
660
|
+
child.scaleX = bsx;
|
|
661
|
+
child.scaleY = bsy;
|
|
662
|
+
}
|
|
663
|
+
child.skewX = 0;
|
|
664
|
+
child.skewY = 0;
|
|
665
|
+
child.rotation = pose.rotation - rest + (mirror && aimLeft ? -totalOffset : totalOffset);
|
|
572
666
|
}
|
|
573
667
|
if (opts.baseZIndex !== false) {
|
|
574
668
|
const baseZ = opts.baseZIndex ?? this.zIndex;
|
|
@@ -628,6 +722,7 @@ var SpriteObject = class extends ImageObject {
|
|
|
628
722
|
_activeDirBase = null;
|
|
629
723
|
_activeDirIndex = -1;
|
|
630
724
|
_animListeners = /* @__PURE__ */ new Set();
|
|
725
|
+
_equipmentBindings = /* @__PURE__ */ new Set();
|
|
631
726
|
constructor(scene, x, y, key, frame) {
|
|
632
727
|
super(scene, x, y, key, frame, "Sprite");
|
|
633
728
|
}
|
|
@@ -714,14 +809,15 @@ var SpriteObject = class extends ImageObject {
|
|
|
714
809
|
const targetAnim = grp.dirClips[dirIdx] ?? grp.dirClips[0];
|
|
715
810
|
const sameBase = this._playing && this._activeDirBase === grp.baseKey;
|
|
716
811
|
this._activeDirIndex = dirIdx;
|
|
717
|
-
if (sameBase && this._anim === targetAnim) {
|
|
812
|
+
if (sameBase && this._anim === targetAnim && opts.startFrame === void 0) {
|
|
718
813
|
if (opts.timeScale !== void 0) this.setTimeScale(opts.timeScale);
|
|
719
814
|
this._activeDirBase = grp.baseKey;
|
|
720
815
|
return this;
|
|
721
816
|
}
|
|
722
817
|
this.play(targetAnim, {
|
|
723
818
|
ignoreIfPlaying: false,
|
|
724
|
-
|
|
819
|
+
startFrame: opts.startFrame,
|
|
820
|
+
preservePhase: opts.startFrame !== void 0 ? Boolean(opts.preservePhase) : sameBase ? opts.preservePhase !== false : Boolean(opts.preservePhase),
|
|
725
821
|
timeScale: opts.timeScale,
|
|
726
822
|
repeat: opts.repeat
|
|
727
823
|
});
|
|
@@ -821,8 +917,129 @@ var SpriteObject = class extends ImageObject {
|
|
|
821
917
|
this.scene._unregisterAnimatedSprite(this);
|
|
822
918
|
this.emit("animcomplete", anim.key, this);
|
|
823
919
|
}
|
|
920
|
+
setFrame(frame) {
|
|
921
|
+
super.setFrame(frame);
|
|
922
|
+
if (this._equipmentBindings && this._equipmentBindings.size > 0) this._syncEquipment();
|
|
923
|
+
return this;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Bind a 3D depth-holdout equipment `ImageObject` / `SpriteObject` (baked via `@holtjs/craft/three` `baker.bakeEquipment`)
|
|
927
|
+
* in exact lockstep with this character sprite:
|
|
928
|
+
* - Automatically resolves `<prefix>/<clip>/d<dir>/f<frame>` on every animation frame & direction turn
|
|
929
|
+
* - Aligns ground-origin `ax/ay` pivots (`useFramePivot()`), `x/y`, `flipX/flipY`, `scale`, `rotation`, `skew`, and `zIndex + zOffset`
|
|
930
|
+
* - Automatically hides `1x1` fully-occluded frames (`0` wasted GPU/Canvas2D draw calls or stray 2.5D shadows!)
|
|
931
|
+
* - Supports O(1) hot-swapping via `binding.setPrefix('equip/axe')` or `binding.setPrefix(null)` (unequip)
|
|
932
|
+
*/
|
|
933
|
+
bindEquipment(target, prefix, opts = {}) {
|
|
934
|
+
let curPrefix = prefix;
|
|
935
|
+
let curTexKey = opts.textureKey;
|
|
936
|
+
const zOffset = opts.zOffset === void 0 ? 1 : opts.zOffset;
|
|
937
|
+
const offsetX = opts.offsetX ?? 0;
|
|
938
|
+
const offsetY = opts.offsetY ?? 0;
|
|
939
|
+
const alphaMul = opts.alpha ?? 1;
|
|
940
|
+
const resolveEquipFrame = (tex) => {
|
|
941
|
+
if (!curPrefix) return null;
|
|
942
|
+
const hf = this.frame;
|
|
943
|
+
if (!hf) return null;
|
|
944
|
+
if (hf.clip && hf.animFrameIndex !== null) {
|
|
945
|
+
if (hf.dir !== null && hf.dir !== void 0) {
|
|
946
|
+
const k1 = `${curPrefix}/${hf.clip}/d${hf.dir}/f${hf.animFrameIndex}`;
|
|
947
|
+
if (tex.has(k1)) return k1;
|
|
948
|
+
const k2 = `${curPrefix}/${hf.clip}/${hf.dir}/${hf.animFrameIndex}`;
|
|
949
|
+
if (tex.has(k2)) return k2;
|
|
950
|
+
} else {
|
|
951
|
+
const k1 = `${curPrefix}/${hf.clip}/f${hf.animFrameIndex}`;
|
|
952
|
+
if (tex.has(k1)) return k1;
|
|
953
|
+
const k2 = `${curPrefix}/${hf.clip}/${hf.animFrameIndex}`;
|
|
954
|
+
if (tex.has(k2)) return k2;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const rawName = String(hf.name);
|
|
958
|
+
if (hf.actor && rawName.startsWith(`${hf.actor}/`)) {
|
|
959
|
+
const cand = `${curPrefix}${rawName.slice(hf.actor.length)}`;
|
|
960
|
+
if (tex.has(cand)) return cand;
|
|
961
|
+
}
|
|
962
|
+
const m = /(?:^|\/)([^/]+\/(?:d\d+\/)?f?\d+)$/.exec(rawName);
|
|
963
|
+
if (m) {
|
|
964
|
+
const cand = `${curPrefix}/${m[1]}`;
|
|
965
|
+
if (tex.has(cand)) return cand;
|
|
966
|
+
}
|
|
967
|
+
if (tex.has(curPrefix)) return curPrefix;
|
|
968
|
+
return null;
|
|
969
|
+
};
|
|
970
|
+
const binding = {
|
|
971
|
+
target,
|
|
972
|
+
get prefix() {
|
|
973
|
+
return curPrefix;
|
|
974
|
+
},
|
|
975
|
+
set prefix(v) {
|
|
976
|
+
curPrefix = v;
|
|
977
|
+
binding.sync();
|
|
978
|
+
},
|
|
979
|
+
enabled: true,
|
|
980
|
+
setPrefix(nextPrefix, textureKey) {
|
|
981
|
+
curPrefix = nextPrefix;
|
|
982
|
+
if (textureKey !== void 0) curTexKey = textureKey;
|
|
983
|
+
binding.sync();
|
|
984
|
+
return binding;
|
|
985
|
+
},
|
|
986
|
+
sync: () => {
|
|
987
|
+
if (!target.active || !this.active) return false;
|
|
988
|
+
if (!binding.enabled || !curPrefix || !this.visible) {
|
|
989
|
+
target.visible = false;
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
const tex = curTexKey ? this.scene.textures.get(curTexKey) : target.texture;
|
|
993
|
+
if (!tex) {
|
|
994
|
+
target.visible = false;
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
const frameKey = resolveEquipFrame(tex);
|
|
998
|
+
if (!frameKey) {
|
|
999
|
+
target.visible = false;
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
if (target.texture !== tex) target.setTexture(tex.key, frameKey);
|
|
1003
|
+
else if (target.frame?.name !== frameKey) target.setFrame(frameKey);
|
|
1004
|
+
target.useFramePivot();
|
|
1005
|
+
if (target.frame.empty || target.frame.cutWidth <= 1 && target.frame.cutHeight <= 1) {
|
|
1006
|
+
target.visible = false;
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
target.visible = true;
|
|
1010
|
+
target.x = this.x + offsetX;
|
|
1011
|
+
target.y = this.y + offsetY;
|
|
1012
|
+
target.flipX = this.flipX;
|
|
1013
|
+
target.flipY = this.flipY;
|
|
1014
|
+
target.scaleX = this.scaleX;
|
|
1015
|
+
target.scaleY = this.scaleY;
|
|
1016
|
+
target.rotation = this.rotation;
|
|
1017
|
+
target.skewX = this.skewX;
|
|
1018
|
+
target.skewY = this.skewY;
|
|
1019
|
+
target.alpha = this.alpha * alphaMul;
|
|
1020
|
+
if (zOffset !== false) target.setZIndex(this.zIndex + zOffset);
|
|
1021
|
+
return true;
|
|
1022
|
+
},
|
|
1023
|
+
destroy: () => {
|
|
1024
|
+
this._equipmentBindings.delete(binding);
|
|
1025
|
+
if (this._equipmentBindings.size === 0) this.scene._unregisterEquippedSprite(this);
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
this._equipmentBindings.add(binding);
|
|
1029
|
+
this.scene._registerEquippedSprite(this);
|
|
1030
|
+
binding.sync();
|
|
1031
|
+
return binding;
|
|
1032
|
+
}
|
|
1033
|
+
/** Internal synchronization hook invoked on frame changes, post-update, and pre-render. */
|
|
1034
|
+
_syncEquipment() {
|
|
1035
|
+
for (const b of this._equipmentBindings) if (!b.target.active) this._equipmentBindings.delete(b);
|
|
1036
|
+
else b.sync();
|
|
1037
|
+
if (this._equipmentBindings.size === 0) this.scene._unregisterEquippedSprite(this);
|
|
1038
|
+
}
|
|
824
1039
|
destroy(fromScene) {
|
|
825
1040
|
this.scene._unregisterAnimatedSprite(this);
|
|
1041
|
+
this.scene._unregisterEquippedSprite(this);
|
|
1042
|
+
this._equipmentBindings.clear();
|
|
826
1043
|
this._animListeners.clear();
|
|
827
1044
|
this._anim = null;
|
|
828
1045
|
this._playing = false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as ScaleMode, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, _ as SpriteSheetConfig, d as AtlasJsonLike, g as GlTextureHost, p as Frame, r as AnimationManager, u as StageAnimation, v as Texture, x as TextureManager, y as TextureImageOptions } from "./anims-
|
|
1
|
+
import { I as ScaleMode, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, _ as SpriteSheetConfig, d as AtlasJsonLike, g as GlTextureHost, p as Frame, r as AnimationManager, u as StageAnimation, v as Texture, x as TextureManager, y as TextureImageOptions } from "./anims-xOSYNG79.js";
|
|
2
2
|
import { c as TweenManager, u as TweenStats } from "./tween-BiF1FUvc.js";
|
|
3
3
|
interface CameraFollowOptions {
|
|
4
4
|
/** Horizontal smoothing factor in `(0, 1]` (`1` = instant lock; default `1`). */
|
|
@@ -301,17 +301,18 @@ declare class ImageObject extends DisplayObject {
|
|
|
301
301
|
y: number;
|
|
302
302
|
} | null;
|
|
303
303
|
/**
|
|
304
|
-
* Read the full transformed 2D pose (`x`, `y`, `rotation`, `zBias`, `hasAngle`
|
|
305
|
-
*
|
|
306
|
-
*
|
|
304
|
+
* Read the full transformed 2D pose (`x`, `y`, `rotation`, `zBias`, `hasAngle`, plus 2x2 projected basis `ux, uy, vx, vy`
|
|
305
|
+
* when baked via `@holtjs/craft/three` `charKit.handBasisSocket`) transforming tangent/basis vectors through the exact
|
|
306
|
+
* `flip -> scale -> rotate/skew -> parentContainer` Jacobian!
|
|
307
307
|
*/
|
|
308
308
|
getAnchorPose(name: string, space?: 'local' | 'parent' | 'world', out?: AnchorPose2D): AnchorPose2D | null;
|
|
309
309
|
/**
|
|
310
310
|
* Align an equipped weapon/tool `DisplayObject` (`axe`, `spear`, `torch`, `shield`) to a named socket (`'hand'`) in one call:
|
|
311
|
-
* -
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
* -
|
|
311
|
+
* - When the socket provides a 2x2 projected 3D basis (`handBasisSocket`), solves the exact 6-DOF affine matrix
|
|
312
|
+
* (`scaleX`, `scaleY`, `rotation`, `skewY`) capturing shaft perspective foreshortening (`||u|| < 1`), `45°/30°`
|
|
313
|
+
* non-orthogonal isometric blade shear (`u · v != 0`), automatic chirality blade reflection, and per-clip wrist angles (`clipAngles`)!
|
|
314
|
+
* - Falls back cleanly to rigid `rotation` + `O(2)` `mirrorBlade` when given a 4-tuple `[x, y, angleRad, zBias]`.
|
|
315
|
+
* - Applies `zBias` (`+1` in front of body, `-1` behind body) via `child.setZIndex(baseZIndex + zBias)`.
|
|
315
316
|
*/
|
|
316
317
|
syncAttachment(child: DisplayObject, anchorName: string, opts?: SyncAttachmentOptions): boolean;
|
|
317
318
|
setTint(color: number): this;
|
|
@@ -323,12 +324,22 @@ declare class ImageObject extends DisplayObject {
|
|
|
323
324
|
interface AnchorPose2D {
|
|
324
325
|
x: number;
|
|
325
326
|
y: number;
|
|
326
|
-
/** Transformed 2D aim/shaft angle in radians (`[-PI, PI]`), accounting for `flipX`, `flipY`, `rotation`, and ancestor `Container`s. */
|
|
327
|
+
/** Transformed 2D aim/shaft angle in radians (`[-PI, PI]`), accounting for `flipX`, `flipY`, `rotation`, `skew`, and ancestor `Container`s. */
|
|
327
328
|
rotation: number;
|
|
328
329
|
/** Front/back occlusion hint (`+1` in front of body, `-1` behind body). */
|
|
329
330
|
zBias: number;
|
|
330
|
-
/** True when the baked frame socket included an explicit 3D->2D projected angle (`
|
|
331
|
+
/** True when the baked frame socket included an explicit 3D->2D projected angle (`>= 4` elements). */
|
|
331
332
|
hasAngle: boolean;
|
|
333
|
+
/** True when the baked frame socket included a full 2x2 projected 3D->2D basis (`8-tuple` from `@holtjs/craft/three` `handBasisSocket`). */
|
|
334
|
+
hasBasis?: boolean;
|
|
335
|
+
/** Transformed 2D projected shaft basis `(ux, uy)` (`hypot(ux, uy)` encodes perspective/orthographic foreshortening!). */
|
|
336
|
+
ux?: number;
|
|
337
|
+
uy?: number;
|
|
338
|
+
/** Transformed 2D projected blade/transverse basis `(vx, vy)` (`u · v != 0` encodes `45°/30°` isometric shear!). */
|
|
339
|
+
vx?: number;
|
|
340
|
+
vy?: number;
|
|
341
|
+
/** Projected shaft foreshortening length `hypot(ux, uy)`. */
|
|
342
|
+
foreshorten?: number;
|
|
332
343
|
}
|
|
333
344
|
interface SyncAttachmentOptions {
|
|
334
345
|
/**
|
|
@@ -336,15 +347,47 @@ interface SyncAttachmentOptions {
|
|
|
336
347
|
* Default `-Math.PI / 2` (pointing straight UP `-Y`, matching upright weapons/tools baked along `+Y` in `@holtjs/craft/three`).
|
|
337
348
|
*/
|
|
338
349
|
readonly restAngle?: number;
|
|
339
|
-
/** Additional additive angle offset in radians (
|
|
350
|
+
/** Additional additive wrist/grip angle offset in radians (in 2x2 basis mode, rotates inside the 3D grip plane before projection!). */
|
|
340
351
|
readonly angleOffset?: number;
|
|
341
|
-
/**
|
|
352
|
+
/** Per-clip wrist/grip angle offsets in radians (e.g. `{ walk: 0.66, idle: 0.66, thrust: 0 }` so spears carry tilted 38° and thrust flat!). */
|
|
353
|
+
readonly clipAngles?: Readonly<Record<string, number>>;
|
|
354
|
+
/** Explicit clip name override when looking up `clipAngles` (defaults to `this.frame.clip` or `SpriteObject.currentAnimKey`). */
|
|
355
|
+
readonly clip?: string;
|
|
356
|
+
/** Base sprite scale (`1` default, or e.g. `0.5` for 2x supersampled sprites) applied before 2x2 foreshortening & shear. */
|
|
357
|
+
readonly baseScale?: number | readonly [number, number];
|
|
358
|
+
/** Enable full 6-DOF affine foreshortening + isometric shear when the socket carries an 8-tuple basis (`default = true`). */
|
|
359
|
+
readonly affineBasis?: boolean;
|
|
360
|
+
/** Minimum foreshortening clamp `[0.02..1]` preventing edge-on 2D sprites from collapsing to 0 width (`default = 0.22`). */
|
|
361
|
+
readonly minForeshorten?: number;
|
|
362
|
+
/** Mirror asymmetric blades (axes, scythes, pistols) across their shaft axis when aiming left (`cos < 0`) in 4-tuple rigid mode (`default = true`). */
|
|
342
363
|
readonly mirrorBlade?: boolean;
|
|
343
364
|
/** Coordinate space used to align `child` (`'local' | 'parent' | 'world'`; default `'parent'`). */
|
|
344
365
|
readonly space?: 'local' | 'parent' | 'world';
|
|
345
366
|
/** Base `zIndex` around which `pose.zBias` (`+1` front / `-1` behind) is applied (`default = this.zIndex`; `false` skips `zIndex`). */
|
|
346
367
|
readonly baseZIndex?: number | false;
|
|
347
368
|
}
|
|
369
|
+
interface BindEquipmentOptions {
|
|
370
|
+
/** Optional explicit texture key when equipment frames live in a separate atlas from `target.texture`. */
|
|
371
|
+
readonly textureKey?: string;
|
|
372
|
+
/** Relative `zIndex` offset applied over the host sprite (`default = 1` so depth-holdout equipment layers above the body; `false` skips `zIndex`). */
|
|
373
|
+
readonly zOffset?: number | false;
|
|
374
|
+
/** Optional position offset `(offsetX, offsetY)` in parent space (`default = 0, 0`). */
|
|
375
|
+
readonly offsetX?: number;
|
|
376
|
+
readonly offsetY?: number;
|
|
377
|
+
/** Optional multiplicative alpha (`default = 1`). */
|
|
378
|
+
readonly alpha?: number;
|
|
379
|
+
}
|
|
380
|
+
interface EquipmentBinding {
|
|
381
|
+
readonly target: ImageObject;
|
|
382
|
+
prefix: string | null;
|
|
383
|
+
enabled: boolean;
|
|
384
|
+
/** O(1) hot-swap to another baked equipment prefix (e.g. `'equip/axe'` -> `'equip/spear'`), or `null` to unequip/hide! */
|
|
385
|
+
setPrefix(nextPrefix: string | null, textureKey?: string): this;
|
|
386
|
+
/** Immediately re-synchronize frame, `ax/ay` pivot, `flipX`, transform, and visibility with the host `SpriteObject`. */
|
|
387
|
+
sync(): boolean;
|
|
388
|
+
/** Unbind and remove from automatic per-step synchronization. */
|
|
389
|
+
destroy(): void;
|
|
390
|
+
}
|
|
348
391
|
interface SpritePlayOptions {
|
|
349
392
|
/** Keep current animation running untouched when already playing the requested key (default `false`, or pass boolean shorthand `sprite.play(key, true)`). */
|
|
350
393
|
readonly ignoreIfPlaying?: boolean;
|
|
@@ -362,7 +405,9 @@ interface DirectionalPlayOptions {
|
|
|
362
405
|
readonly cameraYaw?: number;
|
|
363
406
|
/** Override baked `atlasYaw` in radians (defaults to `group.atlasYaw`, e.g. `Math.PI / 4` from `@holtjs/craft/three`). */
|
|
364
407
|
readonly atlasYaw?: number;
|
|
365
|
-
/**
|
|
408
|
+
/** Zero-based frame index to start on (`default = 0` when starting a new clip; when explicitly set, overrides `preservePhase` and restarts even on the same direction). */
|
|
409
|
+
readonly startFrame?: number;
|
|
410
|
+
/** Preserve walk-cycle phase when switching between directions of the same `baseKey` (`default = true` unless `startFrame` is explicitly set). */
|
|
366
411
|
readonly preservePhase?: boolean;
|
|
367
412
|
/** Playback speed multiplier (default `1`). */
|
|
368
413
|
readonly timeScale?: number;
|
|
@@ -389,6 +434,7 @@ declare class SpriteObject extends ImageObject {
|
|
|
389
434
|
private _activeDirBase;
|
|
390
435
|
private _activeDirIndex;
|
|
391
436
|
private readonly _animListeners;
|
|
437
|
+
private readonly _equipmentBindings;
|
|
392
438
|
constructor(scene: SceneHostLike, x: number, y: number, key: string, frame?: string | number);
|
|
393
439
|
get currentAnim(): StageAnimation | null;
|
|
394
440
|
get currentAnimKey(): string | null;
|
|
@@ -417,6 +463,18 @@ declare class SpriteObject extends ImageObject {
|
|
|
417
463
|
_stepAnim(deltaMs: number): void;
|
|
418
464
|
private _applyAnimFrame;
|
|
419
465
|
private _finishAnim;
|
|
466
|
+
setFrame(frame: string | number): this;
|
|
467
|
+
/**
|
|
468
|
+
* Bind a 3D depth-holdout equipment `ImageObject` / `SpriteObject` (baked via `@holtjs/craft/three` `baker.bakeEquipment`)
|
|
469
|
+
* in exact lockstep with this character sprite:
|
|
470
|
+
* - Automatically resolves `<prefix>/<clip>/d<dir>/f<frame>` on every animation frame & direction turn
|
|
471
|
+
* - Aligns ground-origin `ax/ay` pivots (`useFramePivot()`), `x/y`, `flipX/flipY`, `scale`, `rotation`, `skew`, and `zIndex + zOffset`
|
|
472
|
+
* - Automatically hides `1x1` fully-occluded frames (`0` wasted GPU/Canvas2D draw calls or stray 2.5D shadows!)
|
|
473
|
+
* - Supports O(1) hot-swapping via `binding.setPrefix('equip/axe')` or `binding.setPrefix(null)` (unequip)
|
|
474
|
+
*/
|
|
475
|
+
bindEquipment(target: ImageObject, prefix: string | null, opts?: BindEquipmentOptions): EquipmentBinding;
|
|
476
|
+
/** Internal synchronization hook invoked on frame changes, post-update, and pre-render. */
|
|
477
|
+
_syncEquipment(): void;
|
|
420
478
|
destroy(fromScene?: boolean): void;
|
|
421
479
|
}
|
|
422
480
|
declare class NineSliceObject extends DisplayObject {
|
|
@@ -1813,6 +1871,7 @@ declare class Scene {
|
|
|
1813
1871
|
/** Deterministic EngineClock-driven tween & spring manager (auto-stepped in `Game.step()`). */
|
|
1814
1872
|
readonly tweens: TweenManager;
|
|
1815
1873
|
private readonly _animatedSprites;
|
|
1874
|
+
private readonly _equippedSprites;
|
|
1816
1875
|
private _nodesCreated;
|
|
1817
1876
|
private _nodesDestroyed;
|
|
1818
1877
|
private _disposersRan;
|
|
@@ -1870,6 +1929,9 @@ declare class Scene {
|
|
|
1870
1929
|
_registerAnimatedSprite(sprite: SpriteObject): void;
|
|
1871
1930
|
_unregisterAnimatedSprite(sprite: SpriteObject): void;
|
|
1872
1931
|
_stepAnimations(deltaMs: number): void;
|
|
1932
|
+
_registerEquippedSprite(sprite: SpriteObject): void;
|
|
1933
|
+
_unregisterEquippedSprite(sprite: SpriteObject): void;
|
|
1934
|
+
_syncEquipmentBindings(): void;
|
|
1873
1935
|
_invalidateTextGl(): void;
|
|
1874
1936
|
_destroy(): void;
|
|
1875
1937
|
}
|
|
@@ -1935,4 +1997,4 @@ declare class Game {
|
|
|
1935
1997
|
step(time: number, delta: number): void;
|
|
1936
1998
|
destroy(removeCanvas?: boolean): void;
|
|
1937
1999
|
}
|
|
1938
|
-
export { WebGpuBootstrapResult as $, createInputRecorder as A,
|
|
2000
|
+
export { WebGpuBootstrapResult as $, createInputRecorder as A, NineSliceObject as At, SceneDigestSurfaceEntry as B, SpriteAnimEventListener as Bt, RecordedInputEntry as C, EquipmentBinding as Ct, TimelineClickOptions as D, InstancedColumns as Dt, StagePlugin as E, InstancedBatchObject as Et, SceneDigestEngineSandbox as F, RectangleObject as Ft, InputConfig as G, TextStyleConfig as Gt, SceneDigestSurfaces as H, SpritePlayOptions as Ht, SceneDigestNode as I, SceneHostLike as It, Pointer as J, CameraFollowOptions as Jt, InputPlugin as K, TileSpriteObject as Kt, SceneDigestOptions as L, ShapeBatchColumns as Lt, createInputTimeline as M, PanelOpenSide as Mt, SceneDigest as N, PanelStyleConfig as Nt, TimelineDragOptions as O, MsdfIconConfig as Ot, SceneDigestActiveFocus as P, RectClipMask as Pt, RequestWebGpuOptions as Q, SceneDigestOverlayStats as R, ShapeBatchObject as Rt, InputTimelinePlugin as S, DisplaySemantics as St, StageKernel as T, ImageObject as Tt, buildSceneDigest as U, SyncAttachmentOptions as Ut, SceneDigestSurfaceSource as V, SpriteObject as Vt, sanitizeTrackToken as W, TextObject as Wt, RendererWebGpu as X, HiDpiScaleLike as Xt, PointerSample as Y, HiDpiConfigureOptions as Yt, RendererWebGpuOptions as Z, ActionMap as _, CustomPassOptions as _t, GameLoop as a, RendererGlOptions as at, InputTargetSpec as b, DisplayObject as bt, LoaderPlugin as c, StageRenderTarget as ct, SceneCtor as d, BlitterObject as dt, WebGpuCanvasContextLike as et, SceneInput as f, Bob as ft, ViewportFitResult as g, CustomPassObject as gt, StageRenderer as h, CustomPassCallback as ht, GameConfig as i, RendererGl as it, createInputReplay as j, PanelObject as jt, TimelineKeyOptions as k, MsdfIconObject as kt, ScaleManager as l, AnchorPose2D as lt, SceneManager as m, ContainerFiltersShim as mt, EngineClockSnapshot as n, requestWebGpuDevice as nt, GameObjectFactory as o, RendererStats as ot, SceneLifecycleStats as p, Container as pt, KeyboardPlugin as q, Camera as qt, Game as r, Renderer2D as rt, JsonCache as s, Stage2DCustomImageHandler as st, EngineClock as t, WebGpuDeviceLike as tt, Scene as u, BindEquipmentOptions as ut, InputProvider as v, DirectionalPlayOptions as vt, StageInputEvent as w, Graphics as wt, InputTimelineOptions as x, DisplayObjectType as xt, InputRecorderPlugin as y, DisplayList as yt, SceneDigestSandbox as z, ShapeBatchStyleDefaults as zt };
|