@zylem/game-lib 0.3.14

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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/dist/.vite/manifest.json +8 -0
  4. package/dist/assets/bounce.wav +0 -0
  5. package/dist/assets/coin-sound.mp3 +0 -0
  6. package/dist/assets/zylem-logo.png +0 -0
  7. package/dist/lib/actions/behaviors/actions.d.ts +10 -0
  8. package/dist/lib/actions/behaviors/behavior.d.ts +5 -0
  9. package/dist/lib/actions/behaviors/boundaries/boundary.d.ts +36 -0
  10. package/dist/lib/actions/behaviors/character-controller.d.ts +5 -0
  11. package/dist/lib/actions/behaviors/debug/debug-collision.d.ts +5 -0
  12. package/dist/lib/actions/behaviors/debug/debug-update.d.ts +4 -0
  13. package/dist/lib/actions/behaviors/debug/debug.d.ts +9 -0
  14. package/dist/lib/actions/behaviors/index.d.ts +1 -0
  15. package/dist/lib/actions/behaviors/movement/movement-sequence-2d.d.ts +23 -0
  16. package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.d.ts +10 -0
  17. package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.d.ts +11 -0
  18. package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts +41 -0
  19. package/dist/lib/actions/behaviors/zylem-behavior.d.ts +1 -0
  20. package/dist/lib/actions/capabilities/moveable.d.ts +124 -0
  21. package/dist/lib/actions/capabilities/rotatable.d.ts +110 -0
  22. package/dist/lib/actions/capabilities/transformable.d.ts +6 -0
  23. package/dist/lib/actions/global-change.d.ts +12 -0
  24. package/dist/lib/camera/camera.d.ts +15 -0
  25. package/dist/lib/camera/fixed-2d.d.ts +31 -0
  26. package/dist/lib/camera/perspective.d.ts +8 -0
  27. package/dist/lib/camera/third-person.d.ts +39 -0
  28. package/dist/lib/camera/zylem-camera.d.ts +68 -0
  29. package/dist/lib/collision/collision-builder.d.ts +23 -0
  30. package/dist/lib/collision/collision-delegate.d.ts +11 -0
  31. package/dist/lib/collision/collision-group.d.ts +27 -0
  32. package/dist/lib/collision/collision-mask.d.ts +17 -0
  33. package/dist/lib/collision/collision.d.ts +27 -0
  34. package/dist/lib/collision/physics.d.ts +4 -0
  35. package/dist/lib/collision/utils.d.ts +14 -0
  36. package/dist/lib/collision/world.d.ts +22 -0
  37. package/dist/lib/core/asset-manager.d.ts +1 -0
  38. package/dist/lib/core/base-node-life-cycle.d.ts +53 -0
  39. package/dist/lib/core/base-node.d.ts +32 -0
  40. package/dist/lib/core/entity-asset-loader.d.ts +29 -0
  41. package/dist/lib/core/errors.d.ts +4 -0
  42. package/dist/lib/core/flags.d.ts +2 -0
  43. package/dist/lib/core/game-canvas.d.ts +4 -0
  44. package/dist/lib/core/index.d.ts +4 -0
  45. package/dist/lib/core/lazy-loader.d.ts +81 -0
  46. package/dist/lib/core/lifecycle-base.d.ts +16 -0
  47. package/dist/lib/core/preset-shader.d.ts +10 -0
  48. package/dist/lib/core/three-addons/Timer.d.ts +106 -0
  49. package/dist/lib/core/utility.d.ts +15 -0
  50. package/dist/lib/core/vector.d.ts +3 -0
  51. package/dist/lib/core/vessel.d.ts +11 -0
  52. package/dist/lib/debug/console/console-state.d.ts +19 -0
  53. package/dist/lib/debug/console/console-store.d.ts +5 -0
  54. package/dist/lib/debug/debug-state.d.ts +43 -0
  55. package/dist/lib/debug/debug-store.d.ts +14 -0
  56. package/dist/lib/debug/state-based-debug-loader.d.ts +7 -0
  57. package/dist/lib/device/desktop.d.ts +1 -0
  58. package/dist/lib/device/mobile.d.ts +1 -0
  59. package/dist/lib/device/tablet.d.ts +1 -0
  60. package/dist/lib/entities/actor.d.ts +57 -0
  61. package/dist/lib/entities/box.d.ts +26 -0
  62. package/dist/lib/entities/builder.d.ts +27 -0
  63. package/dist/lib/entities/create.d.ts +14 -0
  64. package/dist/lib/entities/delegates/animation.d.ts +32 -0
  65. package/dist/lib/entities/delegates/debug.d.ts +37 -0
  66. package/dist/lib/entities/delegates/loader.d.ts +11 -0
  67. package/dist/lib/entities/destroy.d.ts +3 -0
  68. package/dist/lib/entities/entity.d.ts +100 -0
  69. package/dist/lib/entities/index.d.ts +11 -0
  70. package/dist/lib/entities/object.d.ts +1 -0
  71. package/dist/lib/entities/plane.d.ts +35 -0
  72. package/dist/lib/entities/rect.d.ts +62 -0
  73. package/dist/lib/entities/sphere.d.ts +28 -0
  74. package/dist/lib/entities/sprite.d.ts +52 -0
  75. package/dist/lib/entities/text.d.ts +41 -0
  76. package/dist/lib/entities/zone.d.ts +53 -0
  77. package/dist/lib/game/game-interfaces.d.ts +28 -0
  78. package/dist/lib/game/game-state.d.ts +10 -0
  79. package/dist/lib/game/game.d.ts +41 -0
  80. package/dist/lib/game/zylem-game.d.ts +44 -0
  81. package/dist/lib/graphics/geometries/XZPlaneGeometry.d.ts +7 -0
  82. package/dist/lib/graphics/material.d.ts +28 -0
  83. package/dist/lib/graphics/mesh.d.ts +18 -0
  84. package/dist/lib/graphics/render-pass.d.ts +16 -0
  85. package/dist/lib/graphics/zylem-scene.d.ts +49 -0
  86. package/dist/lib/input/gamepad-provider.d.ts +13 -0
  87. package/dist/lib/input/input-manager.d.ts +14 -0
  88. package/dist/lib/input/input-provider.d.ts +6 -0
  89. package/dist/lib/input/input.d.ts +51 -0
  90. package/dist/lib/input/keyboard-provider.d.ts +20 -0
  91. package/dist/lib/interfaces/entity.d.ts +31 -0
  92. package/dist/lib/interfaces/game.d.ts +19 -0
  93. package/dist/lib/sounds/index.d.ts +2 -0
  94. package/dist/lib/sounds/ping-pong-sound.d.ts +4 -0
  95. package/dist/lib/sounds/ricochet-sound.d.ts +4 -0
  96. package/dist/lib/stage/debug-entity-cursor.d.ts +23 -0
  97. package/dist/lib/stage/entity-spawner.d.ts +8 -0
  98. package/dist/lib/stage/stage-debug-delegate.d.ts +25 -0
  99. package/dist/lib/stage/stage-state.d.ts +12 -0
  100. package/dist/lib/stage/stage.d.ts +33 -0
  101. package/dist/lib/stage/zylem-stage.d.ts +127 -0
  102. package/dist/lib/systems/test-system.d.ts +1 -0
  103. package/dist/lib/systems/transformable.system.d.ts +24 -0
  104. package/dist/lib/types/entity-types.d.ts +38 -0
  105. package/dist/lib/types/index.d.ts +2 -0
  106. package/dist/lib/types/stage-types.d.ts +34 -0
  107. package/dist/lib/ui/Debug.d.ts +1 -0
  108. package/dist/lib/ui/console/Console.d.ts +6 -0
  109. package/dist/lib/ui/debug-panel/AccordionMenu.d.ts +6 -0
  110. package/dist/lib/ui/debug-panel/Menu.d.ts +5 -0
  111. package/dist/lib/ui/debug-panel/sections/EntitiesSection.d.ts +11 -0
  112. package/dist/lib/ui/debug-panel/sections/GameSection.d.ts +2 -0
  113. package/dist/lib/ui/debug-panel/sections/StagesSection.d.ts +2 -0
  114. package/dist/lib/ui/debug-panel/sections/all.d.ts +3 -0
  115. package/dist/lib/ui/toolbar/Toolbar.d.ts +5 -0
  116. package/dist/main.cjs +3980 -0
  117. package/dist/main.d.ts +40 -0
  118. package/dist/main.js +35583 -0
  119. package/dist/tests/collision/collision.spec.d.ts +1 -0
  120. package/dist/tests/core/game.spec.d.ts +1 -0
  121. package/dist/tests/core/stage.spec.d.ts +1 -0
  122. package/dist/tests/core/vessel.spec.d.ts +1 -0
  123. package/package.json +127 -0
@@ -0,0 +1,53 @@
1
+ import { ColliderDesc } from '@dimforge/rapier3d-compat';
2
+ import { Vector3 } from 'three';
3
+ import { BaseNode } from '../core/base-node';
4
+ import { GameEntityOptions, GameEntity } from './entity';
5
+ import { EntityBuilder } from './builder';
6
+ import { EntityCollisionBuilder } from './builder';
7
+ import { CollisionHandlerDelegate } from '../collision/collision-delegate';
8
+ export type OnHeldParams = {
9
+ delta: number;
10
+ self: ZylemZone;
11
+ visitor: GameEntity<any>;
12
+ heldTime: number;
13
+ globals: any;
14
+ };
15
+ export type OnEnterParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;
16
+ export type OnExitParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;
17
+ type ZylemZoneOptions = GameEntityOptions & {
18
+ size?: Vector3;
19
+ static?: boolean;
20
+ onEnter?: (params: OnEnterParams) => void;
21
+ onHeld?: (params: OnHeldParams) => void;
22
+ onExit?: (params: OnExitParams) => void;
23
+ };
24
+ export declare class ZoneCollisionBuilder extends EntityCollisionBuilder {
25
+ collider(options: ZylemZoneOptions): ColliderDesc;
26
+ }
27
+ export declare class ZoneBuilder extends EntityBuilder<ZylemZone, ZylemZoneOptions> {
28
+ protected createEntity(options: Partial<ZylemZoneOptions>): ZylemZone;
29
+ }
30
+ export declare const ZONE_TYPE: unique symbol;
31
+ export declare class ZylemZone extends GameEntity<ZylemZoneOptions> implements CollisionHandlerDelegate {
32
+ static type: symbol;
33
+ private _enteredZone;
34
+ private _exitedZone;
35
+ private _zoneEntities;
36
+ constructor(options?: ZylemZoneOptions);
37
+ handlePostCollision({ delta }: {
38
+ delta: number;
39
+ }): boolean;
40
+ handleIntersectionEvent({ other, delta }: {
41
+ other: any;
42
+ delta: number;
43
+ }): void;
44
+ onEnter(callback: (params: OnEnterParams) => void): this;
45
+ onHeld(callback: (params: OnHeldParams) => void): this;
46
+ onExit(callback: (params: OnExitParams) => void): this;
47
+ entered(other: any): void;
48
+ exited(delta: number, key: string): void;
49
+ held(delta: number, other: any): void;
50
+ }
51
+ type ZoneOptions = BaseNode | Partial<ZylemZoneOptions>;
52
+ export declare function zone(...args: Array<ZoneOptions>): Promise<ZylemZone>;
53
+ export {};
@@ -0,0 +1,28 @@
1
+ import { UpdateFunction } from "../core/base-node-life-cycle";
2
+ export type BasicTypes = number | string | boolean;
3
+ export type GlobalVariablesType = Record<string, BasicTypes>;
4
+ export type KeyboardMapping = Record<string, string[]>;
5
+ export type MouseMapping = Record<string, string[]>;
6
+ export interface GameInputPlayerConfig {
7
+ key?: KeyboardMapping;
8
+ mouse?: MouseMapping;
9
+ }
10
+ export interface GameInputConfig {
11
+ p1?: GameInputPlayerConfig;
12
+ p2?: GameInputPlayerConfig;
13
+ p3?: GameInputPlayerConfig;
14
+ p4?: GameInputPlayerConfig;
15
+ p5?: GameInputPlayerConfig;
16
+ p6?: GameInputPlayerConfig;
17
+ p7?: GameInputPlayerConfig;
18
+ p8?: GameInputPlayerConfig;
19
+ }
20
+ export interface ZylemGameConfig<StageInterface, GameInterface, TGlobals extends Record<string, BasicTypes> = GlobalVariablesType> {
21
+ id: string;
22
+ globals?: TGlobals;
23
+ stages?: StageInterface[];
24
+ update?: UpdateFunction<GameInterface>;
25
+ debug?: boolean;
26
+ time?: number;
27
+ input?: GameInputConfig;
28
+ }
@@ -0,0 +1,10 @@
1
+ import { BasicTypes, GlobalVariablesType } from './game-interfaces';
2
+ declare const state: {
3
+ id: string;
4
+ globals: GlobalVariablesType;
5
+ time: number;
6
+ };
7
+ export declare function setGlobalState<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType, K extends keyof TGlobals = keyof TGlobals>(key: K, value: TGlobals[K]): void;
8
+ export declare function getGlobalState<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType>(): TGlobals;
9
+ export declare function getGlobalState<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType, K extends keyof TGlobals = keyof TGlobals>(key: K): TGlobals[K];
10
+ export { state };
@@ -0,0 +1,41 @@
1
+ import { BaseNode } from '../core/base-node';
2
+ import { ZylemGame } from './zylem-game';
3
+ import { Stage } from '../stage/stage';
4
+ import { DestroyFunction, IGame, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';
5
+ import { GameEntityLifeCycle } from '../entities/entity';
6
+ import { BasicTypes, GlobalVariablesType, ZylemGameConfig } from './game-interfaces';
7
+ export declare class Game<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType> implements IGame<TGlobals> {
8
+ gameRef: ZylemGame<TGlobals> | null;
9
+ options: GameOptions<TGlobals>;
10
+ private pendingGlobalChangeHandlers;
11
+ update: UpdateFunction<ZylemGame<TGlobals>, TGlobals>;
12
+ setup: SetupFunction<ZylemGame<TGlobals>, TGlobals>;
13
+ destroy: DestroyFunction<ZylemGame<TGlobals>, TGlobals>;
14
+ refErrorMessage: string;
15
+ constructor(options: GameOptions<TGlobals>);
16
+ start(): Promise<this>;
17
+ load(): Promise<ZylemGame<TGlobals>>;
18
+ setOverrides(): void;
19
+ pause(): Promise<void>;
20
+ resume(): Promise<void>;
21
+ reset(): Promise<void>;
22
+ nextStage(): Promise<void>;
23
+ previousStage(): Promise<void>;
24
+ goToStage(): Promise<void>;
25
+ end(): Promise<void>;
26
+ add(...inputs: Array<Stage | Promise<any> | (() => Stage | Promise<any>)>): this;
27
+ getGlobal<K extends keyof TGlobals>(key: K): TGlobals[K];
28
+ setGlobal<K extends keyof TGlobals>(key: K, value: TGlobals[K]): void;
29
+ onGlobalChange<K extends keyof TGlobals>(key: K, callback: (value: TGlobals[K]) => void): void;
30
+ }
31
+ type GameOptions<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType> = Array<ZylemGameConfig<Stage, Game<TGlobals>, TGlobals> | Stage | GameEntityLifeCycle | BaseNode>;
32
+ /**
33
+ * create a new game
34
+ * @param options GameOptions - Array of IGameOptions, Stage, GameEntity, or BaseNode objects
35
+ * @param options.id Game name string (when using IGameOptions)
36
+ * @param options.globals Game globals object (when using IGameOptions)
37
+ * @param options.stages Array of stage objects (when using IGameOptions)
38
+ * @returns Game
39
+ */
40
+ export declare function game<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType>(...options: GameOptions<TGlobals>): Game<TGlobals>;
41
+ export {};
@@ -0,0 +1,44 @@
1
+ import { Game } from './game';
2
+ import { UpdateContext, SetupContext, DestroyContext } from '../core/base-node-life-cycle';
3
+ import { InputManager } from '../input/input-manager';
4
+ import { Timer } from '../core/three-addons/Timer';
5
+ import { ZylemCamera } from '~/lib/camera/zylem-camera';
6
+ import { Stage } from '../stage/stage';
7
+ import { BasicTypes, GlobalVariablesType, ZylemGameConfig } from './game-interfaces';
8
+ export declare class ZylemGame<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType> {
9
+ id: string;
10
+ initialGlobals: TGlobals;
11
+ customSetup: ((params: SetupContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
12
+ customUpdate: ((params: UpdateContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
13
+ customDestroy: ((params: DestroyContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
14
+ stages: Stage[];
15
+ stageMap: Map<string, Stage>;
16
+ currentStageId: string;
17
+ previousTimeStamp: number;
18
+ totalTime: number;
19
+ timer: Timer;
20
+ inputManager: InputManager;
21
+ wrapperRef: Game<TGlobals>;
22
+ statsRef: {
23
+ begin: () => void;
24
+ end: () => void;
25
+ } | null;
26
+ defaultCamera: ZylemCamera | null;
27
+ static FRAME_LIMIT: number;
28
+ static FRAME_DURATION: number;
29
+ static MAX_DELTA_SECONDS: number;
30
+ constructor(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>, wrapperRef: Game<TGlobals>);
31
+ loadStage(stage: Stage): Promise<void>;
32
+ unloadCurrentStage(): void;
33
+ setGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>): void;
34
+ params(): UpdateContext<ZylemGame<TGlobals>, TGlobals>;
35
+ start(): void;
36
+ loop(timestamp: number): void;
37
+ outOfLoop(): void;
38
+ getStage(id: string): Stage | undefined;
39
+ currentStage(): Stage | undefined;
40
+ getGlobal<K extends keyof TGlobals>(key: K): TGlobals[K];
41
+ setGlobal<K extends keyof TGlobals>(key: K, value: TGlobals[K]): void;
42
+ onGlobalChange<K extends keyof TGlobals>(key: K, callback: (value: TGlobals[K]) => void): void;
43
+ }
44
+ export default ZylemGame;
@@ -0,0 +1,7 @@
1
+ import { BufferGeometry } from 'three';
2
+ declare class XZPlaneGeometry extends BufferGeometry {
3
+ constructor(width?: number, height?: number, widthSegments?: number, heightSegments?: number);
4
+ copy(source: any): this;
5
+ static fromJSON(data: any): XZPlaneGeometry;
6
+ }
7
+ export { XZPlaneGeometry };
@@ -0,0 +1,28 @@
1
+ import { Color, Material, Vector2 } from 'three';
2
+ import { shortHash } from '../core/utility';
3
+ import { ZylemShaderType } from '../core/preset-shader';
4
+ export interface MaterialOptions {
5
+ path?: string;
6
+ repeat?: Vector2;
7
+ shader?: ZylemShaderType;
8
+ color?: Color;
9
+ }
10
+ type BatchGeometryMap = Map<symbol, number>;
11
+ interface BatchMaterialMapObject {
12
+ geometryMap: BatchGeometryMap;
13
+ material: Material;
14
+ }
15
+ type BatchKey = ReturnType<typeof shortHash>;
16
+ export type TexturePath = string | null;
17
+ export declare class MaterialBuilder {
18
+ static batchMaterialMap: Map<BatchKey, BatchMaterialMapObject>;
19
+ materials: Material[];
20
+ batchMaterial(options: Partial<MaterialOptions>, entityType: symbol): void;
21
+ build(options: Partial<MaterialOptions>, entityType: symbol): Promise<void>;
22
+ withColor(color: Color): this;
23
+ withShader(shaderType: ZylemShaderType): this;
24
+ setTexture(texturePath?: TexturePath, repeat?: Vector2): Promise<void>;
25
+ setColor(color: Color): void;
26
+ setShader(customShader: ZylemShaderType): void;
27
+ }
28
+ export {};
@@ -0,0 +1,18 @@
1
+ import { BufferGeometry, Material, Mesh } from 'three';
2
+ import { GameEntityOptions } from '../entities/entity';
3
+ /**
4
+ * TODO: allow for multiple materials requires geometry groups
5
+ * TODO: allow for instanced uniforms
6
+ * TODO: allow for geometry groups
7
+ * TODO: allow for batched meshes
8
+ * import { InstancedUniformsMesh } from 'three-instanced-uniforms-mesh';
9
+ * may not need geometry groups for shaders though
10
+ * setGeometry<T extends BufferGeometry>(geometry: T) {
11
+ * MeshBuilder.bachedMesh = new BatchedMesh(10, 5000, 10000, material);
12
+ * }
13
+ */
14
+ export type MeshBuilderOptions = Partial<Pick<GameEntityOptions, 'batched' | 'material'>>;
15
+ export declare class MeshBuilder {
16
+ _build(meshOptions: MeshBuilderOptions, geometry: BufferGeometry, materials: Material[]): Mesh;
17
+ _postBuild(): void;
18
+ }
@@ -0,0 +1,16 @@
1
+ import * as THREE from 'three';
2
+ import { WebGLRenderer, WebGLRenderTarget } from 'three';
3
+ import { Pass, FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
4
+ export default class RenderPass extends Pass {
5
+ fsQuad: FullScreenQuad;
6
+ resolution: THREE.Vector2;
7
+ scene: THREE.Scene;
8
+ camera: THREE.Camera;
9
+ rgbRenderTarget: WebGLRenderTarget;
10
+ normalRenderTarget: WebGLRenderTarget;
11
+ normalMaterial: THREE.Material;
12
+ constructor(resolution: THREE.Vector2, scene: THREE.Scene, camera: THREE.Camera);
13
+ render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget): void;
14
+ material(): THREE.ShaderMaterial;
15
+ dispose(): void;
16
+ }
@@ -0,0 +1,49 @@
1
+ import { Scene, Color, Object3D, Vector3 } from 'three';
2
+ import { Entity } from '../interfaces/entity';
3
+ import { SetupCallback } from '~/lib/interfaces/game';
4
+ import { GameEntity } from '../entities/entity';
5
+ import { ZylemCamera } from '../camera/zylem-camera';
6
+ interface SceneState {
7
+ backgroundColor: Color;
8
+ backgroundImage: string | null;
9
+ }
10
+ export declare class ZylemScene implements Entity<ZylemScene> {
11
+ type: string;
12
+ _setup?: SetupCallback;
13
+ scene: Scene;
14
+ zylemCamera: ZylemCamera;
15
+ containerElement: HTMLElement | null;
16
+ constructor(id: string, camera: ZylemCamera, state: SceneState);
17
+ /**
18
+ * Setup the container element and append camera's renderer
19
+ */
20
+ private setupContainer;
21
+ setup(): void;
22
+ destroy(): void;
23
+ update({ delta }: Partial<any>): void;
24
+ /**
25
+ * Setup camera with the scene
26
+ */
27
+ setupCamera(scene: Scene, camera: ZylemCamera): void;
28
+ /**
29
+ * Setup scene lighting
30
+ */
31
+ setupLighting(scene: Scene): void;
32
+ /**
33
+ * Update renderer size - delegates to camera
34
+ */
35
+ updateRenderer(width: number, height: number): void;
36
+ /**
37
+ * Add object to scene
38
+ */
39
+ add(object: Object3D, position?: Vector3): void;
40
+ /**
41
+ * Add game entity to scene
42
+ */
43
+ addEntity(entity: GameEntity<any>): void;
44
+ /**
45
+ * Add debug helpers to scene
46
+ */
47
+ debugScene(): void;
48
+ }
49
+ export {};
@@ -0,0 +1,13 @@
1
+ import { InputProvider } from './input-provider';
2
+ import { InputGamepad } from './input';
3
+ export declare class GamepadProvider implements InputProvider {
4
+ private gamepadIndex;
5
+ private connected;
6
+ private buttonStates;
7
+ constructor(gamepadIndex: number);
8
+ private handleButtonState;
9
+ private handleAnalogState;
10
+ getInput(delta: number): Partial<InputGamepad>;
11
+ getName(): string;
12
+ isConnected(): boolean;
13
+ }
@@ -0,0 +1,14 @@
1
+ import { InputProvider } from './input-provider';
2
+ import { AnalogState, ButtonState, InputPlayerNumber, Inputs } from './input';
3
+ import { GameInputConfig } from '../game/game-interfaces';
4
+ export declare class InputManager {
5
+ private inputMap;
6
+ private currentInputs;
7
+ private previousInputs;
8
+ constructor(config?: GameInputConfig);
9
+ addInputProvider(playerNumber: InputPlayerNumber, provider: InputProvider): void;
10
+ getInputs(delta: number): Inputs;
11
+ mergeButtonState(a: ButtonState | undefined, b: ButtonState | undefined): ButtonState;
12
+ mergeAnalogState(a: AnalogState | undefined, b: AnalogState | undefined): AnalogState;
13
+ private mergeInputs;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { InputGamepad } from './input';
2
+ export interface InputProvider {
3
+ getInput(delta: number): Partial<InputGamepad>;
4
+ isConnected(): boolean;
5
+ getName(): string;
6
+ }
@@ -0,0 +1,51 @@
1
+ /** Input
2
+ *
3
+ * Maximum number of local players is 8.
4
+ * All input can be mapped to a gamepad or keyboard but shares the common
5
+ * interface represented as a gamepad.
6
+ */
7
+ export type InputPlayerNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
8
+ export type InputPlayer = `p${InputPlayerNumber}`;
9
+ export interface ButtonState {
10
+ pressed: boolean;
11
+ released: boolean;
12
+ held: number;
13
+ }
14
+ export interface AnalogState {
15
+ value: number;
16
+ held: number;
17
+ }
18
+ export interface InputGamepad {
19
+ playerNumber: InputPlayerNumber;
20
+ buttons: {
21
+ A: ButtonState;
22
+ B: ButtonState;
23
+ X: ButtonState;
24
+ Y: ButtonState;
25
+ Start: ButtonState;
26
+ Select: ButtonState;
27
+ L: ButtonState;
28
+ R: ButtonState;
29
+ };
30
+ directions: {
31
+ Up: ButtonState;
32
+ Down: ButtonState;
33
+ Left: ButtonState;
34
+ Right: ButtonState;
35
+ };
36
+ shoulders: {
37
+ LTrigger: ButtonState;
38
+ RTrigger: ButtonState;
39
+ };
40
+ axes: {
41
+ Horizontal: AnalogState;
42
+ Vertical: AnalogState;
43
+ };
44
+ }
45
+ export type Inputs = Record<InputPlayer, InputGamepad>;
46
+ export type ButtonName = keyof InputGamepad['buttons'];
47
+ export type InputHandlerCallback = () => void;
48
+ export interface InputHandler {
49
+ onPress(button: ButtonName, callback: InputHandlerCallback): void;
50
+ update(currentInputs: Inputs): void;
51
+ }
@@ -0,0 +1,20 @@
1
+ import { InputProvider } from './input-provider';
2
+ import { InputGamepad } from './input';
3
+ export declare class KeyboardProvider implements InputProvider {
4
+ private keyStates;
5
+ private keyButtonStates;
6
+ private mapping;
7
+ private includeDefaultBase;
8
+ constructor(mapping?: Record<string, string[]>, options?: {
9
+ includeDefaultBase?: boolean;
10
+ });
11
+ private isKeyPressed;
12
+ private handleButtonState;
13
+ private handleAnalogState;
14
+ private mergeButtonState;
15
+ private applyCustomMapping;
16
+ getInput(delta: number): Partial<InputGamepad>;
17
+ getName(): string;
18
+ private getAxisValue;
19
+ isConnected(): boolean;
20
+ }
@@ -0,0 +1,31 @@
1
+ import { Collider, KinematicCharacterController, RigidBody } from "@dimforge/rapier3d-compat";
2
+ import { Group, Mesh } from "three";
3
+ export type LifecycleFunction<T> = (params?: any) => void;
4
+ export type CollisionOption = (entity: any, other: any, globals?: Global) => void;
5
+ export interface Entity<T = any> {
6
+ setup: (entity: T) => void;
7
+ destroy: () => void;
8
+ update: LifecycleFunction<T>;
9
+ type: string;
10
+ _collision?: (entity: any, other: any, globals?: any) => void;
11
+ _destroy?: (globals?: any) => void;
12
+ name?: string;
13
+ tag?: Set<string>;
14
+ }
15
+ export interface StageEntity extends Entity {
16
+ uuid: string;
17
+ body: RigidBody;
18
+ group: Group;
19
+ mesh: Mesh;
20
+ instanceId: number;
21
+ collider: Collider;
22
+ controlledRotation: boolean;
23
+ characterController: KinematicCharacterController;
24
+ name: string;
25
+ markedForRemoval: boolean;
26
+ }
27
+ export type OptionalVector = {
28
+ x?: number;
29
+ y?: number;
30
+ z?: number;
31
+ };
@@ -0,0 +1,19 @@
1
+ import ZylemGame from '~/lib/game/zylem-game';
2
+ import { ZylemScene } from '~/lib/graphics/zylem-scene';
3
+ import { ZylemCamera } from '~/lib/camera/zylem-camera';
4
+ import { ZylemWorld } from '~/lib/collision/world';
5
+ export type GameRatio = '16:9' | '9:16' | '4:3' | '3:4' | '1:1';
6
+ type Concrete<Type> = {
7
+ [Property in keyof Type]-?: Type[Property];
8
+ };
9
+ export type Conditions<T> = {
10
+ bindings: string[];
11
+ callback: (globals: Concrete<T>, game: ZylemGame) => void;
12
+ };
13
+ export interface SetupCallbackOptions {
14
+ scene: ZylemScene;
15
+ world?: ZylemWorld;
16
+ camera?: ZylemCamera;
17
+ }
18
+ export type SetupCallback = (options: SetupCallbackOptions) => void;
19
+ export {};
@@ -0,0 +1,2 @@
1
+ export { ricochetSound } from "./ricochet-sound";
2
+ export { pingPongBeep } from "./ping-pong-sound";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Plays a ping-pong beep sound effect.
3
+ */
4
+ export declare function pingPongBeep(frequency?: number, duration?: number): void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Plays a ricochet sound effect when boundary collision occurs
3
+ */
4
+ export declare function ricochetSound(frequency?: number, duration?: number): void;
@@ -0,0 +1,23 @@
1
+ import { Color, Object3D, Scene } from 'three';
2
+ /**
3
+ * Debug overlay that displays an axis-aligned bounding box around a target Object3D.
4
+ * Shows a semi-transparent fill plus a wireframe outline. Intended for SELECT/DELETE tools.
5
+ */
6
+ export declare class DebugEntityCursor {
7
+ private scene;
8
+ private container;
9
+ private fillMesh;
10
+ private edgeLines;
11
+ private currentColor;
12
+ private bbox;
13
+ private size;
14
+ private center;
15
+ constructor(scene: Scene);
16
+ setColor(color: Color | number): void;
17
+ /**
18
+ * Update the cursor to enclose the provided Object3D using a world-space AABB.
19
+ */
20
+ updateFromObject(object: Object3D | null | undefined): void;
21
+ hide(): void;
22
+ dispose(): void;
23
+ }
@@ -0,0 +1,8 @@
1
+ import { Vector2 } from "three";
2
+ import { GameEntity } from "../entities";
3
+ import { Stage } from "./stage";
4
+ export interface EntitySpawner {
5
+ spawn: (stage: Stage, x: number, y: number) => Promise<GameEntity<any>>;
6
+ spawnRelative: (source: any, stage: Stage, offset?: Vector2) => Promise<any | void>;
7
+ }
8
+ export declare function entitySpawner(factory: (x: number, y: number) => Promise<any> | GameEntity<any>): EntitySpawner;
@@ -0,0 +1,25 @@
1
+ import { Vector3 } from 'three';
2
+ import { ZylemStage } from './zylem-stage';
3
+ export type AddEntityFactory = (params: {
4
+ position: Vector3;
5
+ normal?: Vector3;
6
+ }) => Promise<any> | any;
7
+ export interface StageDebugDelegateOptions {
8
+ maxRayDistance?: number;
9
+ addEntityFactory?: AddEntityFactory | null;
10
+ }
11
+ export declare class StageDebugDelegate {
12
+ private stage;
13
+ private options;
14
+ private mouseNdc;
15
+ private raycaster;
16
+ private isMouseDown;
17
+ private disposeFns;
18
+ private debugCursor;
19
+ private debugLines;
20
+ constructor(stage: ZylemStage, options?: StageDebugDelegateOptions);
21
+ update(): void;
22
+ dispose(): void;
23
+ private handleActionOnHit;
24
+ private attachDomListeners;
25
+ }
@@ -0,0 +1,12 @@
1
+ import { Color } from 'three';
2
+ import { BaseEntityInterface } from '../types/entity-types';
3
+ import { StageStateInterface } from '../types/stage-types';
4
+ declare const stageState: StageStateInterface;
5
+ declare const setStageState: (state: StageStateInterface) => void;
6
+ declare const setStageBackgroundColor: (value: Color) => void;
7
+ declare const setStageBackgroundImage: (value: string | null) => void;
8
+ declare const setEntitiesToStage: (entities: Partial<BaseEntityInterface>[]) => void;
9
+ declare const setStageVariable: (key: string, value: any) => void;
10
+ declare const getStageVariable: (key: string) => any;
11
+ declare const stageStateToString: (state: StageStateInterface) => string;
12
+ export { stageState, setStageState, setStageBackgroundColor, setStageBackgroundImage, setEntitiesToStage, stageStateToString, setStageVariable, getStageVariable, };
@@ -0,0 +1,33 @@
1
+ import { BaseNode } from '../core/base-node';
2
+ import { DestroyFunction, SetupContext, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';
3
+ import { StageOptions, ZylemStage } from './zylem-stage';
4
+ import { ZylemCamera } from '../camera/zylem-camera';
5
+ import { CameraWrapper } from '../camera/camera';
6
+ type NodeLike = {
7
+ create: Function;
8
+ };
9
+ type AnyNode = NodeLike | Promise<NodeLike>;
10
+ type EntityInput = AnyNode | (() => AnyNode) | (() => Promise<any>);
11
+ export declare class Stage {
12
+ stageRef: ZylemStage;
13
+ options: StageOptions;
14
+ update: UpdateFunction<ZylemStage>;
15
+ setup: SetupFunction<ZylemStage>;
16
+ destroy: DestroyFunction<ZylemStage>;
17
+ constructor(options: StageOptions);
18
+ load(id: string, camera?: ZylemCamera | CameraWrapper | null): Promise<void>;
19
+ addEntities(entities: BaseNode[]): Promise<void>;
20
+ add(...inputs: Array<EntityInput>): void;
21
+ start(params: SetupContext<ZylemStage>): void;
22
+ onUpdate(...callbacks: UpdateFunction<ZylemStage>[]): void;
23
+ onSetup(callback: SetupFunction<ZylemStage>): void;
24
+ onDestroy(callback: DestroyFunction<ZylemStage>): void;
25
+ setVariable(key: string, value: any): void;
26
+ getVariable(key: string): any;
27
+ watchVariable(key: string, callback: (value: any) => void): void;
28
+ }
29
+ /**
30
+ * Create a stage with optional camera
31
+ */
32
+ export declare function stage(...options: StageOptions): Stage;
33
+ export {};