1681-engine 0.5.9 → 0.6.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 (210) hide show
  1. package/CHANGELOG.md +92 -1
  2. package/README.md +15 -6
  3. package/dist/1681-engine.js +588 -465
  4. package/dist/ai/behaviorTree.js +198 -0
  5. package/dist/ai/buildTree.js +54 -0
  6. package/dist/ambient/life/Birds.js +73 -0
  7. package/dist/ambient/life/Butterflies.js +43 -0
  8. package/dist/ambient/life/ChimneySmoke.js +50 -0
  9. package/dist/ambient/life/Drift.js +75 -0
  10. package/dist/ambient/life/Fireflies.js +52 -0
  11. package/dist/ambient/life/lifeMotion.js +49 -0
  12. package/dist/assets/AssetLoader.js +115 -70
  13. package/dist/assets/Prepainter.js +61 -0
  14. package/dist/assets/workerPainter.js +39 -0
  15. package/dist/audio/spatial.js +118 -0
  16. package/dist/cjs/electron/electronLike.d.ts +55 -0
  17. package/dist/cjs/electron/electronLike.js +7 -0
  18. package/dist/cjs/electron/index.d.ts +14 -0
  19. package/dist/cjs/electron/index.js +20 -0
  20. package/dist/cjs/electron/lockdown.d.ts +33 -0
  21. package/dist/cjs/electron/lockdown.js +69 -0
  22. package/dist/cjs/electron/lockdownRules.d.ts +28 -0
  23. package/dist/cjs/electron/lockdownRules.js +61 -0
  24. package/dist/cjs/electron/sessionStore.d.ts +40 -0
  25. package/dist/cjs/electron/sessionStore.js +77 -0
  26. package/dist/cjs/electron/shellId.d.ts +22 -0
  27. package/dist/cjs/electron/shellId.js +31 -0
  28. package/dist/cjs/electron/webFiles.d.ts +13 -0
  29. package/dist/cjs/electron/webFiles.js +52 -0
  30. package/dist/cjs/electron/webPatcher.d.ts +83 -0
  31. package/dist/cjs/electron/webPatcher.js +223 -0
  32. package/dist/cjs/electron/webPointers.d.ts +19 -0
  33. package/dist/cjs/electron/webPointers.js +35 -0
  34. package/dist/cjs/package.json +1 -0
  35. package/dist/cjs/updates/index.d.ts +8 -0
  36. package/dist/cjs/updates/index.js +21 -0
  37. package/dist/cjs/updates/manifest.d.ts +73 -0
  38. package/dist/cjs/updates/manifest.js +67 -0
  39. package/dist/cjs/updates/pickUpdate.d.ts +42 -0
  40. package/dist/cjs/updates/pickUpdate.js +52 -0
  41. package/dist/cjs/updates/webPlan.d.ts +20 -0
  42. package/dist/cjs/updates/webPlan.js +34 -0
  43. package/dist/dialogue/DialogueRunner.js +173 -0
  44. package/dist/dialogue/expr.js +137 -0
  45. package/dist/dialogue/validateDialogue.js +52 -0
  46. package/dist/ecs/prefab.js +94 -0
  47. package/dist/electron/lockdown.js +31 -0
  48. package/dist/electron/lockdownRules.js +42 -0
  49. package/dist/electron/sessionStore.js +48 -0
  50. package/dist/electron/shellId.js +18 -0
  51. package/dist/electron/webFiles.js +36 -0
  52. package/dist/electron/webPatcher.js +153 -0
  53. package/dist/electron/webPointers.js +25 -0
  54. package/dist/electron.js +19 -0
  55. package/dist/input/Actions.js +58 -27
  56. package/dist/input/InputCapture.js +98 -0
  57. package/dist/input/Keymap.js +32 -26
  58. package/dist/input/haptics.js +50 -0
  59. package/dist/input/inputTape.js +68 -0
  60. package/dist/mobile/backButton.js +40 -0
  61. package/dist/mobile/capacitor.js +48 -0
  62. package/dist/mobile/screen.js +31 -0
  63. package/dist/mobile.js +12 -0
  64. package/dist/nav/flowField.js +58 -0
  65. package/dist/nav/steering.js +77 -0
  66. package/dist/net/ApiClient.js +96 -0
  67. package/dist/net/InterpolationBuffer.js +30 -23
  68. package/dist/net/LagCompensator.js +100 -0
  69. package/dist/net/Room.js +122 -43
  70. package/dist/net/RoomHost.js +13 -4
  71. package/dist/net/SpatialHash.js +66 -0
  72. package/dist/pixel/lifeArt.js +83 -0
  73. package/dist/pixel.js +63 -58
  74. package/dist/react/ConfirmButton.js +24 -0
  75. package/dist/react/baseCss.js +1 -0
  76. package/dist/react/labels.js +7 -6
  77. package/dist/react/useJsonSelector.js +13 -0
  78. package/dist/react.js +73 -68
  79. package/dist/tilemap/TilemapView.js +57 -32
  80. package/dist/tilemap/autotile.js +103 -0
  81. package/dist/tilemap/collision.js +29 -18
  82. package/dist/tilemap/ldtk.js +21 -0
  83. package/dist/tilemap/ldtkParse.js +191 -0
  84. package/dist/types/ai/behaviorTree.d.ts +133 -0
  85. package/dist/types/ai/behaviorTree.d.ts.map +1 -0
  86. package/dist/types/ai/buildTree.d.ts +55 -0
  87. package/dist/types/ai/buildTree.d.ts.map +1 -0
  88. package/dist/types/ambient/life/Birds.d.ts +50 -0
  89. package/dist/types/ambient/life/Birds.d.ts.map +1 -0
  90. package/dist/types/ambient/life/Butterflies.d.ts +32 -0
  91. package/dist/types/ambient/life/Butterflies.d.ts.map +1 -0
  92. package/dist/types/ambient/life/ChimneySmoke.d.ts +37 -0
  93. package/dist/types/ambient/life/ChimneySmoke.d.ts.map +1 -0
  94. package/dist/types/ambient/life/Drift.d.ts +58 -0
  95. package/dist/types/ambient/life/Drift.d.ts.map +1 -0
  96. package/dist/types/ambient/life/Fireflies.d.ts +43 -0
  97. package/dist/types/ambient/life/Fireflies.d.ts.map +1 -0
  98. package/dist/types/ambient/life/lifeMotion.d.ts +63 -0
  99. package/dist/types/ambient/life/lifeMotion.d.ts.map +1 -0
  100. package/dist/types/assets/AssetLoader.d.ts +20 -0
  101. package/dist/types/assets/AssetLoader.d.ts.map +1 -1
  102. package/dist/types/assets/Prepainter.d.ts +64 -0
  103. package/dist/types/assets/Prepainter.d.ts.map +1 -0
  104. package/dist/types/assets/workerPainter.d.ts +21 -0
  105. package/dist/types/assets/workerPainter.d.ts.map +1 -0
  106. package/dist/types/audio/spatial.d.ts +107 -0
  107. package/dist/types/audio/spatial.d.ts.map +1 -0
  108. package/dist/types/dialogue/DialogueRunner.d.ts +78 -0
  109. package/dist/types/dialogue/DialogueRunner.d.ts.map +1 -0
  110. package/dist/types/dialogue/expr.d.ts +12 -0
  111. package/dist/types/dialogue/expr.d.ts.map +1 -0
  112. package/dist/types/dialogue/script.d.ts +78 -0
  113. package/dist/types/dialogue/script.d.ts.map +1 -0
  114. package/dist/types/dialogue/validateDialogue.d.ts +21 -0
  115. package/dist/types/dialogue/validateDialogue.d.ts.map +1 -0
  116. package/dist/types/ecs/prefab.d.ts +84 -0
  117. package/dist/types/ecs/prefab.d.ts.map +1 -0
  118. package/dist/types/electron/electronLike.d.ts +56 -0
  119. package/dist/types/electron/electronLike.d.ts.map +1 -0
  120. package/dist/types/electron/index.d.ts +15 -0
  121. package/dist/types/electron/index.d.ts.map +1 -0
  122. package/dist/types/electron/lockdown.d.ts +34 -0
  123. package/dist/types/electron/lockdown.d.ts.map +1 -0
  124. package/dist/types/electron/lockdownRules.d.ts +29 -0
  125. package/dist/types/electron/lockdownRules.d.ts.map +1 -0
  126. package/dist/types/electron/sessionStore.d.ts +41 -0
  127. package/dist/types/electron/sessionStore.d.ts.map +1 -0
  128. package/dist/types/electron/shellId.d.ts +23 -0
  129. package/dist/types/electron/shellId.d.ts.map +1 -0
  130. package/dist/types/electron/webFiles.d.ts +14 -0
  131. package/dist/types/electron/webFiles.d.ts.map +1 -0
  132. package/dist/types/electron/webPatcher.d.ts +84 -0
  133. package/dist/types/electron/webPatcher.d.ts.map +1 -0
  134. package/dist/types/electron/webPointers.d.ts +20 -0
  135. package/dist/types/electron/webPointers.d.ts.map +1 -0
  136. package/dist/types/index.d.ts +30 -3
  137. package/dist/types/index.d.ts.map +1 -1
  138. package/dist/types/input/Actions.d.ts +14 -0
  139. package/dist/types/input/Actions.d.ts.map +1 -1
  140. package/dist/types/input/InputCapture.d.ts +53 -0
  141. package/dist/types/input/InputCapture.d.ts.map +1 -0
  142. package/dist/types/input/Keymap.d.ts +12 -6
  143. package/dist/types/input/Keymap.d.ts.map +1 -1
  144. package/dist/types/input/haptics.d.ts +42 -0
  145. package/dist/types/input/haptics.d.ts.map +1 -0
  146. package/dist/types/input/inputTape.d.ts +66 -0
  147. package/dist/types/input/inputTape.d.ts.map +1 -0
  148. package/dist/types/mobile/backButton.d.ts +30 -0
  149. package/dist/types/mobile/backButton.d.ts.map +1 -0
  150. package/dist/types/mobile/capacitor.d.ts +62 -0
  151. package/dist/types/mobile/capacitor.d.ts.map +1 -0
  152. package/dist/types/mobile/index.d.ts +4 -0
  153. package/dist/types/mobile/index.d.ts.map +1 -0
  154. package/dist/types/mobile/screen.d.ts +27 -0
  155. package/dist/types/mobile/screen.d.ts.map +1 -0
  156. package/dist/types/nav/flowField.d.ts +31 -0
  157. package/dist/types/nav/flowField.d.ts.map +1 -0
  158. package/dist/types/nav/steering.d.ts +47 -0
  159. package/dist/types/nav/steering.d.ts.map +1 -0
  160. package/dist/types/net/ApiClient.d.ts +74 -0
  161. package/dist/types/net/ApiClient.d.ts.map +1 -0
  162. package/dist/types/net/InterpolationBuffer.d.ts +5 -0
  163. package/dist/types/net/InterpolationBuffer.d.ts.map +1 -1
  164. package/dist/types/net/LagCompensator.d.ts +70 -0
  165. package/dist/types/net/LagCompensator.d.ts.map +1 -0
  166. package/dist/types/net/Room.d.ts +72 -3
  167. package/dist/types/net/Room.d.ts.map +1 -1
  168. package/dist/types/net/RoomHost.d.ts +8 -3
  169. package/dist/types/net/RoomHost.d.ts.map +1 -1
  170. package/dist/types/net/SpatialHash.d.ts +25 -0
  171. package/dist/types/net/SpatialHash.d.ts.map +1 -0
  172. package/dist/types/pixel/index.d.ts +1 -0
  173. package/dist/types/pixel/index.d.ts.map +1 -1
  174. package/dist/types/pixel/lifeArt.d.ts +63 -0
  175. package/dist/types/pixel/lifeArt.d.ts.map +1 -0
  176. package/dist/types/react/ConfirmButton.d.ts +26 -0
  177. package/dist/types/react/ConfirmButton.d.ts.map +1 -0
  178. package/dist/types/react/baseCss.d.ts +1 -1
  179. package/dist/types/react/baseCss.d.ts.map +1 -1
  180. package/dist/types/react/index.d.ts +2 -0
  181. package/dist/types/react/index.d.ts.map +1 -1
  182. package/dist/types/react/labels.d.ts +2 -0
  183. package/dist/types/react/labels.d.ts.map +1 -1
  184. package/dist/types/react/useJsonSelector.d.ts +13 -0
  185. package/dist/types/react/useJsonSelector.d.ts.map +1 -0
  186. package/dist/types/tilemap/TilemapView.d.ts +17 -0
  187. package/dist/types/tilemap/TilemapView.d.ts.map +1 -1
  188. package/dist/types/tilemap/autotile.d.ts +95 -0
  189. package/dist/types/tilemap/autotile.d.ts.map +1 -0
  190. package/dist/types/tilemap/collision.d.ts +8 -0
  191. package/dist/types/tilemap/collision.d.ts.map +1 -1
  192. package/dist/types/tilemap/ldtk.d.ts +97 -0
  193. package/dist/types/tilemap/ldtk.d.ts.map +1 -0
  194. package/dist/types/tilemap/ldtkParse.d.ts +26 -0
  195. package/dist/types/tilemap/ldtkParse.d.ts.map +1 -0
  196. package/dist/types/ui/ScrollView.d.ts.map +1 -1
  197. package/dist/types/updates/index.d.ts +9 -0
  198. package/dist/types/updates/index.d.ts.map +1 -0
  199. package/dist/types/updates/manifest.d.ts +74 -0
  200. package/dist/types/updates/manifest.d.ts.map +1 -0
  201. package/dist/types/updates/pickUpdate.d.ts +43 -0
  202. package/dist/types/updates/pickUpdate.d.ts.map +1 -0
  203. package/dist/types/updates/webPlan.d.ts +21 -0
  204. package/dist/types/updates/webPlan.d.ts.map +1 -0
  205. package/dist/ui/ScrollView.js +10 -8
  206. package/dist/updates/manifest.js +35 -0
  207. package/dist/updates/pickUpdate.js +27 -0
  208. package/dist/updates/webPlan.js +14 -0
  209. package/dist/updates.js +15 -0
  210. package/package.json +35 -3
@@ -0,0 +1,64 @@
1
+ /** A painted RGBA image: `w` × `h` pixels, 4 bytes each, row by row (what `ImageData` holds). */
2
+ export interface PaintedPixels {
3
+ w: number;
4
+ h: number;
5
+ pixels: ArrayBuffer;
6
+ }
7
+ /** Paints an item's texture off the main thread (`workerPainter`), or anywhere else that answers with a promise. */
8
+ export interface Painter<T> {
9
+ paint(item: T, id: string): Promise<PaintedPixels>;
10
+ /** Stops it for good (a worker terminated). */
11
+ dispose?(): void;
12
+ }
13
+ /** What a `Prepainter` needs of a texture registry (`TextureRegistry` has it). */
14
+ export interface PrepainterTextures {
15
+ exists(key: string): boolean;
16
+ remove(key: string): void;
17
+ addCanvas(key: string, canvas: HTMLCanvasElement): unknown;
18
+ }
19
+ export interface PrepainterOptions<T> {
20
+ textures: PrepainterTextures;
21
+ /** The item's id, unique among items. */
22
+ id: (item: T) => string;
23
+ /** The texture key an id's painting is kept under (default the id itself). */
24
+ key?: (id: string) => string;
25
+ /** Null where nothing can be painted ahead: then everything is painted on arrival, as without a prepainter. */
26
+ painter: Painter<T> | null;
27
+ /** Turns painted pixels into a canvas (default a DOM canvas; tests hand in a stand-in). */
28
+ canvas?: (painted: PaintedPixels) => HTMLCanvasElement | null;
29
+ /** Told when a painting landed in the registry. */
30
+ onPainted?: (id: string) => void;
31
+ }
32
+ /**
33
+ * Paints ahead the big textures a player may need next (the maps beyond the current one's doors, the next level's
34
+ * backdrop) so the step into them finds them ready instead of painting them there and then — a large map's ground was
35
+ * two seconds of main-thread work, which froze the first step through every door. It also frees the rest: each such
36
+ * texture is one big image, and a long session through thirty-odd places kept every one of them.
37
+ *
38
+ * Whatever is not ready yet is the caller's to paint on arrival, as before; a painter that cannot start or fails only
39
+ * means nothing is painted ahead.
40
+ */
41
+ export declare class Prepainter<T> {
42
+ private readonly options;
43
+ private readonly pending;
44
+ /** Ids whose painting is held as a texture: the current one and its neighbours. */
45
+ private readonly held;
46
+ private readonly key;
47
+ private destroyed;
48
+ constructor(options: PrepainterOptions<T>);
49
+ /**
50
+ * Stands on `current`: its texture (painted by the caller on arrival, or ahead) and its neighbours' are kept, every
51
+ * other one this prepainter held is freed, and the neighbours not yet painted are started.
52
+ */
53
+ enter(current: T, next: readonly T[]): void;
54
+ /** Whether `id` is being painted right now (so a caller may wait for it a moment rather than paint it again). */
55
+ painting(id: string): boolean;
56
+ /** Ids held as textures now. */
57
+ get holding(): ReadonlySet<string>;
58
+ /** Starts painting `item` unless it is painted or under way. */
59
+ prepare(item: T): void;
60
+ /** Stops painting; textures already made are left to the registry. */
61
+ destroy(): void;
62
+ private receive;
63
+ }
64
+ //# sourceMappingURL=Prepainter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Prepainter.d.ts","sourceRoot":"","sources":["../../../src/assets/Prepainter.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,oHAAoH;AACpH,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACnD,+CAA+C;IAC/C,OAAO,CAAC,IAAI,IAAI,CAAC;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC;CAC5D;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,yCAAyC;IACzC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IACxB,8EAA8E;IAC9E,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7B,+GAA+G;IAC/G,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC3B,2FAA2F;IAC3F,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,iBAAiB,GAAG,IAAI,CAAC;IAC9D,mDAAmD;IACnD,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAaD;;;;;;;;GAQG;AACH,qBAAa,UAAU,CAAC,CAAC;IAOX,OAAO,CAAC,QAAQ,CAAC,OAAO;IANpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,mFAAmF;IACnF,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyB;IAC7C,OAAO,CAAC,SAAS,CAAS;gBAEG,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAI1D;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,GAAG,IAAI;IAa3C,iHAAiH;IACjH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI7B,gCAAgC;IAChC,IAAI,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAEjC;IAED,gEAAgE;IAChE,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAatB,sEAAsE;IACtE,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,OAAO;CAYhB"}
@@ -0,0 +1,21 @@
1
+ import type { PaintedPixels, Painter } from './Prepainter.js';
2
+ /** What the worker posts back for one request: the painted pixels (the buffer transferred), or why it could not. */
3
+ export type PaintReply = {
4
+ id: string;
5
+ } & (PaintedPixels | {
6
+ error: string;
7
+ });
8
+ export interface WorkerPainterOptions<T> {
9
+ /** Makes the worker, the first time something is painted: `() => new Worker(new URL('./paint.ts', import.meta.url), { type: 'module' })`. */
10
+ create: () => Worker;
11
+ /** The message posted for an item (default `{ id, item }`); the worker answers with a `PaintReply` naming that id. */
12
+ message?: (item: T, id: string) => unknown;
13
+ }
14
+ /**
15
+ * A `Painter` that paints in a worker. The worker answers each request with a `PaintReply` carrying the request's id,
16
+ * transferring the pixel buffer (`postMessage(reply, { transfer: [reply.pixels] })`) so nothing is copied back. A
17
+ * worker that cannot start or fails rejects everything under way and everything after: a prepainter then simply
18
+ * paints nothing ahead.
19
+ */
20
+ export declare function workerPainter<T>(options: WorkerPainterOptions<T>): Painter<T>;
21
+ //# sourceMappingURL=workerPainter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerPainter.d.ts","sourceRoot":"","sources":["../../../src/assets/workerPainter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE3D,oHAAoH;AACpH,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,CAAC,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE9E,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,6IAA6I;IAC7I,MAAM,EAAE,MAAM,MAAM,CAAC;IACrB,sHAAsH;IACtH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAmD7E"}
@@ -0,0 +1,107 @@
1
+ /** A point in the world, px. */
2
+ export interface Point {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ }
6
+ export interface SpatialMixOptions {
7
+ /** Beyond this (px) the source is not heard (default 480). */
8
+ range?: number;
9
+ /** How the loudness falls off: 1 straight, higher drops faster near the edge of `range` (default 1.5). */
10
+ rolloff?: number;
11
+ /** Px off to one side at which the sound is panned fully that way (default `range / 2`). */
12
+ panWidth?: number;
13
+ /** The furthest it pans, 0–1: 1 is one ear only, which sounds wrong on headphones (default 0.8). */
14
+ maxPan?: number;
15
+ /** Low-pass cutoff (Hz) beside the listener and at the edge of `range`, so far sounds are dull; null for none. */
16
+ muffle?: readonly [number, number] | null;
17
+ }
18
+ /** How a source sounds from where the listener stands. */
19
+ export interface SpatialMix {
20
+ /** Within `range`. */
21
+ audible: boolean;
22
+ /** 0–1. */
23
+ gain: number;
24
+ /** −1 left … 1 right. */
25
+ pan: number;
26
+ /** The low-pass cutoff, Hz (the top of hearing when `muffle` is null). */
27
+ cutoffHz: number;
28
+ }
29
+ /** The mix of a source at `source` heard from `listener`: louder near, panned to its side, duller far. */
30
+ export declare function spatialMix(listener: Point, source: Point, options?: SpatialMixOptions): SpatialMix;
31
+ export interface EmitterOptions extends SpatialMixOptions {
32
+ /** 0–1 (default 1). */
33
+ volume?: number;
34
+ /** Plays on for good (default true); a one-shot ends by itself. */
35
+ loop?: boolean;
36
+ playbackRate?: number;
37
+ }
38
+ /** A sound placed in the world by `SpatialAudio`. */
39
+ export interface SpatialEmitter {
40
+ x: number;
41
+ y: number;
42
+ volume: number;
43
+ /** Playing now: false while out of range (a loop waits silent), and for good once stopped or ended. */
44
+ readonly playing: boolean;
45
+ readonly done: boolean;
46
+ stop(fadeMs?: number): void;
47
+ }
48
+ /**
49
+ * Sounds placed in the world, heard from a listener that moves: a waterfall, a campfire, a machine humming, or a
50
+ * one-shot at a spot. Each emitter is panned to its side, fades with distance and loses its highs far away
51
+ * (`spatialMix`), eased each `update` so a moving source does not click. A loop out of range stops its source to
52
+ * save the voice and starts again at the point it would have reached, so it seems to have played on.
53
+ *
54
+ * ```ts
55
+ * const world = new SpatialAudio(audioContext);
56
+ * const falls = world.emitter(fallsBuffer, 320, 96, { range: 400, volume: 0.6 });
57
+ * // each frame: world.update(hero);
58
+ * ```
59
+ */
60
+ export declare class SpatialAudio {
61
+ readonly context: BaseAudioContext;
62
+ /** Every emitter's gain goes through this: the game's volume setting. */
63
+ readonly output: GainNode;
64
+ private readonly emitters;
65
+ private here;
66
+ constructor(context: BaseAudioContext, destination?: AudioNode);
67
+ /** The listener's place as of the last `update`. */
68
+ get listener(): Point;
69
+ /** How many emitters are alive (playing or waiting out of range). */
70
+ get size(): number;
71
+ /** A sound at (x, y), looping by default. Starts at once when in range of the listener. */
72
+ emitter(buffer: AudioBuffer, x: number, y: number, options?: EmitterOptions): SpatialEmitter;
73
+ /** A one-shot at (x, y), dropped when it ends; skipped (and done at once) when out of range. */
74
+ play(buffer: AudioBuffer, x: number, y: number, options?: Omit<EmitterOptions, 'loop'>): SpatialEmitter;
75
+ /** Moves the listener and re-mixes every emitter. Call once a frame. */
76
+ update(listener?: Point): void;
77
+ /** Stops every emitter. */
78
+ stopAll(fadeMs?: number): void;
79
+ destroy(): void;
80
+ /** @internal */
81
+ forget(e: Emitter): void;
82
+ }
83
+ declare class Emitter implements SpatialEmitter {
84
+ private readonly owner;
85
+ private readonly buffer;
86
+ x: number;
87
+ y: number;
88
+ private readonly options;
89
+ volume: number;
90
+ done: boolean;
91
+ private source;
92
+ private readonly gain;
93
+ private readonly panner;
94
+ private readonly filter;
95
+ /** When the loop would have begun, had it never stopped: where a restart picks it up. */
96
+ private readonly origin;
97
+ private readonly rate;
98
+ constructor(owner: SpatialAudio, buffer: AudioBuffer, x: number, y: number, options: EmitterOptions);
99
+ get playing(): boolean;
100
+ refresh(listener: Point, smooth: boolean): void;
101
+ stop(fadeMs?: number): void;
102
+ private begin;
103
+ private halt;
104
+ private release;
105
+ }
106
+ export {};
107
+ //# sourceMappingURL=spatial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spatial.d.ts","sourceRoot":"","sources":["../../../src/audio/spatial.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0GAA0G;IAC1G,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB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O,IAAI,OAAO,CAErB;IAED,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAkB/C,IAAI,CAAC,MAAM,SAAI,GAAG,IAAI;IAkBtB,OAAO,CAAC,KAAK;IAcb,OAAO,CAAC,IAAI;IAaZ,OAAO,CAAC,OAAO;CAKhB"}
@@ -0,0 +1,78 @@
1
+ import { type ExprValue } from './expr.js';
2
+ import type { DialogueScript, DialogueStep } from './script.js';
3
+ export interface DialogueOptions {
4
+ /** The variables conditions read and `set` writes; shared with the game (default a fresh object). */
5
+ vars?: Record<string, unknown>;
6
+ /** Functions an expression may call, beside the built-in `visited(node)` and `chose(node, index)`. */
7
+ functions?: Record<string, (...args: ExprValue[]) => ExprValue>;
8
+ /** A `do` command: what the game does for it. */
9
+ onCommand?: (name: string, args: readonly unknown[], runner: DialogueRunner) => void;
10
+ /** A line's or a choice's text in the player's language, before `{…}` is filled in (default as written). */
11
+ translate?: (text: string, key: string | undefined) => string;
12
+ }
13
+ /** Where a dialogue was, and what it knew, for a save: plain data. */
14
+ export interface DialogueSave {
15
+ node: string | null;
16
+ line: number;
17
+ vars: Record<string, unknown>;
18
+ visits: Record<string, number>;
19
+ chosen: string[];
20
+ }
21
+ /**
22
+ * Runs a `DialogueScript`: hands the game one step at a time — a line, a set of choices, the end — and moves on when
23
+ * the game says the line was read (`next`) or a choice made (`choose`). It draws nothing: the game's own box shows a
24
+ * `ShownLine` however it likes (a typewriter, a portrait from `tags`).
25
+ *
26
+ * ```ts
27
+ * const talk = new DialogueRunner(script, { vars: save.flags, onCommand: (name, args) => game.run(name, args) });
28
+ * let step = talk.start();
29
+ * // on a press: step = step.type === 'line' ? talk.next() : talk.choose(picked);
30
+ * ```
31
+ */
32
+ export declare class DialogueRunner {
33
+ readonly script: DialogueScript;
34
+ private readonly options;
35
+ readonly vars: Record<string, unknown>;
36
+ private node;
37
+ private line;
38
+ private step;
39
+ private readonly visits;
40
+ private readonly chosen;
41
+ private readonly scope;
42
+ constructor(script: DialogueScript, options?: DialogueOptions);
43
+ /** The step showing now. */
44
+ get current(): DialogueStep;
45
+ /** The node the dialogue is in, or null once it has ended. */
46
+ get at(): string | null;
47
+ /** How many times a node was entered. */
48
+ visited(node: string): number;
49
+ /** Begins at `node` (default the script's `start`, else its first node). */
50
+ start(node?: string | undefined): DialogueStep;
51
+ /** The line showing was read: on to the next line, the choices, or wherever the node leads. */
52
+ next(): DialogueStep;
53
+ /** Picks a choice by its `index` (as shown). A locked or unknown index changes nothing. */
54
+ choose(index: number): DialogueStep;
55
+ /** Jumps to a node from outside (the game's own event broke in). */
56
+ jump(node: string): DialogueStep;
57
+ /** Ends the dialogue now. */
58
+ stop(): DialogueStep;
59
+ /** The value of an expression over this dialogue's variables, for a game that shares the language. */
60
+ evaluate(source: string): ExprValue;
61
+ save(): DialogueSave;
62
+ /** Puts a saved dialogue back where it was, without running the node's `set` and `do` again. */
63
+ restore(save: DialogueSave): DialogueStep;
64
+ private go;
65
+ private enter;
66
+ /** The step from the current line on: the next line that holds, else the choices, else the way on. */
67
+ private show;
68
+ private offered;
69
+ private wayOn;
70
+ private finish;
71
+ private nodeOf;
72
+ private test;
73
+ private assign;
74
+ private run;
75
+ /** `text` translated, with each `{expression}` replaced by its value; `{{` and `}}` are braces. */
76
+ private text;
77
+ }
78
+ //# sourceMappingURL=DialogueRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DialogueRunner.d.ts","sourceRoot":"","sources":["../../../src/dialogue/DialogueRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,KAAK,EAA+D,cAAc,EAAE,YAAY,EAAe,MAAM,UAAU,CAAC;AAEvI,MAAM,WAAW,eAAe;IAC9B,qGAAqG;IACrG,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,sGAAsG;IACtG,SAAS,CAAC,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;IACzC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7B,4EAA4E;IAC5E,KAAK,CAAC,IAAI,qBAAyD,GAAG,YAAY;IAKlF,+FAA+F;IAC/F,IAAI,IAAI,YAAY;IAMpB,2FAA2F;IAC3F,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAYnC,oEAAoE;IACpE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAIhC,6BAA6B;IAC7B,IAAI,IAAI,YAAY;IAIpB,sGAAsG;IACtG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAInC,IAAI,IAAI,YAAY;IAUpB,gGAAgG;IAChG,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY;IAazC,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,KAAK;IAab,sGAAsG;IACtG,OAAO,CAAC,IAAI;IAgBZ,OAAO,CAAC,OAAO;IAYf,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;IAOX,mGAAmG;IACnG,OAAO,CAAC,IAAI;CASb"}
@@ -0,0 +1,12 @@
1
+ export type ExprValue = number | string | boolean | null | undefined;
2
+ /** What an expression reads: variables by (dotted) name, and the functions it may call. */
3
+ export interface ExprScope {
4
+ get(name: string): unknown;
5
+ call(name: string, args: ExprValue[]): ExprValue;
6
+ }
7
+ export type CompiledExpr = (scope: ExprScope) => ExprValue;
8
+ /** Compiles `src`; throws with what and where on a syntax error. */
9
+ export declare function compileExpr(src: string): CompiledExpr;
10
+ /** `compileExpr`, kept: a script asks the same few conditions again and again. */
11
+ export declare function expr(src: string): CompiledExpr;
12
+ //# sourceMappingURL=expr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expr.d.ts","sourceRoot":"","sources":["../../../src/dialogue/expr.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAErE,2FAA2F;AAC3F,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;AAsD3D,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAgHrD;AAID,kFAAkF;AAClF,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAQ9C"}
@@ -0,0 +1,78 @@
1
+ /** One line said: by `speaker` (absent: narration). A bare string is a line of narration. */
2
+ export interface DialogueLine {
3
+ text: string;
4
+ speaker?: string;
5
+ /** Said only when this holds. */
6
+ if?: string;
7
+ /** The game's own marks (a portrait's mood, a sound): handed back with the line. */
8
+ tags?: string[];
9
+ /** A translation key, handed to `translate` with the text. */
10
+ key?: string;
11
+ }
12
+ /** Something the game does, by name: `"open_gate"`, or `{ "name": "give", "args": ["key", 1] }`. */
13
+ export type DialogueCommand = string | {
14
+ name: string;
15
+ args?: unknown[];
16
+ };
17
+ /** One answer the player may pick. */
18
+ export interface DialogueChoice {
19
+ text: string;
20
+ /** Where it leads (absent: the dialogue ends). */
21
+ goto?: string;
22
+ /** Offered only when this holds. */
23
+ if?: string;
24
+ /** When `if` fails, show it greyed out instead of leaving it out (the player sees what they lack). */
25
+ showLocked?: boolean;
26
+ /** Offered only until picked once. */
27
+ once?: boolean;
28
+ /** Assignments run when it is picked: name → expression. */
29
+ set?: Record<string, string>;
30
+ do?: DialogueCommand[];
31
+ key?: string;
32
+ }
33
+ /** A way on from a node with no choices: the first branch whose `if` holds (or that has none) is taken. */
34
+ export interface DialogueBranch {
35
+ if?: string;
36
+ goto: string;
37
+ }
38
+ export interface DialogueNode {
39
+ lines?: (string | DialogueLine)[];
40
+ choices?: DialogueChoice[];
41
+ /** Where to go after the lines when there are no choices: a node, or branches. Absent: the dialogue ends. */
42
+ next?: string | DialogueBranch[];
43
+ /** Assignments run on entering the node, before its lines. */
44
+ set?: Record<string, string>;
45
+ /** Commands run on entering the node, after `set`. */
46
+ do?: DialogueCommand[];
47
+ }
48
+ export interface DialogueScript {
49
+ /** Where `start()` begins (default the first node). */
50
+ start?: string;
51
+ nodes: Record<string, DialogueNode>;
52
+ }
53
+ /** A line as the runner hands it on: with its `{…}` filled in and translated. */
54
+ export interface ShownLine {
55
+ type: 'line';
56
+ node: string;
57
+ speaker: string | undefined;
58
+ text: string;
59
+ tags: readonly string[];
60
+ }
61
+ export interface ShownChoice {
62
+ /** What to pass to `choose`. */
63
+ index: number;
64
+ text: string;
65
+ /** False for a `showLocked` choice whose condition fails: drawn, but not pickable. */
66
+ enabled: boolean;
67
+ }
68
+ export interface ShownChoices {
69
+ type: 'choices';
70
+ node: string;
71
+ choices: ShownChoice[];
72
+ }
73
+ export interface DialogueEnd {
74
+ type: 'end';
75
+ }
76
+ /** Where a dialogue stands: a line to show, choices to offer, or the end. */
77
+ export type DialogueStep = ShownLine | ShownChoices | DialogueEnd;
78
+ //# sourceMappingURL=script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/dialogue/script.ts"],"names":[],"mappings":"AAmBA,6FAA6F;AAC7F,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,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AAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC;CACb;AAED,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { DialogueScript } from './script.js';
2
+ /** One fault in a script: where (`nodes.gate.choices[1].goto`), and what. */
3
+ export interface DialogueIssue {
4
+ path: string;
5
+ message: string;
6
+ /** An error stops the dialogue when reached; a warning is likely a slip (a node nothing leads to). */
7
+ level: 'error' | 'warning';
8
+ }
9
+ export interface ValidateOptions {
10
+ /** The commands the game handles; when given, a `do` naming another is an error. */
11
+ commands?: readonly string[];
12
+ /** The functions the game registered, beside `visited` and `chose`; when given, a call to another is an error. */
13
+ functions?: readonly string[];
14
+ }
15
+ /**
16
+ * Checks a script without running it, for a test or an editor: every `goto` and `next` names a node, every condition,
17
+ * assignment and `{…}` parses, commands and functions are known (when the lists are given), and every node can be
18
+ * reached from the start.
19
+ */
20
+ export declare function validateDialogue(script: DialogueScript, options?: ValidateOptions): DialogueIssue[];
21
+ //# sourceMappingURL=validateDialogue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateDialogue.d.ts","sourceRoot":"","sources":["../../../src/dialogue/validateDialogue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,UAAU,CAAC;AAEhE,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,sGAAsG;IACtG,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,kHAAkH;IAClH,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,eAAoB,GAAG,aAAa,EAAE,CAqFvG"}
@@ -0,0 +1,84 @@
1
+ import type { FieldSpec, FieldsType, FieldValues } from './fields.js';
2
+ import type { ComponentType, Entity, World } from './World.js';
3
+ /** What a prefab's factory values are given: the entity being made and the spawn's own `args`. */
4
+ export interface PrefabContext<A> {
5
+ entity: Entity;
6
+ args: A;
7
+ }
8
+ /**
9
+ * A component's value in a prefab: plain data (copied afresh for every entity, so no two share an object), or a
10
+ * factory called once per entity, for what cannot be copied (a class instance, a sprite) or must differ (a random
11
+ * roll, a position from the spawn's args). `null` in a variant takes away a component its base has.
12
+ */
13
+ export type PrefabValue<T, A = unknown> = T | ((ctx: PrefabContext<A>) => T);
14
+ export type PrefabPart<A = unknown> = readonly [ComponentType<unknown>, PrefabValue<unknown, A> | null];
15
+ /**
16
+ * One part of a prefab, typed: the value is checked against the component's type, and a factory's `ctx` is known.
17
+ * A bare `[type, value]` tuple works too, unchecked.
18
+ */
19
+ export declare function prefabPart<S extends FieldSpec, A = unknown>(type: FieldsType<S>, value: PrefabValue<FieldValues<S>, A> | null): PrefabPart<A>;
20
+ export declare function prefabPart<T, A = unknown>(type: ComponentType<T>, value: PrefabValue<T, A> | null): PrefabPart<A>;
21
+ /** A template for entities: the components each gets, with their starting values. */
22
+ export interface Prefab<A = unknown> {
23
+ readonly name: string;
24
+ /** The components, the base's merged in: a variant's plain-object values are laid over the base's field by field. */
25
+ readonly parts: ReadonlyMap<ComponentType<unknown>, PrefabValue<unknown, A>>;
26
+ readonly base: Prefab<A> | null;
27
+ }
28
+ export interface PrefabOptions<A> {
29
+ /** The prefab this is a variant of: everything it has, with these parts laid over. */
30
+ extends?: Prefab<A>;
31
+ }
32
+ /**
33
+ * Defines a prefab.
34
+ *
35
+ * ```ts
36
+ * const Monster = definePrefab('monster', [prefabPart(Health, { hp: 10, max: 10 }), prefabPart(Brain, () => tree.agent())]);
37
+ * const Boss = definePrefab('boss', [prefabPart(Health, { hp: 200, max: 200 }), prefabPart(Flying, null)], { extends: Monster });
38
+ * spawnPrefab(world, Boss, { with: [[Position, { x: 40, y: 80 }]] });
39
+ * ```
40
+ */
41
+ export declare function definePrefab<A = unknown>(name: string, parts: readonly PrefabPart<A>[], options?: PrefabOptions<A>): Prefab<A>;
42
+ export interface SpawnOptions<A> {
43
+ /** Components added or replaced for this entity only (laid over the prefab's like a variant's). */
44
+ with?: readonly PrefabPart<A>[];
45
+ /** Components of the prefab this entity goes without. */
46
+ without?: readonly ComponentType<unknown>[];
47
+ /** Handed to every factory value. */
48
+ args?: A;
49
+ }
50
+ /** Makes one entity from a prefab: each component's value copied, or made by its factory. */
51
+ export declare function spawnPrefab<A = unknown>(world: World, prefab: Prefab<A>, options?: SpawnOptions<A>): Entity;
52
+ /** Whether `prefab` is `of` or a variant of it, however far down. */
53
+ export declare function isPrefabOf(prefab: Prefab<never> | Prefab<unknown>, of: Prefab<never> | Prefab<unknown>): boolean;
54
+ /** Prefabs as data: `{ "goblin": { "extends": "monster", "components": { "Health": { "hp": 6 }, "Flying": null } } }`. */
55
+ export type PrefabData = Record<string, {
56
+ extends?: string;
57
+ components?: Record<string, unknown>;
58
+ }>;
59
+ /**
60
+ * Prefabs by name, loadable from data a designer edits. Components are named through `component(name, type)`;
61
+ * a value in the data is plain JSON, so factories (a sprite, a brain) are given in code with `factory`.
62
+ */
63
+ export declare class PrefabLibrary {
64
+ private readonly types;
65
+ private readonly factories;
66
+ private readonly prefabs;
67
+ /** Lets data name a component type. */
68
+ component(name: string, type: ComponentType<unknown>): this;
69
+ /** A value made in code for a prefab loaded from data (and its variants): the data cannot hold a function. */
70
+ factory<T>(prefab: string, type: ComponentType<T>, make: (ctx: PrefabContext<unknown>) => T): this;
71
+ /** Adds a prefab made in code. */
72
+ add(prefab: Prefab): this;
73
+ /**
74
+ * Builds the prefabs of `data`, bases before their variants (in any order in the data), and adds them. Throws,
75
+ * naming the prefab, on an unknown component or base, or a prefab that extends itself.
76
+ */
77
+ load(data: PrefabData): this;
78
+ get(name: string): Prefab;
79
+ has(name: string): boolean;
80
+ names(): string[];
81
+ /** `spawnPrefab` by name. */
82
+ spawn<A = unknown>(world: World, name: string, options?: SpawnOptions<A>): Entity;
83
+ }
84
+ //# sourceMappingURL=prefab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefab.d.ts","sourceRoot":"","sources":["../../../src/ecs/prefab.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE5D,kGAAkG;AAClG,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;CACT;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAE7E,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC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lG,kCAAkC;IAClC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKzB;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IA4B5B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMzB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,KAAK,IAAI,MAAM,EAAE;IAIjB,6BAA6B;IAC7B,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAY,CAAC,CAAC,CAAM,GAAG,MAAM;CAGtF"}
@@ -0,0 +1,56 @@
1
+ /** `electron.safeStorage`. */
2
+ export interface SafeStorageLike {
3
+ isEncryptionAvailable(): boolean;
4
+ /** Linux only: `basic_text` means a hard-coded key, which is no encryption at all. */
5
+ getSelectedStorageBackend?(): string;
6
+ encryptString(plainText: string): Uint8Array;
7
+ decryptString(encrypted: Buffer): string;
8
+ }
9
+ /** `electron.ipcMain`. */
10
+ export interface IpcMainLike {
11
+ handle(channel: string, listener: (event: any, ...args: any[]) => unknown): void;
12
+ removeHandler?(channel: string): void;
13
+ }
14
+ /** `electron.shell`. */
15
+ export interface ShellLike {
16
+ openExternal(url: string): Promise<void>;
17
+ }
18
+ /** What `before-input-event` hands a listener (`Electron.Input`). */
19
+ export interface InputLike {
20
+ type: string;
21
+ key: string;
22
+ control: boolean;
23
+ meta: boolean;
24
+ shift: boolean;
25
+ alt: boolean;
26
+ }
27
+ /** An event a listener may cancel. */
28
+ export interface PreventableLike {
29
+ preventDefault(): void;
30
+ }
31
+ /** `electron.Session`, for the permission handlers. */
32
+ export interface SessionLike {
33
+ setPermissionRequestHandler(handler: ((webContents: any, permission: any, callback: (granted: boolean) => void, details: any) => void) | null): void;
34
+ setPermissionCheckHandler(handler: ((webContents: any, permission: any, requestingOrigin: string, details: any) => boolean) | null): void;
35
+ }
36
+ /** `electron.WebContents`. */
37
+ export interface WebContentsLike {
38
+ setWindowOpenHandler(handler: (details: {
39
+ url: string;
40
+ }) => any): void;
41
+ on(event: any, listener: (...args: any[]) => void): unknown;
42
+ toggleDevTools(): void;
43
+ session?: SessionLike;
44
+ }
45
+ /** `electron.BrowserWindow`, as far as a lockdown needs it. */
46
+ export interface WindowLike {
47
+ webContents: WebContentsLike;
48
+ }
49
+ /** `electron.app`, as far as the debugger refusal needs it. */
50
+ export interface AppLike {
51
+ isPackaged: boolean;
52
+ commandLine: {
53
+ hasSwitch(name: string): boolean;
54
+ };
55
+ }
56
+ //# sourceMappingURL=electronLike.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"electronLike.d.ts","sourceRoot":"","sources":["../../../src/electron/electronLike.ts"],"names":[],"mappings":"AAMA,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,qBAAqB,IAAI,OAAO,CAAC;IACjC,sFAAsF;IACtF,yBAAyB,CAAC,IAAI,MAAM,CAAC;IACrC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7C,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1C;AAED,0BAA0B;AAC1B,MAAM,WAAW,WAAW;IAE1B,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;IACjF,aAAa,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC;AAED,wBAAwB;AACxB,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,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1681-engine/electron`: the main-process side of a desktop build on Electron — file-by-file web patching from a
3
+ * release store, the shell's identity, an OS-encrypted session store and a window lockdown. Electron is an optional
4
+ * peer: nothing here imports it, the game hands in its own `app`, `safeStorage`, `ipcMain`, `shell` and windows. Runs
5
+ * in the main process only (it uses Node's `fs` and `crypto`); the pure rules it shares with browsers and phones are
6
+ * `1681-engine/updates`. Importable from ESM (`import`) and from a CommonJS main process (`require`).
7
+ */
8
+ export type { SafeStorageLike, IpcMainLike, ShellLike, InputLike, PreventableLike, SessionLike, WebContentsLike, WindowLike, AppLike } from './electronLike.js';
9
+ export { shellId, type ShellIdOptions } from './shellId.js';
10
+ export { WebPatcher, type WebPatcherOptions } from './webPatcher.js';
11
+ export type { WebPointer, PointerName } from './webPointers.js';
12
+ export { SessionStore, registerSessionStore, type SessionStoreOptions } from './sessionStore.js';
13
+ export { isAllowedExternal, isAllowedNavigation, isDevToolsKey, debuggerRequested, DEBUG_SWITCHES, type ExternalPolicy } from './lockdownRules.js';
14
+ export { lockDownWindow, denyPermissions, refuseDebugLaunch, type LockdownOptions } from './lockdown.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/electron/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7J,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChJ,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { AppLike, SessionLike, ShellLike, WindowLike } from './electronLike.js';
2
+ import { type ExternalPolicy } from './lockdownRules.js';
3
+ /** How {@link lockDownWindow} treats a window. */
4
+ export interface LockdownOptions {
5
+ /** `electron.shell`, which opens an allowed link in the system browser. */
6
+ shell: ShellLike;
7
+ /** The links that may leave for the system browser. */
8
+ external: ExternalPolicy;
9
+ /** `app.isPackaged`: a packaged build refuses the DevTools keys. */
10
+ packaged: boolean;
11
+ /** A dev run's page origin, allowed for navigation; leave unset in a packaged build whatever the environment says. */
12
+ devServerUrl?: string;
13
+ /** In a dev run, this key toggles DevTools. Default `F12`; null for none. */
14
+ devToolsKey?: string | null;
15
+ /** Where refusals are reported. Default `console.log`. */
16
+ log?: (...args: unknown[]) => void;
17
+ }
18
+ /**
19
+ * Keeps a window on the game: a new window is never opened (an allowed link goes to the system browser instead, any
20
+ * other is refused), the window never navigates or redirects away from the game's own page, and a packaged build
21
+ * refuses the DevTools keys (set `webPreferences.devTools: !app.isPackaged` too: the keys are only the visible way in).
22
+ */
23
+ export declare function lockDownWindow(win: WindowLike, o: LockdownOptions): void;
24
+ /**
25
+ * Answers every permission request and check on `session` (camera, microphone, notifications, geolocation…) with no,
26
+ * but those in `allow`. Chromium's default in Electron is yes to almost everything, which a game never needs.
27
+ */
28
+ export declare function denyPermissions(session: SessionLike, allow?: readonly string[]): void;
29
+ /**
30
+ * A packaged app started with a debugger switch quits before it opens a window. Call it first thing in the main
31
+ * process; `exit` defaults to `process.exit` — not `app.exit`, so nothing after the call may run.
32
+ */
33
+ export declare function refuseDebugLaunch(app: AppLike, argv?: readonly string[], exit?: (code: number) => void): boolean;
34
+ //# sourceMappingURL=lockdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockdown.d.ts","sourceRoot":"","sources":["../../../src/electron/lockdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAA4E,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEhI,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,KAAK,EAAE,SAAS,CAAC;IACjB,uDAAuD;IACvD,QAAQ,EAAE,cAAc,CAAC;IACzB,oEAAoE;IACpE,QAAQ,EAAE,OAAO,CAAC;IAClB,sHAAsH;IACtH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,eAAe,GAAG,IAAI,CA8BxE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,IAAI,CAIzF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,GAAE,SAAS,MAAM,EAAiB,EAAE,IAAI,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAA6B,GAAG,OAAO,CAMtJ"}