@inglorious/engine 24.1.4 → 24.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -10
- package/package.json +18 -8
- package/src/animation/due.js +6 -20
- package/src/behaviors/at-fps.js +6 -17
- package/src/behaviors/controls/event-handlers.js +4 -3
- package/src/behaviors/physics/bouncy.js +1 -1
- package/src/core/engine.js +4 -7
- package/src/core/loops/index.js +6 -15
- package/src/core/types.js +2 -14
- package/src/physics/bounds.js +1 -1
- package/src/systems/ticks.js +7 -20
- package/types/ai/movement/dynamic/align.d.ts +19 -0
- package/types/ai/movement/dynamic/arrive.d.ts +22 -0
- package/types/ai/movement/dynamic/evade.d.ts +16 -0
- package/types/ai/movement/dynamic/face.d.ts +10 -0
- package/types/ai/movement/dynamic/flee.d.ts +13 -0
- package/types/ai/movement/dynamic/look-where-youre-going.d.ts +11 -0
- package/types/ai/movement/dynamic/match-velocity.d.ts +11 -0
- package/types/ai/movement/dynamic/pursue.d.ts +16 -0
- package/types/ai/movement/dynamic/seek.d.ts +13 -0
- package/types/ai/movement/dynamic/wander.d.ts +11 -0
- package/types/ai/movement/kinematic/align.d.ts +12 -0
- package/types/ai/movement/kinematic/arrive.d.ts +17 -0
- package/types/ai/movement/kinematic/face.d.ts +9 -0
- package/types/ai/movement/kinematic/flee.d.ts +13 -0
- package/types/ai/movement/kinematic/seek.d.ts +13 -0
- package/types/ai/movement/kinematic/wander-as-seek.d.ts +10 -0
- package/types/ai/movement/kinematic/wander.d.ts +4 -0
- package/types/animation/due.d.ts +8 -0
- package/types/animation/sprite.d.ts +31 -0
- package/types/animation/ticker.d.ts +25 -0
- package/types/behaviors/at-fps.d.ts +15 -0
- package/types/behaviors/audio.d.ts +25 -0
- package/types/behaviors/camera.d.ts +29 -0
- package/types/behaviors/controls/dynamic/modern.d.ts +39 -0
- package/types/behaviors/controls/dynamic/shooter.d.ts +34 -0
- package/types/behaviors/controls/dynamic/tank.d.ts +40 -0
- package/types/behaviors/controls/event-handlers.d.ts +20 -0
- package/types/behaviors/controls/kinematic/modern.d.ts +37 -0
- package/types/behaviors/controls/kinematic/shooter.d.ts +29 -0
- package/types/behaviors/controls/kinematic/tank.d.ts +35 -0
- package/types/behaviors/debug/collision.d.ts +7 -0
- package/types/behaviors/fps.d.ts +21 -0
- package/types/behaviors/game.d.ts +9 -0
- package/types/behaviors/images.d.ts +21 -0
- package/types/behaviors/infinite-scroll.d.ts +15 -0
- package/types/behaviors/input/controls.d.ts +29 -0
- package/types/behaviors/input/gamepad.d.ts +29 -0
- package/types/behaviors/input/hover.d.ts +15 -0
- package/types/behaviors/input/input.d.ts +19 -0
- package/types/behaviors/input/keyboard.d.ts +26 -0
- package/types/behaviors/input/mappings.d.ts +16 -0
- package/types/behaviors/input/mouse.d.ts +44 -0
- package/types/behaviors/input/pointer.d.ts +19 -0
- package/types/behaviors/input/touch.d.ts +46 -0
- package/types/behaviors/particles.d.ts +44 -0
- package/types/behaviors/physics/bouncy.d.ts +20 -0
- package/types/behaviors/physics/clamped.d.ts +20 -0
- package/types/behaviors/physics/jumpable.d.ts +34 -0
- package/types/behaviors/ui/button.d.ts +8 -0
- package/types/behaviors/ui/slider.d.ts +26 -0
- package/types/collision/detection.d.ts +31 -0
- package/types/core/core-events.d.ts +2 -0
- package/types/core/engine.d.ts +28 -0
- package/types/core/loops/animation-frame.d.ts +7 -0
- package/types/core/loops/fixed.d.ts +7 -0
- package/types/core/loops/index.d.ts +16 -0
- package/types/core/middlewares/entity-pool/entity-pool-middleware.d.ts +4 -0
- package/types/core/middlewares/entity-pool/entity-pool.d.ts +9 -0
- package/types/core/middlewares/entity-pool/entity-pools.d.ts +12 -0
- package/types/core/types.d.ts +4 -0
- package/types/index.d.ts +194 -0
- package/types/main.d.ts +1 -0
- package/types/movement/dynamic/modern.d.ts +20 -0
- package/types/movement/dynamic/tank.d.ts +15 -0
- package/types/movement/kinematic/modern.d.ts +12 -0
- package/types/movement/kinematic/tank.d.ts +12 -0
- package/types/physics/anchor.d.ts +37 -0
- package/types/physics/bounds.d.ts +27 -0
- package/types/physics/position.d.ts +8 -0
- package/types/systems/sprite-animation.d.ts +4 -0
- package/types/systems/ticks.d.ts +12 -0
- package/types/test.d.ts +36 -0
- package/src/core/loops/elapsed.js +0 -22
- package/src/core/loops/flash.js +0 -13
- package/src/core/loops/lag.js +0 -26
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GameSystem } from "../index"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Notifies `event` with the elapsed seconds `fps` times a second, for a world
|
|
5
|
+
* that turns at its own rate. Stops on `pause`, starts again on `resume`.
|
|
6
|
+
*/
|
|
7
|
+
export function ticks(options?: {
|
|
8
|
+
/** Defaults to `Infinity`, every frame. */
|
|
9
|
+
fps?: number
|
|
10
|
+
/** Defaults to `"tick"`. */
|
|
11
|
+
event?: string
|
|
12
|
+
}): GameSystem
|
package/types/test.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BaseEntity, EntitiesState, Stored } from "@inglorious/store"
|
|
2
|
+
|
|
3
|
+
import type { Entity, EntityConfig, GameConfig } from "./index"
|
|
4
|
+
|
|
5
|
+
/** A game driven frame by frame, for tests. */
|
|
6
|
+
export interface TestGame {
|
|
7
|
+
/** The names of the sounds played so far. */
|
|
8
|
+
playedSounds: string[]
|
|
9
|
+
/** Asserts `condition`, failing with `description`. */
|
|
10
|
+
check(condition: boolean, description: string): void
|
|
11
|
+
/** One entity, by id, typed as `TEntity`. */
|
|
12
|
+
entity<TEntity extends BaseEntity = Entity>(id: string): Stored<TEntity>
|
|
13
|
+
state(): EntitiesState
|
|
14
|
+
/** The pooled entities in play, of one type or all. */
|
|
15
|
+
pooled<TEntity extends BaseEntity = Entity>(
|
|
16
|
+
typeName?: string,
|
|
17
|
+
): Stored<TEntity>[]
|
|
18
|
+
notify(event: string, payload?: unknown): this
|
|
19
|
+
/** Runs frames. Defaults to one. */
|
|
20
|
+
step(frames?: number): this
|
|
21
|
+
/** Runs the game for `seconds`. */
|
|
22
|
+
advance(seconds: number): this
|
|
23
|
+
/** Taps a key, by `code`, and lets a couple of frames run. */
|
|
24
|
+
press(code: string): this
|
|
25
|
+
/** Holds a key down for `frames` frames, 30 by default, then lets it up. */
|
|
26
|
+
hold(code: string, frames?: number): this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Makes a game to drive in a test, with its sounds watched. `extendWith` adds
|
|
31
|
+
* the game's own moves, which can call the rest with `this`.
|
|
32
|
+
*/
|
|
33
|
+
export function createGame<TExtra extends Record<string, unknown> = {}>(
|
|
34
|
+
gameConfig: GameConfig & { entities: { game: BaseEntity | EntityConfig } },
|
|
35
|
+
extendWith?: TExtra & ThisType<TestGame & TExtra>,
|
|
36
|
+
): TestGame & TExtra
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const ONE_SECOND = 1000
|
|
2
|
-
|
|
3
|
-
export class ElapsedLoop {
|
|
4
|
-
_shouldStop = false
|
|
5
|
-
|
|
6
|
-
start(engine) {
|
|
7
|
-
let previousTime = Date.now()
|
|
8
|
-
|
|
9
|
-
while (!this._shouldStop) {
|
|
10
|
-
const currentTime = Date.now()
|
|
11
|
-
const dt = currentTime - previousTime
|
|
12
|
-
|
|
13
|
-
engine.update(dt / ONE_SECOND)
|
|
14
|
-
|
|
15
|
-
previousTime = currentTime
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
stop() {
|
|
20
|
-
this._shouldStop = true
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/core/loops/flash.js
DELETED
package/src/core/loops/lag.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const ONE_SECOND = 1000
|
|
2
|
-
|
|
3
|
-
export class LagLoop {
|
|
4
|
-
_shouldStop = false
|
|
5
|
-
|
|
6
|
-
start(engine, msPerUpdate) {
|
|
7
|
-
let previousTime = Date.now()
|
|
8
|
-
let lag = 0
|
|
9
|
-
|
|
10
|
-
while (!this._shouldStop) {
|
|
11
|
-
const currentTime = Date.now()
|
|
12
|
-
const dt = currentTime - previousTime
|
|
13
|
-
previousTime = currentTime
|
|
14
|
-
lag += dt
|
|
15
|
-
|
|
16
|
-
while (lag >= msPerUpdate) {
|
|
17
|
-
engine.update(dt / ONE_SECOND)
|
|
18
|
-
lag -= msPerUpdate
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
stop() {
|
|
24
|
-
this._shouldStop = true
|
|
25
|
-
}
|
|
26
|
-
}
|