@inglorious/engine 24.1.5 → 24.2.1

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 (77) hide show
  1. package/README.md +43 -10
  2. package/package.json +18 -8
  3. package/src/behaviors/controls/event-handlers.js +4 -3
  4. package/src/behaviors/physics/bouncy.js +1 -1
  5. package/src/physics/bounds.js +1 -1
  6. package/types/ai/movement/dynamic/align.d.ts +19 -0
  7. package/types/ai/movement/dynamic/arrive.d.ts +22 -0
  8. package/types/ai/movement/dynamic/evade.d.ts +16 -0
  9. package/types/ai/movement/dynamic/face.d.ts +10 -0
  10. package/types/ai/movement/dynamic/flee.d.ts +13 -0
  11. package/types/ai/movement/dynamic/look-where-youre-going.d.ts +11 -0
  12. package/types/ai/movement/dynamic/match-velocity.d.ts +11 -0
  13. package/types/ai/movement/dynamic/pursue.d.ts +16 -0
  14. package/types/ai/movement/dynamic/seek.d.ts +13 -0
  15. package/types/ai/movement/dynamic/wander.d.ts +11 -0
  16. package/types/ai/movement/kinematic/align.d.ts +12 -0
  17. package/types/ai/movement/kinematic/arrive.d.ts +17 -0
  18. package/types/ai/movement/kinematic/face.d.ts +9 -0
  19. package/types/ai/movement/kinematic/flee.d.ts +13 -0
  20. package/types/ai/movement/kinematic/seek.d.ts +13 -0
  21. package/types/ai/movement/kinematic/wander-as-seek.d.ts +10 -0
  22. package/types/ai/movement/kinematic/wander.d.ts +4 -0
  23. package/types/animation/due.d.ts +8 -0
  24. package/types/animation/sprite.d.ts +31 -0
  25. package/types/animation/ticker.d.ts +25 -0
  26. package/types/behaviors/at-fps.d.ts +15 -0
  27. package/types/behaviors/audio.d.ts +25 -0
  28. package/types/behaviors/camera.d.ts +29 -0
  29. package/types/behaviors/controls/dynamic/modern.d.ts +39 -0
  30. package/types/behaviors/controls/dynamic/shooter.d.ts +34 -0
  31. package/types/behaviors/controls/dynamic/tank.d.ts +40 -0
  32. package/types/behaviors/controls/event-handlers.d.ts +20 -0
  33. package/types/behaviors/controls/kinematic/modern.d.ts +37 -0
  34. package/types/behaviors/controls/kinematic/shooter.d.ts +29 -0
  35. package/types/behaviors/controls/kinematic/tank.d.ts +35 -0
  36. package/types/behaviors/debug/collision.d.ts +7 -0
  37. package/types/behaviors/fps.d.ts +21 -0
  38. package/types/behaviors/game.d.ts +9 -0
  39. package/types/behaviors/images.d.ts +21 -0
  40. package/types/behaviors/infinite-scroll.d.ts +15 -0
  41. package/types/behaviors/input/controls.d.ts +29 -0
  42. package/types/behaviors/input/gamepad.d.ts +29 -0
  43. package/types/behaviors/input/hover.d.ts +15 -0
  44. package/types/behaviors/input/input.d.ts +19 -0
  45. package/types/behaviors/input/keyboard.d.ts +26 -0
  46. package/types/behaviors/input/mappings.d.ts +16 -0
  47. package/types/behaviors/input/mouse.d.ts +44 -0
  48. package/types/behaviors/input/pointer.d.ts +19 -0
  49. package/types/behaviors/input/touch.d.ts +46 -0
  50. package/types/behaviors/particles.d.ts +44 -0
  51. package/types/behaviors/physics/bouncy.d.ts +20 -0
  52. package/types/behaviors/physics/clamped.d.ts +20 -0
  53. package/types/behaviors/physics/jumpable.d.ts +34 -0
  54. package/types/behaviors/ui/button.d.ts +8 -0
  55. package/types/behaviors/ui/slider.d.ts +26 -0
  56. package/types/collision/detection.d.ts +31 -0
  57. package/types/core/core-events.d.ts +2 -0
  58. package/types/core/engine.d.ts +28 -0
  59. package/types/core/loops/animation-frame.d.ts +7 -0
  60. package/types/core/loops/fixed.d.ts +7 -0
  61. package/types/core/loops/index.d.ts +16 -0
  62. package/types/core/middlewares/entity-pool/entity-pool-middleware.d.ts +4 -0
  63. package/types/core/middlewares/entity-pool/entity-pool.d.ts +9 -0
  64. package/types/core/middlewares/entity-pool/entity-pools.d.ts +12 -0
  65. package/types/core/types.d.ts +4 -0
  66. package/types/index.d.ts +194 -0
  67. package/types/main.d.ts +1 -0
  68. package/types/movement/dynamic/modern.d.ts +20 -0
  69. package/types/movement/dynamic/tank.d.ts +15 -0
  70. package/types/movement/kinematic/modern.d.ts +12 -0
  71. package/types/movement/kinematic/tank.d.ts +12 -0
  72. package/types/physics/anchor.d.ts +37 -0
  73. package/types/physics/bounds.d.ts +27 -0
  74. package/types/physics/position.d.ts +8 -0
  75. package/types/systems/sprite-animation.d.ts +4 -0
  76. package/types/systems/ticks.d.ts +12 -0
  77. package/types/test.d.ts +36 -0
@@ -0,0 +1,40 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Handler, UpdateHandler } from "../../../index"
4
+ import type { MovementHandlers, MovingEntity } from "../event-handlers"
5
+
6
+ export interface TankParams {
7
+ /** Defaults to 250. */
8
+ maxSpeed?: number
9
+ /** Radians a second. Defaults to 10. */
10
+ maxAngularSpeed?: number
11
+ /** Defaults to 500. */
12
+ maxAcceleration?: number
13
+ }
14
+
15
+ export interface TankEntity extends MovingEntity {
16
+ position: Vector3
17
+ orientation?: number
18
+ maxSpeed?: number
19
+ maxAngularSpeed?: number
20
+ /** Defaults to 500. */
21
+ maxAcceleration?: number
22
+ friction?: number
23
+ }
24
+
25
+ type TankActions =
26
+ | "turnLeft"
27
+ | "turnRight"
28
+ | "moveForward"
29
+ | "moveBackward"
30
+ | "strafe"
31
+ | "move"
32
+ | "turn"
33
+
34
+ /** Turns left and right, and accelerates forward and backward from where it faces. */
35
+ export function tankControls(params?: TankParams): Decorator<
36
+ MovementHandlers<TankActions> & {
37
+ create: Handler<TankEntity, unknown>
38
+ update: UpdateHandler<TankEntity>
39
+ }
40
+ >
@@ -0,0 +1,20 @@
1
+ import type { Entity, Handler } from "../../index"
2
+
3
+ /** What each movement action is: `true` while held, or a stick's value from -1 to 1. */
4
+ export type Movement = Partial<Record<string, boolean | number>>
5
+
6
+ export interface MovingEntity extends Entity {
7
+ movement?: Movement
8
+ }
9
+
10
+ /** The handlers `createMovementEventHandlers` makes for `TName`, and their `…End`. */
11
+ export type MovementHandlers<TName extends string> = {
12
+ [K in TName]: Handler<MovingEntity, { value: number } | undefined>
13
+ } & {
14
+ [K in TName as `${K}End`]: Handler<MovingEntity>
15
+ }
16
+
17
+ /** Records each action on the entity's `movement` while it is held. */
18
+ export function createMovementEventHandlers<TName extends string>(
19
+ events: TName[],
20
+ ): MovementHandlers<TName>
@@ -0,0 +1,37 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Handler, UpdateHandler } from "../../../index"
4
+ import type { MovementHandlers, MovingEntity } from "../event-handlers"
5
+
6
+ export interface ModernVelocityParams {
7
+ /** Defaults to 250. */
8
+ maxSpeed?: number
9
+ }
10
+
11
+ export interface ModernVelocityEntity extends MovingEntity {
12
+ position: Vector3
13
+ maxSpeed?: number
14
+ }
15
+
16
+ type ModernActions =
17
+ | "moveLeft"
18
+ | "moveRight"
19
+ | "moveUp"
20
+ | "moveDown"
21
+ | "moveLeftRight"
22
+ | "moveUpDown"
23
+
24
+ export type ModernVelocityHandlers = MovementHandlers<ModernActions> & {
25
+ create: Handler<ModernVelocityEntity, unknown>
26
+ update: UpdateHandler<ModernVelocityEntity>
27
+ }
28
+
29
+ /** Sets the velocity from the arrows or a stick, in screen directions. */
30
+ export function modernVelocity(
31
+ params?: ModernVelocityParams,
32
+ ): Decorator<ModernVelocityHandlers>
33
+
34
+ /** Moves with the velocity `modernVelocity` sets. */
35
+ export function modernControls(
36
+ params?: ModernVelocityParams,
37
+ ): Decorator<ModernVelocityHandlers>
@@ -0,0 +1,29 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Handler, UpdateHandler } from "../../../index"
4
+ import type { MovementHandlers, MovingEntity } from "../event-handlers"
5
+
6
+ export interface ShooterParams {
7
+ /** Defaults to 250. */
8
+ maxSpeed?: number
9
+ /** Radians a second. Defaults to a full turn. */
10
+ maxAngularSpeed?: number
11
+ }
12
+
13
+ export interface ShooterEntity extends MovingEntity {
14
+ position: Vector3
15
+ orientation?: number
16
+ maxSpeed?: number
17
+ maxAngularSpeed?: number
18
+ }
19
+
20
+ type ShooterActions =
21
+ "moveLeft" | "moveRight" | "moveUp" | "moveDown" | "move" | "strafe" | "turn"
22
+
23
+ /** Moves relative to where it faces, and faces the `mouse` entity. */
24
+ export function shooterControls(params?: ShooterParams): Decorator<
25
+ MovementHandlers<ShooterActions> & {
26
+ create: Handler<ShooterEntity, unknown>
27
+ update: UpdateHandler<ShooterEntity>
28
+ }
29
+ >
@@ -0,0 +1,35 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Handler, UpdateHandler } from "../../../index"
4
+ import type { MovementHandlers, MovingEntity } from "../event-handlers"
5
+
6
+ export interface TankParams {
7
+ /** Defaults to 250. */
8
+ maxSpeed?: number
9
+ /** Radians a second. Defaults to 10. */
10
+ maxAngularSpeed?: number
11
+ }
12
+
13
+ export interface TankEntity extends MovingEntity {
14
+ position: Vector3
15
+ orientation?: number
16
+ maxSpeed?: number
17
+ maxAngularSpeed?: number
18
+ }
19
+
20
+ type TankActions =
21
+ | "turnLeft"
22
+ | "turnRight"
23
+ | "moveForward"
24
+ | "moveBackward"
25
+ | "strafe"
26
+ | "move"
27
+ | "turn"
28
+
29
+ /** Turns left and right, and moves forward and backward from where it faces. */
30
+ export function tankControls(params?: TankParams): Decorator<
31
+ MovementHandlers<TankActions> & {
32
+ create: Handler<TankEntity, unknown>
33
+ update: UpdateHandler<TankEntity>
34
+ }
35
+ >
@@ -0,0 +1,7 @@
1
+ import type { Decorator, Entity, Render, Shape } from "../../index"
2
+
3
+ /** Draws the entity's collision shapes over it while the game's `debug` is on. */
4
+ export function collisionGizmos(params?: {
5
+ /** How to draw each shape. */
6
+ shapes?: Partial<Record<Shape, Render>>
7
+ }): Decorator<{ render: Render<Entity> }>
@@ -0,0 +1,21 @@
1
+ import type { Entity, Handler, UpdateHandler } from "../index"
2
+
3
+ export interface FpsParams {
4
+ /** Decimals shown. Defaults to 1. */
5
+ accuracy?: number
6
+ size?: number
7
+ /** Seconds between readings. Defaults to 1. */
8
+ speed?: number
9
+ defaultValue?: number
10
+ }
11
+
12
+ export interface FpsEntity extends Entity {
13
+ /** The last frame's seconds, as `value`, read every `speed` seconds. */
14
+ dt?: FpsParams & { value?: number }
15
+ }
16
+
17
+ /** Reads the frame time, for `renderFps` to show. */
18
+ export function fps(params?: FpsParams): {
19
+ create: Handler<FpsEntity>
20
+ update: UpdateHandler<FpsEntity>
21
+ }
@@ -0,0 +1,9 @@
1
+ import type { GameEntity, Handler } from "../index"
2
+
3
+ /** The `game` entity's own handlers: pause, resume, quit, and `C` and `D` for debug and dev mode. */
4
+ export function game(): {
5
+ pause: Handler<GameEntity>
6
+ resume: Handler<GameEntity>
7
+ quit: Handler<GameEntity>
8
+ keyboardKeyUp: Handler<GameEntity, string>
9
+ }
@@ -0,0 +1,21 @@
1
+ import type { BaseEntity } from "@inglorious/store"
2
+
3
+ /** An image to load, by id. */
4
+ export interface ImageSource {
5
+ url: string
6
+ }
7
+
8
+ export interface ImagesEntity extends BaseEntity {
9
+ images: Record<string, ImageSource>
10
+ }
11
+
12
+ /** A loaded image, with the id it was loaded under. */
13
+ export type LoadedImage = HTMLImageElement & { id: string }
14
+
15
+ /** Loads images up front with `init`, or on demand with `load`, and hands them out by id. */
16
+ export function images(): {
17
+ init: (entity: ImagesEntity) => Promise<void>
18
+ load: (id: string, src: string) => Promise<LoadedImage>
19
+ get: (id: string) => LoadedImage | undefined
20
+ stop: () => void
21
+ }
@@ -0,0 +1,15 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Entity, UpdateHandler } from "../index"
4
+
5
+ export interface InfiniteScrollEntity extends Entity {
6
+ position: Vector3
7
+ velocity: Vector3
8
+ /** `loop` is where the image repeats. */
9
+ image: { loop: Vector3 }
10
+ }
11
+
12
+ /** Scrolls with its velocity, wrapping around at the image's `loop`, unless the game is paused. */
13
+ export function infiniteScroll(): {
14
+ update: UpdateHandler<InfiniteScrollEntity>
15
+ }
@@ -0,0 +1,29 @@
1
+ import type { GamepadEntity, gamepad, gamepadsPoller } from "./gamepad"
2
+ import type { input, InputEntity } from "./input"
3
+ import type { InputMapping, keyboard, KeyboardEntity } from "./keyboard"
4
+ import type { pointer, PointerEntity } from "./pointer"
5
+
6
+ /** The types every control needs, spread under `types`. */
7
+ export function controlTypes(): {
8
+ Keyboard: ReturnType<typeof keyboard>
9
+ Pointer: ReturnType<typeof pointer>
10
+ GamepadsPoller: ReturnType<typeof gamepadsPoller>
11
+ Gamepad: ReturnType<typeof gamepad>
12
+ Input: ReturnType<typeof input>
13
+ }
14
+
15
+ /**
16
+ * The entities that listen for input, spread under `entities`. `mapping`
17
+ * turns keys, axes and buttons into actions; a click or a touch presses
18
+ * `pointerActions`.
19
+ */
20
+ export function createControlEntities(
21
+ mapping?: InputMapping,
22
+ pointerActions?: string[],
23
+ ): {
24
+ gamepads: { type: "GamepadsPoller" }
25
+ keyboard: KeyboardEntity
26
+ gamepad: GamepadEntity
27
+ input: InputEntity
28
+ pointer: PointerEntity
29
+ }
@@ -0,0 +1,29 @@
1
+ import type { BaseEntity } from "@inglorious/store"
2
+
3
+ import type { Handler, UpdateHandler } from "../../index"
4
+ import type { InputMapping } from "./keyboard"
5
+
6
+ export interface GamepadsPollerEntity extends BaseEntity {
7
+ gamepadStateCache?: Record<number, { axes: number[]; buttons: boolean[] }>
8
+ }
9
+
10
+ export interface GamepadEntity extends BaseEntity {
11
+ type: "Gamepad"
12
+ mapping: InputMapping
13
+ }
14
+
15
+ /** Polls the gamepads every frame, and notifies `gamepadAxis`, `gamepadPress` and `gamepadRelease`. */
16
+ export function gamepadsPoller(): {
17
+ create: Handler<GamepadsPollerEntity>
18
+ update: UpdateHandler<GamepadsPollerEntity>
19
+ }
20
+
21
+ /** Turns gamepad axes and buttons into `inputAxis`, `inputPress` and `inputRelease`. */
22
+ export function gamepad(): {
23
+ mappingChange: Handler<GamepadEntity, InputMapping>
24
+ gamepadAxis: Handler<GamepadEntity, { axis: string; value: number }>
25
+ gamepadPress: Handler<GamepadEntity, { button: string }>
26
+ gamepadRelease: Handler<GamepadEntity, { button: string }>
27
+ }
28
+
29
+ export function createGamepadEntity(mapping?: InputMapping): GamepadEntity
@@ -0,0 +1,15 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Handler } from "../../index"
4
+ import type { MouseEntity } from "./mouse"
5
+
6
+ /** Turns the mouse into a hand over anything with a hitbox. */
7
+ export function hover(cursors?: {
8
+ /** The cursor away from anything pressable. Defaults to `"arrow"`. */
9
+ off?: string
10
+ }): Decorator<{
11
+ create: Handler<MouseEntity, unknown>
12
+ mouseMove: Handler<MouseEntity, Vector3>
13
+ mouseDown: Handler<MouseEntity, Vector3>
14
+ mouseUp: Handler<MouseEntity, Vector3>
15
+ }>
@@ -0,0 +1,19 @@
1
+ import type { BaseEntity } from "@inglorious/store"
2
+
3
+ import type { Handler } from "../../index"
4
+
5
+ export interface InputEntity extends BaseEntity {
6
+ type: "Input"
7
+ }
8
+
9
+ /**
10
+ * Notifies each action by name: `moveLeft` with `{ value }` for an axis, with
11
+ * nothing for a press, and `moveLeftEnd` on release.
12
+ */
13
+ export function input(): {
14
+ inputAxis: Handler<InputEntity, { action: string; value: number }>
15
+ inputPress: Handler<InputEntity, { action: string }>
16
+ inputRelease: Handler<InputEntity, { action: string }>
17
+ }
18
+
19
+ export function createInputEntity(): InputEntity
@@ -0,0 +1,26 @@
1
+ import type { BaseEntity } from "@inglorious/store"
2
+
3
+ import type { Handler } from "../../index"
4
+
5
+ /** Maps keys (by `code`), gamepad axes (`Axis0`…) and buttons (`Btn0`…) to actions. */
6
+ export type InputMapping = Record<string, string>
7
+
8
+ export interface KeyboardEntity extends BaseEntity {
9
+ type: "Keyboard"
10
+ mapping: InputMapping
11
+ }
12
+
13
+ /**
14
+ * Turns key presses into `inputPress` and `inputRelease` of their actions,
15
+ * and notifies `keyboardKeyDown`, `keyboardKeyUp` and `keyboardChar`.
16
+ */
17
+ export function keyboard(): {
18
+ create: Handler<KeyboardEntity, unknown>
19
+ mappingChange: Handler<KeyboardEntity, InputMapping>
20
+ stop: () => void
21
+ destroy: () => void
22
+ keyboardKeyDown: Handler<KeyboardEntity, string>
23
+ keyboardKeyUp: Handler<KeyboardEntity, string>
24
+ }
25
+
26
+ export function createKeyboardEntity(mapping?: InputMapping): KeyboardEntity
@@ -0,0 +1,16 @@
1
+ import type { StateChangePayload } from "@inglorious/store/fsm"
2
+
3
+ import type { Decorator, Entity, Handler } from "../../index"
4
+ import type { InputMapping } from "./keyboard"
5
+
6
+ export interface MappedEntity extends Entity {
7
+ state?: string
8
+ }
9
+
10
+ /** Notifies `mappingChange` with what each state of the entity's machine answers to. */
11
+ export function mappings(
12
+ mappingsByState: Record<string, InputMapping>,
13
+ ): Decorator<{
14
+ create: Handler<MappedEntity, unknown>
15
+ stateChange: Handler<MappedEntity, StateChangePayload>
16
+ }>
@@ -0,0 +1,44 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Entity, GameApi, Handler } from "../../index"
4
+
5
+ export interface MouseEntity extends Entity {
6
+ position: Vector3
7
+ /** The id of the entity pressed, until it is released. */
8
+ pressedId?: string
9
+ /** What `renderMouse` draws: `"crosshair"`, `"arrow"` or `"hand"`. */
10
+ cursor?: string
11
+ }
12
+
13
+ /**
14
+ * Follows the pointer, and notifies `entityPress`, `entityRelease` and
15
+ * `entityClick` with the id of the entity under it, or `scenePress`,
16
+ * `sceneRelease` and `sceneClick` with the position.
17
+ */
18
+ export function mouse(): {
19
+ create: Handler<MouseEntity>
20
+ mouseMove: Handler<MouseEntity, Vector3>
21
+ mouseDown: Handler<MouseEntity, Vector3>
22
+ mouseUp: Handler<MouseEntity, Vector3>
23
+ mouseClick: Handler<MouseEntity, Vector3>
24
+ }
25
+
26
+ /** Turns a point on the page into a position in the game. */
27
+ export type ToGamePosition = (clientX: number, clientY: number) => Vector3
28
+
29
+ /** DOM listeners that notify the mouse's events, in game positions. */
30
+ export function trackMouse(
31
+ parent: HTMLElement | null,
32
+ api: GameApi,
33
+ toGamePosition: ToGamePosition,
34
+ ): {
35
+ onMouseMove: (event: MouseEvent) => void
36
+ onClick: (event: MouseEvent) => void
37
+ onMouseDown: (event: MouseEvent) => void
38
+ onMouseUp: (event: MouseEvent) => void
39
+ onMouseWheel: (event: WheelEvent) => void
40
+ }
41
+
42
+ export function createMouseEntity<TOverrides extends Partial<MouseEntity>>(
43
+ overrides?: TOverrides,
44
+ ): MouseEntity & { type: "Mouse"; layer: number } & TOverrides
@@ -0,0 +1,19 @@
1
+ import type { BaseEntity } from "@inglorious/store"
2
+ import type { Vector3 } from "@inglorious/utils/vector.js"
3
+
4
+ import type { Handler } from "../../index"
5
+
6
+ export interface PointerEntity extends BaseEntity {
7
+ type: "Pointer"
8
+ /** The actions a click or a touch presses. */
9
+ actions: string[]
10
+ }
11
+
12
+ /** Presses the entity's actions on a click, or for as long as a touch lasts. */
13
+ export function pointer(): {
14
+ mouseClick: Handler<PointerEntity, Vector3>
15
+ touchStart: Handler<PointerEntity, { index: number; position: Vector3 }>
16
+ touchEnd: Handler<PointerEntity, { index: number; position: Vector3 }>
17
+ }
18
+
19
+ export function createPointerEntity(actions?: string[]): PointerEntity
@@ -0,0 +1,46 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Collision, Entity, GameApi, Handler } from "../../index"
4
+ import type { ToGamePosition } from "./mouse"
5
+
6
+ export interface TouchEntity extends Entity {
7
+ /** Each finger's position, by its index. */
8
+ positions: (Vector3 | undefined)[]
9
+ /** The entity each finger is on, by its index. */
10
+ targetIds: (string | undefined)[]
11
+ isSwiping?: boolean
12
+ collisions: Record<string, Collision>
13
+ }
14
+
15
+ /** What a touch event carries: which finger, and where. */
16
+ export interface TouchPayload {
17
+ index: number
18
+ position: Vector3
19
+ }
20
+
21
+ /**
22
+ * Notifies `entityTouchStart`, `entityTouchMove` and `entityTouchEnd` for the
23
+ * entity under a finger, or `sceneTouchStart`, `sceneTouchEnd` with the position.
24
+ */
25
+ export function touch(): {
26
+ touchStart: Handler<TouchEntity, TouchPayload>
27
+ touchMove: Handler<TouchEntity, TouchPayload>
28
+ touchEnd: Handler<TouchEntity, Pick<TouchPayload, "index">>
29
+ }
30
+
31
+ /** DOM listeners that notify the touch events, in game positions. */
32
+ export function trackTouch(
33
+ parent: HTMLElement | null,
34
+ api: GameApi,
35
+ toGamePosition: ToGamePosition,
36
+ ): {
37
+ onTouchStart: (event: TouchEvent) => void
38
+ onTouchMove: (event: TouchEvent) => void
39
+ onTouchCancel: (event: TouchEvent) => void
40
+ onTouchEnd: (event: TouchEvent) => void
41
+ }
42
+
43
+ export function createTouchEntity(): TouchEntity & {
44
+ type: "Touch"
45
+ layer: number
46
+ }
@@ -0,0 +1,44 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Entity, GameApi, UpdateHandler } from "../index"
4
+
5
+ export interface ParticleEntity extends Entity {
6
+ position: Vector3
7
+ velocity: Vector3
8
+ acceleration: Vector3
9
+ /** Seconds since it was emitted. */
10
+ age: number
11
+ /** Seconds it lasts. */
12
+ life: number
13
+ startOpacity: number
14
+ opacity: number
15
+ }
16
+
17
+ /** Drifts and fades over its life, then despawns. */
18
+ export function particle(): {
19
+ update: UpdateHandler<ParticleEntity>
20
+ }
21
+
22
+ export interface BurstParams {
23
+ /** Defaults to 1. */
24
+ count?: number
25
+ /** Defaults to `"Particle"`. */
26
+ type?: string
27
+ size?: Vector3
28
+ /** The shortest and longest a particle lasts, in seconds. Defaults to 1. */
29
+ lifetime?: readonly [number, number]
30
+ /** Each particle's acceleration is drawn between these, axis by axis. */
31
+ acceleration?: readonly [Vector3, Vector3]
32
+ /** The half-extent of the box particles are emitted in. */
33
+ spread?: Vector3
34
+ velocity?: Vector3
35
+ /** Defaults to 1. */
36
+ opacity?: number
37
+ layer?: number
38
+ image?: unknown
39
+ tint?: string
40
+ position?: Vector3
41
+ }
42
+
43
+ /** Spawns a burst of pooled particles. */
44
+ export function emitBurst(api: GameApi, params: BurstParams): void
@@ -0,0 +1,20 @@
1
+ import type { Decorator, Entity, Handler } from "../../index"
2
+
3
+ export interface BouncyParams {
4
+ /** How much of a full jump it bounces back up. Defaults to 1. */
5
+ bounciness?: number
6
+ }
7
+
8
+ export interface BouncyEntity extends Entity, BouncyParams {
9
+ maxJump?: number
10
+ maxLeap?: number
11
+ maxSpeed?: number
12
+ vy?: number
13
+ groundObject?: Entity
14
+ }
15
+
16
+ /** Bounces back up when `jumpable` says the entity landed. */
17
+ export function bouncy(params?: BouncyParams): Decorator<{
18
+ create: Handler<BouncyEntity, unknown>
19
+ land: Handler<BouncyEntity, { entityId: string; targetId: string }>
20
+ }>
@@ -0,0 +1,20 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Entity, Handler, UpdateHandler } from "../../index"
4
+
5
+ export interface ClampedParams {
6
+ /** The collision group whose shape is kept inside. Defaults to `"bounds"`. */
7
+ collisionGroup?: string
8
+ /** The axis a circle's depth is on. Defaults to `"y"`. */
9
+ depthAxis?: "y" | "z"
10
+ }
11
+
12
+ export interface ClampedEntity extends Entity {
13
+ position: Vector3
14
+ }
15
+
16
+ /** Keeps the entity inside the game's size. */
17
+ export function clamped(params?: ClampedParams): Decorator<{
18
+ create: Handler<ClampedEntity, unknown>
19
+ update: UpdateHandler<ClampedEntity>
20
+ }>
@@ -0,0 +1,34 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Entity, Handler, UpdateHandler } from "../../index"
4
+
5
+ export interface JumpableParams {
6
+ /** Defaults to 250. */
7
+ maxSpeed?: number
8
+ /** How high a jump goes. Defaults to 100. */
9
+ maxJump?: number
10
+ /** How far a jump goes. Defaults to 100. */
11
+ maxLeap?: number
12
+ /** Jumps before it has to land again. Defaults to 1. */
13
+ maxJumps?: number
14
+ }
15
+
16
+ export interface JumpableEntity extends Entity, JumpableParams {
17
+ position: Vector3
18
+ size: Vector3
19
+ velocity?: Vector3
20
+ vy?: number
21
+ jumpsLeft?: number
22
+ /** What it stands on. */
23
+ groundObject?: Entity
24
+ }
25
+
26
+ /**
27
+ * Jumps on `jump`, falls, and stands on anything in the `platform` collision
28
+ * group, notifying `land` when it does.
29
+ */
30
+ export function jumpable(params?: JumpableParams): Decorator<{
31
+ create: Handler<JumpableEntity, unknown>
32
+ jump: Handler<JumpableEntity, unknown>
33
+ update: UpdateHandler<JumpableEntity>
34
+ }>
@@ -0,0 +1,8 @@
1
+ import type { Decorator, Entity, GameType } from "../../index"
2
+
3
+ export interface ButtonEntity extends Entity {
4
+ state?: "default" | "pressed"
5
+ }
6
+
7
+ /** Looks pressed from `entityPress` to `entityRelease`, and announces it through `stateChange`. */
8
+ export function button(): Decorator<GameType<ButtonEntity>>
@@ -0,0 +1,26 @@
1
+ import type { Vector3 } from "@inglorious/utils/vector.js"
2
+
3
+ import type { Decorator, Entity, Handler } from "../../index"
4
+
5
+ export interface SliderBounds {
6
+ /** Defaults to 0. */
7
+ min?: number
8
+ /** Defaults to 1. */
9
+ max?: number
10
+ /** Defaults to 0, any value. */
11
+ step?: number
12
+ }
13
+
14
+ export interface SliderEntity extends Entity, SliderBounds {
15
+ position: Vector3
16
+ value?: number
17
+ isDragging?: boolean
18
+ }
19
+
20
+ /** Follows the pointer while pressed, and notifies `valueChange` with `{ entityId, value }`. */
21
+ export function slider(bounds?: SliderBounds): Decorator<{
22
+ create: Handler<SliderEntity, unknown>
23
+ entityPress: Handler<SliderEntity, string>
24
+ mouseMove: Handler<SliderEntity, Vector3>
25
+ entityRelease: Handler<SliderEntity, string>
26
+ }>