@zylem/behaviors 0.3.0 → 0.4.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/LICENSE +21 -0
- package/dist/{behavior-system-DYbx-x_-.d.ts → behavior-system-DSNek0W9.d.ts} +205 -29
- package/dist/{chunk-RER2IDPW.js → chunk-4URF65BR.js} +1 -0
- package/dist/chunk-4URF65BR.js.map +1 -0
- package/dist/{chunk-YYJP62QD.js → chunk-4V7TIRO2.js} +1 -0
- package/dist/chunk-4V7TIRO2.js.map +1 -0
- package/dist/{chunk-F7E23E26.js → chunk-4WH2ZN7P.js} +1 -0
- package/dist/chunk-4WH2ZN7P.js.map +1 -0
- package/dist/{chunk-VPZ32CCD.js → chunk-5SM5SH5O.js} +29 -28
- package/dist/chunk-5SM5SH5O.js.map +1 -0
- package/dist/{chunk-L76JG73P.js → chunk-5XZWTFGF.js} +7 -4
- package/dist/chunk-5XZWTFGF.js.map +1 -0
- package/dist/{chunk-HIBJDA5Z.js → chunk-64HKCSXD.js} +21 -17
- package/dist/chunk-64HKCSXD.js.map +1 -0
- package/dist/{chunk-WSKD7GY3.js → chunk-7JJEIADR.js} +1 -0
- package/dist/chunk-7JJEIADR.js.map +1 -0
- package/dist/{chunk-F6LFX4V3.js → chunk-BXP4K7RF.js} +3 -2
- package/dist/chunk-BXP4K7RF.js.map +1 -0
- package/dist/{chunk-2HKY6WF7.js → chunk-EIWQM6U3.js} +1 -0
- package/dist/chunk-EIWQM6U3.js.map +1 -0
- package/dist/{chunk-YDLO5M7S.js → chunk-EZNCCO4L.js} +1 -0
- package/dist/chunk-EZNCCO4L.js.map +1 -0
- package/dist/{chunk-T2P4JTQN.js → chunk-FRJDQM23.js} +110 -155
- package/dist/chunk-FRJDQM23.js.map +1 -0
- package/dist/{chunk-FHDYJ5WP.js → chunk-FTDZAKZW.js} +5 -17
- package/dist/chunk-FTDZAKZW.js.map +1 -0
- package/dist/{chunk-D53GNZXP.js → chunk-GFARAJV2.js} +6 -7
- package/dist/chunk-GFARAJV2.js.map +1 -0
- package/dist/{chunk-IQRG5BAZ.js → chunk-GTLA6LOJ.js} +18 -23
- package/dist/chunk-GTLA6LOJ.js.map +1 -0
- package/dist/{chunk-VO5J64DG.js → chunk-H4TJ7X4O.js} +4 -6
- package/dist/chunk-H4TJ7X4O.js.map +1 -0
- package/dist/{chunk-6UMC6BB5.js → chunk-HNESASBB.js} +7 -8
- package/dist/chunk-HNESASBB.js.map +1 -0
- package/dist/{chunk-4DVDFCVY.js → chunk-HZMY3TT4.js} +1 -0
- package/dist/chunk-HZMY3TT4.js.map +1 -0
- package/dist/{chunk-2HLZBWGD.js → chunk-IZJFUAXB.js} +1 -0
- package/dist/chunk-IZJFUAXB.js.map +1 -0
- package/dist/{chunk-UFHYR2LV.js → chunk-JXMF4NUI.js} +51 -2
- package/dist/chunk-JXMF4NUI.js.map +1 -0
- package/dist/{chunk-ZHBD65AZ.js → chunk-KDY5N6J4.js} +1 -0
- package/dist/chunk-KDY5N6J4.js.map +1 -0
- package/dist/chunk-KFFETUAL.js +40 -0
- package/dist/chunk-KFFETUAL.js.map +1 -0
- package/dist/chunk-LL4FLHIY.js +12 -0
- package/dist/chunk-LL4FLHIY.js.map +1 -0
- package/dist/{chunk-BC3IJYS7.js → chunk-MJFMNRMZ.js} +15 -15
- package/dist/chunk-MJFMNRMZ.js.map +1 -0
- package/dist/{chunk-WHKPWIQO.js → chunk-OHCPV2NT.js} +1 -0
- package/dist/chunk-OHCPV2NT.js.map +1 -0
- package/dist/{chunk-RQWWUML4.js → chunk-OTLSUYQQ.js} +2 -1
- package/dist/chunk-OTLSUYQQ.js.map +1 -0
- package/dist/{chunk-E4HTCQPK.js → chunk-PWF757B6.js} +7 -8
- package/dist/chunk-PWF757B6.js.map +1 -0
- package/dist/{chunk-4EWASZHB.js → chunk-QVCMJ4Q2.js} +1 -0
- package/dist/chunk-QVCMJ4Q2.js.map +1 -0
- package/dist/{chunk-FOOM42MK.js → chunk-RONH2KDI.js} +12 -13
- package/dist/chunk-RONH2KDI.js.map +1 -0
- package/dist/chunk-RTRFJVCZ.js +454 -0
- package/dist/chunk-RTRFJVCZ.js.map +1 -0
- package/dist/{chunk-IEA7F73P.js → chunk-UL6Q5HDP.js} +25 -2
- package/dist/chunk-UL6Q5HDP.js.map +1 -0
- package/dist/{chunk-K6CWKFHL.js → chunk-UYFOLI2X.js} +1 -0
- package/dist/chunk-UYFOLI2X.js.map +1 -0
- package/dist/{chunk-RD2YTTXY.js → chunk-V74N7D6Q.js} +9 -8
- package/dist/chunk-V74N7D6Q.js.map +1 -0
- package/dist/{chunk-ERS6SNA5.js → chunk-WOMHL23C.js} +2 -1
- package/dist/chunk-WOMHL23C.js.map +1 -0
- package/dist/{chunk-RHW3IDQX.js → chunk-WWVD5DR5.js} +1 -0
- package/dist/chunk-WWVD5DR5.js.map +1 -0
- package/dist/{chunk-SBACY5SU.js → chunk-WXXXJ22R.js} +14 -15
- package/dist/chunk-WXXXJ22R.js.map +1 -0
- package/dist/{chunk-6Y3GB76J.js → chunk-XLUJDKCT.js} +9 -8
- package/dist/chunk-XLUJDKCT.js.map +1 -0
- package/dist/{chunk-7Y6JVZ5H.js → chunk-XP3ASVGJ.js} +14 -10
- package/dist/chunk-XP3ASVGJ.js.map +1 -0
- package/dist/{chunk-7U4WFBWM.js → chunk-Y7YIAWPW.js} +11 -0
- package/dist/chunk-Y7YIAWPW.js.map +1 -0
- package/dist/{chunk-7IZ36Y5G.js → chunk-ZA43LPRM.js} +5 -24
- package/dist/chunk-ZA43LPRM.js.map +1 -0
- package/dist/{chunk-J5XLB24H.js → chunk-ZRQWSURL.js} +3 -2
- package/dist/chunk-ZRQWSURL.js.map +1 -0
- package/dist/cooldown.d.ts +2 -1
- package/dist/cooldown.js +3 -2
- package/dist/cooldown.js.map +1 -0
- package/dist/coordinators/boundary-ricochet-3d.d.ts +12 -5
- package/dist/coordinators/boundary-ricochet-3d.js +4 -2
- package/dist/coordinators/boundary-ricochet-3d.js.map +1 -0
- package/dist/coordinators/boundary-ricochet.d.ts +9 -7
- package/dist/coordinators/boundary-ricochet.js +4 -2
- package/dist/coordinators/boundary-ricochet.js.map +1 -0
- package/dist/coordinators/first-person-shooter.d.ts +9 -8
- package/dist/coordinators/first-person-shooter.js +4 -3
- package/dist/coordinators/first-person-shooter.js.map +1 -0
- package/dist/coordinators/multidirectional-space-shooter.d.ts +12 -9
- package/dist/coordinators/multidirectional-space-shooter.js +5 -4
- package/dist/coordinators/multidirectional-space-shooter.js.map +1 -0
- package/dist/coordinators/top-down-shooter.d.ts +9 -8
- package/dist/coordinators/top-down-shooter.js +5 -4
- package/dist/coordinators/top-down-shooter.js.map +1 -0
- package/dist/core.d.ts +4 -4
- package/dist/core.js +9 -36
- package/dist/core.js.map +1 -0
- package/dist/destructible-3d.d.ts +2 -1
- package/dist/destructible-3d.js +4 -3
- package/dist/destructible-3d.js.map +1 -0
- package/dist/destructible-prebake.js +2 -1
- package/dist/destructible-prebake.js.map +1 -0
- package/dist/first-person.d.ts +12 -12
- package/dist/first-person.js +12 -11
- package/dist/first-person.js.map +1 -0
- package/dist/index.d.ts +37 -14
- package/dist/index.js +85 -55
- package/dist/index.js.map +1 -0
- package/dist/jumper-2d.d.ts +7 -6
- package/dist/jumper-2d.js +8 -7
- package/dist/jumper-2d.js.map +1 -0
- package/dist/jumper-3d.d.ts +12 -11
- package/dist/jumper-3d.js +9 -8
- package/dist/jumper-3d.js.map +1 -0
- package/dist/{moveable-BCRpjAQb.d.ts → moveable-BLTHO7Jq.d.ts} +2 -78
- package/dist/particle-emitter/presets.js +2 -1
- package/dist/particle-emitter/presets.js.map +1 -0
- package/dist/particle-emitter.d.ts +1 -1
- package/dist/particle-emitter.js +5 -4
- package/dist/particle-emitter.js.map +1 -0
- package/dist/platformer-2d.d.ts +306 -0
- package/dist/platformer-2d.js +23 -0
- package/dist/platformer-2d.js.map +1 -0
- package/dist/platformer-3d.d.ts +74 -87
- package/dist/platformer-3d.js +7 -6
- package/dist/platformer-3d.js.map +1 -0
- package/dist/ricochet-2d.d.ts +1 -1
- package/dist/ricochet-2d.js +5 -4
- package/dist/ricochet-2d.js.map +1 -0
- package/dist/ricochet-3d.d.ts +1 -1
- package/dist/ricochet-3d.js +5 -4
- package/dist/ricochet-3d.js.map +1 -0
- package/dist/runtime-2d.d.ts +93 -2
- package/dist/runtime-2d.js +146 -22
- package/dist/runtime-2d.js.map +1 -0
- package/dist/screen-visibility.d.ts +2 -1
- package/dist/screen-visibility.js +3 -2
- package/dist/screen-visibility.js.map +1 -0
- package/dist/screen-wrap.d.ts +2 -1
- package/dist/screen-wrap.js +5 -4
- package/dist/screen-wrap.js.map +1 -0
- package/dist/shooter-2d.d.ts +5 -3
- package/dist/shooter-2d.js +5 -4
- package/dist/shooter-2d.js.map +1 -0
- package/dist/shooter-fire-DGripl0z.d.ts +55 -0
- package/dist/thruster.d.ts +8 -18
- package/dist/thruster.js +9 -8
- package/dist/thruster.js.map +1 -0
- package/dist/top-down-movement.d.ts +7 -4
- package/dist/top-down-movement.js +8 -7
- package/dist/top-down-movement.js.map +1 -0
- package/dist/{use-behavior-D_82jAL3.d.ts → use-behavior-h9-T5FSv.d.ts} +1 -1
- package/dist/world-boundary-2d.d.ts +2 -1
- package/dist/world-boundary-2d.js +6 -5
- package/dist/world-boundary-2d.js.map +1 -0
- package/dist/world-boundary-3d.d.ts +2 -1
- package/dist/world-boundary-3d.js +6 -5
- package/dist/world-boundary-3d.js.map +1 -0
- package/package.json +8 -7
- package/dist/chunk-23HQH3GJ.js +0 -34
- package/dist/chunk-K4UBXSZL.js +0 -175
- package/dist/runtime-pong.d.ts +0 -92
- package/dist/runtime-pong.js +0 -37
|
@@ -10,6 +10,15 @@ function normalizeDirection2D(x, y) {
|
|
|
10
10
|
y: y / length
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
+
function normalizeDirection2DInto(x, y, out) {
|
|
14
|
+
const length = Math.hypot(x, y);
|
|
15
|
+
if (length <= DIRECTION_EPSILON) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
out.x = x / length;
|
|
19
|
+
out.y = y / length;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
13
22
|
function angleFromDirection2D(direction) {
|
|
14
23
|
return Math.atan2(-direction.x, direction.y);
|
|
15
24
|
}
|
|
@@ -42,8 +51,10 @@ function getRotationAngle2D(rotation) {
|
|
|
42
51
|
|
|
43
52
|
export {
|
|
44
53
|
normalizeDirection2D,
|
|
54
|
+
normalizeDirection2DInto,
|
|
45
55
|
angleFromDirection2D,
|
|
46
56
|
directionFromAngle2D,
|
|
47
57
|
rotateLocalOffset2D,
|
|
48
58
|
getRotationAngle2D
|
|
49
59
|
};
|
|
60
|
+
//# sourceMappingURL=chunk-Y7YIAWPW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/behaviors/shared/direction-2d.ts"],"sourcesContent":["export interface Direction2D {\n\tx: number;\n\ty: number;\n}\n\nconst DIRECTION_EPSILON = 1e-6;\n\nexport function normalizeDirection2D(x: number, y: number): Direction2D | null {\n\tconst length = Math.hypot(x, y);\n\tif (length <= DIRECTION_EPSILON) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tx: x / length,\n\t\ty: y / length,\n\t};\n}\n\n/**\n * Allocation-free variant of {@link normalizeDirection2D} for per-frame paths.\n * Writes the normalized direction into `out` and returns true, or returns\n * false (leaving `out` untouched) when the input is effectively zero-length.\n */\nexport function normalizeDirection2DInto(\n\tx: number,\n\ty: number,\n\tout: Direction2D,\n): boolean {\n\tconst length = Math.hypot(x, y);\n\tif (length <= DIRECTION_EPSILON) {\n\t\treturn false;\n\t}\n\n\tout.x = x / length;\n\tout.y = y / length;\n\treturn true;\n}\n\nexport function angleFromDirection2D(direction: Direction2D): number {\n\treturn Math.atan2(-direction.x, direction.y);\n}\n\nexport function directionFromAngle2D(angle: number): Direction2D {\n\treturn {\n\t\tx: Math.sin(-angle),\n\t\ty: Math.cos(-angle),\n\t};\n}\n\nexport function rightFromAngle2D(angle: number): Direction2D {\n\treturn {\n\t\tx: Math.cos(angle),\n\t\ty: Math.sin(angle),\n\t};\n}\n\nexport function rotateLocalOffset2D(\n\toffset: Direction2D,\n\tangle: number,\n): Direction2D {\n\tconst right = rightFromAngle2D(angle);\n\tconst forward = directionFromAngle2D(angle);\n\treturn {\n\t\tx: right.x * offset.x + forward.x * offset.y,\n\t\ty: right.y * offset.x + forward.y * offset.y,\n\t};\n}\n\nexport function getRotationAngle2D(\n\trotation: { x: number; y: number; z: number; w: number },\n): number {\n\treturn Math.atan2(\n\t\t2 * (rotation.w * rotation.z + rotation.x * rotation.y),\n\t\t1 - 2 * (rotation.y * rotation.y + rotation.z * rotation.z),\n\t);\n}\n"],"mappings":";AAKA,IAAM,oBAAoB;AAEnB,SAAS,qBAAqB,GAAW,GAA+B;AAC9E,QAAM,SAAS,KAAK,MAAM,GAAG,CAAC;AAC9B,MAAI,UAAU,mBAAmB;AAChC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG,IAAI;AAAA,IACP,GAAG,IAAI;AAAA,EACR;AACD;AAOO,SAAS,yBACf,GACA,GACA,KACU;AACV,QAAM,SAAS,KAAK,MAAM,GAAG,CAAC;AAC9B,MAAI,UAAU,mBAAmB;AAChC,WAAO;AAAA,EACR;AAEA,MAAI,IAAI,IAAI;AACZ,MAAI,IAAI,IAAI;AACZ,SAAO;AACR;AAEO,SAAS,qBAAqB,WAAgC;AACpE,SAAO,KAAK,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC;AAC5C;AAEO,SAAS,qBAAqB,OAA4B;AAChE,SAAO;AAAA,IACN,GAAG,KAAK,IAAI,CAAC,KAAK;AAAA,IAClB,GAAG,KAAK,IAAI,CAAC,KAAK;AAAA,EACnB;AACD;AAEO,SAAS,iBAAiB,OAA4B;AAC5D,SAAO;AAAA,IACN,GAAG,KAAK,IAAI,KAAK;AAAA,IACjB,GAAG,KAAK,IAAI,KAAK;AAAA,EAClB;AACD;AAEO,SAAS,oBACf,QACA,OACc;AACd,QAAM,QAAQ,iBAAiB,KAAK;AACpC,QAAM,UAAU,qBAAqB,KAAK;AAC1C,SAAO;AAAA,IACN,GAAG,MAAM,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO;AAAA,IAC3C,GAAG,MAAM,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO;AAAA,EAC5C;AACD;AAEO,SAAS,mBACf,UACS;AACT,SAAO,KAAK;AAAA,IACX,KAAK,SAAS,IAAI,SAAS,IAAI,SAAS,IAAI,SAAS;AAAA,IACrD,IAAI,KAAK,SAAS,IAAI,SAAS,IAAI,SAAS,IAAI,SAAS;AAAA,EAC1D;AACD;","names":[]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-IEA7F73P.js";
|
|
2
|
+
fireShooter2DIfRequested
|
|
3
|
+
} from "./chunk-UL6Q5HDP.js";
|
|
5
4
|
import {
|
|
6
5
|
createTopDownMovementInputComponent
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-EIWQM6U3.js";
|
|
8
7
|
|
|
9
8
|
// src/lib/coordinators/top-down-shooter.coordinator.ts
|
|
10
9
|
var TopDownShooterCoordinator = class {
|
|
@@ -24,29 +23,11 @@ var TopDownShooterCoordinator = class {
|
|
|
24
23
|
this.entity.$topDownMovement.moveY = input.moveY;
|
|
25
24
|
this.entity.$topDownMovement.faceX = input.aimX;
|
|
26
25
|
this.entity.$topDownMovement.faceY = input.aimY;
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const sourcePosition = this.entity.body?.translation();
|
|
31
|
-
if (!sourcePosition) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const aim = resolveAim2D(
|
|
35
|
-
input.aimX,
|
|
36
|
-
input.aimY,
|
|
37
|
-
getEntityFacingAngle2D(this.entity)
|
|
38
|
-
);
|
|
39
|
-
void this.shooter.fire({
|
|
40
|
-
source: this.entity,
|
|
41
|
-
stage: this.stage,
|
|
42
|
-
target: {
|
|
43
|
-
x: sourcePosition.x + aim.direction.x,
|
|
44
|
-
y: sourcePosition.y + aim.direction.y
|
|
45
|
-
}
|
|
46
|
-
});
|
|
26
|
+
fireShooter2DIfRequested(this.entity, this.shooter, this.stage, input);
|
|
47
27
|
}
|
|
48
28
|
};
|
|
49
29
|
|
|
50
30
|
export {
|
|
51
31
|
TopDownShooterCoordinator
|
|
52
32
|
};
|
|
33
|
+
//# sourceMappingURL=chunk-ZA43LPRM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/coordinators/top-down-shooter.coordinator.ts"],"sourcesContent":["import {\n\tcreateTopDownMovementInputComponent,\n\ttype TopDownMovementInputComponent,\n} from '../behaviors/top-down-movement/components';\nimport type {\n\tShooter2DHandle,\n\tShooter2DSourceEntity,\n\tShooter2DStageLike,\n} from '../behaviors/shooter-2d/shooter-2d.descriptor';\nimport {\n\tfireShooter2DIfRequested,\n\ttype Shooter2DAimFireInput,\n} from './shared/shooter-fire';\n\nexport interface TopDownShooterInput extends Shooter2DAimFireInput {\n\tmoveX: number;\n\tmoveY: number;\n}\n\nexport type TopDownShooterEntity = Shooter2DSourceEntity & {\n\t$topDownMovement?: TopDownMovementInputComponent;\n};\n\n/**\n * Coordinator that fans a single input snapshot out to the top-down movement\n * behavior (move + face axes) and the Shooter2D behavior (fire requests).\n */\nexport class TopDownShooterCoordinator {\n\tconstructor(\n\t\tprivate entity: TopDownShooterEntity,\n\t\tprivate shooter: Shooter2DHandle,\n\t\tprivate stage: Shooter2DStageLike,\n\t) {}\n\n\tpublic update(input: TopDownShooterInput): void {\n\t\tif (!this.entity.$topDownMovement) {\n\t\t\tthis.entity.$topDownMovement = createTopDownMovementInputComponent();\n\t\t}\n\n\t\tthis.entity.$topDownMovement.moveX = input.moveX;\n\t\tthis.entity.$topDownMovement.moveY = input.moveY;\n\t\tthis.entity.$topDownMovement.faceX = input.aimX;\n\t\tthis.entity.$topDownMovement.faceY = input.aimY;\n\n\t\tfireShooter2DIfRequested(this.entity, this.shooter, this.stage, input);\n\t}\n}\n"],"mappings":";;;;;;;;AA2BO,IAAM,4BAAN,MAAgC;AAAA,EACtC,YACS,QACA,SACA,OACP;AAHO;AACA;AACA;AAAA,EACN;AAAA,EAHM;AAAA,EACA;AAAA,EACA;AAAA,EAGF,OAAO,OAAkC;AAC/C,QAAI,CAAC,KAAK,OAAO,kBAAkB;AAClC,WAAK,OAAO,mBAAmB,oCAAoC;AAAA,IACpE;AAEA,SAAK,OAAO,iBAAiB,QAAQ,MAAM;AAC3C,SAAK,OAAO,iBAAiB,QAAQ,MAAM;AAC3C,SAAK,OAAO,iBAAiB,QAAQ,MAAM;AAC3C,SAAK,OAAO,iBAAiB,QAAQ,MAAM;AAE3C,6BAAyB,KAAK,QAAQ,KAAK,SAAS,KAAK,OAAO,KAAK;AAAA,EACtE;AACD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineBehavior
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EZNCCO4L.js";
|
|
4
4
|
|
|
5
5
|
// src/lib/behaviors/cooldown/cooldown-store.ts
|
|
6
6
|
import { proxy } from "valtio";
|
|
@@ -53,7 +53,7 @@ function getCooldownStore() {
|
|
|
53
53
|
return cooldownStore;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// src/lib/behaviors/cooldown/cooldown
|
|
56
|
+
// src/lib/behaviors/cooldown/cooldown.descriptor.ts
|
|
57
57
|
var COOLDOWN_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:cooldown");
|
|
58
58
|
var CooldownSystem = class {
|
|
59
59
|
constructor(getBehaviorLinks) {
|
|
@@ -115,3 +115,4 @@ export {
|
|
|
115
115
|
getCooldownStore,
|
|
116
116
|
CooldownBehavior
|
|
117
117
|
};
|
|
118
|
+
//# sourceMappingURL=chunk-ZRQWSURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/behaviors/cooldown/cooldown-store.ts","../src/lib/behaviors/cooldown/cooldown.descriptor.ts"],"sourcesContent":["import { proxy } from 'valtio';\n\n/**\n * A single cooldown entry in the global store.\n */\nexport interface CooldownEntry {\n\t/** Identifier for this cooldown */\n\tname: string;\n\t/** Total cooldown time in seconds */\n\tduration: number;\n\t/** Time accumulated since last fire */\n\telapsed: number;\n\t/** Whether the cooldown is ready (elapsed >= duration) */\n\tready: boolean;\n\t/** Normalized progress 0..1 (0 = just fired, 1 = ready) */\n\tprogress: number;\n\t/** Whether this cooldown is currently counting down */\n\tactive: boolean;\n}\n\n/**\n * Global reactive cooldown registry (valtio proxy).\n * Accessible from entities, behaviors, and UI components.\n */\nconst cooldownStore = proxy<Record<string, CooldownEntry>>({});\n\n/**\n * Register a named cooldown in the global store.\n * If a cooldown with the same name already exists, it is overwritten.\n *\n * @param name Unique cooldown identifier\n * @param duration Cooldown duration in seconds\n * @param immediate If true, the cooldown starts ready (default: true)\n */\nexport function registerCooldown(\n\tname: string,\n\tduration: number,\n\timmediate: boolean = true,\n): void {\n\tcooldownStore[name] = {\n\t\tname,\n\t\tduration,\n\t\telapsed: immediate ? duration : 0,\n\t\tready: immediate,\n\t\tprogress: immediate ? 1 : 0,\n\t\tactive: !immediate,\n\t};\n}\n\n/**\n * Get a cooldown entry by name.\n * Returns undefined if the cooldown has not been registered.\n */\nexport function getCooldown(name: string): CooldownEntry | undefined {\n\treturn cooldownStore[name];\n}\n\n/**\n * Fire (trigger) a cooldown, resetting its timer.\n * Sets the cooldown to not-ready and starts the countdown.\n */\nexport function fireCooldown(name: string): void {\n\tconst entry = cooldownStore[name];\n\tif (!entry) return;\n\tentry.elapsed = 0;\n\tentry.ready = false;\n\tentry.progress = 0;\n\tentry.active = true;\n}\n\n/**\n * Force a cooldown to ready immediately.\n */\nexport function resetCooldown(name: string): void {\n\tconst entry = cooldownStore[name];\n\tif (!entry) return;\n\tentry.elapsed = entry.duration;\n\tentry.ready = true;\n\tentry.progress = 1;\n\tentry.active = false;\n}\n\n/**\n * Advance all active cooldowns by delta seconds.\n * Called once per frame by the CooldownBehavior system.\n */\nexport function tickCooldowns(delta: number): void {\n\tfor (const name in cooldownStore) {\n\t\tconst entry = cooldownStore[name];\n\t\tif (!entry.active) continue;\n\n\t\tentry.elapsed += delta;\n\t\tif (entry.elapsed >= entry.duration) {\n\t\t\tentry.elapsed = entry.duration;\n\t\t\tentry.ready = true;\n\t\t\tentry.progress = 1;\n\t\t\tentry.active = false;\n\t\t} else {\n\t\t\tentry.progress = entry.duration > 0 ? entry.elapsed / entry.duration : 1;\n\t\t}\n\t}\n}\n\n/**\n * Get the raw cooldown store (for advanced/debugging use).\n */\nexport function getCooldownStore(): Record<string, CooldownEntry> {\n\treturn cooldownStore;\n}\n","/**\n * CooldownBehavior\n *\n * A stage-scoped behavior that manages named cooldowns via the global CooldownStore.\n * Entities use this to register, check, and fire cooldowns.\n * UI components (CooldownIcon) can read from the same store.\n */\n\nimport { defineBehavior, type BehaviorRef } from '../behavior-descriptor';\nimport type { BehaviorEntityLink, BehaviorSystem } from '../behavior-system';\nimport {\n\tregisterCooldown,\n\tgetCooldown,\n\tfireCooldown,\n\tresetCooldown,\n\ttickCooldowns,\n} from './cooldown-store';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Options\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface CooldownConfig {\n\t/** Duration in seconds */\n\tduration: number;\n\t/** Whether the cooldown starts ready (default: true) */\n\timmediate?: boolean;\n}\n\nexport interface CooldownOptions {\n\t/**\n\t * Named cooldowns to register.\n\t * Keys are the cooldown names, values are their config.\n\t */\n\tcooldowns: Record<string, CooldownConfig>;\n}\n\ninterface CompiledCooldownEntry {\n\tname: string;\n\tduration: number;\n\timmediate: boolean;\n}\n\nconst COOLDOWN_BEHAVIOR_KEY = Symbol.for('zylem:behavior:cooldown');\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Handle\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Handle methods returned by entity.use(CooldownBehavior, ...).\n */\nexport interface CooldownHandle {\n\t/** Check if a named cooldown is ready */\n\tisReady(name: string): boolean;\n\t/** Fire (trigger) a named cooldown, resetting its timer */\n\tfire(name: string): void;\n\t/** Force a cooldown to ready immediately */\n\treset(name: string): void;\n\t/** Get cooldown progress 0..1 (0 = just fired, 1 = ready) */\n\tgetProgress(name: string): number;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// System\n// ─────────────────────────────────────────────────────────────────────────────\n\nclass CooldownSystem implements BehaviorSystem {\n\tconstructor(\n\t\tprivate getBehaviorLinks?: (key: symbol) => Iterable<BehaviorEntityLink>,\n\t) { }\n\n\tupdate(_ecs: unknown, delta: number): void {\n\t\tconst links = this.getBehaviorLinks?.(COOLDOWN_BEHAVIOR_KEY);\n\t\tif (links) {\n\t\t\tfor (const link of links) {\n\t\t\t\tensureCooldownEntriesRegistered(link.ref as BehaviorRef<CooldownOptions>);\n\t\t\t}\n\t\t}\n\n\t\ttickCooldowns(delta);\n\t}\n\n\tdestroy(_ecs: unknown): void { }\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Handle factory\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction createCooldownHandle(ref: BehaviorRef<CooldownOptions>): CooldownHandle {\n\tensureCooldownEntriesRegistered(ref);\n\n\treturn {\n\t\tisReady: (name: string) => getCooldown(name)?.ready ?? false,\n\t\tfire: (name: string) => fireCooldown(name),\n\t\treset: (name: string) => resetCooldown(name),\n\t\tgetProgress: (name: string) => getCooldown(name)?.progress ?? 1,\n\t};\n}\n\nfunction getCompiledCooldownEntries(\n\tref: BehaviorRef<CooldownOptions>,\n): CompiledCooldownEntry[] {\n\tconst compiled = (ref as any).__compiledCooldownEntries as CompiledCooldownEntry[] | undefined;\n\tif (compiled) return compiled;\n\n\tconst entries = Object.entries(ref.options.cooldowns).map(([name, config]) => ({\n\t\tname,\n\t\tduration: config.duration,\n\t\timmediate: config.immediate ?? true,\n\t}));\n\t(ref as any).__compiledCooldownEntries = entries;\n\treturn entries;\n}\n\nfunction ensureCooldownEntriesRegistered(ref: BehaviorRef<CooldownOptions>): void {\n\tif ((ref as any).__cooldownsRegistered) return;\n\n\tfor (const entry of getCompiledCooldownEntries(ref)) {\n\t\tregisterCooldown(entry.name, entry.duration, entry.immediate);\n\t}\n\n\t(ref as any).__cooldownsRegistered = true;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Behavior Definition\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * CooldownBehavior\n *\n * @example\n * ```ts\n * import { CooldownBehavior } from '@zylem/game-lib/behavior';\n * import { moveBy } from '@zylem/game-lib/actions';\n *\n * const hero = createBox({ ... });\n * const cd = hero.use(CooldownBehavior, {\n * cooldowns: {\n * attack: { duration: 5 },\n * dash: { duration: 2, immediate: false },\n * },\n * });\n *\n * hero.onUpdate(({ me, inputs }) => {\n * if (cd.isReady('attack') && inputs.p1.buttons.A.pressed) {\n * cd.fire('attack');\n * // perform attack\n * }\n * if (cd.isReady('dash') && inputs.p1.buttons.B.pressed) {\n * cd.fire('dash');\n * me.runAction(moveBy({ x: 10, duration: 0.3 }));\n * }\n * });\n * ```\n */\nexport const CooldownBehavior = defineBehavior<CooldownOptions, CooldownHandle>({\n\tname: 'cooldown',\n\tdefaultOptions: { cooldowns: {} },\n\tsystemFactory: (ctx) =>\n\t\tnew CooldownSystem(ctx.getBehaviorLinks),\n\tcreateHandle: createCooldownHandle,\n});\n"],"mappings":";;;;;AAAA,SAAS,aAAa;AAwBtB,IAAM,gBAAgB,MAAqC,CAAC,CAAC;AAUtD,SAAS,iBACf,MACA,UACA,YAAqB,MACd;AACP,gBAAc,IAAI,IAAI;AAAA,IACrB;AAAA,IACA;AAAA,IACA,SAAS,YAAY,WAAW;AA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SAAS,qBAAqB,KAAmD;AAChF,kCAAgC,GAAG;AAEnC,SAAO;AAAA,IACN,SAAS,CAAC,SAAiB,YAAY,IAAI,GAAG,SAAS;AAAA,IACvD,MAAM,CAAC,SAAiB,aAAa,IAAI;AAAA,IACzC,OAAO,CAAC,SAAiB,cAAc,IAAI;AAAA,IAC3C,aAAa,CAAC,SAAiB,YAAY,IAAI,GAAG,YAAY;AAAA,EAC/D;AACD;AAEA,SAAS,2BACR,KAC0B;AAC1B,QAAM,WAAY,IAAY;AAC9B,MAAI,SAAU,QAAO;AAErB,QAAM,UAAU,OAAO,QAAQ,IAAI,QAAQ,SAAS,EAAE,IAAI,CAAC,CAAC,MAAM,MAAM,OAAO;AAAA,IAC9E;AAAA,IACA,UAAU,OAAO;AAAA,IACjB,WAAW,OAAO,aAAa;AAAA,EAChC,EAAE;AACF,EAAC,IAAY,4BAA4B;AACzC,SAAO;AACR;AAEA,SAAS,gCAAgC,KAAyC;AACjF,MAAK,IAAY,sBAAuB;AAExC,aAAW,SAAS,2BAA2B,GAAG,GAAG;AACpD,qBAAiB,MAAM,MAAM,MAAM,UAAU,MAAM,SAAS;AAAA,EAC7D;AAEA,EAAC,IAAY,wBAAwB;AACtC;AAkCO,IAAM,mBAAmB,eAAgD;AAAA,EAC/E,MAAM;AAAA,EACN,gBAAgB,EAAE,WAAW,CAAC,EAAE;AAAA,EAChC,eAAe,CAAC,QACf,IAAI,eAAe,IAAI,gBAAgB;AAAA,EACxC,cAAc;AACf,CAAC;","names":[]}
|
package/dist/cooldown.d.ts
CHANGED
package/dist/cooldown.js
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
registerCooldown,
|
|
7
7
|
resetCooldown,
|
|
8
8
|
tickCooldowns
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-ZRQWSURL.js";
|
|
10
|
+
import "./chunk-EZNCCO4L.js";
|
|
11
11
|
export {
|
|
12
12
|
CooldownBehavior,
|
|
13
13
|
fireCooldown,
|
|
@@ -17,3 +17,4 @@ export {
|
|
|
17
17
|
resetCooldown,
|
|
18
18
|
tickCooldowns
|
|
19
19
|
};
|
|
20
|
+
//# sourceMappingURL=cooldown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { M as MoveableEntity } from '../moveable-BLTHO7Jq.js';
|
|
2
|
+
import { B as BaseEntityInterface } from '../entity-types-CmtQ-IBp.js';
|
|
3
3
|
import { Ricochet3DHandle } from '../ricochet-3d.js';
|
|
4
4
|
import { WorldBoundary3DHandle } from '../world-boundary-3d.js';
|
|
5
5
|
import 'three';
|
|
6
6
|
import '@dimforge/rapier3d-compat';
|
|
7
|
+
import '../behavior-system-DSNek0W9.js';
|
|
7
8
|
import '../sync-state-machine-CZyspBpj.js';
|
|
8
9
|
import 'typescript-fsm';
|
|
9
|
-
import '../entity-types-CmtQ-IBp.js';
|
|
10
10
|
|
|
11
|
+
/** Entity shape required by the 3D boundary-ricochet coordinator. */
|
|
12
|
+
type BoundaryRicochet3DEntity = BaseEntityInterface & MoveableEntity;
|
|
13
|
+
/**
|
|
14
|
+
* Coordinator that bridges WorldBoundary3DBehavior and Ricochet3DBehavior.
|
|
15
|
+
* Snaps the body back to the boundary's clamped position before reflecting,
|
|
16
|
+
* so fast entities can't tunnel outside the box between frames.
|
|
17
|
+
*/
|
|
11
18
|
declare class BoundaryRicochet3DCoordinator {
|
|
12
19
|
private entity;
|
|
13
20
|
private boundary;
|
|
14
21
|
private ricochet;
|
|
15
|
-
constructor(entity:
|
|
22
|
+
constructor(entity: BoundaryRicochet3DEntity, boundary: WorldBoundary3DHandle, ricochet: Ricochet3DHandle);
|
|
16
23
|
update(): boolean;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
|
-
export { BoundaryRicochet3DCoordinator };
|
|
26
|
+
export { BoundaryRicochet3DCoordinator, type BoundaryRicochet3DEntity };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BoundaryRicochet3DCoordinator
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-KFFETUAL.js";
|
|
4
|
+
import "../chunk-OHCPV2NT.js";
|
|
5
|
+
import "../chunk-LL4FLHIY.js";
|
|
5
6
|
export {
|
|
6
7
|
BoundaryRicochet3DCoordinator
|
|
7
8
|
};
|
|
9
|
+
//# sourceMappingURL=boundary-ricochet-3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { G as GameEntity } from '../behavior-system-DYbx-x_-.js';
|
|
2
1
|
import { Ricochet2DHandle } from '../ricochet-2d.js';
|
|
3
2
|
import { WorldBoundary2DHandle } from '../world-boundary-2d.js';
|
|
4
|
-
import { M as MoveableEntity } from '../moveable-
|
|
5
|
-
import '../entity-types-CmtQ-IBp.js';
|
|
6
|
-
import 'three';
|
|
7
|
-
import '@dimforge/rapier3d-compat';
|
|
3
|
+
import { M as MoveableEntity } from '../moveable-BLTHO7Jq.js';
|
|
4
|
+
import { B as BaseEntityInterface } from '../entity-types-CmtQ-IBp.js';
|
|
8
5
|
import '../sync-state-machine-CZyspBpj.js';
|
|
9
6
|
import 'typescript-fsm';
|
|
7
|
+
import '../behavior-system-DSNek0W9.js';
|
|
8
|
+
import '@dimforge/rapier3d-compat';
|
|
9
|
+
import 'three';
|
|
10
10
|
|
|
11
|
+
/** Entity shape required by the 2D boundary-ricochet coordinator. */
|
|
12
|
+
type BoundaryRicochetEntity = BaseEntityInterface & MoveableEntity;
|
|
11
13
|
/**
|
|
12
14
|
* Coordinator that bridges WorldBoundary2DBehavior and Ricochet2DBehavior.
|
|
13
15
|
*
|
|
@@ -21,7 +23,7 @@ declare class BoundaryRicochetCoordinator {
|
|
|
21
23
|
private entity;
|
|
22
24
|
private boundary;
|
|
23
25
|
private ricochet;
|
|
24
|
-
constructor(entity:
|
|
26
|
+
constructor(entity: BoundaryRicochetEntity, boundary: WorldBoundary2DHandle, ricochet: Ricochet2DHandle);
|
|
25
27
|
/**
|
|
26
28
|
* Update loop - call this every frame.
|
|
27
29
|
* Applies ricochet via transformStore and notifies listeners.
|
|
@@ -31,4 +33,4 @@ declare class BoundaryRicochetCoordinator {
|
|
|
31
33
|
update(): boolean;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
export { BoundaryRicochetCoordinator };
|
|
36
|
+
export { BoundaryRicochetCoordinator, type BoundaryRicochetEntity };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BoundaryRicochetCoordinator
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-XP3ASVGJ.js";
|
|
4
|
+
import "../chunk-KDY5N6J4.js";
|
|
5
|
+
import "../chunk-LL4FLHIY.js";
|
|
5
6
|
export {
|
|
6
7
|
BoundaryRicochetCoordinator
|
|
7
8
|
};
|
|
9
|
+
//# sourceMappingURL=boundary-ricochet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { G as GameEntity } from '../behavior-system-DYbx-x_-.js';
|
|
2
1
|
import { F as FirstPersonInputComponent } from '../components-qWwOsvwh.js';
|
|
3
2
|
import { b as JumpInput3D } from '../components--hjBMTnz.js';
|
|
4
3
|
|
|
@@ -16,20 +15,22 @@ interface FirstPersonShooterInput {
|
|
|
16
15
|
interface FirstPersonShooterControllerHandle {
|
|
17
16
|
getYaw(): number;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
getState(): unknown;
|
|
21
|
-
}
|
|
22
|
-
type FirstPersonShooterEntity = GameEntity<any> & {
|
|
18
|
+
type FirstPersonShooterEntity = {
|
|
23
19
|
$fps?: FirstPersonInputComponent;
|
|
24
20
|
$jumper?: JumpInput3D;
|
|
25
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Coordinator that fans a single input snapshot out to the first-person
|
|
24
|
+
* behavior (`$fps`) and the Jumper3D behavior (`$jumper`), converting local
|
|
25
|
+
* move axes into the camera-relative world direction the jumper uses for
|
|
26
|
+
* air control.
|
|
27
|
+
*/
|
|
26
28
|
declare class FirstPersonShooterCoordinator {
|
|
27
29
|
private entity;
|
|
28
30
|
private fpsController;
|
|
29
|
-
|
|
30
|
-
constructor(entity: FirstPersonShooterEntity, fpsController: FirstPersonShooterControllerHandle, jumper: FirstPersonShooterJumperHandle);
|
|
31
|
+
constructor(entity: FirstPersonShooterEntity, fpsController: FirstPersonShooterControllerHandle);
|
|
31
32
|
update(input: FirstPersonShooterInput): void;
|
|
32
33
|
private getMoveDirWorld;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export { FirstPersonShooterCoordinator, type FirstPersonShooterInput };
|
|
36
|
+
export { FirstPersonShooterCoordinator, type FirstPersonShooterEntity, type FirstPersonShooterInput };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FirstPersonShooterCoordinator
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-H4TJ7X4O.js";
|
|
4
|
+
import "../chunk-QVCMJ4Q2.js";
|
|
5
|
+
import "../chunk-4WH2ZN7P.js";
|
|
6
6
|
export {
|
|
7
7
|
FirstPersonShooterCoordinator
|
|
8
8
|
};
|
|
9
|
+
//# sourceMappingURL=first-person-shooter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { G as GameEntity } from '../behavior-system-DYbx-x_-.js';
|
|
2
1
|
import { T as ThrusterInputComponent } from '../components-B29WHGQN.js';
|
|
3
2
|
import { Shooter2DSourceEntity, Shooter2DHandle, Shooter2DStageLike } from '../shooter-2d.js';
|
|
3
|
+
import { S as Shooter2DAimFireInput } from '../shooter-fire-DGripl0z.js';
|
|
4
|
+
import '../behavior-system-DSNek0W9.js';
|
|
5
|
+
import '@dimforge/rapier3d-compat';
|
|
4
6
|
import '../vector-Bm65-FOG.js';
|
|
5
7
|
import 'three';
|
|
6
|
-
import '@dimforge/rapier3d-compat';
|
|
7
8
|
|
|
8
|
-
interface MultidirectionalSpaceShooterInput {
|
|
9
|
+
interface MultidirectionalSpaceShooterInput extends Shooter2DAimFireInput {
|
|
9
10
|
moveX: number;
|
|
10
11
|
moveY: number;
|
|
11
|
-
aimX: number;
|
|
12
|
-
aimY: number;
|
|
13
|
-
shootPressed: boolean;
|
|
14
|
-
shootHeld: boolean;
|
|
15
12
|
}
|
|
16
|
-
type MultidirectionalSpaceShooterEntity =
|
|
13
|
+
type MultidirectionalSpaceShooterEntity = Shooter2DSourceEntity & {
|
|
17
14
|
$thruster?: ThrusterInputComponent;
|
|
15
|
+
setRotationZ(angle: number): void;
|
|
18
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Coordinator that fans a single input snapshot out to the thruster behavior
|
|
19
|
+
* (vector thrust), entity rotation (aim), and the Shooter2D behavior (fire
|
|
20
|
+
* requests).
|
|
21
|
+
*/
|
|
19
22
|
declare class MultidirectionalSpaceShooterCoordinator {
|
|
20
23
|
private entity;
|
|
21
24
|
private shooter;
|
|
@@ -24,4 +27,4 @@ declare class MultidirectionalSpaceShooterCoordinator {
|
|
|
24
27
|
update(input: MultidirectionalSpaceShooterInput): void;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
export { MultidirectionalSpaceShooterCoordinator, type MultidirectionalSpaceShooterInput };
|
|
30
|
+
export { MultidirectionalSpaceShooterCoordinator, type MultidirectionalSpaceShooterEntity, type MultidirectionalSpaceShooterInput };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MultidirectionalSpaceShooterCoordinator
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-FTDZAKZW.js";
|
|
4
|
+
import "../chunk-UL6Q5HDP.js";
|
|
5
|
+
import "../chunk-IZJFUAXB.js";
|
|
6
|
+
import "../chunk-Y7YIAWPW.js";
|
|
7
7
|
export {
|
|
8
8
|
MultidirectionalSpaceShooterCoordinator
|
|
9
9
|
};
|
|
10
|
+
//# sourceMappingURL=multidirectional-space-shooter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { a as TopDownMovementInputComponent } from '../components-XCpL6IYt.js';
|
|
2
2
|
import { Shooter2DSourceEntity, Shooter2DHandle, Shooter2DStageLike } from '../shooter-2d.js';
|
|
3
|
-
import '../
|
|
3
|
+
import { S as Shooter2DAimFireInput } from '../shooter-fire-DGripl0z.js';
|
|
4
|
+
import '../behavior-system-DSNek0W9.js';
|
|
5
|
+
import '@dimforge/rapier3d-compat';
|
|
4
6
|
import '../vector-Bm65-FOG.js';
|
|
5
7
|
import 'three';
|
|
6
|
-
import '@dimforge/rapier3d-compat';
|
|
7
8
|
|
|
8
|
-
interface TopDownShooterInput {
|
|
9
|
+
interface TopDownShooterInput extends Shooter2DAimFireInput {
|
|
9
10
|
moveX: number;
|
|
10
11
|
moveY: number;
|
|
11
|
-
aimX: number;
|
|
12
|
-
aimY: number;
|
|
13
|
-
shootPressed: boolean;
|
|
14
|
-
shootHeld: boolean;
|
|
15
12
|
}
|
|
16
13
|
type TopDownShooterEntity = Shooter2DSourceEntity & {
|
|
17
14
|
$topDownMovement?: TopDownMovementInputComponent;
|
|
18
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Coordinator that fans a single input snapshot out to the top-down movement
|
|
18
|
+
* behavior (move + face axes) and the Shooter2D behavior (fire requests).
|
|
19
|
+
*/
|
|
19
20
|
declare class TopDownShooterCoordinator {
|
|
20
21
|
private entity;
|
|
21
22
|
private shooter;
|
|
@@ -24,4 +25,4 @@ declare class TopDownShooterCoordinator {
|
|
|
24
25
|
update(input: TopDownShooterInput): void;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export { TopDownShooterCoordinator, type TopDownShooterInput };
|
|
28
|
+
export { TopDownShooterCoordinator, type TopDownShooterEntity, type TopDownShooterInput };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TopDownShooterCoordinator
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-ZA43LPRM.js";
|
|
4
|
+
import "../chunk-UL6Q5HDP.js";
|
|
5
|
+
import "../chunk-EIWQM6U3.js";
|
|
6
|
+
import "../chunk-Y7YIAWPW.js";
|
|
7
7
|
export {
|
|
8
8
|
TopDownShooterCoordinator
|
|
9
9
|
};
|
|
10
|
+
//# sourceMappingURL=top-down-shooter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export { u as
|
|
1
|
+
import { H as VelocityIntentMode, T as TransformState } from './behavior-system-DSNek0W9.js';
|
|
2
|
+
export { B as BaseBehaviorHandle, a as BehaviorDescriptor, b as BehaviorEntityLink, c as BehaviorHandle, d as BehaviorRef, e as BehaviorSystem, f as BehaviorSystemContext, g as BehaviorSystemFactory, C as CreateEntityFn, D as DefineBehaviorConfig, G as GameEntity, h as GameEntityOptions, S as StageBodyKind, i as StageBoundaryDim, j as StageBoundaryDimValue, k as StageEventType, l as StageFirstPersonInput, m as StageFirstPersonOptions, n as StageJumper2DOptions, o as StageJumper3DOptions, p as StagePlatformer3DOptions, q as StagePose, r as StageRicochetDim, s as StageRicochetDimValue, t as StageRicochetOptions, u as StageRicochetReflection, v as StageRicochetReflectionValue, w as StageScreenWrapOptions, x as StageShooter2DOptions, y as StageThrusterOptions, z as StageTopDownOptions, A as StageTopDownPlane, E as StageTopDownPlaneValue, F as StageWorldBoundaryOptions, V as VelocityIntent, W as WasmStageRuntime, I as WasmStageRuntimeOptions, J as createTransformStore, K as defineBehavior } from './behavior-system-DSNek0W9.js';
|
|
3
|
+
export { u as useBehavior } from './use-behavior-h9-T5FSv.js';
|
|
3
4
|
export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent } from './components-BWG1GkZA.js';
|
|
4
|
-
|
|
5
|
-
export { E as EntityWithBody, M as MoveableEntity, V as VelocityIntent, c as createTransformStore, g as getPosition, b as getVelocity, m as makeMoveable, d as move, e as moveForwardXY, f as moveX, h as moveXY, i as moveXZ, j as moveY, k as moveZ, r as resetTransformStore, l as resetVelocity, s as setPosition, n as setPositionX, o as setPositionY, p as setPositionZ, w as wrapAround3D, q as wrapAroundXY } from './moveable-BCRpjAQb.js';
|
|
5
|
+
export { E as EntityWithBody, M as MoveableEntity, g as getPosition, a as getVelocity, m as makeMoveable, b as move, c as moveForwardXY, d as moveX, e as moveXY, f as moveXZ, h as moveY, i as moveZ, r as resetVelocity, s as setPosition, j as setPositionX, k as setPositionY, l as setPositionZ, w as wrapAround3D, n as wrapAroundXY } from './moveable-BLTHO7Jq.js';
|
|
6
6
|
export { V as VEC2_ONE, a as VEC2_ZERO, b as VEC3_ONE, c as VEC3_ZERO, d as Vec2, e as Vec2Components, f as Vec2Input, g as Vec3, h as Vec3Components, i as Vec3Input, j as isVec2Input, k as isVec3Input, n as normalizeVec2, l as normalizeVec3, t as toRapierVector3, m as toThreeVector2, o as toThreeVector3 } from './vector-Bm65-FOG.js';
|
|
7
7
|
export { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
|
|
8
8
|
export { F as FirstPersonPerspective } from './first-person-perspective-C9Mptl0-.js';
|
package/dist/core.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
createPhysicsBodyComponent,
|
|
3
3
|
createTransformComponent,
|
|
4
4
|
useBehavior
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UYFOLI2X.js";
|
|
6
6
|
import {
|
|
7
7
|
StageBodyKind,
|
|
8
8
|
StageBoundaryDim,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
StageRicochetDim,
|
|
11
11
|
StageRicochetReflection,
|
|
12
12
|
StageTopDownPlane
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-4V7TIRO2.js";
|
|
14
14
|
import {
|
|
15
15
|
VEC2_ONE,
|
|
16
16
|
VEC2_ZERO,
|
|
@@ -23,20 +23,20 @@ import {
|
|
|
23
23
|
toRapierVector3,
|
|
24
24
|
toThreeVector2,
|
|
25
25
|
toThreeVector3
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-WWVD5DR5.js";
|
|
27
27
|
import {
|
|
28
28
|
clearVelocityIntent,
|
|
29
29
|
setVelocityIntent
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-OTLSUYQQ.js";
|
|
31
31
|
import {
|
|
32
32
|
SyncStateMachine,
|
|
33
33
|
t
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-4URF65BR.js";
|
|
35
35
|
import {
|
|
36
36
|
defineBehavior
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-EZNCCO4L.js";
|
|
38
38
|
|
|
39
|
-
// src/lib/
|
|
39
|
+
// src/lib/capabilities/transform-store.ts
|
|
40
40
|
import { proxy } from "valtio";
|
|
41
41
|
function createTransformStore(initial) {
|
|
42
42
|
const defaultState = {
|
|
@@ -48,7 +48,6 @@ function createTransformStore(initial) {
|
|
|
48
48
|
dirty: {
|
|
49
49
|
position: false,
|
|
50
50
|
rotation: false,
|
|
51
|
-
velocity: false,
|
|
52
51
|
velocityX: false,
|
|
53
52
|
velocityY: false,
|
|
54
53
|
velocityZ: false,
|
|
@@ -66,34 +65,8 @@ function createTransformStore(initial) {
|
|
|
66
65
|
}
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
|
-
function resetTransformStore(store) {
|
|
70
|
-
store.position.x = 0;
|
|
71
|
-
store.position.y = 0;
|
|
72
|
-
store.position.z = 0;
|
|
73
|
-
store.rotation.x = 0;
|
|
74
|
-
store.rotation.y = 0;
|
|
75
|
-
store.rotation.z = 0;
|
|
76
|
-
store.rotation.w = 1;
|
|
77
|
-
store.velocity.x = 0;
|
|
78
|
-
store.velocity.y = 0;
|
|
79
|
-
store.velocity.z = 0;
|
|
80
|
-
store.angularVelocity.x = 0;
|
|
81
|
-
store.angularVelocity.y = 0;
|
|
82
|
-
store.angularVelocity.z = 0;
|
|
83
|
-
for (const sourceId of Object.keys(store.velocityChannels)) {
|
|
84
|
-
delete store.velocityChannels[sourceId];
|
|
85
|
-
}
|
|
86
|
-
store.dirty.position = false;
|
|
87
|
-
store.dirty.rotation = false;
|
|
88
|
-
store.dirty.velocity = false;
|
|
89
|
-
store.dirty.velocityX = false;
|
|
90
|
-
store.dirty.velocityY = false;
|
|
91
|
-
store.dirty.velocityZ = false;
|
|
92
|
-
store.dirty.velocityChannels = false;
|
|
93
|
-
store.dirty.angularVelocity = false;
|
|
94
|
-
}
|
|
95
68
|
|
|
96
|
-
// src/lib/
|
|
69
|
+
// src/lib/capabilities/moveable.ts
|
|
97
70
|
import { Vector3 } from "three";
|
|
98
71
|
function moveX(entity, delta) {
|
|
99
72
|
if (!entity.transformStore) return;
|
|
@@ -309,7 +282,6 @@ export {
|
|
|
309
282
|
moveZ,
|
|
310
283
|
normalizeVec2,
|
|
311
284
|
normalizeVec3,
|
|
312
|
-
resetTransformStore,
|
|
313
285
|
resetVelocity,
|
|
314
286
|
setPosition,
|
|
315
287
|
setPositionX,
|
|
@@ -324,3 +296,4 @@ export {
|
|
|
324
296
|
wrapAround3D,
|
|
325
297
|
wrapAroundXY
|
|
326
298
|
};
|
|
299
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/capabilities/transform-store.ts","../src/lib/capabilities/moveable.ts","../src/lib/entities/entity.ts"],"sourcesContent":["import { proxy } from 'valtio';\n\nexport type VelocityIntentMode = 'replace' | 'add';\n\nexport interface VelocityIntent {\n\tx?: number;\n\ty?: number;\n\tz?: number;\n\tmode: VelocityIntentMode;\n\tpriority?: number;\n}\n\n/**\n * Transform state managed by Valtio for batched physics updates.\n * \n * This store accumulates transformation intents during the frame,\n * then applies them all at once after onUpdate() callbacks complete.\n * \n * Design decisions:\n * - Position: Accumulated deltas (additive)\n * - Rotation: Last value wins (replacement)\n * - Velocity: Accumulated deltas (additive)\n * - Angular velocity: Accumulated deltas (additive)\n */\nexport interface TransformState {\n\t/** Position deltas to be applied (accumulated) */\n\tposition: { x: number; y: number; z: number };\n\t\n\t/** Rotation quaternion (last value wins) */\n\trotation: { x: number; y: number; z: number; w: number };\n\t\n\t/** Linear velocity (accumulated) */\n\tvelocity: { x: number; y: number; z: number };\n\t\n\t/** Angular velocity (accumulated) */\n\tangularVelocity: { x: number; y: number; z: number };\n\n\t/** Per-source velocity intents composed once per frame */\n\tvelocityChannels: Record<string, VelocityIntent>;\n\t\n\t/** Dirty flags to track what needs to be applied */\n\tdirty: {\n\t\tposition: boolean;\n\t\trotation: boolean;\n\t\tvelocityX: boolean;\n\t\tvelocityY: boolean;\n\t\tvelocityZ: boolean;\n\t\tvelocityChannels: boolean;\n\t\tangularVelocity: boolean;\n\t};\n}\n\n/**\n * Create a new transform store with optional initial values.\n * The store is a Valtio proxy, making it reactive for debugging/visualization.\n * \n * @param initial Optional initial state values\n * @returns Reactive transform state\n */\nexport function createTransformStore(initial?: Partial<TransformState>): TransformState {\n\tconst defaultState: TransformState = {\n\t\tposition: { x: 0, y: 0, z: 0 },\n\t\trotation: { x: 0, y: 0, z: 0, w: 1 },\n\t\tvelocity: { x: 0, y: 0, z: 0 },\n\t\tangularVelocity: { x: 0, y: 0, z: 0 },\n\t\tvelocityChannels: {},\n\t\tdirty: {\n\t\t\tposition: false,\n\t\t\trotation: false,\n\t\t\tvelocityX: false,\n\t\t\tvelocityY: false,\n\t\t\tvelocityZ: false,\n\t\t\tvelocityChannels: false,\n\t\t\tangularVelocity: false,\n\t\t},\n\t};\n\n\treturn proxy({\n\t\t...defaultState,\n\t\t...initial,\n\t\t// Ensure dirty flags are properly initialized even if partial initial state\n\t\tdirty: {\n\t\t\t...defaultState.dirty,\n\t\t\t...initial?.dirty,\n\t\t},\n\t});\n}\n\n","import { Vector3 } from 'three';\nimport { RigidBody, Vector } from '@dimforge/rapier3d-compat';\nimport type { TransformState } from './transform-store';\nimport { createTransformStore } from './transform-store';\nimport { setVelocityIntent } from './velocity-intents';\n\nexport interface EntityWithBody {\n\tbody: RigidBody | null;\n\ttransformStore?: TransformState;\n}\n\n/**\n * Move an entity along the X axis, preserving other velocities.\n */\nexport function moveX(entity: EntityWithBody, delta: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(entity.transformStore, 'actions', { x: delta }, { mode: 'replace' });\n}\n\n/**\n * Move an entity along the Y axis, preserving other velocities.\n */\nexport function moveY(entity: EntityWithBody, delta: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(entity.transformStore, 'actions', { y: delta }, { mode: 'replace' });\n}\n\n/**\n * Move an entity along the Z axis, preserving other velocities.\n */\nexport function moveZ(entity: EntityWithBody, delta: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(entity.transformStore, 'actions', { z: delta }, { mode: 'replace' });\n}\n\n/**\n * Move an entity along the X and Y axis, preserving Z velocity.\n */\nexport function moveXY(entity: EntityWithBody, deltaX: number, deltaY: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(\n\t\tentity.transformStore,\n\t\t'actions',\n\t\t{ x: deltaX, y: deltaY },\n\t\t{ mode: 'replace' },\n\t);\n}\n\n/**\n * Move an entity along the X and Z axis, preserving Y velocity.\n */\nexport function moveXZ(entity: EntityWithBody, deltaX: number, deltaZ: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(\n\t\tentity.transformStore,\n\t\t'actions',\n\t\t{ x: deltaX, z: deltaZ },\n\t\t{ mode: 'replace' },\n\t);\n}\n\n/**\n * Move entity based on a vector, adding to existing velocities.\n */\nexport function move(entity: EntityWithBody, vector: Vector3): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(\n\t\tentity.transformStore,\n\t\t'actions',\n\t\t{ x: vector.x, y: vector.y, z: vector.z },\n\t\t{ mode: 'add' },\n\t);\n}\n\n/**\n * Reset entity velocity\n */\nexport function resetVelocity(entity: EntityWithBody): void {\n\tif (!entity.body) return;\n\tentity.body.setLinvel(new Vector3(0, 0, 0), true);\n\tentity.body.setLinearDamping(5);\n}\n\n/**\n * Move entity forward in 2D space, preserving Z velocity\n */\nexport function moveForwardXY(entity: EntityWithBody, delta: number, rotation2DAngle: number): void {\n\tconst deltaX = Math.sin(-rotation2DAngle) * delta;\n\tconst deltaY = Math.cos(-rotation2DAngle) * delta;\n\tmoveXY(entity, deltaX, deltaY);\n}\n\n/**\n * Get entity position\n */\nexport function getPosition(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.translation();\n}\n\n/**\n * Get entity velocity\n */\nexport function getVelocity(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.linvel();\n}\n\n/**\n * Set entity position\n */\nexport function setPosition(entity: EntityWithBody, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity X position\n */\nexport function setPositionX(entity: EntityWithBody, x: number): void {\n\tif (!entity.body) return;\n\tconst { y, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Y position\n */\nexport function setPositionY(entity: EntityWithBody, y: number): void {\n\tif (!entity.body) return;\n\tconst { x, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Z position\n */\nexport function setPositionZ(entity: EntityWithBody, z: number): void {\n\tif (!entity.body) return;\n\tconst { x, y } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Wrap entity around 2D bounds\n */\nexport function wrapAroundXY(entity: EntityWithBody, boundsX: number, boundsY: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\n\tif (newX !== x || newY !== y) {\n\t\tsetPosition(entity, newX, newY, 0);\n\t}\n}\n\n/**\n * Wrap entity around 3D bounds\n */\nexport function wrapAround3D(entity: EntityWithBody, boundsX: number, boundsY: number, boundsZ: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y, z } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\tconst newZ = z > boundsZ ? -boundsZ : (z < -boundsZ ? boundsZ : z);\n\n\tif (newX !== x || newY !== y || newZ !== z) {\n\t\tsetPosition(entity, newX, newY, newZ);\n\t}\n}\n\n/**\n * Enhanced moveable entity with bound methods\n */\nexport interface MoveableEntity extends EntityWithBody {\n\tmoveX(delta: number): void;\n\tmoveY(delta: number): void;\n\tmoveZ(delta: number): void;\n\tmoveXY(deltaX: number, deltaY: number): void;\n\tmoveXZ(deltaX: number, deltaZ: number): void;\n\tmove(vector: Vector3): void;\n\tresetVelocity(): void;\n\tmoveForwardXY(delta: number, rotation2DAngle: number): void;\n\tgetPosition(): Vector | null;\n\tgetVelocity(): Vector | null;\n\tsetPosition(x: number, y: number, z: number): void;\n\tsetPositionX(x: number): void;\n\tsetPositionY(y: number): void;\n\tsetPositionZ(z: number): void;\n\twrapAroundXY(boundsX: number, boundsY: number): void;\n\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;\n}\n\n/**\n * Enhance an entity with additive movement methods.\n * Automatically creates a transform store if one doesn't exist.\n */\nexport function makeMoveable<T extends EntityWithBody>(entity: T): T & MoveableEntity {\n\tconst moveable = entity as T & MoveableEntity;\n\n\t// Create transform store if it doesn't exist\n\tif (!moveable.transformStore) {\n\t\tmoveable.transformStore = createTransformStore();\n\t}\n\n\tmoveable.moveX = (delta: number) => moveX(entity, delta);\n\tmoveable.moveY = (delta: number) => moveY(entity, delta);\n\tmoveable.moveZ = (delta: number) => moveZ(entity, delta);\n\tmoveable.moveXY = (deltaX: number, deltaY: number) => moveXY(entity, deltaX, deltaY);\n\tmoveable.moveXZ = (deltaX: number, deltaZ: number) => moveXZ(entity, deltaX, deltaZ);\n\tmoveable.move = (vector: Vector3) => move(entity, vector);\n\tmoveable.resetVelocity = () => resetVelocity(entity);\n\tmoveable.moveForwardXY = (delta: number, rotation2DAngle: number) => moveForwardXY(entity, delta, rotation2DAngle);\n\tmoveable.getPosition = () => getPosition(entity);\n\tmoveable.getVelocity = () => getVelocity(entity);\n\tmoveable.setPosition = (x: number, y: number, z: number) => setPosition(entity, x, y, z);\n\tmoveable.setPositionX = (x: number) => setPositionX(entity, x);\n\tmoveable.setPositionY = (y: number) => setPositionY(entity, y);\n\tmoveable.setPositionZ = (z: number) => setPositionZ(entity, z);\n\tmoveable.wrapAroundXY = (boundsX: number, boundsY: number) => wrapAroundXY(entity, boundsX, boundsY);\n\tmoveable.wrapAround3D = (boundsX: number, boundsY: number, boundsZ: number) => wrapAround3D(entity, boundsX, boundsY, boundsZ);\n\n\treturn moveable;\n}","import type { Collider, RigidBody } from '@dimforge/rapier3d-compat';\nimport type {\n\tBehaviorDescriptor,\n\tBehaviorHandle,\n\tBehaviorRef,\n} from '../behaviors/behavior-descriptor';\nimport type { TransformState } from '../capabilities/transform-store';\n\n/**\n * Minimal, runtime-agnostic entity options contract.\n *\n * The full engine entity (in `@zylem/game-lib`) provides a richer options type,\n * but behaviors only rely on this loose shape.\n */\nexport interface GameEntityOptions {\n\t[key: string]: any;\n\tname?: string;\n}\n\n/**\n * Structural stand-in for the engine `GameEntity`.\n *\n * Behaviors annotate against this loose contract so that `@zylem/behaviors`\n * (and its `@zylem/behaviors/core` surface) never has to depend on the concrete\n * `@zylem/game-lib` entity implementation. The real engine entity is\n * structurally assignable to this type.\n */\nexport class GameEntity<TOptions = unknown> {\n\t[key: string]: any;\n\n\tuuid!: string;\n\tname!: string;\n\ttype!: string;\n\toptions?: TOptions & Record<string, unknown>;\n\tgroup: any = null;\n\tmesh?: any;\n\tmaterials?: any[];\n\tbody: RigidBody | null = null;\n\tcollider: Collider | null = null;\n\tcolliderDesc?: any;\n\tcolliderDescs: any[] = [];\n\tbodyDesc?: any;\n\tphysicsAttached = false;\n\truntimeHandle?: number;\n\ttransformStore?: TransformState;\n\tnodeDestroy?: any;\n\tisInstanced?: boolean;\n\n\tprivate __behaviorRefs: BehaviorRef<any>[] = [];\n\n\tcreate(): this {\n\t\treturn this;\n\t}\n\n\tonCleanup(callback: () => void): this {\n\t\tvoid callback;\n\t\treturn this;\n\t}\n\n\tsetPosition(_x: number, _y: number, _z: number): void {}\n\tsetRotation(_x: number, _y: number, _z: number): void {}\n\tsetRotationZ(_z: number): void {}\n\tsetScale(_x: number, _y: number, _z: number): void {}\n\n\t/**\n\t * Attach a behavior to this entity. The real engine entity does substantially\n\t * more, but this functional stub stores the merged ref and builds the handle\n\t * so descriptor/handle logic (and tests that drive behaviors directly) work\n\t * without the full engine.\n\t */\n\tuse<\n\t\tO extends Record<string, any>,\n\t\tH extends Record<string, any> = Record<string, never>,\n\t>(\n\t\tdescriptor: BehaviorDescriptor<O, H>,\n\t\toptions?: Partial<O>,\n\t): BehaviorHandle<O, H> {\n\t\tconst mergedOptions = {\n\t\t\t...(descriptor.defaultOptions as O),\n\t\t\t...(options ?? {}),\n\t\t} as O;\n\t\tconst ref: BehaviorRef<O> = { descriptor, options: mergedOptions };\n\t\tthis.__behaviorRefs.push(ref as BehaviorRef<any>);\n\n\t\tconst baseHandle = {\n\t\t\tgetFSM: () => ref.fsm ?? null,\n\t\t\tgetOptions: () => ref.options,\n\t\t\tref,\n\t\t};\n\t\tconst extra = descriptor.createHandle\n\t\t\t? descriptor.createHandle(ref)\n\t\t\t: ({} as H);\n\t\treturn { ...baseHandle, ...extra } as BehaviorHandle<O, H>;\n\t}\n\n\t/** Live behavior refs attached via {@link use}. */\n\tgetBehaviorRefs(): BehaviorRef<any>[] {\n\t\treturn this.__behaviorRefs;\n\t}\n}\n\n/**\n * Factory contract injected into behavior systems via\n * {@link BehaviorSystemContext.createEntity}. The host engine supplies the real\n * entity factory at stage-construction time.\n */\nexport type CreateEntityFn = (\n\toptions?: Partial<GameEntityOptions>,\n) => GameEntity<GameEntityOptions>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AA2Df,SAAS,qBAAqB,SAAmD;AACvF,QAAM,eAA+B;AAAA,IACpC,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IAC7B,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IACnC,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IAC7B,iBAAiB,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IACpC,kBAAkB,CAAC;AAAA,IACnB,OAAO;AAAA,MACN,UAAU;AAAA,MACV,UAAU;AAAA,MACV,WAAW;AAAA,M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,EAChC,SAAS,IAAY,IAAY,IAAkB;AAAA,EAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpD,IAIC,YACA,SACuB;AACvB,UAAM,gBAAgB;AAAA,MACrB,GAAI,WAAW;AAAA,MACf,GAAI,WAAW,CAAC;AAAA,IACjB;AACA,UAAM,MAAsB,EAAE,YAAY,SAAS,cAAc;AACjE,SAAK,eAAe,KAAK,GAAuB;AAEhD,UAAM,aAAa;AAAA,MAClB,QAAQ,MAAM,IAAI,OAAO;AAAA,MACzB,YAAY,MAAM,IAAI;AAAA,MACtB;AAAA,IACD;AACA,UAAM,QAAQ,WAAW,eACtB,WAAW,aAAa,GAAG,IAC1B,CAAC;AACL,WAAO,EAAE,GAAG,YAAY,GAAG,MAAM;AAAA,EAClC;AAAA;AAAA,EAGA,kBAAsC;AACrC,WAAO,KAAK;AAAA,EACb;AACD;","names":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { a as BehaviorDescriptor } from './behavior-system-
|
|
1
|
+
import { a as BehaviorDescriptor } from './behavior-system-DSNek0W9.js';
|
|
2
2
|
import { Material } from 'three';
|
|
3
3
|
import { FractureOptions, DestructibleMesh } from '@dgreenheck/three-pinata';
|
|
4
4
|
export { DestructibleMesh, FractureOptions, VoronoiOptions } from '@dgreenheck/three-pinata';
|
|
5
5
|
export { D as DestructiblePrebakeWorkerAPI, P as PlainBufferGeometryPayload, a as PlainFractureOptions, c as PrebakeWorkerRequest, d as PrebakeWorkerResponse } from './payload-BQzu-oY_.js';
|
|
6
|
+
import '@dimforge/rapier3d-compat';
|
|
6
7
|
|
|
7
8
|
type FractureOptionsInput = NonNullable<ConstructorParameters<typeof FractureOptions>[0]>;
|
|
8
9
|
type Destructible3DFragmentColliderShape = 'convexHull' | 'cuboid' | 'trimesh';
|
package/dist/destructible-3d.js
CHANGED
|
@@ -2,11 +2,12 @@ import {
|
|
|
2
2
|
Destructible3DBehavior,
|
|
3
3
|
DestructibleMesh,
|
|
4
4
|
FractureOptions
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-BXP4K7RF.js";
|
|
6
|
+
import "./chunk-HZMY3TT4.js";
|
|
7
|
+
import "./chunk-EZNCCO4L.js";
|
|
8
8
|
export {
|
|
9
9
|
Destructible3DBehavior,
|
|
10
10
|
DestructibleMesh,
|
|
11
11
|
FractureOptions
|
|
12
12
|
};
|
|
13
|
+
//# sourceMappingURL=destructible-3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|