@zylem/behaviors 0.2.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/README.md +26 -0
- package/dist/behavior-system-DYbx-x_-.d.ts +307 -0
- package/dist/chunk-2C3Z5GE7.js +176 -0
- package/dist/chunk-2C3Z5GE7.js.map +1 -0
- package/dist/chunk-2CLT36VB.js +241 -0
- package/dist/chunk-2CLT36VB.js.map +1 -0
- package/dist/chunk-3PYGRHAL.js +35 -0
- package/dist/chunk-3PYGRHAL.js.map +1 -0
- package/dist/chunk-4I6E6DGV.js +212 -0
- package/dist/chunk-4I6E6DGV.js.map +1 -0
- package/dist/chunk-4URF65BR.js +44 -0
- package/dist/chunk-4URF65BR.js.map +1 -0
- package/dist/chunk-6C6NXNEW.js +38 -0
- package/dist/chunk-6C6NXNEW.js.map +1 -0
- package/dist/chunk-ARJWUNRE.js +431 -0
- package/dist/chunk-ARJWUNRE.js.map +1 -0
- package/dist/chunk-BXP4K7RF.js +1205 -0
- package/dist/chunk-BXP4K7RF.js.map +1 -0
- package/dist/chunk-DYLH6K7B.js +44 -0
- package/dist/chunk-DYLH6K7B.js.map +1 -0
- package/dist/chunk-EIWQM6U3.js +27 -0
- package/dist/chunk-EIWQM6U3.js.map +1 -0
- package/dist/chunk-EZNCCO4L.js +14 -0
- package/dist/chunk-EZNCCO4L.js.map +1 -0
- package/dist/chunk-F3KRX2V4.js +457 -0
- package/dist/chunk-F3KRX2V4.js.map +1 -0
- package/dist/chunk-FPTWVCPN.js +53 -0
- package/dist/chunk-FPTWVCPN.js.map +1 -0
- package/dist/chunk-GCNRXAKH.js +37 -0
- package/dist/chunk-GCNRXAKH.js.map +1 -0
- package/dist/chunk-GYURWCIQ.js +1985 -0
- package/dist/chunk-GYURWCIQ.js.map +1 -0
- package/dist/chunk-HZMY3TT4.js +244 -0
- package/dist/chunk-HZMY3TT4.js.map +1 -0
- package/dist/chunk-ID5QJYF5.js +50 -0
- package/dist/chunk-ID5QJYF5.js.map +1 -0
- package/dist/chunk-JAN34G6S.js +552 -0
- package/dist/chunk-JAN34G6S.js.map +1 -0
- package/dist/chunk-K3UNLQ7W.js +118 -0
- package/dist/chunk-K3UNLQ7W.js.map +1 -0
- package/dist/chunk-KDY5N6J4.js +82 -0
- package/dist/chunk-KDY5N6J4.js.map +1 -0
- package/dist/chunk-KOZUNIIE.js +413 -0
- package/dist/chunk-KOZUNIIE.js.map +1 -0
- package/dist/chunk-KS72RZHX.js +30 -0
- package/dist/chunk-KS72RZHX.js.map +1 -0
- package/dist/chunk-LD5SMIB3.js +32 -0
- package/dist/chunk-LD5SMIB3.js.map +1 -0
- package/dist/chunk-OHCPV2NT.js +86 -0
- package/dist/chunk-OHCPV2NT.js.map +1 -0
- package/dist/chunk-OYWFPIHF.js +115 -0
- package/dist/chunk-OYWFPIHF.js.map +1 -0
- package/dist/chunk-POZER3MQ.js +407 -0
- package/dist/chunk-POZER3MQ.js.map +1 -0
- package/dist/chunk-RTRVBEIB.js +56 -0
- package/dist/chunk-RTRVBEIB.js.map +1 -0
- package/dist/chunk-RTVRUNYR.js +29 -0
- package/dist/chunk-RTVRUNYR.js.map +1 -0
- package/dist/chunk-SS7ELMJ7.js +406 -0
- package/dist/chunk-SS7ELMJ7.js.map +1 -0
- package/dist/chunk-STCCNLPC.js +160 -0
- package/dist/chunk-STCCNLPC.js.map +1 -0
- package/dist/chunk-SVLNF434.js +261 -0
- package/dist/chunk-SVLNF434.js.map +1 -0
- package/dist/chunk-UYFOLI2X.js +24 -0
- package/dist/chunk-UYFOLI2X.js.map +1 -0
- package/dist/chunk-VAN4WW3F.js +67 -0
- package/dist/chunk-VAN4WW3F.js.map +1 -0
- package/dist/chunk-WOMHL23C.js +369 -0
- package/dist/chunk-WOMHL23C.js.map +1 -0
- package/dist/chunk-WWVD5DR5.js +120 -0
- package/dist/chunk-WWVD5DR5.js.map +1 -0
- package/dist/chunk-XG2YMCJW.js +201 -0
- package/dist/chunk-XG2YMCJW.js.map +1 -0
- package/dist/chunk-XIJNE67Y.js +210 -0
- package/dist/chunk-XIJNE67Y.js.map +1 -0
- package/dist/chunk-Y6UJOUE5.js +44 -0
- package/dist/chunk-Y6UJOUE5.js.map +1 -0
- package/dist/chunk-YUO6SKJD.js +348 -0
- package/dist/chunk-YUO6SKJD.js.map +1 -0
- package/dist/components--hjBMTnz.d.ts +120 -0
- package/dist/components-B29WHGQN.d.ts +39 -0
- package/dist/components-BWG1GkZA.d.ts +20 -0
- package/dist/components-XCpL6IYt.d.ts +18 -0
- package/dist/components-qWwOsvwh.d.ts +43 -0
- package/dist/cooldown.d.ts +116 -0
- package/dist/cooldown.js +20 -0
- package/dist/cooldown.js.map +1 -0
- package/dist/coordinators/boundary-ricochet-3d.d.ts +19 -0
- package/dist/coordinators/boundary-ricochet-3d.js +8 -0
- package/dist/coordinators/boundary-ricochet-3d.js.map +1 -0
- package/dist/coordinators/boundary-ricochet.d.ts +34 -0
- package/dist/coordinators/boundary-ricochet.js +8 -0
- package/dist/coordinators/boundary-ricochet.js.map +1 -0
- package/dist/coordinators/first-person-shooter.d.ts +35 -0
- package/dist/coordinators/first-person-shooter.js +9 -0
- package/dist/coordinators/first-person-shooter.js.map +1 -0
- package/dist/coordinators/multidirectional-space-shooter.d.ts +27 -0
- package/dist/coordinators/multidirectional-space-shooter.js +10 -0
- package/dist/coordinators/multidirectional-space-shooter.js.map +1 -0
- package/dist/coordinators/top-down-shooter.d.ts +27 -0
- package/dist/coordinators/top-down-shooter.js +10 -0
- package/dist/coordinators/top-down-shooter.js.map +1 -0
- package/dist/core.d.ts +25 -0
- package/dist/core.js +327 -0
- package/dist/core.js.map +1 -0
- package/dist/destructible-3d.d.ts +42 -0
- package/dist/destructible-3d.js +13 -0
- package/dist/destructible-3d.js.map +1 -0
- package/dist/destructible-prebake.d.ts +28 -0
- package/dist/destructible-prebake.js +23 -0
- package/dist/destructible-prebake.js.map +1 -0
- package/dist/entity-types-CmtQ-IBp.d.ts +15 -0
- package/dist/first-person-perspective-C9Mptl0-.d.ts +23 -0
- package/dist/first-person.d.ts +204 -0
- package/dist/first-person.js +27 -0
- package/dist/first-person.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +263 -0
- package/dist/index.js.map +1 -0
- package/dist/jumper-2d.d.ts +113 -0
- package/dist/jumper-2d.js +27 -0
- package/dist/jumper-2d.js.map +1 -0
- package/dist/jumper-3d.d.ts +164 -0
- package/dist/jumper-3d.js +29 -0
- package/dist/jumper-3d.js.map +1 -0
- package/dist/moveable-BCRpjAQb.d.ts +176 -0
- package/dist/particle-emitter/presets.d.ts +46 -0
- package/dist/particle-emitter/presets.js +15 -0
- package/dist/particle-emitter/presets.js.map +1 -0
- package/dist/particle-emitter.d.ts +78 -0
- package/dist/particle-emitter.js +15 -0
- package/dist/particle-emitter.js.map +1 -0
- package/dist/payload-BQzu-oY_.d.ts +89 -0
- package/dist/platformer-3d.d.ts +347 -0
- package/dist/platformer-3d.js +23 -0
- package/dist/platformer-3d.js.map +1 -0
- package/dist/ricochet-2d.d.ts +274 -0
- package/dist/ricochet-2d.js +16 -0
- package/dist/ricochet-2d.js.map +1 -0
- package/dist/ricochet-3d.d.ts +116 -0
- package/dist/ricochet-3d.js +16 -0
- package/dist/ricochet-3d.js.map +1 -0
- package/dist/runtime-2d.d.ts +2 -0
- package/dist/runtime-2d.js +32 -0
- package/dist/runtime-2d.js.map +1 -0
- package/dist/runtime-pong.d.ts +92 -0
- package/dist/runtime-pong.js +38 -0
- package/dist/runtime-pong.js.map +1 -0
- package/dist/screen-visibility.d.ts +74 -0
- package/dist/screen-visibility.js +10 -0
- package/dist/screen-visibility.js.map +1 -0
- package/dist/screen-wrap.d.ts +86 -0
- package/dist/screen-wrap.js +16 -0
- package/dist/screen-wrap.js.map +1 -0
- package/dist/shooter-2d.d.ts +77 -0
- package/dist/shooter-2d.js +12 -0
- package/dist/shooter-2d.js.map +1 -0
- package/dist/spark-DDlIg1nM.d.ts +148 -0
- package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
- package/dist/thruster.d.ts +132 -0
- package/dist/thruster.js +26 -0
- package/dist/thruster.js.map +1 -0
- package/dist/top-down-movement.d.ts +40 -0
- package/dist/top-down-movement.js +20 -0
- package/dist/top-down-movement.js.map +1 -0
- package/dist/use-behavior-D_82jAL3.d.ts +13 -0
- package/dist/vector-Bm65-FOG.d.ts +45 -0
- package/dist/world-boundary-2d.d.ts +141 -0
- package/dist/world-boundary-2d.js +21 -0
- package/dist/world-boundary-2d.js.map +1 -0
- package/dist/world-boundary-3d.d.ts +75 -0
- package/dist/world-boundary-3d.js +21 -0
- package/dist/world-boundary-3d.js.map +1 -0
- package/package.json +161 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Zylem Behaviors
|
|
2
|
+
|
|
3
|
+
Tree-shakable Zylem behavior descriptors, systems, coordinators, and shared behavior helpers.
|
|
4
|
+
|
|
5
|
+
Use per-behavior entrypoints when you want bundlers to pull only the behavior family you import:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { ScreenWrapBehavior } from '@zylem/behaviors/screen-wrap';
|
|
9
|
+
import { CooldownBehavior } from '@zylem/behaviors/cooldown';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The package is ESM-only and declares `sideEffects: false`.
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Node >= 22.12.0
|
|
17
|
+
- pnpm >= 10.32.1
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm install
|
|
23
|
+
pnpm build
|
|
24
|
+
pnpm typecheck
|
|
25
|
+
pnpm test
|
|
26
|
+
```
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BehaviorDescriptor
|
|
3
|
+
*
|
|
4
|
+
* Type-safe behavior descriptors that provide options inference.
|
|
5
|
+
* Used with entity.use() to declaratively attach behaviors to entities.
|
|
6
|
+
*
|
|
7
|
+
* Each behavior can define its own handle type via `createHandle`,
|
|
8
|
+
* providing behavior-specific methods with full type safety.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Base handle returned by entity.use() for lazy access to behavior runtime.
|
|
13
|
+
* FSM is null until entity is spawned and components are initialized.
|
|
14
|
+
*/
|
|
15
|
+
interface BaseBehaviorHandle<O extends Record<string, any> = Record<string, any>> {
|
|
16
|
+
/** Get the FSM instance (null until entity is spawned) */
|
|
17
|
+
getFSM(): any | null;
|
|
18
|
+
/** Get the current options */
|
|
19
|
+
getOptions(): O;
|
|
20
|
+
/** Access the underlying behavior ref */
|
|
21
|
+
readonly ref: BehaviorRef<O>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reference to a behavior stored on an entity
|
|
25
|
+
*/
|
|
26
|
+
interface BehaviorRef<O extends Record<string, any> = Record<string, any>> {
|
|
27
|
+
/** The behavior descriptor */
|
|
28
|
+
descriptor: BehaviorDescriptor<O, any>;
|
|
29
|
+
/** Merged options (defaults + overrides) */
|
|
30
|
+
options: O;
|
|
31
|
+
/** Optional FSM instance - set lazily when entity is spawned */
|
|
32
|
+
fsm?: any;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A typed behavior descriptor that associates a symbol key with:
|
|
36
|
+
* - Default options (providing type inference)
|
|
37
|
+
* - A system factory to create the behavior system
|
|
38
|
+
* - An optional handle factory for behavior-specific methods
|
|
39
|
+
*/
|
|
40
|
+
interface BehaviorDescriptor<O extends Record<string, any> = Record<string, any>, H extends Record<string, any> = Record<string, never>, I = unknown> {
|
|
41
|
+
/** Unique symbol identifying this behavior */
|
|
42
|
+
readonly key: symbol;
|
|
43
|
+
/** Default options (used for type inference) */
|
|
44
|
+
readonly defaultOptions: O;
|
|
45
|
+
/** Factory to create the behavior system */
|
|
46
|
+
readonly systemFactory: any;
|
|
47
|
+
/**
|
|
48
|
+
* Optional factory to create behavior-specific handle methods.
|
|
49
|
+
* These methods are merged into the handle returned by entity.use().
|
|
50
|
+
*/
|
|
51
|
+
readonly createHandle?: (ref: any) => H;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The full handle type returned by entity.use().
|
|
55
|
+
* Combines base handle with behavior-specific methods.
|
|
56
|
+
*/
|
|
57
|
+
type BehaviorHandle<O extends Record<string, any> = Record<string, any>, H extends Record<string, any> = Record<string, never>> = BaseBehaviorHandle<O> & H;
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for defining a new behavior
|
|
60
|
+
*/
|
|
61
|
+
interface DefineBehaviorConfig<O extends Record<string, any>, H extends Record<string, any> = Record<string, never>, I = unknown> {
|
|
62
|
+
/** Human-readable name for debugging */
|
|
63
|
+
name: string;
|
|
64
|
+
/** Default options - these define the type */
|
|
65
|
+
defaultOptions: O;
|
|
66
|
+
/** Factory function to create the system */
|
|
67
|
+
systemFactory: BehaviorSystemFactory;
|
|
68
|
+
/**
|
|
69
|
+
* Optional factory to create behavior-specific handle methods.
|
|
70
|
+
* The returned object is merged into the handle returned by entity.use().
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* createHandle: (ref) => ({
|
|
75
|
+
* getLastHits: () => ref.fsm?.getLastHits() ?? null,
|
|
76
|
+
* getMovement: (moveX, moveY) => ref.fsm?.getMovement(moveX, moveY) ?? { moveX, moveY },
|
|
77
|
+
* }),
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
createHandle?: (ref: BehaviorRef<O>) => H;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Define a typed behavior descriptor.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* export const WorldBoundary2DBehavior = defineBehavior({
|
|
88
|
+
* name: 'world-boundary-2d',
|
|
89
|
+
* defaultOptions: { boundaries: { top: 0, bottom: 0, left: 0, right: 0 } },
|
|
90
|
+
* systemFactory: (ctx) => new WorldBoundary2DSystem(ctx.world),
|
|
91
|
+
* createHandle: (ref) => ({
|
|
92
|
+
* getLastHits: () => ref.fsm?.getLastHits() ?? null,
|
|
93
|
+
* getMovement: (moveX: number, moveY: number) =>
|
|
94
|
+
* ref.fsm?.getMovement(moveX, moveY) ?? { moveX, moveY },
|
|
95
|
+
* }),
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* // Usage - handle has getLastHits and getMovement with full types
|
|
99
|
+
* const boundary = ship.use(WorldBoundary2DBehavior, { ... });
|
|
100
|
+
* const hits = boundary.getLastHits(); // Fully typed!
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare function defineBehavior<O extends Record<string, any>, H extends Record<string, any> = Record<string, never>, I = unknown>(config: DefineBehaviorConfig<O, H, I>): BehaviorDescriptor<O, H, I>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Minimal, runtime-agnostic entity options contract.
|
|
107
|
+
*
|
|
108
|
+
* The full engine entity (in `@zylem/game-lib`) provides a richer options type,
|
|
109
|
+
* but behaviors only rely on this loose shape.
|
|
110
|
+
*/
|
|
111
|
+
interface GameEntityOptions {
|
|
112
|
+
[key: string]: any;
|
|
113
|
+
name?: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Structural stand-in for the engine `GameEntity`.
|
|
117
|
+
*
|
|
118
|
+
* Behaviors annotate against this loose contract so that `@zylem/behaviors`
|
|
119
|
+
* (and its `@zylem/behaviors/core` surface) never has to depend on the concrete
|
|
120
|
+
* `@zylem/game-lib` entity implementation. The real engine entity is
|
|
121
|
+
* structurally assignable to this type.
|
|
122
|
+
*/
|
|
123
|
+
declare class GameEntity<TOptions = unknown> {
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
uuid: string;
|
|
126
|
+
name: string;
|
|
127
|
+
type: string;
|
|
128
|
+
options?: TOptions & Record<string, unknown>;
|
|
129
|
+
group: any;
|
|
130
|
+
mesh?: any;
|
|
131
|
+
materials?: any[];
|
|
132
|
+
body: any;
|
|
133
|
+
collider: any;
|
|
134
|
+
colliderDesc?: any;
|
|
135
|
+
colliderDescs: any[];
|
|
136
|
+
bodyDesc?: any;
|
|
137
|
+
physicsAttached: boolean;
|
|
138
|
+
runtimeHandle?: number;
|
|
139
|
+
transformStore?: any;
|
|
140
|
+
nodeDestroy?: any;
|
|
141
|
+
isInstanced?: boolean;
|
|
142
|
+
private __behaviorRefs;
|
|
143
|
+
create(): this;
|
|
144
|
+
onCleanup(callback: () => void): this;
|
|
145
|
+
setPosition(_x: number, _y: number, _z: number): void;
|
|
146
|
+
setRotation(_x: number, _y: number, _z: number): void;
|
|
147
|
+
setRotationZ(_z: number): void;
|
|
148
|
+
setScale(_x: number, _y: number, _z: number): void;
|
|
149
|
+
/**
|
|
150
|
+
* Attach a behavior to this entity. The real engine entity does substantially
|
|
151
|
+
* more, but this functional stub stores the merged ref and builds the handle
|
|
152
|
+
* so descriptor/handle logic (and tests that drive behaviors directly) work
|
|
153
|
+
* without the full engine.
|
|
154
|
+
*/
|
|
155
|
+
use<O extends Record<string, any>, H extends Record<string, any> = Record<string, never>>(descriptor: BehaviorDescriptor<O, H>, options?: Partial<O>): BehaviorHandle<O, H>;
|
|
156
|
+
/** Live behavior refs attached via {@link use}. */
|
|
157
|
+
getBehaviorRefs(): BehaviorRef<any>[];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Factory contract injected into behavior systems via
|
|
161
|
+
* {@link BehaviorSystemContext.createEntity}. The host engine supplies the real
|
|
162
|
+
* entity factory at stage-construction time.
|
|
163
|
+
*/
|
|
164
|
+
type CreateEntityFn = (options?: Partial<GameEntityOptions>) => GameEntity<GameEntityOptions>;
|
|
165
|
+
|
|
166
|
+
declare const StageBodyKind: {
|
|
167
|
+
readonly Dynamic: 0;
|
|
168
|
+
readonly Static: 1;
|
|
169
|
+
readonly KinematicPosition: 2;
|
|
170
|
+
readonly KinematicVelocity: 3;
|
|
171
|
+
};
|
|
172
|
+
declare const StageBoundaryDim: {
|
|
173
|
+
readonly Two: 2;
|
|
174
|
+
readonly Three: 3;
|
|
175
|
+
};
|
|
176
|
+
declare const StageRicochetDim: {
|
|
177
|
+
readonly Two: 2;
|
|
178
|
+
readonly Three: 3;
|
|
179
|
+
};
|
|
180
|
+
declare const StageRicochetReflection: {
|
|
181
|
+
readonly Mirror: 0;
|
|
182
|
+
readonly Angled: 1;
|
|
183
|
+
};
|
|
184
|
+
declare const StageTopDownPlane: {
|
|
185
|
+
readonly Xy: 0;
|
|
186
|
+
readonly Xz: 1;
|
|
187
|
+
};
|
|
188
|
+
declare const StageEventType: {
|
|
189
|
+
readonly CollisionStarted: 1;
|
|
190
|
+
readonly CollisionStopped: 2;
|
|
191
|
+
readonly BoundaryHit: 3;
|
|
192
|
+
readonly Ricochet: 4;
|
|
193
|
+
readonly RegionEntered: 5;
|
|
194
|
+
readonly JumpStarted: 6;
|
|
195
|
+
readonly Landed: 7;
|
|
196
|
+
readonly Wrapped: 8;
|
|
197
|
+
readonly CooldownFired: 9;
|
|
198
|
+
};
|
|
199
|
+
interface WasmStageRuntime {
|
|
200
|
+
getPose(handle: number): any;
|
|
201
|
+
attachThruster(handle: number, opts: any): boolean;
|
|
202
|
+
setThrusterInput(handle: number, thrust: number, rotate: number): void;
|
|
203
|
+
attachTopDown(handle: number, opts: {
|
|
204
|
+
plane: number;
|
|
205
|
+
speed: number;
|
|
206
|
+
faceMovement?: boolean;
|
|
207
|
+
}): boolean;
|
|
208
|
+
setTopDownInput(handle: number, moveX: number, moveY: number): void;
|
|
209
|
+
attachShooter2D(handle: number, opts: any): boolean;
|
|
210
|
+
attachScreenWrap(handle: number, opts: any): boolean;
|
|
211
|
+
queryScreenWrap(handle: number): any;
|
|
212
|
+
attachWorldBoundary(handle: number, dim: number, opts: any): boolean;
|
|
213
|
+
queryWorldBoundary(handle: number): any;
|
|
214
|
+
attachRicochet(handle: number, dim: number, opts: any): boolean;
|
|
215
|
+
attachPlatformer3D(handle: number, opts: any): boolean;
|
|
216
|
+
setPlatformer3DInputAxes(handle: number, moveX: number, moveZ: number): void;
|
|
217
|
+
setPlatformer3DInputButtons(handle: number, jump: boolean, run: boolean): void;
|
|
218
|
+
attachFirstPerson(handle: number, opts: any): boolean;
|
|
219
|
+
setFirstPersonInput(handle: number, input: any): void;
|
|
220
|
+
attachJumper2D(handle: number, opts: any): boolean;
|
|
221
|
+
setJumper2DInput(handle: number, jumpPressed: boolean): void;
|
|
222
|
+
attachJumper3D(handle: number, opts: any): boolean;
|
|
223
|
+
setJumper3DInput(handle: number, jumpPressed: boolean): void;
|
|
224
|
+
}
|
|
225
|
+
/** Default options used when constructing a wasm-backed Stage runtime. */
|
|
226
|
+
interface WasmStageRuntimeOptions {
|
|
227
|
+
initialCapacity?: number;
|
|
228
|
+
gravity?: readonly [number, number, number];
|
|
229
|
+
imports?: WebAssembly.Imports;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* BehaviorSystem Interface
|
|
234
|
+
*
|
|
235
|
+
* Legacy behavior systems reserved the first `update` argument for an ECS world
|
|
236
|
+
* handle; it is always `undefined` now.
|
|
237
|
+
*/
|
|
238
|
+
/** @deprecated Retained only for the first argument slot of `BehaviorSystem.update`. */
|
|
239
|
+
type BehaviorEcsHandle = unknown;
|
|
240
|
+
/**
|
|
241
|
+
* A behavior system that processes entities with specific components.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* class ThrusterMovementSystem implements BehaviorSystem {
|
|
246
|
+
* update(_ecs: BehaviorEcsHandle | undefined, delta: number): void {
|
|
247
|
+
* // Iterate behavior links, push intent into wasm runtime, etc.
|
|
248
|
+
* }
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
interface BehaviorSystem {
|
|
253
|
+
/** Optional eager initialization when a behavior link is registered on a live entity */
|
|
254
|
+
attach?(link: BehaviorEntityLink): void;
|
|
255
|
+
/** Called once per frame. The first argument is always `undefined` (reserved legacy slot). */
|
|
256
|
+
update(ecs: BehaviorEcsHandle | undefined, delta: number): void;
|
|
257
|
+
/** Optional cleanup when a behavior link is detached from a live entity */
|
|
258
|
+
detach?(link: BehaviorEntityLink): void;
|
|
259
|
+
/** Optional cleanup when stage is destroyed */
|
|
260
|
+
destroy?(ecs?: BehaviorEcsHandle): void;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Runtime link between a spawned entity and one of its behavior refs.
|
|
264
|
+
* Systems can iterate these links to avoid scanning all world entities.
|
|
265
|
+
*/
|
|
266
|
+
interface BehaviorEntityLink {
|
|
267
|
+
entity: any;
|
|
268
|
+
ref: any;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Context provided to behavior-system factories.
|
|
272
|
+
*
|
|
273
|
+
* After the runtime-only stage migration, `wasmStage` is the source of
|
|
274
|
+
* truth — descriptors should call `wasmStage.attach<X>(handle, opts)` /
|
|
275
|
+
* `wasmStage.query<X>(handle)` from inside the system instead of touching
|
|
276
|
+
* `entity.body` directly. The legacy `world` / `scene` fields remain for
|
|
277
|
+
* unmigrated descriptors.
|
|
278
|
+
*/
|
|
279
|
+
interface BehaviorSystemContext {
|
|
280
|
+
world: any;
|
|
281
|
+
scene: any;
|
|
282
|
+
/** Wasm-driven Stage runtime; omitted when the stage has no wasm module. */
|
|
283
|
+
wasmStage?: WasmStageRuntime | null;
|
|
284
|
+
/**
|
|
285
|
+
* Returns live behavior links for a descriptor key.
|
|
286
|
+
* O(1) lookup into a pre-built stage index.
|
|
287
|
+
*/
|
|
288
|
+
getBehaviorLinks?: (key: symbol) => Iterable<BehaviorEntityLink>;
|
|
289
|
+
/**
|
|
290
|
+
* Host-injected entity factory. Behaviors that spawn entities at runtime
|
|
291
|
+
* (e.g. destructible-3d fragments) use this instead of importing the engine
|
|
292
|
+
* entity factory directly, keeping the behavior layer decoupled.
|
|
293
|
+
*/
|
|
294
|
+
createEntity?: CreateEntityFn;
|
|
295
|
+
/**
|
|
296
|
+
* Host-injected accessor for the global game-state bag, passed to entity
|
|
297
|
+
* lifecycle hooks (e.g. `nodeDestroy`).
|
|
298
|
+
*/
|
|
299
|
+
getGlobals?: () => any;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Factory function that creates a BehaviorSystem.
|
|
303
|
+
* Receives the stage for access to world, scene, etc.
|
|
304
|
+
*/
|
|
305
|
+
type BehaviorSystemFactory<T extends BehaviorSystem = BehaviorSystem> = (stage: BehaviorSystemContext) => T;
|
|
306
|
+
|
|
307
|
+
export { type BaseBehaviorHandle as B, type CreateEntityFn as C, type DefineBehaviorConfig as D, GameEntity as G, StageBodyKind as S, type WasmStageRuntime as W, type BehaviorDescriptor as a, type BehaviorEcsHandle as b, type BehaviorEntityLink as c, type BehaviorHandle as d, type BehaviorRef as e, type BehaviorSystem as f, type BehaviorSystemContext as g, type BehaviorSystemFactory as h, type GameEntityOptions as i, StageBoundaryDim as j, StageEventType as k, StageRicochetDim as l, StageRicochetReflection as m, StageTopDownPlane as n, type WasmStageRuntimeOptions as o, defineBehavior as p };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineBehavior
|
|
3
|
+
} from "./chunk-EZNCCO4L.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/behaviors/runtime-pong/runtime-pong.descriptors.ts
|
|
6
|
+
var runtimeNoopSystemFactory = () => ({
|
|
7
|
+
update(_ecs, _delta) {
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
var RUNTIME_PONG_BALL_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:runtime-pong-ball");
|
|
11
|
+
var RUNTIME_PADDLE_INPUT_2D_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:runtime-paddle-input-2d");
|
|
12
|
+
var RUNTIME_WORLD_BOUNDARY_2D_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:runtime-world-boundary-2d");
|
|
13
|
+
var RUNTIME_RICOCHET_2D_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:runtime-ricochet-2d");
|
|
14
|
+
var RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:runtime-trigger-region-2d");
|
|
15
|
+
var RUNTIME_GOAL_ZONE_2D_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:runtime-goal-zone-2d");
|
|
16
|
+
var RICOCHET_LISTENERS = /* @__PURE__ */ Symbol("runtime-ricochet-listeners");
|
|
17
|
+
var TRIGGER_REGION_LISTENERS = /* @__PURE__ */ Symbol("runtime-trigger-region-listeners");
|
|
18
|
+
var GOAL_LISTENERS = /* @__PURE__ */ Symbol("runtime-goal-listeners");
|
|
19
|
+
var RUNTIME_BALL_SET_POSITION = /* @__PURE__ */ Symbol("runtime-ball-set-position");
|
|
20
|
+
var RUNTIME_BALL_SET_VELOCITY = /* @__PURE__ */ Symbol("runtime-ball-set-velocity");
|
|
21
|
+
var RUNTIME_BALL_GET_POSITION = /* @__PURE__ */ Symbol("runtime-ball-get-position");
|
|
22
|
+
var RuntimePongBallBehavior = defineBehavior({
|
|
23
|
+
name: "runtime-pong-ball",
|
|
24
|
+
defaultOptions: {
|
|
25
|
+
initialVelocity: [0, 0]
|
|
26
|
+
},
|
|
27
|
+
systemFactory: runtimeNoopSystemFactory,
|
|
28
|
+
createHandle: (ref) => ({
|
|
29
|
+
setRuntimePosition(x, y, z = 0) {
|
|
30
|
+
const callback = ref[RUNTIME_BALL_SET_POSITION];
|
|
31
|
+
callback?.(x, y, z);
|
|
32
|
+
},
|
|
33
|
+
setRuntimeVelocity(x, y) {
|
|
34
|
+
const callback = ref[RUNTIME_BALL_SET_VELOCITY];
|
|
35
|
+
callback?.(x, y);
|
|
36
|
+
},
|
|
37
|
+
getRuntimePosition() {
|
|
38
|
+
const callback = ref[RUNTIME_BALL_GET_POSITION];
|
|
39
|
+
return callback?.() ?? null;
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
var RuntimePaddleInput2DBehavior = defineBehavior({
|
|
44
|
+
name: "runtime-paddle-input-2d",
|
|
45
|
+
defaultOptions: {
|
|
46
|
+
player: "p1",
|
|
47
|
+
speed: 5
|
|
48
|
+
},
|
|
49
|
+
systemFactory: runtimeNoopSystemFactory
|
|
50
|
+
});
|
|
51
|
+
var RuntimeWorldBoundary2DBehavior = defineBehavior({
|
|
52
|
+
name: "runtime-world-boundary-2d",
|
|
53
|
+
defaultOptions: {
|
|
54
|
+
boundaries: {
|
|
55
|
+
left: 0,
|
|
56
|
+
right: 0,
|
|
57
|
+
bottom: 0,
|
|
58
|
+
top: 0
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
systemFactory: runtimeNoopSystemFactory
|
|
62
|
+
});
|
|
63
|
+
var RuntimeRicochet2DBehavior = defineBehavior({
|
|
64
|
+
name: "runtime-ricochet-2d",
|
|
65
|
+
defaultOptions: {
|
|
66
|
+
minSpeed: 2,
|
|
67
|
+
maxSpeed: 20,
|
|
68
|
+
speedMultiplier: 1.05,
|
|
69
|
+
reflectionMode: "angled",
|
|
70
|
+
maxAngleDeg: 60
|
|
71
|
+
},
|
|
72
|
+
systemFactory: runtimeNoopSystemFactory,
|
|
73
|
+
createHandle: (ref) => ({
|
|
74
|
+
onRicochet(callback) {
|
|
75
|
+
const listeners = ref[RICOCHET_LISTENERS] ?? [];
|
|
76
|
+
if (!ref[RICOCHET_LISTENERS]) {
|
|
77
|
+
ref[RICOCHET_LISTENERS] = listeners;
|
|
78
|
+
}
|
|
79
|
+
listeners.push(callback);
|
|
80
|
+
return () => {
|
|
81
|
+
const index = listeners.indexOf(callback);
|
|
82
|
+
if (index >= 0) {
|
|
83
|
+
listeners.splice(index, 1);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
var RuntimeTriggerRegion2DBehavior = defineBehavior({
|
|
90
|
+
name: "runtime-trigger-region-2d",
|
|
91
|
+
defaultOptions: {
|
|
92
|
+
triggerId: 0,
|
|
93
|
+
halfExtents: [0.5, 2.5]
|
|
94
|
+
},
|
|
95
|
+
systemFactory: runtimeNoopSystemFactory,
|
|
96
|
+
createHandle: (ref) => ({
|
|
97
|
+
onRegionEnter(callback) {
|
|
98
|
+
const listeners = ref[TRIGGER_REGION_LISTENERS] ?? [];
|
|
99
|
+
if (!ref[TRIGGER_REGION_LISTENERS]) {
|
|
100
|
+
ref[TRIGGER_REGION_LISTENERS] = listeners;
|
|
101
|
+
}
|
|
102
|
+
listeners.push(callback);
|
|
103
|
+
return () => {
|
|
104
|
+
const index = listeners.indexOf(callback);
|
|
105
|
+
if (index >= 0) {
|
|
106
|
+
listeners.splice(index, 1);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
var RuntimeGoalZone2DBehavior = defineBehavior({
|
|
113
|
+
name: "runtime-goal-zone-2d",
|
|
114
|
+
defaultOptions: {
|
|
115
|
+
scorer: "p1"
|
|
116
|
+
},
|
|
117
|
+
systemFactory: runtimeNoopSystemFactory,
|
|
118
|
+
createHandle: (ref) => ({
|
|
119
|
+
onGoal(callback) {
|
|
120
|
+
const listeners = ref[GOAL_LISTENERS] ?? [];
|
|
121
|
+
if (!ref[GOAL_LISTENERS]) {
|
|
122
|
+
ref[GOAL_LISTENERS] = listeners;
|
|
123
|
+
}
|
|
124
|
+
listeners.push(callback);
|
|
125
|
+
return () => {
|
|
126
|
+
const index = listeners.indexOf(callback);
|
|
127
|
+
if (index >= 0) {
|
|
128
|
+
listeners.splice(index, 1);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
function emitRuntimeRicochet(ref, event) {
|
|
135
|
+
const listeners = ref[RICOCHET_LISTENERS];
|
|
136
|
+
for (const listener of listeners ?? []) {
|
|
137
|
+
listener(event);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function emitRuntimeTriggerRegionEnter(ref, event) {
|
|
141
|
+
const listeners = ref[TRIGGER_REGION_LISTENERS];
|
|
142
|
+
for (const listener of listeners ?? []) {
|
|
143
|
+
listener(event);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function emitRuntimeGoal(ref, event) {
|
|
147
|
+
const listeners = ref[GOAL_LISTENERS];
|
|
148
|
+
for (const listener of listeners ?? []) {
|
|
149
|
+
listener(event);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function bindRuntimePongBallHandle(ref, controls) {
|
|
153
|
+
ref[RUNTIME_BALL_SET_POSITION] = controls.setPosition;
|
|
154
|
+
ref[RUNTIME_BALL_SET_VELOCITY] = controls.setVelocity;
|
|
155
|
+
ref[RUNTIME_BALL_GET_POSITION] = controls.getPosition;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
RUNTIME_PONG_BALL_BEHAVIOR_KEY,
|
|
160
|
+
RUNTIME_PADDLE_INPUT_2D_BEHAVIOR_KEY,
|
|
161
|
+
RUNTIME_WORLD_BOUNDARY_2D_BEHAVIOR_KEY,
|
|
162
|
+
RUNTIME_RICOCHET_2D_BEHAVIOR_KEY,
|
|
163
|
+
RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY,
|
|
164
|
+
RUNTIME_GOAL_ZONE_2D_BEHAVIOR_KEY,
|
|
165
|
+
RuntimePongBallBehavior,
|
|
166
|
+
RuntimePaddleInput2DBehavior,
|
|
167
|
+
RuntimeWorldBoundary2DBehavior,
|
|
168
|
+
RuntimeRicochet2DBehavior,
|
|
169
|
+
RuntimeTriggerRegion2DBehavior,
|
|
170
|
+
RuntimeGoalZone2DBehavior,
|
|
171
|
+
emitRuntimeRicochet,
|
|
172
|
+
emitRuntimeTriggerRegionEnter,
|
|
173
|
+
emitRuntimeGoal,
|
|
174
|
+
bindRuntimePongBallHandle
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=chunk-2C3Z5GE7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/behaviors/runtime-pong/runtime-pong.descriptors.ts"],"sourcesContent":["import {\n\tdefineBehavior,\n\ttype BehaviorRef,\n} from '../behavior-descriptor';\nimport type { BehaviorSystem } from '../behavior-system';\n\nexport interface RuntimePongBallOptions {\n\tinitialVelocity: readonly [number, number];\n}\n\nexport interface RuntimePongBallHandle {\n\tsetRuntimePosition(x: number, y: number, z?: number): void;\n\tsetRuntimeVelocity(x: number, y: number): void;\n\tgetRuntimePosition(): { x: number; y: number; z: number } | null;\n}\n\nexport interface RuntimePaddleInput2DOptions {\n\tplayer: 'p1' | 'p2';\n\tspeed: number;\n}\n\nexport interface RuntimeWorldBoundary2DOptions {\n\tboundaries: {\n\t\tleft: number;\n\t\tright: number;\n\t\tbottom: number;\n\t\ttop: number;\n\t};\n}\n\nexport interface RuntimeRicochet2DOptions {\n\tminSpeed: number;\n\tmaxSpeed: number;\n\tspeedMultiplier: number;\n\treflectionMode: 'simple' | 'angled';\n\tmaxAngleDeg: number;\n}\n\nexport interface RuntimeRicochet2DEvent {\n\tkind: 'wall' | 'paddle';\n}\n\nexport interface RuntimeRicochet2DHandle {\n\tonRicochet(callback: (event: RuntimeRicochet2DEvent) => void): () => void;\n}\n\n/** Registers a gameplay2d trigger AABB (sensor); wasm reports overlap via {@link emitRuntimeTriggerRegionEnter}. */\nexport interface RuntimeTriggerRegion2DOptions {\n\ttriggerId: number;\n\thalfExtents: readonly [number, number];\n}\n\nexport interface RuntimeTriggerRegion2DEvent {\n\ttriggerId: number;\n}\n\nexport interface RuntimeTriggerRegion2DHandle {\n\tonRegionEnter(callback: (event: RuntimeTriggerRegion2DEvent) => void): () => void;\n}\n\nexport interface RuntimeGoalZone2DOptions {\n\tscorer: 'p1' | 'p2';\n}\n\nexport interface RuntimeGoalZone2DEvent {\n\tscorer: 'p1' | 'p2';\n}\n\nexport interface RuntimeGoalZone2DHandle {\n\tonGoal(callback: (event: RuntimeGoalZone2DEvent) => void): () => void;\n}\n\nconst runtimeNoopSystemFactory = (): BehaviorSystem => ({\n\tupdate(_ecs: unknown, _delta: number) {},\n});\n\nexport const RUNTIME_PONG_BALL_BEHAVIOR_KEY = Symbol.for('zylem:behavior:runtime-pong-ball');\nexport const RUNTIME_PADDLE_INPUT_2D_BEHAVIOR_KEY = Symbol.for('zylem:behavior:runtime-paddle-input-2d');\nexport const RUNTIME_WORLD_BOUNDARY_2D_BEHAVIOR_KEY = Symbol.for('zylem:behavior:runtime-world-boundary-2d');\nexport const RUNTIME_RICOCHET_2D_BEHAVIOR_KEY = Symbol.for('zylem:behavior:runtime-ricochet-2d');\nexport const RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY = Symbol.for('zylem:behavior:runtime-trigger-region-2d');\nexport const RUNTIME_GOAL_ZONE_2D_BEHAVIOR_KEY = Symbol.for('zylem:behavior:runtime-goal-zone-2d');\n\nconst RICOCHET_LISTENERS = Symbol('runtime-ricochet-listeners');\nconst TRIGGER_REGION_LISTENERS = Symbol('runtime-trigger-region-listeners');\nconst GOAL_LISTENERS = Symbol('runtime-goal-listeners');\nconst RUNTIME_BALL_SET_POSITION = Symbol('runtime-ball-set-position');\nconst RUNTIME_BALL_SET_VELOCITY = Symbol('runtime-ball-set-velocity');\nconst RUNTIME_BALL_GET_POSITION = Symbol('runtime-ball-get-position');\n\nexport const RuntimePongBallBehavior = defineBehavior<\n\tRuntimePongBallOptions,\n\tRuntimePongBallHandle\n>({\n\tname: 'runtime-pong-ball',\n\tdefaultOptions: {\n\t\tinitialVelocity: [0, 0] as [number, number],\n\t},\n\tsystemFactory: runtimeNoopSystemFactory,\n\tcreateHandle: (ref: BehaviorRef<RuntimePongBallOptions>) => ({\n\t\tsetRuntimePosition(x: number, y: number, z: number = 0): void {\n\t\t\tconst callback = (ref as any)[RUNTIME_BALL_SET_POSITION] as\n\t\t\t\t| ((x: number, y: number, z: number) => void)\n\t\t\t\t| undefined;\n\t\t\tcallback?.(x, y, z);\n\t\t},\n\t\tsetRuntimeVelocity(x: number, y: number): void {\n\t\t\tconst callback = (ref as any)[RUNTIME_BALL_SET_VELOCITY] as\n\t\t\t\t| ((x: number, y: number) => void)\n\t\t\t\t| undefined;\n\t\t\tcallback?.(x, y);\n\t\t},\n\t\tgetRuntimePosition(): { x: number; y: number; z: number } | null {\n\t\t\tconst callback = (ref as any)[RUNTIME_BALL_GET_POSITION] as\n\t\t\t\t| (() => { x: number; y: number; z: number } | null)\n\t\t\t\t| undefined;\n\t\t\treturn callback?.() ?? null;\n\t\t},\n\t}),\n});\n\nexport const RuntimePaddleInput2DBehavior = defineBehavior<RuntimePaddleInput2DOptions>({\n\tname: 'runtime-paddle-input-2d',\n\tdefaultOptions: {\n\t\tplayer: 'p1',\n\t\tspeed: 5,\n\t} as RuntimePaddleInput2DOptions,\n\tsystemFactory: runtimeNoopSystemFactory,\n});\n\nexport const RuntimeWorldBoundary2DBehavior = defineBehavior({\n\tname: 'runtime-world-boundary-2d',\n\tdefaultOptions: {\n\t\tboundaries: {\n\t\t\tleft: 0,\n\t\t\tright: 0,\n\t\t\tbottom: 0,\n\t\t\ttop: 0,\n\t\t},\n\t},\n\tsystemFactory: runtimeNoopSystemFactory,\n});\n\nexport const RuntimeRicochet2DBehavior = defineBehavior<\n\tRuntimeRicochet2DOptions,\n\tRuntimeRicochet2DHandle\n>({\n\tname: 'runtime-ricochet-2d',\n\tdefaultOptions: {\n\t\tminSpeed: 2,\n\t\tmaxSpeed: 20,\n\t\tspeedMultiplier: 1.05,\n\t\treflectionMode: 'angled' as const,\n\t\tmaxAngleDeg: 60,\n\t},\n\tsystemFactory: runtimeNoopSystemFactory,\n\tcreateHandle: (ref: BehaviorRef<RuntimeRicochet2DOptions>) => ({\n\t\tonRicochet(callback: (event: RuntimeRicochet2DEvent) => void): () => void {\n\t\t\tconst listeners =\n\t\t\t\t((ref as any)[RICOCHET_LISTENERS] as Array<(event: RuntimeRicochet2DEvent) => void> | undefined)\n\t\t\t\t?? [];\n\t\t\tif (!(ref as any)[RICOCHET_LISTENERS]) {\n\t\t\t\t(ref as any)[RICOCHET_LISTENERS] = listeners;\n\t\t\t}\n\t\t\tlisteners.push(callback);\n\t\t\treturn () => {\n\t\t\t\tconst index = listeners.indexOf(callback);\n\t\t\t\tif (index >= 0) {\n\t\t\t\t\tlisteners.splice(index, 1);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t}),\n});\n\nexport const RuntimeTriggerRegion2DBehavior = defineBehavior<\n\tRuntimeTriggerRegion2DOptions,\n\tRuntimeTriggerRegion2DHandle\n>({\n\tname: 'runtime-trigger-region-2d',\n\tdefaultOptions: {\n\t\ttriggerId: 0,\n\t\thalfExtents: [0.5, 2.5] as [number, number],\n\t},\n\tsystemFactory: runtimeNoopSystemFactory,\n\tcreateHandle: (ref: BehaviorRef<RuntimeTriggerRegion2DOptions>) => ({\n\t\tonRegionEnter(callback: (event: RuntimeTriggerRegion2DEvent) => void): () => void {\n\t\t\tconst listeners =\n\t\t\t\t((ref as any)[TRIGGER_REGION_LISTENERS] as\n\t\t\t\t\t| Array<(event: RuntimeTriggerRegion2DEvent) => void>\n\t\t\t\t\t| undefined) ?? [];\n\t\t\tif (!(ref as any)[TRIGGER_REGION_LISTENERS]) {\n\t\t\t\t(ref as any)[TRIGGER_REGION_LISTENERS] = listeners;\n\t\t\t}\n\t\t\tlisteners.push(callback);\n\t\t\treturn () => {\n\t\t\t\tconst index = listeners.indexOf(callback);\n\t\t\t\tif (index >= 0) {\n\t\t\t\t\tlisteners.splice(index, 1);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t}),\n});\n\nexport const RuntimeGoalZone2DBehavior = defineBehavior<\n\tRuntimeGoalZone2DOptions,\n\tRuntimeGoalZone2DHandle\n>({\n\tname: 'runtime-goal-zone-2d',\n\tdefaultOptions: {\n\t\tscorer: 'p1',\n\t} as RuntimeGoalZone2DOptions,\n\tsystemFactory: runtimeNoopSystemFactory,\n\tcreateHandle: (ref: BehaviorRef<RuntimeGoalZone2DOptions>) => ({\n\t\tonGoal(callback: (event: RuntimeGoalZone2DEvent) => void): () => void {\n\t\t\tconst listeners =\n\t\t\t\t((ref as any)[GOAL_LISTENERS] as Array<(event: RuntimeGoalZone2DEvent) => void> | undefined)\n\t\t\t\t?? [];\n\t\t\tif (!(ref as any)[GOAL_LISTENERS]) {\n\t\t\t\t(ref as any)[GOAL_LISTENERS] = listeners;\n\t\t\t}\n\t\t\tlisteners.push(callback);\n\t\t\treturn () => {\n\t\t\t\tconst index = listeners.indexOf(callback);\n\t\t\t\tif (index >= 0) {\n\t\t\t\t\tlisteners.splice(index, 1);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t}),\n});\n\nexport function emitRuntimeRicochet(\n\tref: BehaviorRef<RuntimeRicochet2DOptions>,\n\tevent: RuntimeRicochet2DEvent,\n): void {\n\tconst listeners = (ref as any)[RICOCHET_LISTENERS] as\n\t\t| Array<(event: RuntimeRicochet2DEvent) => void>\n\t\t| undefined;\n\tfor (const listener of listeners ?? []) {\n\t\tlistener(event);\n\t}\n}\n\nexport function emitRuntimeTriggerRegionEnter(\n\tref: BehaviorRef<RuntimeTriggerRegion2DOptions>,\n\tevent: RuntimeTriggerRegion2DEvent,\n): void {\n\tconst listeners = (ref as any)[TRIGGER_REGION_LISTENERS] as\n\t\t| Array<(event: RuntimeTriggerRegion2DEvent) => void>\n\t\t| undefined;\n\tfor (const listener of listeners ?? []) {\n\t\tlistener(event);\n\t}\n}\n\nexport function emitRuntimeGoal(\n\tref: BehaviorRef<RuntimeGoalZone2DOptions>,\n\tevent: RuntimeGoalZone2DEvent,\n): void {\n\tconst listeners = (ref as any)[GOAL_LISTENERS] as\n\t\t| Array<(event: RuntimeGoalZone2DEvent) => void>\n\t\t| undefined;\n\tfor (const listener of listeners ?? []) {\n\t\tlistener(event);\n\t}\n}\n\nexport function bindRuntimePongBallHandle(\n\tref: BehaviorRef<RuntimePongBallOptions>,\n\tcontrols: {\n\t\tsetPosition: (x: number, y: number, z: number) => void;\n\t\tsetVelocity: (x: number, y: number) => void;\n\t\tgetPosition: () => { x: number; y: number; z: number } | null;\n\t},\n): void {\n\t(ref as any)[RUNTIME_BALL_SET_POSITION] = controls.setPosition;\n\t(ref as any)[RUNTIME_BALL_SET_VELOCITY] = controls.setVelocity;\n\t(ref as any)[RUNTIME_BALL_GET_POSITION] = controls.getPosition;\n}\n"],"mappings":"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","names":[]}
|