@zylem/game-lib 0.6.4 → 0.7.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 +3 -1
- package/dist/actions.d.ts +255 -8
- package/dist/actions.js +1 -936
- package/dist/audio.d.ts +13 -0
- package/dist/audio.js +1 -0
- package/dist/base-node-life-cycle-CnJ-7zX-.d.ts +143 -0
- package/dist/behavior.d.ts +3 -0
- package/dist/behavior.js +1 -0
- package/dist/chunk-4QLJUQSJ.js +1 -0
- package/dist/chunk-73VZQZUL.js +1 -0
- package/dist/chunk-A34ZG3L4.js +1 -0
- package/dist/chunk-CDPY4VOQ.js +1 -0
- package/dist/chunk-DR6XXZE7.js +19 -0
- package/dist/chunk-FM5TBEPO.js +1 -0
- package/dist/chunk-G2IIMSUH.js +1 -0
- package/dist/chunk-MSC2BEO5.js +1 -0
- package/dist/chunk-NIH5CONO.js +1 -0
- package/dist/chunk-ONWXGBWB.js +1 -0
- package/dist/chunk-QEDQDR27.js +1 -0
- package/dist/chunk-QXVH6POE.js +1 -0
- package/dist/chunk-RXDTAWI2.js +29 -0
- package/dist/chunk-WKHW2QO2.js +1 -0
- package/dist/chunk-XRP4JJXL.js +1 -0
- package/dist/chunk-YHEWKN7N.js +1 -0
- package/dist/chunk-YHKXQ2ZN.js +1 -0
- package/dist/core.d.ts +206 -14
- package/dist/core.js +24 -12424
- package/dist/debug.d.ts +24 -0
- package/dist/debug.js +1 -0
- package/dist/default-controls-BGc61yYl.d.ts +111 -0
- package/dist/{entity-vj-HTjzU.d.ts → entity-DNkYKfdp.d.ts} +452 -578
- package/dist/entity-type-map-C94h2TDW.d.ts +781 -0
- package/dist/entity.d.ts +265 -0
- package/dist/entity.js +1 -0
- package/dist/events.d.ts +172 -0
- package/dist/events.js +1 -0
- package/dist/game-Cuj5gy7U.d.ts +1590 -0
- package/dist/game-default-PZLLHYL7.js +1 -0
- package/dist/game-interfaces-tfpM5NBk.d.ts +90 -0
- package/dist/globals.d.ts +104 -0
- package/dist/globals.js +1 -0
- package/dist/graphics.d.ts +83 -0
- package/dist/graphics.js +1 -0
- package/dist/input-ui.d.ts +34 -0
- package/dist/input-ui.js +1 -0
- package/dist/input.d.ts +72 -0
- package/dist/input.js +1 -0
- package/dist/material-Wz83vTTp.d.ts +151 -0
- package/dist/runtime.d.ts +433 -0
- package/dist/runtime.js +1 -0
- package/dist/web-components.d.ts +67 -0
- package/dist/web-components.js +9 -0
- package/dist/world-C9zdyl5d.d.ts +103 -0
- package/dist/{camera-4XO5gbQH.d.ts → zylem-stage-runtime-Cs-UDEVU.d.ts} +201 -329
- package/package.json +52 -63
- package/dist/actions.js.map +0 -1
- package/dist/behavior/jumper-2d.d.ts +0 -114
- package/dist/behavior/jumper-2d.js +0 -711
- package/dist/behavior/jumper-2d.js.map +0 -1
- package/dist/behavior/platformer-3d.d.ts +0 -296
- package/dist/behavior/platformer-3d.js +0 -761
- package/dist/behavior/platformer-3d.js.map +0 -1
- package/dist/behavior/ricochet-2d.d.ts +0 -275
- package/dist/behavior/ricochet-2d.js +0 -425
- package/dist/behavior/ricochet-2d.js.map +0 -1
- package/dist/behavior/ricochet-3d.d.ts +0 -117
- package/dist/behavior/ricochet-3d.js +0 -443
- package/dist/behavior/ricochet-3d.js.map +0 -1
- package/dist/behavior/screen-visibility.d.ts +0 -79
- package/dist/behavior/screen-visibility.js +0 -358
- package/dist/behavior/screen-visibility.js.map +0 -1
- package/dist/behavior/screen-wrap.d.ts +0 -87
- package/dist/behavior/screen-wrap.js +0 -246
- package/dist/behavior/screen-wrap.js.map +0 -1
- package/dist/behavior/shooter-2d.d.ts +0 -79
- package/dist/behavior/shooter-2d.js +0 -180
- package/dist/behavior/shooter-2d.js.map +0 -1
- package/dist/behavior/thruster.d.ts +0 -11
- package/dist/behavior/thruster.js +0 -292
- package/dist/behavior/thruster.js.map +0 -1
- package/dist/behavior/top-down-movement.d.ts +0 -56
- package/dist/behavior/top-down-movement.js +0 -125
- package/dist/behavior/top-down-movement.js.map +0 -1
- package/dist/behavior/world-boundary-2d.d.ts +0 -142
- package/dist/behavior/world-boundary-2d.js +0 -235
- package/dist/behavior/world-boundary-2d.js.map +0 -1
- package/dist/behavior/world-boundary-3d.d.ts +0 -76
- package/dist/behavior/world-boundary-3d.js +0 -274
- package/dist/behavior/world-boundary-3d.js.map +0 -1
- package/dist/behavior-descriptor-BXnVR8Ki.d.ts +0 -159
- package/dist/blueprints-DmbK2dki.d.ts +0 -26
- package/dist/camera.d.ts +0 -6
- package/dist/camera.js +0 -1993
- package/dist/camera.js.map +0 -1
- package/dist/composition-BASvMKrW.d.ts +0 -218
- package/dist/core-CARRaS55.d.ts +0 -541
- package/dist/core.js.map +0 -1
- package/dist/entities-ChFirVL9.d.ts +0 -410
- package/dist/entities.d.ts +0 -9
- package/dist/entities.js +0 -4986
- package/dist/entities.js.map +0 -1
- package/dist/entity-Bq_eNEDI.d.ts +0 -28
- package/dist/entity-types-DAu8sGJH.d.ts +0 -26
- package/dist/global-change-2JvMaz44.d.ts +0 -25
- package/dist/main.d.ts +0 -1353
- package/dist/main.js +0 -19525
- package/dist/main.js.map +0 -1
- package/dist/physics-pose-DCc4oE44.d.ts +0 -25
- package/dist/physics-protocol-BDD3P5W2.d.ts +0 -200
- package/dist/physics-worker.d.ts +0 -21
- package/dist/physics-worker.js +0 -306
- package/dist/physics-worker.js.map +0 -1
- package/dist/physics.d.ts +0 -205
- package/dist/physics.js +0 -577
- package/dist/physics.js.map +0 -1
- package/dist/stage-types-C19IhuzA.d.ts +0 -731
- package/dist/stage.d.ts +0 -52
- package/dist/stage.js +0 -8479
- package/dist/stage.js.map +0 -1
- package/dist/sync-state-machine-CZyspBpj.d.ts +0 -16
- package/dist/thruster-23lzoPZd.d.ts +0 -180
- package/dist/world-DfgxoNMt.d.ts +0 -105
package/dist/main.d.ts
DELETED
|
@@ -1,1353 +0,0 @@
|
|
|
1
|
-
import { G as Game, D as DeviceProfile } from './core-CARRaS55.js';
|
|
2
|
-
export { A as AspectRatio, e as AspectRatioValue, a as GameConfigLike, b as GameDeviceConfig, R as ResolutionInput, d as ResolveGameConfigRuntime, i as RetroPreset, j as RetroPresetKey, k as RetroResolution, V as Vect3, c as createGame, g as gameConfig, f as getDisplayAspect, h as getPresetResolution, p as parseResolution, v as vessel } from './core-CARRaS55.js';
|
|
3
|
-
import { G as GameInputConfig } from './stage-types-C19IhuzA.js';
|
|
4
|
-
export { a as StageOptions, Z as ZylemGameConfig, d as createDisk, c as createStage } from './stage-types-C19IhuzA.js';
|
|
5
|
-
import { S as StageBlueprint } from './blueprints-DmbK2dki.js';
|
|
6
|
-
export { e as entitySpawner } from './blueprints-DmbK2dki.js';
|
|
7
|
-
import { b as CameraBehavior, a as CameraWrapper, F as FirstPersonPerspective } from './camera-4XO5gbQH.js';
|
|
8
|
-
export { m as CameraAction, k as CameraContext, C as CameraManager, d as CameraOptions, l as CameraPerspective, o as CameraPipeline, n as CameraPipelineState, h as CameraPose, u as FirstPersonOptions, t as Fixed2DOptions, q as Fixed2DPerspective, v as PerspectiveOptions, P as PerspectiveType, e as Perspectives, j as PoseDelta, f as RendererType, s as ThirdPersonOptions, p as ThirdPersonPerspective, T as TransformLike, V as Viewport, g as ZylemRenderer, c as createCamera, r as createPerspective, i as isWebGPUSupported } from './camera-4XO5gbQH.js';
|
|
9
|
-
import { Vector3, Color, Mesh, Euler, Vector2 } from 'three';
|
|
10
|
-
import * as three from 'three';
|
|
11
|
-
export { three as THREE };
|
|
12
|
-
import { S as StageEntity } from './entity-Bq_eNEDI.js';
|
|
13
|
-
export { A as ACTOR_TYPE, B as BOX_TYPE, C as CONE_TYPE, m as CYLINDER_TYPE, o as PILL_TYPE, P as PLANE_TYPE, k as PYRAMID_TYPE, R as RECT_TYPE, a as SPHERE_TYPE, S as SPRITE_TYPE, T as TEXT_TYPE, g as ZONE_TYPE, e as ZylemBox, v as createActor, q as createBox, y as createCone, D as createCylinder, E as createPill, t as createPlane, z as createPyramid, x as createRect, r as createSphere, s as createSprite, w as createText, u as createZone } from './entities-ChFirVL9.js';
|
|
14
|
-
import { I as GameEntity, P as GameEntityOptions, V as Vec3, R as MaterialOptions, W as MoveableEntity, O as BaseNode, X as InputPlayer } from './entity-vj-HTjzU.js';
|
|
15
|
-
export { A as Action, a6 as CollisionComponent, af as EntityConfigPayload, ab as EntityEvents, a7 as EventEmitterDelegate, aa as GameEvents, ac as GameLoadingPayload, N as LoadingEvent, L as SetupContext, ae as StageConfigPayload, Q as StageEvents, ad as StateDispatchPayload, U as UpdateContext, a9 as ZylemEvents, Z as ZylemShader, ag as ZylemShaderObject, ah as ZylemTSLShader, _ as boxCollision, a0 as coneCollision, Y as create, a2 as cylinderCollision, aj as isGLSLShader, ai as isTSLShader, m as move, a3 as pillCollision, a4 as planeCollision, a1 as pyramidCollision, g as resetVelocity, p as rotateInDirection, $ as sphereCollision, a5 as zoneCollision, a8 as zylemEventBus } from './entity-vj-HTjzU.js';
|
|
16
|
-
import { c as BehaviorDescriptor } from './behavior-descriptor-BXnVR8Ki.js';
|
|
17
|
-
export { d as BehaviorHandle, e as BehaviorRef, B as BehaviorSystem, b as BehaviorSystemFactory, D as DefineBehaviorConfig, f as defineBehavior } from './behavior-descriptor-BXnVR8Ki.js';
|
|
18
|
-
import { T as ThrusterInputComponent } from './thruster-23lzoPZd.js';
|
|
19
|
-
export { B as Behavior, P as PhysicsBodyComponent, m as PlayerInput, p as ThrusterBehavior, q as ThrusterBehaviorOptions, o as ThrusterEntity, j as ThrusterEvent, k as ThrusterFSM, l as ThrusterFSMContext, n as ThrusterMovementBehavior, d as ThrusterMovementComponent, i as ThrusterState, e as ThrusterStateComponent, a as TransformComponent, b as createPhysicsBodyComponent, g as createThrusterInputComponent, f as createThrusterMovementComponent, h as createThrusterStateComponent, c as createTransformComponent } from './thruster-23lzoPZd.js';
|
|
20
|
-
import { TopDownMovementInputComponent } from './behavior/top-down-movement.js';
|
|
21
|
-
export { TopDownMovementBehavior, TopDownMovementBehaviorOptions, TopDownMovementComponent, TopDownMovementEntity, TopDownMovementHandle, TopDownMovementRuntimeBehavior, TopDownMovementStateComponent, createTopDownMovementComponent, createTopDownMovementInputComponent, createTopDownMovementStateComponent } from './behavior/top-down-movement.js';
|
|
22
|
-
import { Shooter2DSourceEntity, Shooter2DHandle, Shooter2DStageLike } from './behavior/shooter-2d.js';
|
|
23
|
-
export { Shooter2DBehavior, Shooter2DBehaviorOptions, Shooter2DFireArgs, Shooter2DProjectileFactory, Shooter2DStateComponent, Shooter2DTarget, createShooter2DStateComponent } from './behavior/shooter-2d.js';
|
|
24
|
-
export { ScreenWrapBehavior, ScreenWrapEvent, ScreenWrapFSM, ScreenWrapOptions, ScreenWrapState } from './behavior/screen-wrap.js';
|
|
25
|
-
export { ScreenVisibilityBehavior, ScreenVisibilityChangeContext, ScreenVisibilityFSM, ScreenVisibilityHandle, ScreenVisibilityOptions, ScreenVisibilitySize, ScreenVisibilitySnapshot } from './behavior/screen-visibility.js';
|
|
26
|
-
import { WorldBoundary2DHandle } from './behavior/world-boundary-2d.js';
|
|
27
|
-
export { WorldBoundary2DBehavior, WorldBoundary2DBounds, WorldBoundary2DEvent, WorldBoundary2DFSM, WorldBoundary2DHit, WorldBoundary2DHits, WorldBoundary2DOptions, WorldBoundary2DPosition, WorldBoundary2DState, computeWorldBoundary2DHits, hasAnyWorldBoundary2DHit } from './behavior/world-boundary-2d.js';
|
|
28
|
-
import { WorldBoundary3DHandle } from './behavior/world-boundary-3d.js';
|
|
29
|
-
export { WorldBoundary3DBehavior, WorldBoundary3DBounds, WorldBoundary3DEvent, WorldBoundary3DFSM, WorldBoundary3DHit, WorldBoundary3DHits, WorldBoundary3DOptions, WorldBoundary3DPosition, WorldBoundary3DState, computeWorldBoundary3DHits, hasAnyWorldBoundary3DHit } from './behavior/world-boundary-3d.js';
|
|
30
|
-
import { Ricochet2DHandle } from './behavior/ricochet-2d.js';
|
|
31
|
-
export { Ricochet2DBehavior, Ricochet2DCollisionContext, Ricochet2DEvent, Ricochet2DFSM, Ricochet2DOptions, Ricochet2DResult, Ricochet2DState, RicochetCallback } from './behavior/ricochet-2d.js';
|
|
32
|
-
import { Ricochet3DHandle } from './behavior/ricochet-3d.js';
|
|
33
|
-
export { Ricochet3DBehavior, Ricochet3DCallback, Ricochet3DCollisionContext, Ricochet3DEvent, Ricochet3DFSM, Ricochet3DOptions, Ricochet3DResult, Ricochet3DState } from './behavior/ricochet-3d.js';
|
|
34
|
-
export { Platformer3DBehavior, Platformer3DBehaviorOptions, Platformer3DContext, Platformer3DEntity, Platformer3DEvent, Platformer3DFSM, Platformer3DInputComponent, Platformer3DMovementBehavior, Platformer3DMovementComponent, Platformer3DState, Platformer3DStateComponent, PlatformerCollisionContext, createPlatformer3DInputComponent, createPlatformer3DMovementComponent, createPlatformer3DStateComponent } from './behavior/platformer-3d.js';
|
|
35
|
-
import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
|
|
36
|
-
export { JumpConfig2D, JumpContext2D, JumpInput2D, JumpState2D, Jumper2D, Jumper2DBehavior, Jumper2DBehaviorOptions, Jumper2DEntity, Jumper2DEvent, Jumper2DFSM, Jumper2DState, Jumper2DTickEvent, Jumper2DTickResult, createJumpConfig2D, createJumpInput2D, createJumpState2D } from './behavior/jumper-2d.js';
|
|
37
|
-
export { c as callFunc, d as delay, m as moveBy, a as moveTo, o as onPress, b as onRelease, p as parallel, e as repeat, f as repeatForever, r as rotateBy, s as sequence, t as throttle } from './composition-BASvMKrW.js';
|
|
38
|
-
export { Howl } from 'howler';
|
|
39
|
-
import * as RAPIER from '@dimforge/rapier3d-compat';
|
|
40
|
-
export { RAPIER };
|
|
41
|
-
export { g as globalChange, a as globalChanges, v as variableChange, b as variableChanges } from './global-change-2JvMaz44.js';
|
|
42
|
-
export { Fn, float, time, uniform, uv, vec3, vec4 } from 'three/tsl';
|
|
43
|
-
import 'bitecs';
|
|
44
|
-
import './world-DfgxoNMt.js';
|
|
45
|
-
import './entity-types-DAu8sGJH.js';
|
|
46
|
-
import './physics-pose-DCc4oE44.js';
|
|
47
|
-
import '@sinclair/typebox';
|
|
48
|
-
import 'three/webgpu';
|
|
49
|
-
import 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
50
|
-
import 'mitt';
|
|
51
|
-
import 'typescript-fsm';
|
|
52
|
-
|
|
53
|
-
declare const stageState: {
|
|
54
|
-
previous: StageBlueprint | null;
|
|
55
|
-
current: StageBlueprint | null;
|
|
56
|
-
next: StageBlueprint | null;
|
|
57
|
-
isLoading: boolean;
|
|
58
|
-
};
|
|
59
|
-
declare const StageManager: {
|
|
60
|
-
staticRegistry: Map<string, {
|
|
61
|
-
name?: string | undefined;
|
|
62
|
-
assets?: string[] | undefined;
|
|
63
|
-
id: string;
|
|
64
|
-
entities: {
|
|
65
|
-
position?: [number, number] | undefined;
|
|
66
|
-
data?: {
|
|
67
|
-
[x: string]: any;
|
|
68
|
-
} | undefined;
|
|
69
|
-
id: string;
|
|
70
|
-
type: string;
|
|
71
|
-
}[];
|
|
72
|
-
}>;
|
|
73
|
-
registerStaticStage(id: string, blueprint: StageBlueprint): void;
|
|
74
|
-
loadStageData(stageId: string): Promise<StageBlueprint>;
|
|
75
|
-
transitionForward(nextStageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Manually set the next stage to pre-load it.
|
|
78
|
-
*/
|
|
79
|
-
preloadNext(stageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>): Promise<void>;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Options for the followTarget behavior.
|
|
84
|
-
*/
|
|
85
|
-
interface FollowTargetOptions {
|
|
86
|
-
/** Key in CameraContext.targets to follow. Default 'primary'. */
|
|
87
|
-
targetKey?: string;
|
|
88
|
-
/** Position offset from the target. Default (0, 0, 0). */
|
|
89
|
-
offset?: Vector3;
|
|
90
|
-
/**
|
|
91
|
-
* Per-frame interpolation factor (0-1). Controls how quickly the
|
|
92
|
-
* pose converges on the target each frame.
|
|
93
|
-
* 1 = instant snap, lower = smoother follow.
|
|
94
|
-
* Default 0.1.
|
|
95
|
-
*/
|
|
96
|
-
lerpFactor?: number;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* A simple follow behavior that moves the camera pose toward a target's position + offset.
|
|
100
|
-
*
|
|
101
|
-
* This behavior modifies only the position (and lookAt) of the incoming pose,
|
|
102
|
-
* leaving rotation/fov/zoom to the perspective or other behaviors.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```ts
|
|
106
|
-
* camera.addBehavior('follow', createFollowTarget({ targetKey: 'player', offset: new Vector3(0, 3, 8) }));
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function createFollowTarget(options?: FollowTargetOptions): CameraBehavior;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Options for setCameraFeed.
|
|
113
|
-
*/
|
|
114
|
-
interface CameraFeedOptions {
|
|
115
|
-
/** Render target width in pixels. Only used when the camera does not
|
|
116
|
-
* already have a render target. @default 512 */
|
|
117
|
-
width?: number;
|
|
118
|
-
/** Render target height in pixels. Only used when the camera does not
|
|
119
|
-
* already have a render target. @default 512 */
|
|
120
|
-
height?: number;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Display a camera's live feed on an entity's mesh surface.
|
|
124
|
-
*
|
|
125
|
-
* This is the primary user-facing function for "jumbotron", security-camera,
|
|
126
|
-
* or broadcast-style effects. It ensures the camera has an offscreen render
|
|
127
|
-
* target and replaces the entity's mesh material with one that shows the
|
|
128
|
-
* camera's rendered output.
|
|
129
|
-
*
|
|
130
|
-
* @param entity The entity whose mesh will display the camera feed.
|
|
131
|
-
* @param camera The camera whose view will be rendered to the texture.
|
|
132
|
-
* @param options Optional dimensions for the render target.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```ts
|
|
136
|
-
* const feedCam = createCamera({
|
|
137
|
-
* perspective: Perspectives.ThirdPerson,
|
|
138
|
-
* position: new Vector3(0, 30, 60),
|
|
139
|
-
* target: new Vector3(0, 0, 0),
|
|
140
|
-
* renderToTexture: { width: 1024, height: 576 },
|
|
141
|
-
* });
|
|
142
|
-
*
|
|
143
|
-
* const screen = createBox({ size: { x: 16, y: 9, z: 0.2 } });
|
|
144
|
-
* screen.onSetup(({ me }) => {
|
|
145
|
-
* setCameraFeed(me, feedCam);
|
|
146
|
-
* });
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
declare function setCameraFeed(entity: StageEntity, camera: CameraWrapper, options?: CameraFeedOptions): void;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Factory interface for generating entity copies
|
|
153
|
-
*/
|
|
154
|
-
interface TemplateFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions> {
|
|
155
|
-
/** The template entity used for cloning */
|
|
156
|
-
readonly template: E;
|
|
157
|
-
/**
|
|
158
|
-
* Generate multiple copies of the template entity
|
|
159
|
-
* @param count Number of copies to generate
|
|
160
|
-
* @returns Array of new entity instances
|
|
161
|
-
*/
|
|
162
|
-
generate(count: number): E[];
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Create an entity factory from a template entity.
|
|
166
|
-
*
|
|
167
|
-
* @param template The entity to use as a template for cloning
|
|
168
|
-
* @returns Factory object with generate() method
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* const asteroidTemplate = createSprite({ images: [{ name: 'asteroid', file: asteroidImg }] });
|
|
173
|
-
* const asteroidFactory = createEntityFactory(asteroidTemplate);
|
|
174
|
-
* const asteroids = asteroidFactory.generate(10);
|
|
175
|
-
*
|
|
176
|
-
* asteroids.forEach((asteroid, i) => {
|
|
177
|
-
* asteroid.setPosition(Math.random() * 20 - 10, Math.random() * 15 - 7.5, 0);
|
|
178
|
-
* stage.add(asteroid);
|
|
179
|
-
* });
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
declare function createEntityFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions>(template: E): TemplateFactory<E, O>;
|
|
183
|
-
|
|
184
|
-
/** Shared options that every mesh factory accepts. */
|
|
185
|
-
interface BaseMeshOptions {
|
|
186
|
-
/** Offset position relative to the entity origin */
|
|
187
|
-
position?: Vec3;
|
|
188
|
-
/** Material options (texture, shader, etc.) */
|
|
189
|
-
material?: Partial<MaterialOptions>;
|
|
190
|
-
/** Convenience color override */
|
|
191
|
-
color?: Color;
|
|
192
|
-
}
|
|
193
|
-
interface BoxMeshOptions extends BaseMeshOptions {
|
|
194
|
-
/** Box dimensions (default: 1x1x1) */
|
|
195
|
-
size?: Vec3;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Create a box mesh.
|
|
199
|
-
*/
|
|
200
|
-
declare function boxMesh(opts?: BoxMeshOptions): Mesh;
|
|
201
|
-
interface SphereMeshOptions extends BaseMeshOptions {
|
|
202
|
-
/** Sphere radius (default: 1) */
|
|
203
|
-
radius?: number;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Create a sphere mesh.
|
|
207
|
-
*/
|
|
208
|
-
declare function sphereMesh(opts?: SphereMeshOptions): Mesh;
|
|
209
|
-
interface ConeMeshOptions extends BaseMeshOptions {
|
|
210
|
-
/** Base radius (default: 1) */
|
|
211
|
-
radius?: number;
|
|
212
|
-
/** Height (default: 2) */
|
|
213
|
-
height?: number;
|
|
214
|
-
/** Radial segments (default: 32) */
|
|
215
|
-
radialSegments?: number;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Create a cone mesh.
|
|
219
|
-
*/
|
|
220
|
-
declare function coneMesh(opts?: ConeMeshOptions): Mesh;
|
|
221
|
-
interface PyramidMeshOptions extends BaseMeshOptions {
|
|
222
|
-
/** Base radius (default: 1) */
|
|
223
|
-
radius?: number;
|
|
224
|
-
/** Height (default: 2) */
|
|
225
|
-
height?: number;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Create a pyramid mesh (4-sided cone).
|
|
229
|
-
*/
|
|
230
|
-
declare function pyramidMesh(opts?: PyramidMeshOptions): Mesh;
|
|
231
|
-
interface CylinderMeshOptions extends BaseMeshOptions {
|
|
232
|
-
/** Top radius (default: 1) */
|
|
233
|
-
radiusTop?: number;
|
|
234
|
-
/** Bottom radius (default: 1) */
|
|
235
|
-
radiusBottom?: number;
|
|
236
|
-
/** Height (default: 2) */
|
|
237
|
-
height?: number;
|
|
238
|
-
/** Radial segments (default: 32) */
|
|
239
|
-
radialSegments?: number;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Create a cylinder mesh.
|
|
243
|
-
*/
|
|
244
|
-
declare function cylinderMesh(opts?: CylinderMeshOptions): Mesh;
|
|
245
|
-
interface PillMeshOptions extends BaseMeshOptions {
|
|
246
|
-
/** Capsule hemisphere radius (default: 0.5) */
|
|
247
|
-
radius?: number;
|
|
248
|
-
/** Cylindrical section length (default: 1) */
|
|
249
|
-
length?: number;
|
|
250
|
-
/** Cap segments (default: 10) */
|
|
251
|
-
capSegments?: number;
|
|
252
|
-
/** Radial segments (default: 20) */
|
|
253
|
-
radialSegments?: number;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Create a pill (capsule) mesh.
|
|
257
|
-
*/
|
|
258
|
-
declare function pillMesh(opts?: PillMeshOptions): Mesh;
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Type-safe helper to apply a behavior to an entity and return the entity cast to the behavior's interface.
|
|
262
|
-
*
|
|
263
|
-
* @param entity The entity to apply the behavior to
|
|
264
|
-
* @param descriptor The behavior descriptor
|
|
265
|
-
* @param options Behavior options
|
|
266
|
-
* @returns The entity, cast to E & I (where I is the behavior's interface)
|
|
267
|
-
*/
|
|
268
|
-
declare function useBehavior<E extends GameEntity<any>, O extends Record<string, any>, H extends Record<string, any>, I>(entity: E, descriptor: BehaviorDescriptor<O, H, I>, options?: Partial<O>): E & I;
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* First Person Controller ECS Components
|
|
272
|
-
*
|
|
273
|
-
* Components for first-person movement and camera control:
|
|
274
|
-
* - Movement configuration (walk/run speed, sensitivity, eye height)
|
|
275
|
-
* - Input intent (WASD movement + mouse look deltas)
|
|
276
|
-
* - Runtime state (yaw, pitch, speed)
|
|
277
|
-
*/
|
|
278
|
-
interface FirstPersonMovementComponent {
|
|
279
|
-
/** Base walking speed (units/sec) */
|
|
280
|
-
walkSpeed: number;
|
|
281
|
-
/** Sprint/run speed (units/sec) */
|
|
282
|
-
runSpeed: number;
|
|
283
|
-
/** Look sensitivity multiplier applied to raw input deltas */
|
|
284
|
-
lookSensitivity: number;
|
|
285
|
-
/** Vertical offset above entity position for eye/camera placement */
|
|
286
|
-
eyeHeight: number;
|
|
287
|
-
}
|
|
288
|
-
declare function createFirstPersonMovementComponent(options?: Partial<FirstPersonMovementComponent>): FirstPersonMovementComponent;
|
|
289
|
-
interface FirstPersonInputComponent {
|
|
290
|
-
/** Horizontal movement input (-1 to 1, strafe) */
|
|
291
|
-
moveX: number;
|
|
292
|
-
/** Forward/backward movement input (-1 to 1) */
|
|
293
|
-
moveZ: number;
|
|
294
|
-
/** Horizontal look delta (mouse/stick, raw value before sensitivity) */
|
|
295
|
-
lookX: number;
|
|
296
|
-
/** Vertical look delta (mouse/stick, raw value before sensitivity) */
|
|
297
|
-
lookY: number;
|
|
298
|
-
/** Sprint button held */
|
|
299
|
-
sprint: boolean;
|
|
300
|
-
}
|
|
301
|
-
declare function createFirstPersonInputComponent(): FirstPersonInputComponent;
|
|
302
|
-
interface FirstPersonStateComponent {
|
|
303
|
-
/** Current yaw in radians */
|
|
304
|
-
yaw: number;
|
|
305
|
-
/** Current pitch in radians */
|
|
306
|
-
pitch: number;
|
|
307
|
-
/** Current movement speed being applied */
|
|
308
|
-
currentSpeed: number;
|
|
309
|
-
}
|
|
310
|
-
declare function createFirstPersonStateComponent(): FirstPersonStateComponent;
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* First Person Controller Finite State Machine
|
|
314
|
-
*
|
|
315
|
-
* Manages state transitions for first-person movement:
|
|
316
|
-
* - Idle: Standing still
|
|
317
|
-
* - Walking: Moving at walk speed
|
|
318
|
-
* - Running: Moving at run/sprint speed
|
|
319
|
-
*/
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* First-person movement states
|
|
323
|
-
*/
|
|
324
|
-
declare enum FirstPersonState {
|
|
325
|
-
Idle = "idle",
|
|
326
|
-
Walking = "walking",
|
|
327
|
-
Running = "running"
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Events that trigger state transitions
|
|
331
|
-
*/
|
|
332
|
-
declare enum FirstPersonEvent {
|
|
333
|
-
Walk = "walk",
|
|
334
|
-
Run = "run",
|
|
335
|
-
Stop = "stop"
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Context for the FSM
|
|
339
|
-
*/
|
|
340
|
-
interface FirstPersonContext {
|
|
341
|
-
input: FirstPersonInputComponent;
|
|
342
|
-
state: FirstPersonStateComponent;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* First Person Controller FSM
|
|
346
|
-
*/
|
|
347
|
-
declare class FirstPersonFSM {
|
|
348
|
-
private ctx;
|
|
349
|
-
machine: SyncStateMachine<FirstPersonState, FirstPersonEvent, never>;
|
|
350
|
-
constructor(ctx: FirstPersonContext);
|
|
351
|
-
/** Get the current state */
|
|
352
|
-
getState(): FirstPersonState;
|
|
353
|
-
/** Dispatch an event to the FSM */
|
|
354
|
-
dispatch(event: FirstPersonEvent): void;
|
|
355
|
-
/** Get the current yaw from context */
|
|
356
|
-
getYaw(): number;
|
|
357
|
-
/** Get the current pitch from context */
|
|
358
|
-
getPitch(): number;
|
|
359
|
-
/**
|
|
360
|
-
* Update FSM based on current input and state.
|
|
361
|
-
*/
|
|
362
|
-
update(input: FirstPersonInputComponent, state: FirstPersonStateComponent): void;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* First Person Controller Behavior System
|
|
367
|
-
*
|
|
368
|
-
* Handles first-person camera control and movement:
|
|
369
|
-
* - Reads input component for WASD movement and mouse look deltas
|
|
370
|
-
* - Drives a FirstPersonPerspective (yaw/pitch accumulation)
|
|
371
|
-
* - Writes velocity to transformStore (physics-based movement)
|
|
372
|
-
* - Syncs camera position from the entity's rigid body each frame
|
|
373
|
-
* - Positions an optional viewmodel entity relative to the camera
|
|
374
|
-
*/
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Viewmodel configuration for an entity that follows the camera.
|
|
378
|
-
*/
|
|
379
|
-
interface ViewmodelConfig {
|
|
380
|
-
/** The entity whose visual group should be positioned relative to the camera. */
|
|
381
|
-
entity: any;
|
|
382
|
-
/** Offset from the eye position in camera-local space (right, down, forward). */
|
|
383
|
-
offset: Vector3;
|
|
384
|
-
/** Additional rotation applied to the viewmodel in local space (Euler angles in radians). */
|
|
385
|
-
rotation?: Euler;
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Entity interface for first-person controller.
|
|
389
|
-
* Entities with this behavior have these components attached.
|
|
390
|
-
*/
|
|
391
|
-
interface FirstPersonEntity {
|
|
392
|
-
uuid: string;
|
|
393
|
-
body: any;
|
|
394
|
-
transformStore: any;
|
|
395
|
-
firstPerson: FirstPersonMovementComponent;
|
|
396
|
-
$fps: FirstPersonInputComponent;
|
|
397
|
-
firstPersonState: FirstPersonStateComponent;
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* First Person Controller Behavior
|
|
401
|
-
*
|
|
402
|
-
* Core movement + look system for first-person cameras.
|
|
403
|
-
* Reads from entity.$fps input component and drives a FirstPersonPerspective.
|
|
404
|
-
*/
|
|
405
|
-
declare class FirstPersonControllerBehavior {
|
|
406
|
-
private world;
|
|
407
|
-
private perspectives;
|
|
408
|
-
private viewmodels;
|
|
409
|
-
constructor(world: any);
|
|
410
|
-
/**
|
|
411
|
-
* Associate a FirstPersonPerspective with an entity (by uuid).
|
|
412
|
-
* Called once by the descriptor system when the behavior is initialized.
|
|
413
|
-
*/
|
|
414
|
-
setPerspective(entityUuid: string, perspective: FirstPersonPerspective): void;
|
|
415
|
-
hasPerspective(entityUuid: string): boolean;
|
|
416
|
-
/**
|
|
417
|
-
* Attach a viewmodel (weapon/item) to an entity.
|
|
418
|
-
* The viewmodel entity's group will be positioned relative to the camera each frame.
|
|
419
|
-
*/
|
|
420
|
-
setViewmodel(entityUuid: string, config: ViewmodelConfig): void;
|
|
421
|
-
hasViewmodel(entityUuid: string): boolean;
|
|
422
|
-
/**
|
|
423
|
-
* Update one first-person entity.
|
|
424
|
-
*/
|
|
425
|
-
updateEntity(entity: any, _delta: number): void;
|
|
426
|
-
/**
|
|
427
|
-
* Update all first-person entities.
|
|
428
|
-
*/
|
|
429
|
-
update(delta: number): void;
|
|
430
|
-
/**
|
|
431
|
-
* Position a viewmodel entity relative to the camera's eye position and rotation.
|
|
432
|
-
*
|
|
433
|
-
* The physics transform system overwrites group.position from the rigid body
|
|
434
|
-
* each frame, so we must also move the body to keep them in sync.
|
|
435
|
-
*/
|
|
436
|
-
private positionViewmodel;
|
|
437
|
-
/** Cleanup */
|
|
438
|
-
destroy(): void;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* First-person controller behavior options (typed for entity.use() autocomplete).
|
|
443
|
-
*/
|
|
444
|
-
interface FirstPersonControllerOptions {
|
|
445
|
-
/** Base walking speed (default: 8) */
|
|
446
|
-
walkSpeed?: number;
|
|
447
|
-
/** Sprint/run speed (default: 16) */
|
|
448
|
-
runSpeed?: number;
|
|
449
|
-
/** Look sensitivity multiplier (default: 2) */
|
|
450
|
-
lookSensitivity?: number;
|
|
451
|
-
/** Eye height offset above entity position (default: 1.7) */
|
|
452
|
-
eyeHeight?: number;
|
|
453
|
-
/** The FirstPersonPerspective to drive (from camera.getPerspective()) */
|
|
454
|
-
perspective?: FirstPersonPerspective;
|
|
455
|
-
/** Optional viewmodel (weapon/item) to position relative to the camera */
|
|
456
|
-
viewmodel?: {
|
|
457
|
-
entity: any;
|
|
458
|
-
offset: Vector3;
|
|
459
|
-
rotation?: Euler;
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* FirstPersonController - typed descriptor for first-person movement and camera control.
|
|
464
|
-
*
|
|
465
|
-
* Provides complete first-person controller including:
|
|
466
|
-
* - WASD movement relative to camera yaw
|
|
467
|
-
* - Mouse look driving a FirstPersonPerspective
|
|
468
|
-
* - Optional viewmodel positioning (weapon/item following camera)
|
|
469
|
-
* - Walk/run state tracking via FSM
|
|
470
|
-
*
|
|
471
|
-
* @example
|
|
472
|
-
* ```typescript
|
|
473
|
-
* import { FirstPersonController, FirstPersonPerspective, createActor, createCamera, Perspectives } from "@zylem/game-lib";
|
|
474
|
-
*
|
|
475
|
-
* const fpsCamera = createCamera({ perspective: Perspectives.FirstPerson, ... });
|
|
476
|
-
* const fps = fpsCamera.getPerspective<FirstPersonPerspective>();
|
|
477
|
-
*
|
|
478
|
-
* const player = createActor({ name: 'player', ... });
|
|
479
|
-
* const controller = player.use(FirstPersonController, {
|
|
480
|
-
* perspective: fps,
|
|
481
|
-
* walkSpeed: 8,
|
|
482
|
-
* runSpeed: 16,
|
|
483
|
-
* lookSensitivity: 2,
|
|
484
|
-
* });
|
|
485
|
-
*
|
|
486
|
-
* // In update loop - write input, behavior handles the rest
|
|
487
|
-
* player.onUpdate(({ inputs }) => {
|
|
488
|
-
* player.$fps.moveX = inputs.p1.axes.Horizontal.value;
|
|
489
|
-
* player.$fps.moveZ = inputs.p1.axes.Vertical.value;
|
|
490
|
-
* player.$fps.lookX = inputs.p1.axes.SecondaryHorizontal.value;
|
|
491
|
-
* player.$fps.lookY = inputs.p1.axes.SecondaryVertical.value;
|
|
492
|
-
* player.$fps.sprint = inputs.p1.shoulders.LTrigger.held > 0;
|
|
493
|
-
* });
|
|
494
|
-
* ```
|
|
495
|
-
*/
|
|
496
|
-
declare const FirstPersonController: BehaviorDescriptor<FirstPersonControllerOptions, {
|
|
497
|
-
getState: () => FirstPersonState;
|
|
498
|
-
getYaw: () => number;
|
|
499
|
-
getPitch: () => number;
|
|
500
|
-
attachViewmodel: (entity: any, offset: Vector3) => void;
|
|
501
|
-
}, FirstPersonEntity>;
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Jumper 3D ECS Components
|
|
505
|
-
*
|
|
506
|
-
* Type definitions and factory functions for the 3D jump behavior system.
|
|
507
|
-
*
|
|
508
|
-
* - JumpConfig3D: tunable parameters (stored as the capability component)
|
|
509
|
-
* - JumpInput3D: per-tick intent written by the player/AI controller
|
|
510
|
-
* - JumpContext3D: per-tick snapshot provided by the system adapter
|
|
511
|
-
* - JumpState3D: internal runtime state owned by the behavior
|
|
512
|
-
*/
|
|
513
|
-
interface Vec3Like {
|
|
514
|
-
x: number;
|
|
515
|
-
y: number;
|
|
516
|
-
z: number;
|
|
517
|
-
}
|
|
518
|
-
interface JumpConfig3D {
|
|
519
|
-
/** Desired peak height in world units */
|
|
520
|
-
jumpHeight: number;
|
|
521
|
-
/** Gravity magnitude (positive, e.g. 20) */
|
|
522
|
-
gravity: number;
|
|
523
|
-
/** Terminal fall speed magnitude (optional) */
|
|
524
|
-
maxFallSpeed?: number;
|
|
525
|
-
/** 1 = single jump, 2 = double, etc. */
|
|
526
|
-
maxJumps: number;
|
|
527
|
-
/** Reset jump counter when grounded (usually true) */
|
|
528
|
-
resetJumpsOnGround: boolean;
|
|
529
|
-
/** Reset jump counter on wall contact (future wall-jump support) */
|
|
530
|
-
resetJumpsOnWall?: boolean;
|
|
531
|
-
/** Grace period after leaving ground where first jump is still allowed (ms) */
|
|
532
|
-
coyoteTimeMs: number;
|
|
533
|
-
/** Queue a jump press this many ms before landing (ms) */
|
|
534
|
-
jumpBufferMs: number;
|
|
535
|
-
/** Optional cooldown between consecutive jumps (ms) */
|
|
536
|
-
minTimeBetweenJumpsMs?: number;
|
|
537
|
-
/** Variable jump height via early release */
|
|
538
|
-
variableJump?: {
|
|
539
|
-
enabled: boolean;
|
|
540
|
-
/** Gravity multiplier applied when jump is released early while ascending */
|
|
541
|
-
cutGravityMultiplier: number;
|
|
542
|
-
/** Max hold duration before the cut triggers automatically (ms, optional) */
|
|
543
|
-
maxHoldMs?: number;
|
|
544
|
-
};
|
|
545
|
-
/** Optional planar (XZ) launch / air-control overrides */
|
|
546
|
-
planar?: {
|
|
547
|
-
/** One-time planar speed applied at takeoff */
|
|
548
|
-
launchPlanarSpeed?: number;
|
|
549
|
-
/** If true, preserve current planar speed instead of replacing it */
|
|
550
|
-
preservePlanarSpeed?: boolean;
|
|
551
|
-
airControl?: {
|
|
552
|
-
maxPlanarSpeed: number;
|
|
553
|
-
/** Acceleration per second while airborne */
|
|
554
|
-
acceleration: number;
|
|
555
|
-
/** Deceleration per second when no input */
|
|
556
|
-
deceleration: number;
|
|
557
|
-
};
|
|
558
|
-
};
|
|
559
|
-
/** Snappier descent tuning */
|
|
560
|
-
fall?: {
|
|
561
|
-
/** Gravity multiplier while falling (e.g. 1.5-2.5) */
|
|
562
|
-
fallGravityMultiplier: number;
|
|
563
|
-
/** Additional multiplier when fast-fall input is held */
|
|
564
|
-
fastFallMultiplier?: number;
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
declare function createJumpConfig3D(options?: Partial<JumpConfig3D>): JumpConfig3D;
|
|
568
|
-
interface JumpInput3D {
|
|
569
|
-
/** True on the frame the jump button is first pressed (rising edge) */
|
|
570
|
-
jumpPressed: boolean;
|
|
571
|
-
/** True while the jump button is held down */
|
|
572
|
-
jumpHeld: boolean;
|
|
573
|
-
/** True on the frame the jump button is released (falling edge) */
|
|
574
|
-
jumpReleased: boolean;
|
|
575
|
-
/** Desired planar direction in world space (camera-relative), optional */
|
|
576
|
-
moveDirWorld?: Vec3Like;
|
|
577
|
-
/** Hold to drop faster (e.g. crouch / down input) */
|
|
578
|
-
fastFall?: boolean;
|
|
579
|
-
}
|
|
580
|
-
declare function createJumpInput3D(): JumpInput3D;
|
|
581
|
-
interface JumpContext3D {
|
|
582
|
-
/** Frame delta in seconds */
|
|
583
|
-
dt: number;
|
|
584
|
-
/** World up direction (usually 0,1,0) */
|
|
585
|
-
up: Vec3Like;
|
|
586
|
-
/** Current vertical (Y) velocity of the entity */
|
|
587
|
-
velocityY: number;
|
|
588
|
-
/** Current horizontal velocity of the entity (read from body) */
|
|
589
|
-
horizontalVelocity: {
|
|
590
|
-
x: number;
|
|
591
|
-
z: number;
|
|
592
|
-
};
|
|
593
|
-
/** Whether the entity is on the ground */
|
|
594
|
-
isGrounded: boolean;
|
|
595
|
-
/** Surface normal at ground contact (optional) */
|
|
596
|
-
groundNormal?: Vec3Like;
|
|
597
|
-
/** Time since entity was last grounded (ms) */
|
|
598
|
-
timeSinceGroundedMs: number;
|
|
599
|
-
/** Set only the vertical (Y) component of velocity */
|
|
600
|
-
setVerticalVelocity(y: number): void;
|
|
601
|
-
/** Set only the horizontal (X/Z) components of velocity */
|
|
602
|
-
setHorizontalVelocity(x: number, z: number): void;
|
|
603
|
-
}
|
|
604
|
-
interface JumpState3D {
|
|
605
|
-
/** Number of jumps consumed since last reset */
|
|
606
|
-
jumpsUsed: number;
|
|
607
|
-
/** Timestamp (ms) of the most recent jump execution */
|
|
608
|
-
lastJumpTimeMs: number;
|
|
609
|
-
/** Remaining ms in the jump-buffer window (counts down) */
|
|
610
|
-
bufferedJumpMs: number;
|
|
611
|
-
/** Remaining ms in the coyote-time window (counts down) */
|
|
612
|
-
coyoteMs: number;
|
|
613
|
-
/** True while the entity is in a jump arc (ascending phase) */
|
|
614
|
-
isJumping: boolean;
|
|
615
|
-
/** Elapsed ms since jump button was first held (for variable jump) */
|
|
616
|
-
jumpHoldMs: number;
|
|
617
|
-
/** Whether the variable-jump cut has already been applied this jump */
|
|
618
|
-
jumpCutApplied: boolean;
|
|
619
|
-
}
|
|
620
|
-
declare function createJumpState3D(): JumpState3D;
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* Jumper 3D Behavior — Pure Jump Physics
|
|
624
|
-
*
|
|
625
|
-
* A stateless tick function that receives configuration, input, context, and
|
|
626
|
-
* state, then applies jump physics through the context's velocity helpers.
|
|
627
|
-
*
|
|
628
|
-
* Vertical velocity (Y) is owned exclusively by this behavior.
|
|
629
|
-
* Horizontal velocity (X/Z) is only touched when airborne planar control
|
|
630
|
-
* is configured; otherwise the movement controller owns X/Z.
|
|
631
|
-
*/
|
|
632
|
-
|
|
633
|
-
declare class Jumper3DBehavior {
|
|
634
|
-
/**
|
|
635
|
-
* Advance the jump system by one frame.
|
|
636
|
-
*
|
|
637
|
-
* Call order within a frame:
|
|
638
|
-
* 1. Movement controller writes X/Z via transformStore.dirty.velocityX/Z.
|
|
639
|
-
* 2. `tick()` writes Y via ctx.setVerticalVelocity().
|
|
640
|
-
* (Optionally writes X/Z when airborne planar control is active.)
|
|
641
|
-
*/
|
|
642
|
-
tick(config: JumpConfig3D, input: JumpInput3D, ctx: JumpContext3D, state: JumpState3D): JumperTickResult;
|
|
643
|
-
}
|
|
644
|
-
/** Events emitted by a single tick (used by FSM). */
|
|
645
|
-
declare enum JumperTickEvent {
|
|
646
|
-
None = "none",
|
|
647
|
-
Jump = "jump",
|
|
648
|
-
Fall = "fall",
|
|
649
|
-
Land = "land"
|
|
650
|
-
}
|
|
651
|
-
interface JumperTickResult {
|
|
652
|
-
event: JumperTickEvent;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Jumper 3D Finite State Machine
|
|
657
|
-
*
|
|
658
|
-
* Three high-level states driven by events emitted from the behavior tick:
|
|
659
|
-
* Grounded ──Jump──▶ Jumping
|
|
660
|
-
* Grounded ──Fall──▶ Falling (walked off a ledge)
|
|
661
|
-
* Jumping ──Fall──▶ Falling (apex / descending)
|
|
662
|
-
* Jumping ──Jump──▶ Jumping (multi-jump)
|
|
663
|
-
* Jumping ──Land──▶ Grounded (rare — very short hop)
|
|
664
|
-
* Falling ──Land──▶ Grounded
|
|
665
|
-
* Falling ──Jump──▶ Jumping (air-jump while falling)
|
|
666
|
-
*/
|
|
667
|
-
|
|
668
|
-
declare enum Jumper3DState {
|
|
669
|
-
Grounded = "grounded",
|
|
670
|
-
Jumping = "jumping",
|
|
671
|
-
Falling = "falling"
|
|
672
|
-
}
|
|
673
|
-
declare enum Jumper3DEvent {
|
|
674
|
-
Jump = "jump",
|
|
675
|
-
Fall = "fall",
|
|
676
|
-
Land = "land"
|
|
677
|
-
}
|
|
678
|
-
interface Jumper3DFSMContext {
|
|
679
|
-
state: JumpState3D;
|
|
680
|
-
}
|
|
681
|
-
declare class Jumper3DFSM {
|
|
682
|
-
private ctx;
|
|
683
|
-
machine: SyncStateMachine<Jumper3DState, Jumper3DEvent, never>;
|
|
684
|
-
constructor(ctx: Jumper3DFSMContext);
|
|
685
|
-
getState(): Jumper3DState;
|
|
686
|
-
dispatch(event: Jumper3DEvent): void;
|
|
687
|
-
isJumping(): boolean;
|
|
688
|
-
isFalling(): boolean;
|
|
689
|
-
isGrounded(): boolean;
|
|
690
|
-
getJumpsUsed(): number;
|
|
691
|
-
/**
|
|
692
|
-
* Translate a tick event into an FSM dispatch.
|
|
693
|
-
* Also handles the implicit Grounded→Falling transition when the entity
|
|
694
|
-
* is no longer grounded but no explicit event was emitted (e.g. walked
|
|
695
|
-
* off a ledge without jumping).
|
|
696
|
-
*/
|
|
697
|
-
applyTickEvent(tickEvent: string, isGrounded: boolean): void;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
interface Jumper3DBehaviorOptions {
|
|
701
|
-
/** Desired peak height in world units (default: 2.5) */
|
|
702
|
-
jumpHeight?: number;
|
|
703
|
-
/** Gravity magnitude applied by the behavior (default: 20) */
|
|
704
|
-
gravity?: number;
|
|
705
|
-
/** Terminal fall speed (optional) */
|
|
706
|
-
maxFallSpeed?: number;
|
|
707
|
-
/** Max concurrent jumps, 1 = single, 2 = double, etc. (default: 1) */
|
|
708
|
-
maxJumps?: number;
|
|
709
|
-
/** Reset jump counter on ground (default: true) */
|
|
710
|
-
resetJumpsOnGround?: boolean;
|
|
711
|
-
/** Reset jump counter on wall contact (default: undefined) */
|
|
712
|
-
resetJumpsOnWall?: boolean;
|
|
713
|
-
/** Coyote time in ms (default: 100) */
|
|
714
|
-
coyoteTimeMs?: number;
|
|
715
|
-
/** Jump buffer in ms (default: 80) */
|
|
716
|
-
jumpBufferMs?: number;
|
|
717
|
-
/** Min cooldown between jumps in ms (optional) */
|
|
718
|
-
minTimeBetweenJumpsMs?: number;
|
|
719
|
-
/** Variable jump height config (optional) */
|
|
720
|
-
variableJump?: JumpConfig3D['variableJump'];
|
|
721
|
-
/** Planar control config (optional) */
|
|
722
|
-
planar?: JumpConfig3D['planar'];
|
|
723
|
-
/** Fall tuning (optional) */
|
|
724
|
-
fall?: JumpConfig3D['fall'];
|
|
725
|
-
/** Ground-detection ray length (default: 1.0) */
|
|
726
|
-
groundRayLength?: number;
|
|
727
|
-
/** Max support distance that counts as grounded and can snap to ground */
|
|
728
|
-
snapToGroundDistance?: number;
|
|
729
|
-
/** Enable debug visualization for ground probe rays (default: false) */
|
|
730
|
-
debugGroundProbe?: boolean;
|
|
731
|
-
}
|
|
732
|
-
interface Jumper3DEntity {
|
|
733
|
-
uuid: string;
|
|
734
|
-
body: any;
|
|
735
|
-
transformStore: any;
|
|
736
|
-
jumper: JumpConfig3D;
|
|
737
|
-
$jumper: JumpInput3D;
|
|
738
|
-
jumperState: JumpState3D;
|
|
739
|
-
}
|
|
740
|
-
/**
|
|
741
|
-
* Jumper3D — composable 3D jump behavior.
|
|
742
|
-
*
|
|
743
|
-
* Provides height-based jumping, multi-jump, coyote time, jump buffering,
|
|
744
|
-
* variable jump height, configurable fall gravity, and optional air control.
|
|
745
|
-
*
|
|
746
|
-
* Designed to compose with any movement controller (e.g. FirstPersonController)
|
|
747
|
-
* — the controller writes X/Z velocity and Jumper3D writes Y velocity.
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* ```typescript
|
|
751
|
-
* import { Jumper3D } from "@zylem/game-lib";
|
|
752
|
-
*
|
|
753
|
-
* const jumper = player.use(Jumper3D, {
|
|
754
|
-
* jumpHeight: 2.5,
|
|
755
|
-
* gravity: 20,
|
|
756
|
-
* maxJumps: 2,
|
|
757
|
-
* coyoteTimeMs: 100,
|
|
758
|
-
* jumpBufferMs: 80,
|
|
759
|
-
* variableJump: { enabled: true, cutGravityMultiplier: 3 },
|
|
760
|
-
* fall: { fallGravityMultiplier: 1.5 },
|
|
761
|
-
* });
|
|
762
|
-
*
|
|
763
|
-
* player.onUpdate(({ inputs }) => {
|
|
764
|
-
* player.$jumper.jumpPressed = inputs.p1.buttons.A.pressed;
|
|
765
|
-
* player.$jumper.jumpHeld = inputs.p1.buttons.A.held > 0;
|
|
766
|
-
* player.$jumper.jumpReleased = inputs.p1.buttons.A.released;
|
|
767
|
-
*
|
|
768
|
-
* const state = jumper.getState(); // Grounded | Jumping | Falling
|
|
769
|
-
* });
|
|
770
|
-
* ```
|
|
771
|
-
*/
|
|
772
|
-
declare const Jumper3D: BehaviorDescriptor<Jumper3DBehaviorOptions, {
|
|
773
|
-
getState: () => Jumper3DState;
|
|
774
|
-
isJumping: () => boolean;
|
|
775
|
-
getJumpsUsed: () => number;
|
|
776
|
-
getJumpsRemaining: () => number;
|
|
777
|
-
}, Jumper3DEntity>;
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* CooldownBehavior
|
|
781
|
-
*
|
|
782
|
-
* A stage-scoped behavior that manages named cooldowns via the global CooldownStore.
|
|
783
|
-
* Entities use this to register, check, and fire cooldowns.
|
|
784
|
-
* UI components (CooldownIcon) can read from the same store.
|
|
785
|
-
*/
|
|
786
|
-
interface CooldownConfig {
|
|
787
|
-
/** Duration in seconds */
|
|
788
|
-
duration: number;
|
|
789
|
-
/** Whether the cooldown starts ready (default: true) */
|
|
790
|
-
immediate?: boolean;
|
|
791
|
-
}
|
|
792
|
-
interface CooldownOptions {
|
|
793
|
-
/**
|
|
794
|
-
* Named cooldowns to register.
|
|
795
|
-
* Keys are the cooldown names, values are their config.
|
|
796
|
-
*/
|
|
797
|
-
cooldowns: Record<string, CooldownConfig>;
|
|
798
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* Handle methods returned by entity.use(CooldownBehavior, ...).
|
|
801
|
-
*/
|
|
802
|
-
interface CooldownHandle {
|
|
803
|
-
/** Check if a named cooldown is ready */
|
|
804
|
-
isReady(name: string): boolean;
|
|
805
|
-
/** Fire (trigger) a named cooldown, resetting its timer */
|
|
806
|
-
fire(name: string): void;
|
|
807
|
-
/** Force a cooldown to ready immediately */
|
|
808
|
-
reset(name: string): void;
|
|
809
|
-
/** Get cooldown progress 0..1 (0 = just fired, 1 = ready) */
|
|
810
|
-
getProgress(name: string): number;
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* CooldownBehavior
|
|
814
|
-
*
|
|
815
|
-
* @example
|
|
816
|
-
* ```ts
|
|
817
|
-
* import { CooldownBehavior, moveBy } from '@zylem/game-lib';
|
|
818
|
-
*
|
|
819
|
-
* const hero = createBox({ ... });
|
|
820
|
-
* const cd = hero.use(CooldownBehavior, {
|
|
821
|
-
* cooldowns: {
|
|
822
|
-
* attack: { duration: 5 },
|
|
823
|
-
* dash: { duration: 2, immediate: false },
|
|
824
|
-
* },
|
|
825
|
-
* });
|
|
826
|
-
*
|
|
827
|
-
* hero.onUpdate(({ me, inputs }) => {
|
|
828
|
-
* if (cd.isReady('attack') && inputs.p1.buttons.A.pressed) {
|
|
829
|
-
* cd.fire('attack');
|
|
830
|
-
* // perform attack
|
|
831
|
-
* }
|
|
832
|
-
* if (cd.isReady('dash') && inputs.p1.buttons.B.pressed) {
|
|
833
|
-
* cd.fire('dash');
|
|
834
|
-
* me.runAction(moveBy({ x: 10, duration: 0.3 }));
|
|
835
|
-
* }
|
|
836
|
-
* });
|
|
837
|
-
* ```
|
|
838
|
-
*/
|
|
839
|
-
declare const CooldownBehavior: BehaviorDescriptor<CooldownOptions, CooldownHandle, unknown>;
|
|
840
|
-
|
|
841
|
-
/**
|
|
842
|
-
* A single cooldown entry in the global store.
|
|
843
|
-
*/
|
|
844
|
-
interface CooldownEntry {
|
|
845
|
-
/** Identifier for this cooldown */
|
|
846
|
-
name: string;
|
|
847
|
-
/** Total cooldown time in seconds */
|
|
848
|
-
duration: number;
|
|
849
|
-
/** Time accumulated since last fire */
|
|
850
|
-
elapsed: number;
|
|
851
|
-
/** Whether the cooldown is ready (elapsed >= duration) */
|
|
852
|
-
ready: boolean;
|
|
853
|
-
/** Normalized progress 0..1 (0 = just fired, 1 = ready) */
|
|
854
|
-
progress: number;
|
|
855
|
-
/** Whether this cooldown is currently counting down */
|
|
856
|
-
active: boolean;
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Register a named cooldown in the global store.
|
|
860
|
-
* If a cooldown with the same name already exists, it is overwritten.
|
|
861
|
-
*
|
|
862
|
-
* @param name Unique cooldown identifier
|
|
863
|
-
* @param duration Cooldown duration in seconds
|
|
864
|
-
* @param immediate If true, the cooldown starts ready (default: true)
|
|
865
|
-
*/
|
|
866
|
-
declare function registerCooldown(name: string, duration: number, immediate?: boolean): void;
|
|
867
|
-
/**
|
|
868
|
-
* Get a cooldown entry by name.
|
|
869
|
-
* Returns undefined if the cooldown has not been registered.
|
|
870
|
-
*/
|
|
871
|
-
declare function getCooldown(name: string): CooldownEntry | undefined;
|
|
872
|
-
/**
|
|
873
|
-
* Fire (trigger) a cooldown, resetting its timer.
|
|
874
|
-
* Sets the cooldown to not-ready and starts the countdown.
|
|
875
|
-
*/
|
|
876
|
-
declare function fireCooldown(name: string): void;
|
|
877
|
-
/**
|
|
878
|
-
* Force a cooldown to ready immediately.
|
|
879
|
-
*/
|
|
880
|
-
declare function resetCooldown(name: string): void;
|
|
881
|
-
/**
|
|
882
|
-
* Advance all active cooldowns by delta seconds.
|
|
883
|
-
* Called once per frame by the CooldownBehavior system.
|
|
884
|
-
*/
|
|
885
|
-
declare function tickCooldowns(delta: number): void;
|
|
886
|
-
/**
|
|
887
|
-
* Get the raw cooldown store (for advanced/debugging use).
|
|
888
|
-
*/
|
|
889
|
-
declare function getCooldownStore(): Record<string, CooldownEntry>;
|
|
890
|
-
|
|
891
|
-
/**
|
|
892
|
-
* Coordinator that bridges WorldBoundary2DBehavior and Ricochet2DBehavior.
|
|
893
|
-
*
|
|
894
|
-
* Automatically handles:
|
|
895
|
-
* 1. Checking boundary hits
|
|
896
|
-
* 2. Computing collision normals
|
|
897
|
-
* 3. Requesting ricochet result
|
|
898
|
-
* 4. Applying movement
|
|
899
|
-
*/
|
|
900
|
-
declare class BoundaryRicochetCoordinator {
|
|
901
|
-
private entity;
|
|
902
|
-
private boundary;
|
|
903
|
-
private ricochet;
|
|
904
|
-
constructor(entity: GameEntity<any> & MoveableEntity, boundary: WorldBoundary2DHandle, ricochet: Ricochet2DHandle);
|
|
905
|
-
/**
|
|
906
|
-
* Update loop - call this every frame.
|
|
907
|
-
* Applies ricochet via transformStore and notifies listeners.
|
|
908
|
-
*
|
|
909
|
-
* @returns true if ricochet was applied, false otherwise
|
|
910
|
-
*/
|
|
911
|
-
update(): boolean;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
declare class BoundaryRicochet3DCoordinator {
|
|
915
|
-
private entity;
|
|
916
|
-
private boundary;
|
|
917
|
-
private ricochet;
|
|
918
|
-
constructor(entity: GameEntity<any> & MoveableEntity, boundary: WorldBoundary3DHandle, ricochet: Ricochet3DHandle);
|
|
919
|
-
update(): boolean;
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
interface FirstPersonShooterInput {
|
|
923
|
-
moveX: number;
|
|
924
|
-
moveZ: number;
|
|
925
|
-
lookX: number;
|
|
926
|
-
lookY: number;
|
|
927
|
-
sprint: boolean;
|
|
928
|
-
jumpPressed: boolean;
|
|
929
|
-
jumpHeld: boolean;
|
|
930
|
-
jumpReleased: boolean;
|
|
931
|
-
fastFall?: boolean;
|
|
932
|
-
}
|
|
933
|
-
interface FirstPersonShooterControllerHandle {
|
|
934
|
-
getYaw(): number;
|
|
935
|
-
}
|
|
936
|
-
interface FirstPersonShooterJumperHandle {
|
|
937
|
-
getState(): unknown;
|
|
938
|
-
}
|
|
939
|
-
type FirstPersonShooterEntity = GameEntity<any> & {
|
|
940
|
-
$fps?: FirstPersonInputComponent;
|
|
941
|
-
$jumper?: JumpInput3D;
|
|
942
|
-
};
|
|
943
|
-
declare class FirstPersonShooterCoordinator {
|
|
944
|
-
private entity;
|
|
945
|
-
private fpsController;
|
|
946
|
-
private jumper;
|
|
947
|
-
constructor(entity: FirstPersonShooterEntity, fpsController: FirstPersonShooterControllerHandle, jumper: FirstPersonShooterJumperHandle);
|
|
948
|
-
update(input: FirstPersonShooterInput): void;
|
|
949
|
-
private getMoveDirWorld;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
interface TopDownShooterInput {
|
|
953
|
-
moveX: number;
|
|
954
|
-
moveY: number;
|
|
955
|
-
aimX: number;
|
|
956
|
-
aimY: number;
|
|
957
|
-
shootPressed: boolean;
|
|
958
|
-
shootHeld: boolean;
|
|
959
|
-
}
|
|
960
|
-
type TopDownShooterEntity = Shooter2DSourceEntity & {
|
|
961
|
-
$topDownMovement?: TopDownMovementInputComponent;
|
|
962
|
-
};
|
|
963
|
-
declare class TopDownShooterCoordinator {
|
|
964
|
-
private entity;
|
|
965
|
-
private shooter;
|
|
966
|
-
private stage;
|
|
967
|
-
constructor(entity: TopDownShooterEntity, shooter: Shooter2DHandle, stage: Shooter2DStageLike);
|
|
968
|
-
update(input: TopDownShooterInput): void;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
interface MultidirectionalSpaceShooterInput {
|
|
972
|
-
moveX: number;
|
|
973
|
-
moveY: number;
|
|
974
|
-
aimX: number;
|
|
975
|
-
aimY: number;
|
|
976
|
-
shootPressed: boolean;
|
|
977
|
-
shootHeld: boolean;
|
|
978
|
-
}
|
|
979
|
-
type MultidirectionalSpaceShooterEntity = GameEntity<any> & Shooter2DSourceEntity & {
|
|
980
|
-
$thruster?: ThrusterInputComponent;
|
|
981
|
-
};
|
|
982
|
-
declare class MultidirectionalSpaceShooterCoordinator {
|
|
983
|
-
private entity;
|
|
984
|
-
private shooter;
|
|
985
|
-
private stage;
|
|
986
|
-
constructor(entity: MultidirectionalSpaceShooterEntity, shooter: Shooter2DHandle, stage: Shooter2DStageLike);
|
|
987
|
-
update(input: MultidirectionalSpaceShooterInput): void;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
* CooldownIcon -- a WoW-style cooldown icon UI entity.
|
|
992
|
-
*
|
|
993
|
-
* Renders a square icon with a semi-transparent clockwise sweep overlay
|
|
994
|
-
* that reflects cooldown progress from the CooldownStore. Optionally shows
|
|
995
|
-
* remaining time text in the center.
|
|
996
|
-
*
|
|
997
|
-
* Modeled after ZylemRect's canvas-based viewport-attached sprite pattern.
|
|
998
|
-
*/
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* Reference point on the viewport for positioning UI elements.
|
|
1002
|
-
* The offset in `screenPosition` is applied relative to this anchor.
|
|
1003
|
-
*/
|
|
1004
|
-
type ScreenAnchor = 'top-left' | 'top-center' | 'top-right' | 'center-left' | 'center' | 'center-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
1005
|
-
/** Preset icon sizes in view units. */
|
|
1006
|
-
declare const ICON_SIZE_PRESETS: {
|
|
1007
|
-
readonly xs: 8;
|
|
1008
|
-
readonly sm: 16;
|
|
1009
|
-
readonly md: 32;
|
|
1010
|
-
readonly lg: 48;
|
|
1011
|
-
readonly xl: 64;
|
|
1012
|
-
};
|
|
1013
|
-
/** Named size preset. */
|
|
1014
|
-
type IconSizePreset = keyof typeof ICON_SIZE_PRESETS;
|
|
1015
|
-
/**
|
|
1016
|
-
* Icon size expressed as a named preset, a square unit value, or
|
|
1017
|
-
* a `{ width, height }` object for non-square icons.
|
|
1018
|
-
*
|
|
1019
|
-
* All numeric values are in **view units** (viewport height = 192 units).
|
|
1020
|
-
*/
|
|
1021
|
-
type IconSize = IconSizePreset | number | {
|
|
1022
|
-
width: number;
|
|
1023
|
-
height: number;
|
|
1024
|
-
};
|
|
1025
|
-
type ZylemCooldownIconOptions = GameEntityOptions & {
|
|
1026
|
-
/** Name of the cooldown in the CooldownStore */
|
|
1027
|
-
cooldown: string;
|
|
1028
|
-
/** Texture path for the icon background (optional) */
|
|
1029
|
-
icon?: string;
|
|
1030
|
-
/** Solid fill color when no icon texture is provided */
|
|
1031
|
-
fillColor?: Color | string;
|
|
1032
|
-
/**
|
|
1033
|
-
* Size of the icon in view units, a named preset, or a `{ width, height }` object.
|
|
1034
|
-
*
|
|
1035
|
-
* Presets: `'xs'` (8), `'sm'` (16), `'md'` (32), `'lg'` (48), `'xl'` (64).
|
|
1036
|
-
* A bare number creates a square icon of that many units.
|
|
1037
|
-
* The viewport height equals 192 units; width scales with aspect ratio.
|
|
1038
|
-
*
|
|
1039
|
-
* @default 'md'
|
|
1040
|
-
*/
|
|
1041
|
-
iconSize?: IconSize;
|
|
1042
|
-
/** Whether to show remaining time text */
|
|
1043
|
-
showTimer?: boolean;
|
|
1044
|
-
/** Whether to attach to the camera viewport (default: true) */
|
|
1045
|
-
stickToViewport?: boolean;
|
|
1046
|
-
/**
|
|
1047
|
-
* Viewport anchor the icon is positioned relative to.
|
|
1048
|
-
* @default 'top-left'
|
|
1049
|
-
*/
|
|
1050
|
-
screenAnchor?: ScreenAnchor;
|
|
1051
|
-
/**
|
|
1052
|
-
* Offset from the {@link screenAnchor} in **view units**.
|
|
1053
|
-
* Positive x = right, positive y = down.
|
|
1054
|
-
* Accepts a `Vector2` or a plain `{ x, y }` object.
|
|
1055
|
-
* @default { x: 0, y: 0 }
|
|
1056
|
-
*/
|
|
1057
|
-
screenPosition?: Vector2 | {
|
|
1058
|
-
x: number;
|
|
1059
|
-
y: number;
|
|
1060
|
-
};
|
|
1061
|
-
/** Distance from camera (default: 1) */
|
|
1062
|
-
zDistance?: number;
|
|
1063
|
-
/** Color of the sweep overlay (default: semi-transparent black) */
|
|
1064
|
-
overlayColor?: string;
|
|
1065
|
-
};
|
|
1066
|
-
declare class ZylemCooldownIcon extends GameEntity<ZylemCooldownIconOptions> {
|
|
1067
|
-
static type: symbol;
|
|
1068
|
-
private _sprite;
|
|
1069
|
-
private _texture;
|
|
1070
|
-
private _canvas;
|
|
1071
|
-
private _ctx;
|
|
1072
|
-
private _cameraRef;
|
|
1073
|
-
private _iconTexture;
|
|
1074
|
-
private _iconImage;
|
|
1075
|
-
private _lastRenderedProgress;
|
|
1076
|
-
constructor(options?: ZylemCooldownIconOptions);
|
|
1077
|
-
private createSprite;
|
|
1078
|
-
private redraw;
|
|
1079
|
-
private toCssColor;
|
|
1080
|
-
private getResolution;
|
|
1081
|
-
private iconSetup;
|
|
1082
|
-
private iconUpdate;
|
|
1083
|
-
/**
|
|
1084
|
-
* Resolve screen position to pixels.
|
|
1085
|
-
* Computes the anchor point in pixels, then adds the view-unit offset.
|
|
1086
|
-
*/
|
|
1087
|
-
private resolveScreenPosition;
|
|
1088
|
-
/**
|
|
1089
|
-
* Resolve `iconSize` to screen pixels using the view-unit grid.
|
|
1090
|
-
* Viewport height = {@link VIEW_UNITS_HEIGHT} units; width scales with aspect ratio.
|
|
1091
|
-
*/
|
|
1092
|
-
private resolveIconSize;
|
|
1093
|
-
/** Compute the world-space half-extents at a given distance from the camera. */
|
|
1094
|
-
private computeWorldExtents;
|
|
1095
|
-
private updateStickyTransform;
|
|
1096
|
-
/**
|
|
1097
|
-
* Dispose Three.js / DOM resources when the entity is destroyed.
|
|
1098
|
-
*/
|
|
1099
|
-
private iconDestroy;
|
|
1100
|
-
}
|
|
1101
|
-
type CooldownIconOptions = BaseNode | Partial<ZylemCooldownIconOptions>;
|
|
1102
|
-
/**
|
|
1103
|
-
* Create a WoW-style cooldown icon UI entity.
|
|
1104
|
-
*
|
|
1105
|
-
* @example
|
|
1106
|
-
* ```ts
|
|
1107
|
-
* const attackIcon = createCooldownIcon({
|
|
1108
|
-
* cooldown: 'attack',
|
|
1109
|
-
* icon: swordIconPath,
|
|
1110
|
-
* screenAnchor: 'top-center', // reference point on the viewport
|
|
1111
|
-
* screenPosition: { x: 0, y: 10 }, // offset in view units from anchor
|
|
1112
|
-
* iconSize: 'sm', // preset (16 × 16 view units)
|
|
1113
|
-
* // iconSize: 24, // square (24 × 24 view units)
|
|
1114
|
-
* // iconSize: { width: 16, height: 24 }, // custom rectangle
|
|
1115
|
-
* });
|
|
1116
|
-
* ```
|
|
1117
|
-
*/
|
|
1118
|
-
declare function createCooldownIcon(...args: Array<CooldownIconOptions>): ZylemCooldownIcon;
|
|
1119
|
-
|
|
1120
|
-
declare function destroy(entity: any, globals?: any): void;
|
|
1121
|
-
|
|
1122
|
-
/**
|
|
1123
|
-
* Plays a ricochet sound effect when boundary collision occurs
|
|
1124
|
-
*/
|
|
1125
|
-
declare function ricochetSound(frequency?: number, duration?: number): void;
|
|
1126
|
-
|
|
1127
|
-
/**
|
|
1128
|
-
* Plays a ping-pong beep sound effect.
|
|
1129
|
-
*/
|
|
1130
|
-
declare function pingPongBeep(frequency?: number, duration?: number): void;
|
|
1131
|
-
|
|
1132
|
-
/**
|
|
1133
|
-
* Maps arrow keys to axes (Horizontal/Vertical) for the given player.
|
|
1134
|
-
* @example stage.setInputConfiguration(useArrowsForAxes('p1'));
|
|
1135
|
-
*/
|
|
1136
|
-
declare function useArrowsForAxes(player: InputPlayer): GameInputConfig;
|
|
1137
|
-
/**
|
|
1138
|
-
* Maps arrow keys to secondary axes for the given player.
|
|
1139
|
-
* @example stage.setInputConfiguration(useArrowsForSecondaryAxes('p1'));
|
|
1140
|
-
*/
|
|
1141
|
-
declare function useArrowsForSecondaryAxes(player: InputPlayer): GameInputConfig;
|
|
1142
|
-
/**
|
|
1143
|
-
* Maps arrow keys to directions (Up/Down/Left/Right) for the given player.
|
|
1144
|
-
* Useful when `includeDefaults` is false and you still want arrow-key directions.
|
|
1145
|
-
* @example stage.setInputConfiguration(useArrowsForDirections('p1'));
|
|
1146
|
-
*/
|
|
1147
|
-
declare function useArrowsForDirections(player: InputPlayer): GameInputConfig;
|
|
1148
|
-
/**
|
|
1149
|
-
* Maps W/A/S/D keys to directions (Up/Down/Left/Right) for the given player.
|
|
1150
|
-
* @example stage.setInputConfiguration(useWASDForDirections('p1'));
|
|
1151
|
-
*/
|
|
1152
|
-
declare function useWASDForDirections(player: InputPlayer): GameInputConfig;
|
|
1153
|
-
/**
|
|
1154
|
-
* Maps W/A/S/D keys to axes (Horizontal/Vertical) for the given player.
|
|
1155
|
-
* @example stage.setInputConfiguration(useWASDForAxes('p1'));
|
|
1156
|
-
*/
|
|
1157
|
-
declare function useWASDForAxes(player: InputPlayer): GameInputConfig;
|
|
1158
|
-
/**
|
|
1159
|
-
* Maps I/J/K/L keys to axes (Horizontal/Vertical) for the given player.
|
|
1160
|
-
* @example stage.setInputConfiguration(useIJKLForAxes('p1'));
|
|
1161
|
-
*/
|
|
1162
|
-
declare function useIJKLForAxes(player: InputPlayer): GameInputConfig;
|
|
1163
|
-
/**
|
|
1164
|
-
* Maps I/J/K/L keys to directions (Up/Down/Left/Right) for the given player.
|
|
1165
|
-
* @example stage.setInputConfiguration(useIJKLForDirections('p1'));
|
|
1166
|
-
*/
|
|
1167
|
-
declare function useIJKLForDirections(player: InputPlayer): GameInputConfig;
|
|
1168
|
-
/**
|
|
1169
|
-
* Enables mouse-look with pointer lock for the given player.
|
|
1170
|
-
* Mouse movement maps to SecondaryHorizontal/SecondaryVertical axes;
|
|
1171
|
-
* left click maps to LTrigger, right click to RTrigger.
|
|
1172
|
-
* @example stage.setInputConfiguration(useMouseLook('p1'));
|
|
1173
|
-
*/
|
|
1174
|
-
declare function useMouseLook(player: InputPlayer, options?: {
|
|
1175
|
-
sensitivity?: number;
|
|
1176
|
-
}): GameInputConfig;
|
|
1177
|
-
/**
|
|
1178
|
-
* Enables basic mouse input (no pointer lock) for the given player.
|
|
1179
|
-
* @example stage.setInputConfiguration(useMouse('p1'));
|
|
1180
|
-
*/
|
|
1181
|
-
declare function useMouse(player: InputPlayer, options?: {
|
|
1182
|
-
sensitivity?: number;
|
|
1183
|
-
}): GameInputConfig;
|
|
1184
|
-
/**
|
|
1185
|
-
* Deep-merges multiple GameInputConfig objects into one.
|
|
1186
|
-
* At the player level, configs are merged (both apply).
|
|
1187
|
-
* At the key level, later configs win on conflict.
|
|
1188
|
-
* @example mergeInputConfigs(useArrowsForAxes('p1'), useWASDForDirections('p1'));
|
|
1189
|
-
*/
|
|
1190
|
-
declare function mergeInputConfigs(...configs: GameInputConfig[]): GameInputConfig;
|
|
1191
|
-
|
|
1192
|
-
/**
|
|
1193
|
-
* Set a global value by path.
|
|
1194
|
-
* Emits a 'game:state:updated' event when the value changes.
|
|
1195
|
-
* @example setGlobal('score', 100)
|
|
1196
|
-
* @example setGlobal('player.health', 50)
|
|
1197
|
-
*/
|
|
1198
|
-
declare function setGlobal(path: string, value: unknown): void;
|
|
1199
|
-
/**
|
|
1200
|
-
* Create/initialize a global with a default value.
|
|
1201
|
-
* Only sets the value if it doesn't already exist.
|
|
1202
|
-
* Use this to ensure globals have initial values before game starts.
|
|
1203
|
-
* @example createGlobal('score', 0)
|
|
1204
|
-
* @example createGlobal('player.health', 100)
|
|
1205
|
-
*/
|
|
1206
|
-
declare function createGlobal<T>(path: string, defaultValue: T): T;
|
|
1207
|
-
/**
|
|
1208
|
-
* Get a global value by path.
|
|
1209
|
-
* @example getGlobal('score') // 100
|
|
1210
|
-
* @example getGlobal<number>('player.health') // 50
|
|
1211
|
-
*/
|
|
1212
|
-
declare function getGlobal<T = unknown>(path: string): T | undefined;
|
|
1213
|
-
/**
|
|
1214
|
-
* Subscribe to changes on a global value at a specific path.
|
|
1215
|
-
* Returns an unsubscribe function. Subscriptions are automatically
|
|
1216
|
-
* cleaned up when the game is disposed.
|
|
1217
|
-
* @example const unsub = onGlobalChange('score', (val) => console.log(val));
|
|
1218
|
-
*/
|
|
1219
|
-
declare function onGlobalChange<T = unknown>(path: string, callback: (value: T) => void): () => void;
|
|
1220
|
-
/**
|
|
1221
|
-
* Subscribe to changes on multiple global paths.
|
|
1222
|
-
* Callback fires when any of the paths change, receiving all current values.
|
|
1223
|
-
* Subscriptions are automatically cleaned up when the game is disposed.
|
|
1224
|
-
* @example const unsub = onGlobalChanges(['score', 'lives'], ([score, lives]) => console.log(score, lives));
|
|
1225
|
-
*/
|
|
1226
|
-
declare function onGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T) => void): () => void;
|
|
1227
|
-
/**
|
|
1228
|
-
* Get the entire globals object (read-only snapshot).
|
|
1229
|
-
*/
|
|
1230
|
-
declare function getGlobals<T = Record<string, unknown>>(): T;
|
|
1231
|
-
/**
|
|
1232
|
-
* Unsubscribe all active global subscriptions.
|
|
1233
|
-
* Used internally on game dispose to prevent old callbacks from firing.
|
|
1234
|
-
*/
|
|
1235
|
-
declare function clearGlobalSubscriptions(): void;
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
* Set a variable on an object by path.
|
|
1239
|
-
* @example setVariable(stage1, 'totalAngle', 0.5)
|
|
1240
|
-
* @example setVariable(entity, 'enemy.count', 10)
|
|
1241
|
-
*/
|
|
1242
|
-
declare function setVariable(target: object, path: string, value: unknown): void;
|
|
1243
|
-
/**
|
|
1244
|
-
* Create/initialize a variable with a default value on a target object.
|
|
1245
|
-
* Only sets the value if it doesn't already exist.
|
|
1246
|
-
* @example createVariable(stage1, 'totalAngle', 0)
|
|
1247
|
-
* @example createVariable(entity, 'enemy.count', 10)
|
|
1248
|
-
*/
|
|
1249
|
-
declare function createVariable<T>(target: object, path: string, defaultValue: T): T;
|
|
1250
|
-
/**
|
|
1251
|
-
* Get a variable from an object by path.
|
|
1252
|
-
* @example getVariable(stage1, 'totalAngle') // 0.5
|
|
1253
|
-
* @example getVariable<number>(entity, 'enemy.count') // 10
|
|
1254
|
-
*/
|
|
1255
|
-
declare function getVariable<T = unknown>(target: object, path: string): T | undefined;
|
|
1256
|
-
/**
|
|
1257
|
-
* Subscribe to changes on a variable at a specific path for a target object.
|
|
1258
|
-
* Returns an unsubscribe function.
|
|
1259
|
-
* @example const unsub = onVariableChange(stage1, 'score', (val) => console.log(val));
|
|
1260
|
-
*/
|
|
1261
|
-
declare function onVariableChange<T = unknown>(target: object, path: string, callback: (value: T) => void): () => void;
|
|
1262
|
-
/**
|
|
1263
|
-
* Subscribe to changes on multiple variable paths for a target object.
|
|
1264
|
-
* Callback fires when any of the paths change, receiving all current values.
|
|
1265
|
-
* Returns an unsubscribe function.
|
|
1266
|
-
* @example const unsub = onVariableChanges(stage1, ['count', 'total'], ([count, total]) => console.log(count, total));
|
|
1267
|
-
*/
|
|
1268
|
-
declare function onVariableChanges<T extends unknown[] = unknown[]>(target: object, paths: string[], callback: (values: T) => void): () => void;
|
|
1269
|
-
|
|
1270
|
-
type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'none';
|
|
1271
|
-
interface DebugState {
|
|
1272
|
-
enabled: boolean;
|
|
1273
|
-
paused: boolean;
|
|
1274
|
-
tool: DebugTools;
|
|
1275
|
-
selectedEntity: GameEntity<any> | null;
|
|
1276
|
-
hoveredEntity: GameEntity<any> | null;
|
|
1277
|
-
flags: Set<string>;
|
|
1278
|
-
}
|
|
1279
|
-
declare const debugState: DebugState;
|
|
1280
|
-
declare function setPaused(paused: boolean): void;
|
|
1281
|
-
declare function setDebugTool(tool: DebugTools): void;
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* State interface for editor-to-game communication
|
|
1285
|
-
*/
|
|
1286
|
-
interface ZylemGameState {
|
|
1287
|
-
gameState?: {
|
|
1288
|
-
debugFlag?: boolean;
|
|
1289
|
-
[key: string]: unknown;
|
|
1290
|
-
};
|
|
1291
|
-
toolbarState?: {
|
|
1292
|
-
tool?: DebugTools;
|
|
1293
|
-
paused?: boolean;
|
|
1294
|
-
};
|
|
1295
|
-
[key: string]: unknown;
|
|
1296
|
-
}
|
|
1297
|
-
declare class ZylemGameElement extends HTMLElement {
|
|
1298
|
-
private _game;
|
|
1299
|
-
private _state;
|
|
1300
|
-
private container;
|
|
1301
|
-
private resizeObserver;
|
|
1302
|
-
private _viewportProfile;
|
|
1303
|
-
private static readonly HOST_CONFIG_MARKER;
|
|
1304
|
-
constructor();
|
|
1305
|
-
/**
|
|
1306
|
-
* Focus the game container for keyboard input
|
|
1307
|
-
*/
|
|
1308
|
-
focus(): void;
|
|
1309
|
-
connectedCallback(): void;
|
|
1310
|
-
set game(game: Game<any>);
|
|
1311
|
-
get game(): Game<any> | null;
|
|
1312
|
-
set state(value: ZylemGameState);
|
|
1313
|
-
get state(): ZylemGameState;
|
|
1314
|
-
set viewportProfile(value: DeviceProfile);
|
|
1315
|
-
get viewportProfile(): DeviceProfile;
|
|
1316
|
-
static get observedAttributes(): string[];
|
|
1317
|
-
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
1318
|
-
/**
|
|
1319
|
-
* Sync the web component's state with the game-lib's internal debug state
|
|
1320
|
-
*/
|
|
1321
|
-
private syncDebugState;
|
|
1322
|
-
/**
|
|
1323
|
-
* Sync toolbar state with game-lib's debug state
|
|
1324
|
-
*/
|
|
1325
|
-
private syncToolbarState;
|
|
1326
|
-
disconnectedCallback(): void;
|
|
1327
|
-
private attachHostContainer;
|
|
1328
|
-
private syncDisplayRuntime;
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
declare const fireShader: {
|
|
1332
|
-
vertex: string;
|
|
1333
|
-
fragment: string;
|
|
1334
|
-
};
|
|
1335
|
-
|
|
1336
|
-
declare const starShader: {
|
|
1337
|
-
vertex: string;
|
|
1338
|
-
fragment: string;
|
|
1339
|
-
};
|
|
1340
|
-
|
|
1341
|
-
declare const standardShader: {
|
|
1342
|
-
vertex: string;
|
|
1343
|
-
fragment: string;
|
|
1344
|
-
};
|
|
1345
|
-
|
|
1346
|
-
declare const debugShader: {
|
|
1347
|
-
vertex: string;
|
|
1348
|
-
fragment: string;
|
|
1349
|
-
};
|
|
1350
|
-
|
|
1351
|
-
declare const objectVertexShader = "\nuniform vec2 uvScale;\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n}\n";
|
|
1352
|
-
|
|
1353
|
-
export { BehaviorDescriptor, BoundaryRicochet3DCoordinator, BoundaryRicochetCoordinator, CameraBehavior, type CameraFeedOptions, CameraWrapper, CooldownBehavior, type CooldownConfig, type CooldownEntry, type CooldownHandle, type CooldownOptions, type DebugTools, DeviceProfile, type FirstPersonContext, FirstPersonController, FirstPersonControllerBehavior, type FirstPersonControllerOptions, type FirstPersonEntity, FirstPersonEvent, FirstPersonFSM, type FirstPersonInputComponent, type FirstPersonMovementComponent, FirstPersonPerspective, FirstPersonShooterCoordinator, type FirstPersonShooterInput, FirstPersonState, type FirstPersonStateComponent, type FollowTargetOptions, Game, type IconSize, type IconSizePreset, type JumpConfig3D, type JumpContext3D, type JumpInput3D, type JumpState3D, Jumper3D, Jumper3DBehavior, type Jumper3DBehaviorOptions, type Jumper3DEntity, Jumper3DEvent, Jumper3DFSM, Jumper3DState, JumperTickEvent, type JumperTickResult, MultidirectionalSpaceShooterCoordinator, type MultidirectionalSpaceShooterInput, Ricochet2DHandle, Ricochet3DHandle, type ScreenAnchor, Shooter2DHandle, Shooter2DSourceEntity, Shooter2DStageLike, StageBlueprint, StageEntity, StageManager, type TemplateFactory, ThrusterInputComponent, TopDownMovementInputComponent, TopDownShooterCoordinator, type TopDownShooterInput, type Vec3Like, type ViewmodelConfig, WorldBoundary2DHandle, WorldBoundary3DHandle, ZylemGameElement, type ZylemGameState, boxMesh, clearGlobalSubscriptions, coneMesh, createCooldownIcon, createEntityFactory, createFirstPersonInputComponent, createFirstPersonMovementComponent, createFirstPersonStateComponent, createFollowTarget, createGlobal, createJumpConfig3D, createJumpInput3D, createJumpState3D, createVariable, cylinderMesh, debugShader, debugState, destroy, fireCooldown, fireShader, getCooldown, getCooldownStore, getGlobal, getGlobals, getVariable, mergeInputConfigs, objectVertexShader, onGlobalChange, onGlobalChanges, onVariableChange, onVariableChanges, pillMesh, pingPongBeep, pyramidMesh, registerCooldown, resetCooldown, ricochetSound, setCameraFeed, setDebugTool, setGlobal, setPaused, setVariable, sphereMesh, stageState, standardShader, starShader, tickCooldowns, useArrowsForAxes, useArrowsForDirections, useArrowsForSecondaryAxes, useBehavior, useIJKLForAxes, useIJKLForDirections, useMouse, useMouseLook, useWASDForAxes, useWASDForDirections };
|