@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.
Files changed (86) hide show
  1. package/README.md +43 -10
  2. package/package.json +18 -8
  3. package/src/animation/due.js +6 -20
  4. package/src/behaviors/at-fps.js +6 -17
  5. package/src/behaviors/controls/event-handlers.js +4 -3
  6. package/src/behaviors/physics/bouncy.js +1 -1
  7. package/src/core/engine.js +4 -7
  8. package/src/core/loops/index.js +6 -15
  9. package/src/core/types.js +2 -14
  10. package/src/physics/bounds.js +1 -1
  11. package/src/systems/ticks.js +7 -20
  12. package/types/ai/movement/dynamic/align.d.ts +19 -0
  13. package/types/ai/movement/dynamic/arrive.d.ts +22 -0
  14. package/types/ai/movement/dynamic/evade.d.ts +16 -0
  15. package/types/ai/movement/dynamic/face.d.ts +10 -0
  16. package/types/ai/movement/dynamic/flee.d.ts +13 -0
  17. package/types/ai/movement/dynamic/look-where-youre-going.d.ts +11 -0
  18. package/types/ai/movement/dynamic/match-velocity.d.ts +11 -0
  19. package/types/ai/movement/dynamic/pursue.d.ts +16 -0
  20. package/types/ai/movement/dynamic/seek.d.ts +13 -0
  21. package/types/ai/movement/dynamic/wander.d.ts +11 -0
  22. package/types/ai/movement/kinematic/align.d.ts +12 -0
  23. package/types/ai/movement/kinematic/arrive.d.ts +17 -0
  24. package/types/ai/movement/kinematic/face.d.ts +9 -0
  25. package/types/ai/movement/kinematic/flee.d.ts +13 -0
  26. package/types/ai/movement/kinematic/seek.d.ts +13 -0
  27. package/types/ai/movement/kinematic/wander-as-seek.d.ts +10 -0
  28. package/types/ai/movement/kinematic/wander.d.ts +4 -0
  29. package/types/animation/due.d.ts +8 -0
  30. package/types/animation/sprite.d.ts +31 -0
  31. package/types/animation/ticker.d.ts +25 -0
  32. package/types/behaviors/at-fps.d.ts +15 -0
  33. package/types/behaviors/audio.d.ts +25 -0
  34. package/types/behaviors/camera.d.ts +29 -0
  35. package/types/behaviors/controls/dynamic/modern.d.ts +39 -0
  36. package/types/behaviors/controls/dynamic/shooter.d.ts +34 -0
  37. package/types/behaviors/controls/dynamic/tank.d.ts +40 -0
  38. package/types/behaviors/controls/event-handlers.d.ts +20 -0
  39. package/types/behaviors/controls/kinematic/modern.d.ts +37 -0
  40. package/types/behaviors/controls/kinematic/shooter.d.ts +29 -0
  41. package/types/behaviors/controls/kinematic/tank.d.ts +35 -0
  42. package/types/behaviors/debug/collision.d.ts +7 -0
  43. package/types/behaviors/fps.d.ts +21 -0
  44. package/types/behaviors/game.d.ts +9 -0
  45. package/types/behaviors/images.d.ts +21 -0
  46. package/types/behaviors/infinite-scroll.d.ts +15 -0
  47. package/types/behaviors/input/controls.d.ts +29 -0
  48. package/types/behaviors/input/gamepad.d.ts +29 -0
  49. package/types/behaviors/input/hover.d.ts +15 -0
  50. package/types/behaviors/input/input.d.ts +19 -0
  51. package/types/behaviors/input/keyboard.d.ts +26 -0
  52. package/types/behaviors/input/mappings.d.ts +16 -0
  53. package/types/behaviors/input/mouse.d.ts +44 -0
  54. package/types/behaviors/input/pointer.d.ts +19 -0
  55. package/types/behaviors/input/touch.d.ts +46 -0
  56. package/types/behaviors/particles.d.ts +44 -0
  57. package/types/behaviors/physics/bouncy.d.ts +20 -0
  58. package/types/behaviors/physics/clamped.d.ts +20 -0
  59. package/types/behaviors/physics/jumpable.d.ts +34 -0
  60. package/types/behaviors/ui/button.d.ts +8 -0
  61. package/types/behaviors/ui/slider.d.ts +26 -0
  62. package/types/collision/detection.d.ts +31 -0
  63. package/types/core/core-events.d.ts +2 -0
  64. package/types/core/engine.d.ts +28 -0
  65. package/types/core/loops/animation-frame.d.ts +7 -0
  66. package/types/core/loops/fixed.d.ts +7 -0
  67. package/types/core/loops/index.d.ts +16 -0
  68. package/types/core/middlewares/entity-pool/entity-pool-middleware.d.ts +4 -0
  69. package/types/core/middlewares/entity-pool/entity-pool.d.ts +9 -0
  70. package/types/core/middlewares/entity-pool/entity-pools.d.ts +12 -0
  71. package/types/core/types.d.ts +4 -0
  72. package/types/index.d.ts +194 -0
  73. package/types/main.d.ts +1 -0
  74. package/types/movement/dynamic/modern.d.ts +20 -0
  75. package/types/movement/dynamic/tank.d.ts +15 -0
  76. package/types/movement/kinematic/modern.d.ts +12 -0
  77. package/types/movement/kinematic/tank.d.ts +12 -0
  78. package/types/physics/anchor.d.ts +37 -0
  79. package/types/physics/bounds.d.ts +27 -0
  80. package/types/physics/position.d.ts +8 -0
  81. package/types/systems/sprite-animation.d.ts +4 -0
  82. package/types/systems/ticks.d.ts +12 -0
  83. package/types/test.d.ts +36 -0
  84. package/src/core/loops/elapsed.js +0 -22
  85. package/src/core/loops/flash.js +0 -13
  86. package/src/core/loops/lag.js +0 -26
@@ -0,0 +1,8 @@
1
+ import type { Entity } from "../index"
2
+
3
+ /** The height an entity's position must be at to stand on top of `target`. */
4
+ export function calculateLandingPosition(
5
+ entity: Entity,
6
+ target: Entity,
7
+ collisionGroup?: string,
8
+ ): number
@@ -0,0 +1,4 @@
1
+ import type { GameSystem } from "../index"
2
+
3
+ /** Plays the animation of every entity with a `sprite` that has a `state`. */
4
+ export function spriteAnimationSystem(): GameSystem
@@ -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
@@ -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
- }
@@ -1,13 +0,0 @@
1
- export class FlashLoop {
2
- _shouldStop = false
3
-
4
- start(engine) {
5
- while (!this._shouldStop) {
6
- engine.update()
7
- }
8
- }
9
-
10
- stop() {
11
- this._shouldStop = true
12
- }
13
- }
@@ -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
- }