@inglorious/engine 24.14.0 → 24.15.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 CHANGED
@@ -173,14 +173,14 @@ The default is to **stop**. Anything that keeps going has to say so, so forgetti
173
173
 
174
174
  ## Testing a game
175
175
 
176
- `@inglorious/engine/test` is the harness for testing a game against its own store: no
176
+ `@inglorious/engine/test.js` is the harness for testing a game against its own store: no
177
177
  canvas, no browser, no loop.
178
178
 
179
179
  ```javascript
180
180
  // test/game.test.js
181
181
  import { beforeEach, describe, expect, test } from "vitest"
182
182
 
183
- import { createGame } from "@inglorious/engine/test"
183
+ import { createGame } from "@inglorious/engine/test.js"
184
184
 
185
185
  import gameConfig from "../src/game.ijs"
186
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/engine",
3
- "version": "24.14.0",
3
+ "version": "24.15.0",
4
4
  "description": "A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "sideEffects": false,
43
43
  "dependencies": {
44
- "@inglorious/utils": "^5.10.0"
44
+ "@inglorious/utils": "^5.11.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@inglorious/store": "^12.9.6",
@@ -39,6 +39,19 @@ export function images() {
39
39
  return imageCache.get(id)
40
40
  },
41
41
 
42
+ // An image the game made rather than loaded: a canvas it painted, such as pixel art
43
+ // baked by `@inglorious/renderer-2d/image/pixels.js`. It is kept here, by id, because an
44
+ // entity can only name an image: the store copies entities with `structuredClone`,
45
+ // which refuses canvases (MDN, "The structured clone algorithm":
46
+ // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm),
47
+ // and a store holding one would copy its pixels on every change anyway.
48
+ set(id, image) {
49
+ image.id = id
50
+ imageCache.set(id, image)
51
+ loadingPromises.delete(id)
52
+ return image
53
+ },
54
+
42
55
  stop() {
43
56
  imageCache.clear()
44
57
  loadingPromises.clear()
@@ -100,7 +100,7 @@ export function createParticles({
100
100
  * fades out over its lifetime, then leaves the pool. New ones come from `burst`, called
101
101
  * by the type's own handlers.
102
102
  *
103
- * Pair it with `renderParticles` from `@inglorious/renderer-2d/particles.js`.
103
+ * Pair it with `renderParticles` from `@inglorious/renderer-2d/crowds/particles.js`.
104
104
  */
105
105
  export function particles() {
106
106
  return {
@@ -12,10 +12,23 @@ export interface ImagesEntity extends BaseEntity {
12
12
  /** A loaded image, with the id it was loaded under. */
13
13
  export type LoadedImage = HTMLImageElement & { id: string }
14
14
 
15
- /** Loads images up front with `init`, or on demand with `load`, and hands them out by id. */
15
+ /** Anything `drawImage` takes that a game can make itself, such as a painted canvas. */
16
+ export type MadeImage = (OffscreenCanvas | HTMLCanvasElement | ImageBitmap) & {
17
+ id: string
18
+ }
19
+
20
+ /**
21
+ * Loads images up front with `init`, or on demand with `load`, and hands them out by id.
22
+ * `set` keeps an image the game made (a canvas it painted) under an id, for entities to
23
+ * name as they name a loaded one.
24
+ */
16
25
  export function images(): {
17
26
  init: (entity: ImagesEntity) => Promise<void>
18
27
  load: (id: string, src: string) => Promise<LoadedImage>
19
- get: (id: string) => LoadedImage | undefined
28
+ get: (id: string) => LoadedImage | MadeImage | undefined
29
+ set: (
30
+ id: string,
31
+ image: OffscreenCanvas | HTMLCanvasElement | ImageBitmap,
32
+ ) => MadeImage
20
33
  stop: () => void
21
34
  }