threedog 2.1.0 → 2.2.2

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/CHANGELOG.md +45 -0
  2. package/core/assets/Animator.js +1 -1
  3. package/core/audio/Audio.js +55 -8
  4. package/core/audio/audioReverb.js +2 -2
  5. package/core/base/Random.js +1 -1
  6. package/core/base/errorCodes.js +1 -1
  7. package/core/engine/Loading.js +3 -1
  8. package/core/engine/copies.js +1 -1
  9. package/core/engine/loop.js +1 -0
  10. package/core/input/Input.js +3 -3
  11. package/core/inspect/InspectPerf.js +1 -1
  12. package/core/inspect/describeText.js +3 -2
  13. package/core/inspect/metadata.generated.js +76 -24
  14. package/core/ops/holds.js +1 -1
  15. package/core/ops/sharedPoint.js +6 -1
  16. package/core/saves/Saves.js +24 -12
  17. package/core/saves/saveVersions.js +15 -0
  18. package/core/scene/Rays.js +1 -1
  19. package/core/scene/Views.js +20 -1
  20. package/core/scene/canvasBox.js +9 -0
  21. package/core/scene/sceneMethods.js +2 -1
  22. package/core/threads/Jobs.js +1 -1
  23. package/docs/AI.md +2 -2
  24. package/docs/API.md +2 -2
  25. package/docs/COMMANDS.md +4 -3
  26. package/docs/api/audio.md +1 -0
  27. package/docs/api/music.md +2 -2
  28. package/docs/api/saves.md +2 -1
  29. package/docs/api/settings.md +0 -2
  30. package/docs/recipes/02-npc.md +1 -1
  31. package/docs/recipes/03-items-pickups.md +4 -5
  32. package/docs/recipes/06-clock-events.md +2 -6
  33. package/docs/recipes/07-flow-scenes-pause.md +1 -1
  34. package/docs/recipes/08-weather-sky.md +2 -4
  35. package/docs/recipes/09-materials-lights-models.md +2 -2
  36. package/docs/recipes/14-custom-module.md +4 -1
  37. package/docs/recipes/15-perf.md +9 -5
  38. package/docs/recipes/16-dev-bridge.md +46 -36
  39. package/docs/recipes/20-content-actions-save.md +1 -0
  40. package/docs/recipes/21-camera.md +3 -4
  41. package/docs/recipes/26-ui-parts.md +3 -2
  42. package/docs/recipes/31-audio.md +19 -3
  43. package/docs/recipes/44-water-weather-hooks.md +1 -1
  44. package/docs/recipes/52-around-the-picture.md +1 -1
  45. package/docs/recipes/55-mods-time-wrap.md +5 -1
  46. package/docs/recipes/56-webgpu-tsl.md +5 -7
  47. package/docs/recipes/58-input.md +4 -1
  48. package/docs/recipes/60-judge-the-picture.md +5 -5
  49. package/llms.txt +1 -1
  50. package/modules/camera/common.js +1 -1
  51. package/modules/collision/Collision.js +1 -1
  52. package/modules/debug/DebugPanel.js +1 -1
  53. package/modules/gameplay/Dialogue.js +1 -1
  54. package/modules/gameplay/Interactions.js +1 -1
  55. package/modules/gameplay/Inventory.js +1 -1
  56. package/modules/gameplay/Quests.js +1 -1
  57. package/modules/hud/parts.js +1 -1
  58. package/modules/music/Music.js +35 -3
  59. package/modules/particles/Particles.js +1 -1
  60. package/modules/rigid/RigidBodies.js +1 -1
  61. package/modules/settings/Settings.js +22 -16
  62. package/modules/settings/sections.js +1 -1
  63. package/modules/swarm/Swarm.js +1 -1
  64. package/modules/timeline/Timeline.js +1 -1
  65. package/modules/timeline/letterbox.js +1 -1
  66. package/package.json +1 -1
  67. package/render/PostFX.js +7 -1
  68. package/render/fx/detail.tsl.js +3 -0
  69. package/types/core.d.ts +2 -0
  70. package/types/gameplay.d.ts +6 -7
  71. package/types/generated/core/audio/Audio.d.ts +10 -0
  72. package/types/generated/core/saves/Saves.d.ts +6 -1
  73. package/types/generated/modules/music/Music.d.ts +4 -13
  74. package/ui/Focus.js +1 -1
  75. package/ui/Parts.js +19 -7
  76. package/ui/defaults.js +1 -1
  77. package/ui/theme.js +14 -8
package/CHANGELOG.md CHANGED
@@ -2,6 +2,51 @@
2
2
 
3
3
  What changed in each version and how a game upgrades.
4
4
 
5
+ ## 2.2.2 (2026-11-19)
6
+
7
+ Upgrading from 2.2.1: nothing to change.
8
+
9
+ - Fixed: `engine.step()` follows a changed viewport (canvas, camera and the UI root) even when no frame was drawn since, so a frozen or stepped page reads the new size on its next step; `engine.renderOnce()` resets `renderer.info`, so draw-call and triangle counts no longer add up across calls
10
+ - Changed (tools): an unknown option on a dev-bridge command says the working form (`errors latest 3`, `state key=value`, `step 2`, `hold <action> <seconds>`, `describe <path>`); `step` on a title screen says how to leave it (`state play=1`, or `--page "/?play"`); `snap` waits for loading to finish, as `shot` does, before it captures
11
+ - Changed (tools): `check` reminds when a game calls three's `bumpMap(` (rule R40): for a height computed in the shader use `detailBump` from `threedog/tsl`; `bumpMap` needs a texture
12
+ - Docs: recipe 16 §2a shows how to hold an action across `threedog snap`, and to step once after changing the viewport on a headless page
13
+
14
+ ## 2.2.1 (2026-11-19)
15
+
16
+ Upgrading from 2.2.0: install `@threedog/tools@2.2.1` (the other packages only move with it). Nothing else changes.
17
+
18
+ - Fixed (tools): the published 2.2.0 tools package left out its `expect/` folder, so `threedog check`, `shot`, `test` and `expect` crashed on start after `npm install`. A test now packs every package and fails when shipped code imports a file the package leaves out
19
+ - Fixed (tools): two kinds of plain JS that TypeScript cannot follow were `✗` errors and failed `check`; they are now `!` reminders: a member read on a value whose type inference lost (`never`, as three's TSL declarations give for some `vec2(…).add(uniform(…))`), and an array literal passed where a fixed pair is declared (`repeat = [1, 1]` into a `[number, number]` option)
20
+
21
+ ## 2.2.0 (2026-11-19)
22
+
23
+ Upgrading from 2.1: a game changes code only if it uses one of these. `engine.settings.open()` / `close()` / `toggle()` / `isOpen()` become `engine.ui.open('settings')` / `ui.close('settings')` / `ui.isOpen('settings')`, and an input binding on context `win-settings` moves to `ui-settings`. `engine.ui.open` / `close` with a name that is not a full-screen part now throws (fix the name). `engine.mod(point, { id })` on a point that is not per record throws (drop the id, or define the point `{ per: 'optional' }`). `engine.post.add` throws `post-effect` on an unknown key or a wrong type in the definition. Your own CSS that layered over the title screen by z-index: the title is now at 22 (was 80), and the layers are the `--threedog-z-*` variables. Tools: `--no-build` needs one earlier build of the same kind on this machine, and a `threedog test` spec's timeout starts when the engine is up (nothing to change: specs only get more time).
24
+
25
+ - Removed: `settings.open`, `settings.close`, `settings.toggle` and `settings.isOpen` (on `engine.settings`): settings is a full-screen ui part, so use `engine.ui.open('settings')`, `engine.ui.close('settings')` and `engine.ui.isOpen('settings')` (one way to open every window). Its input context is now `ui-settings` (was `win-settings`)
26
+ - Changed: `engine.ui.open` and `engine.ui.close` throw `ui-misuse` on a name that is not a full-screen part (`close` used to do nothing); `engine.ui.isOpen` answers false for it
27
+ - Fixed: the title screen sits below windows, so Settings opened from the title shows on top; game UI layers are one table of CSS variables `--threedog-z-*` (title 22, windows 25, toast 35, fade 90, loading 100)
28
+ - Changed (tools): a failed `threedog test` whose page has an audio context that stays out of "running" even after `resume()` adds an "environment problem: the headless browser got no audio device" line (the test still fails)
29
+ - Added: `saves.list()` rows carry `summary`: mark a part `summary: true` in `saves.define` to show level, gold or play time on a start screen without loading the slot (read from the stored save and migrated like a load; a save `load()` would refuse lists with `{}`). Save format and old saves are unchanged
30
+ - Added: `engine.audio.addNode(bus | 'master', ctx => node)` puts your own Web Audio node in a bus's path (for example a low-pass on `sfx` only); the reverb send follows it; the handle's `remove()` links the path back, and links the game made itself (an analyser on `audio.master`) are left alone
31
+ - Added: music tracks made by code: `engine.music.define(name, { generate({ ctx, output, start, end }) })` (`music.tracks` entries may now hold `generate`, which excludes `url` and `stems`: both throw `music-track`; existing tracks need no change). They use the same `play`, rules, fades, ducking and stingers as file tracks; as a stinger, call `end()` when the piece is over
32
+ - Changed: `engine.mod` on a point that is not per record throws on `{ id }` (the id was never read; define the point `{ per: 'optional' }` for one value per id). Saves holding such entries still load; the unused entry is dropped with one warning
33
+ - Changed: `engine.post.add(effect)` checks the definition's keys and types before adding anything (`facts` is a function `() => object`) and throws `post-effect`
34
+ - Added: the `describeText` state line names who froze the game ("halted, frozen by menu"); `views.show` watches the camera pose as owned `views-camera`, so a script that overwrites a shown view is reported once as `owned-prop`
35
+ - Changed (tools): every tool build (shot, test, capture, perf, stress, real-webgpu) goes into its own folder `.threedog/tool-build/<kind>-<pid>-<n>/`, so another session's build no longer breaks a page you are serving; `--no-build` serves the last successful build of the same kind on this machine and fails when there is none
36
+ - Changed (tools): `shot` opens a page under one `--load-timeout` deadline and says which step it was stuck at; a `threedog test` spec's timeout starts when the engine is up (opening the page has its own 60 s); the dev server's headless page words a reload during a command as "run the command again"; the busy-server probe asks twice
37
+ - Added (tools): `threedog expect <value> (--min n | --max n | --is v) --why "reason" [--point name]` records what must stay true in the game's `expectations.jsonl` (writing the same value and point again changes it and shows the earlier reason); `threedog expect drop` and `threedog expect list [--json]`
38
+ - Added (tools): `threedog shot --point <name>` shoots a point of `shots.json` (the same picture as `threedog hub`) and checks the game's expectations on that reading: one line when all hold, the failing ones with their reasons otherwise; `threedog expect shot.*` then records which renderer drew the number (`WebGL · gpu`, `WebGL · software`) and its value at the time; `threedog shot --point <p> --software` writes a number the tests can check. `--point` refuses the options the point sets (`--time`, `--weather`, `--pos`, `--at`, `--view`, `--cam`, `--play`, `--wait`), and `--json` carries `expectations` and `expectationProblems`
39
+ - Added (tools): `threedog test` runs a game's `expectations.jsonl`: one item per point (or one on `/` when no entry names a point); each point item opens the page as `shot --point` and the hub do (its page, size, loading and UI settled) and judges its own entries, entries without a point get one item on `/`; a failing expectation fails the test, and what cannot be measured here (a picture number written on the GPU, while tests draw with software rendering; a stopped page) is counted under "did not run" instead of passing silently
40
+ - Added (tools): `check` rule R72 reads a game's `expectations.jsonl`: a line that cannot be read or says the same thing twice is an error; a thin reason or a point missing from `shots.json` only reminds
41
+ - Changed (tools): `check` reminds about more hand-made copies of engine systems (a sound written into `audio.config.sounds`, `audio.master` rewired by hand, a ready flag of your own, an own bag with a cap or a shop) and no longer flags a distance compared with a number as a box overlap; each reminder names its recipe section with the `threedog how --read` command
42
+ - Changed (template): a new game's `CLAUDE.md` says `check` reminders (`!` lines) only remind and only `✗` lines must be fixed, and points to `threedog expect`, `declare module` for your own handle on `engine`, and asking `threedog how` once before working around something the engine seems unable to do
43
+ - Docs: recipe 16 §12 explains expectations (keep a number in range, with the reason) and `threedog how` finds it; recipe headings now name what they teach where answers were missed (game over and win screens, an NPC you talk to, sea around an island, street lamps), and scattered answers moved into the section that owns them
44
+ - Fixed (tools): a save from the in-page editor tells the dev server at once, so the reload after moving an NPC shows its new start (the file watcher waits for a write to settle since the half-written-file fix, and the page reloaded before it)
45
+ - Changed (tools): `threedog how` also answers from the COMMANDS tables; when no section fits well it says so and shows the closest three as one line each, instead of one confident wrong section
46
+ - Changed (tools): each `check` reminder line ends with the `threedog how --read …` command for its recipe section; `check --rule R40` lists every reminder, as the MCP check does; `npm run map` fails when an error code's `docs` pointer names a section that is not there
47
+ - Changed (tools): reminders from `check`, R40 and the MCP come out of one place with a small budget and fixed prefixes (`✗` must fix, `!` reminder); a reminder never fails a command
48
+ - Fixed (tools): every `threedog` command sweeps up headless browsers that a killed tool left behind (a whole browser with its children, not only the children of a closed one), so stopped commands no longer leave them spinning
49
+
5
50
  ## 2.1.0 (2026-11-18)
6
51
 
7
52
  Upgrading from 2.0: nothing to change unless your game listens to `module:restored` (now `module:fresh`) or `settings:shadows` (follow the shared point `shadows.enabled`); the player's render-scale choice is now a ceiling for `engine.setPixelRatio` (see below). The pre-2.0 `Unreleased` notes follow.
@@ -318,4 +318,4 @@ export class Animator {
318
318
  dispose() { this._dropHook(); ikClear(this); this.mixer.stopAllAction(); }
319
319
  }
320
320
 
321
- export const handRolled = [{ kind: 'animation', seen: 'an AnimationMixer of its own', use: 'engine.assets.animate(model, { states }): states, crossfades, sync with game time and pause (recipe 13)', quiet: /\bassets\.animate\b/, code: /\bnew\s+(?:THREE\.)?AnimationMixer\s*\(|\bmixer\.update\s*\(/i }];
321
+ export const handRolled = [{ kind: 'animation', docRef: 'recipes/13-animation.md §5', seen: 'an AnimationMixer of its own', use: 'engine.assets.animate(model, { states }): states, crossfades, sync with game time and pause', quiet: /\bassets\.animate\b/, code: /\bnew\s+(?:THREE\.)?AnimationMixer\s*\(|\bmixer\.update\s*\(/i }];
@@ -55,6 +55,9 @@ export class Audio {
55
55
  this.packs = new Map();
56
56
  /** @internal */ this._packWatch = new Set();
57
57
  /** @internal */ this._duckNodes = {};
58
+ /** @internal bus name -> the node after the bus's insert chain: where its reverb send taps and where master is fed from */ this._tails = {};
59
+ /** @internal audio.addNode() registrations in call order: { bus, make, node } (node is null until the context exists) */ this._inserts = [];
60
+ /** @internal bus name (or 'master') -> the nodes the engine linked in a row, head to tail: relinking cuts exactly these links, never one the game made itself */ this._chains = {};
58
61
  /** @internal */ this._ducks = new Set();
59
62
  /** @internal */ this._voices = new Map(); // name -> live voices (voice limit, info)
60
63
  /** @internal */ this._last = new Map(); // name -> { at, variant } (cooldown, no-repeat)
@@ -70,7 +73,7 @@ export class Audio {
70
73
  /** @internal page.js: the page froze the game, or let it go */
71
74
  _hold(on) { this._held = on; if (this.ctx) (on ? this.ctx.suspend() : this.ctx.resume()).catch(() => {}); }
72
75
  /** @internal Close the audio context (engine.dispose calls it): playing sounds and nodes modules attached stop together */
73
- dispose() { this.ctx?.close(); this.ctx = null; }
76
+ dispose() { this.ctx?.close(); this.ctx = null; this._inserts.length = 0; this._chains = {}; }
74
77
 
75
78
  /** @internal */
76
79
  _init() {
@@ -81,6 +84,8 @@ export class Audio {
81
84
  /** The master GainNode (every bus ends here) @type {any} */
82
85
  this.master = this.buses.master = ctx.createGain(); this.master.gain.value = this.levels.master; this.master.connect(ctx.destination);
83
86
  for (const name of Object.keys(this.levels)) if (name !== 'master') this._makeBus(name);
87
+ for (const e of this._inserts) e.node = e.make(ctx); // asked for before the first click: built now that the buses exist
88
+ for (const bus of new Set(this._inserts.map(e => e.bus))) this._relink(bus);
84
89
  this._applyDucks(0);
85
90
  this._reverb?.build();
86
91
  const len = ctx.sampleRate * 2, buf = ctx.createBuffer(1, len, ctx.sampleRate), d = buf.getChannelData(0);
@@ -90,11 +95,12 @@ export class Audio {
90
95
  const ready = () => { if (ctx.state === 'running' && !this._readySent) { this._readySent = true; this.engine.events.emit('audio:ready'); } };
91
96
  ctx.addEventListener('statechange', ready); ready();
92
97
  }
93
- /** @internal a bus is two gains: its level (what setVolume sets) then its duck (what duck() lowers), so the two never fight */
98
+ /** @internal a bus is two gains: its level (what setVolume sets) then its duck (what duck() lowers), so the two never fight; then the game's inserts, then a tail gain
99
+ * that is the fixed point reverb sends and master are fed from (inserts come and go without the reverb having to be re-linked) */
94
100
  _makeBus(name) {
95
- const ctx = this.ctx, g = ctx.createGain(), d = ctx.createGain();
96
- g.gain.value = this.levels[name]; g.connect(d).connect(this.master);
97
- this.buses[name] = g; this._duckNodes[name] = d;
101
+ const ctx = this.ctx, g = ctx.createGain(), d = ctx.createGain(), tail = ctx.createGain();
102
+ g.gain.value = this.levels[name]; g.connect(d).connect(tail).connect(this.master);
103
+ this.buses[name] = g; this._duckNodes[name] = d; this._tails[name] = tail;
98
104
  this._reverb?.busMade(name);
99
105
  }
100
106
  /** Is audio usable (the player has clicked/pressed a key)? @returns {boolean} @experimental */
@@ -127,13 +133,50 @@ export class Audio {
127
133
  if (handles.get(name) !== h) return;
128
134
  handles.delete(name);
129
135
  delete this.levels[name];
130
- if (this.ctx) { this.buses[name].disconnect(); this._duckNodes[name].disconnect(); } // sounds still playing on this bus are cut with the node (bus gone, no sound should linger)
136
+ for (const e of this._inserts.filter(e => e.bus === name)) this._unwire(e, false);
137
+ this._cut(name);
138
+ if (this.ctx) { this.buses[name].disconnect(); this._duckNodes[name].disconnect(); this._tails[name].disconnect(); } // sounds still playing on this bus are cut with the node (bus gone, no sound should linger)
131
139
  this._reverb?.busGone(name);
132
- delete this.buses[name]; delete this._duckNodes[name];
140
+ delete this.buses[name]; delete this._duckNodes[name]; delete this._tails[name];
133
141
  } };
134
142
  handles.set(name, h);
135
143
  return h;
136
144
  }
145
+ /**
146
+ * Your Web Audio node in a bus's path, after volume and duck, before master and reverb, in call order ('master': before the speakers).
147
+ * `make(ctx)` returns the node; it runs once audio is unlocked; taps you add to it stay
148
+ * @param {string} bus
149
+ * @param {(ctx: AudioContext) => AudioNode} make
150
+ * @returns {{ remove(): void }} remove() takes the node out and links the path back (repeat calls do nothing)
151
+ */
152
+ addNode(bus, make) {
153
+ if (bus !== 'master' && !(bus in this.levels)) this._bus(bus); // throws, listing the buses
154
+ const e = { bus, make, node: null };
155
+ this._inserts.push(e);
156
+ if (this.ctx) { e.node = make(this.ctx); this._relink(bus); }
157
+ return { remove: () => this._unwire(e) };
158
+ }
159
+ /** @internal take one insert out; relink false when its whole bus is going */
160
+ _unwire(e, relink = true) {
161
+ const i = this._inserts.indexOf(e); if (i < 0) return;
162
+ this._inserts.splice(i, 1);
163
+ if (e.node && relink) this._relink(e.bus); // the old chain still names e.node, so relinking cuts its links
164
+ }
165
+ /** @internal undo the links the engine made for a bus's chain (default: the plain head -> tail link that _makeBus / _init made) */
166
+ _cut(bus) {
167
+ const c = this._chains[bus]; delete this._chains[bus];
168
+ if (c) for (let i = 1; i < c.length; i++) c[i - 1].disconnect(c[i]);
169
+ }
170
+ /** @internal link a bus (or master) as head -> its inserts in call order -> tail. Only the engine's own links are cut first (disconnect(next), not disconnect()):
171
+ * master is public, and a game's analyser on it, or a tap it made from its own insert node, must survive another insert coming or going */
172
+ _relink(bus) {
173
+ const master = bus === 'master', head = master ? this.master : this._duckNodes[bus], tail = master ? this.ctx.destination : this._tails[bus];
174
+ this._chains[bus] ??= [head, tail];
175
+ this._cut(bus);
176
+ const chain = [head, ...this._inserts.filter(e => e.bus === bus && e.node).map(e => e.node), tail];
177
+ for (let i = 1; i < chain.length; i++) chain[i - 1].connect(chain[i]);
178
+ this._chains[bus] = chain;
179
+ }
137
180
  /**
138
181
  * Set a bus volume 0-1 ('master' for the total)
139
182
  * @param {string} bus
@@ -325,4 +368,8 @@ export class Audio {
325
368
  play(url, opts = {}) { return playFile(this, url, opts); }
326
369
  }
327
370
 
328
- export const handRolled = [{ kind: 'audio', seen: 'an AudioContext / Audio element of its own', use: 'engine.audio: engine.audio.play(url, { bus, volume }) or named sounds, with buses and volume settings (recipe 31)', code: /\bnew\s+(?:window\.)?(?:AudioContext|webkitAudioContext)\b|\bnew\s+Audio\s*\(/ }];
371
+ export const handRolled = [{ kind: 'audio', docRef: 'recipes/31-audio.md §2', seen: 'an AudioContext / Audio element of its own', use: 'engine.audio: engine.audio.play(url, { bus, volume }) or named sounds, with buses and volume settings', code: /\bnew\s+(?:window\.)?(?:AudioContext|webkitAudioContext)\b|\bnew\s+Audio\s*\(/ },
372
+ // Writing into the live config skips the content pack; taking master apart skips the chain the engine relinks when a node is added or a bus changes
373
+ { kind: 'sounds', docRef: 'recipes/31-audio.md §8', seen: 'a sound written straight into audio.config.sounds', use: "createEngine({ audio: { sounds } }) or a content pack's sounds section: engine.audio reads them once, with voices and distance", code: /\bconfig\??\.sounds\s*(?:\[|=(?!=))|\bObject\.assign\(\s*[\w.?]*config\??\.sounds\b/ },
374
+ { kind: 'audiochain', docRef: 'recipes/31-audio.md §2', seen: 'master taken apart and rewired by hand', use: 'engine.audio.addNode(bus, ctx => node): the engine puts your node in the chain and relinks it when buses change', code: /\bmaster\??\.disconnect\s*\(/ },
375
+ ];
@@ -1,5 +1,5 @@
1
1
  // The one reverb (helper of Audio.js, engine.audio.reverb): a send/return on the bus graph. Each bus that sends taps its own output (after its
2
- // level and duck, so the settings slider and a duck lower the echo with the dry sound) into one ConvolverNode, whose return goes into master
2
+ // level, duck and the game's inserts, so the settings slider and a duck lower the echo with the dry sound) into one ConvolverNode, whose return goes into master
3
3
  // (the master slider covers it). Off until the game calls reverb(); nothing is built before that, and nothing plays through it the game did not send.
4
4
  // Why one convolver with a generated impulse: decaying noise is the classic cheap room (Moorer; Tone.js Reverb does the same), the convolution
5
5
  // runs on the audio thread at a fixed cost however many sounds send, and no impulse file has to ship. One reverb, not one per zone: a place
@@ -77,7 +77,7 @@ export class Reverb {
77
77
  /** One bus's send toward its amount. The node is made once per bus and kept (with its tap, so off() can cut both ends); a bus with no node
78
78
  * yet (added later) is linked when it is made */
79
79
  _send(bus, fade) {
80
- const n = this.nodes, tap = this.audio._duckNodes[bus]; if (!tap) return;
80
+ const n = this.nodes, tap = this.audio._tails[bus]; if (!tap) return;
81
81
  let s = n.sends[bus];
82
82
  if (!s) { const g = this.audio.ctx.createGain(); g.gain.value = 0; tap.connect(g).connect(n.input); s = n.sends[bus] = { g, tap }; }
83
83
  this._to(s.g.gain, this.set.sends[bus], fade);
@@ -59,4 +59,4 @@ export class Random {
59
59
  }
60
60
  }
61
61
 
62
- export const handRolled = [{ kind: 'random', seen: 'Math.random() in game code', use: 'engine.random (seeded: next / range / int / pick / chance; replays, tests and saves get the same numbers)', code: /\bMath\.random\s*\(/, notRaw: /particle|spark|dust|confetti|debris|twinkle|flicker|jitter|smoke|puff|droplet|bubble|petal|glitter|wobble/i, gameplayOnly: true }];
62
+ export const handRolled = [{ kind: 'random', seen: 'Math.random() in game code', use: 'engine.random (seeded: next / range / int / pick / chance; replays, tests and saves get the same numbers)', code: /\bMath\.random\s*\(/, notRaw: /particle|spark|dust|confetti|debris|twinkle|flicker|jitter|smoke|puff|droplet|bubble|petal|glitter|wobble|getChannelData/i, gameplayOnly: true }];
@@ -433,7 +433,7 @@ export const ERROR_CODES = {
433
433
  docs: ['api/settings.md'],
434
434
  fix: 'settings({ sections }) contains a built-in section that does not exist. Use a listed name, or register one with engine.settings.addSection(id, { title, render }).' },
435
435
  'time-owner-conflict': {
436
- docs: ['recipes/06-clock-events.md §"The time table (the single source; other docs link here)"', 'api/calendar.md'],
436
+ docs: ['recipes/06-clock-events.md §"The time table: read the current game time"', 'api/calendar.md'],
437
437
  fix: 'calendar() and sky({ time }) both set the time of day. calendar owns time while it is installed: move the starting time to calendar({ time }) and remove sky({ time }).' },
438
438
  'save-provider-changed': {
439
439
  docs: ['recipes/20-content-actions-save.md §"Save failures and versions"', 'api/saves.md'],
@@ -178,4 +178,6 @@ export function failureText(t) {
178
178
  return `${j.kind} "${j.name}" <- ${s.url ?? j.name}: ${err.message}${where.length ? ` [${where.join(', ')}]` : ''}`;
179
179
  }
180
180
 
181
- export const handRolled = [{ kind: 'loading', seen: 'a loading screen of its own', use: 'engine.loading: tracks what is loading, shows progress and has a view you can replace (recipe 07)', quiet: /\bengine\.loading\b/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, raw: /(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)[^,;{}]*(?:loading|loader|load-?bar|progress-?bar)|(?:loading|loader|load-?bar|progress-?bar)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)/i }];
181
+ export const handRolled = [{ kind: 'loading', docRef: 'recipes/07-flow-scenes-pause.md §1b', seen: 'a loading screen of its own', use: 'engine.loading: tracks what is loading, shows progress and has a view you can replace', quiet: /\bengine\.loading\b/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, raw: /(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)[^,;{}]*(?:loading|loader|load-?bar|progress-?bar)|(?:loading|loader|load-?bar|progress-?bar)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)/i },
182
+ // A 'the picture is finished' flag of the game's own is a second readiness that start(), the loading screen and shot cannot see
183
+ { kind: 'ready', docRef: 'recipes/14-custom-module.md §1', seen: 'a ready / flush flag of your own (read from the URL or hung on window)', use: 'a module isReady(e) and engine.loading.track(name, promise): start() and shot wait for them, no flag to set', quiet: /\bisReady\b|\bloading\.track\b/, raw: /URLSearchParams\([^)]*\)\s*\.get\(\s*['"][^'"]*(?:flush|ready|settle|finish)[^'"]*['"]|\(?window\)?\.\w+\s*=\s*\{[^}]*\b(?:finish|flush|ready|settle)\w*\b/i }];
@@ -6,7 +6,7 @@
6
6
  // A hot reload re-runs the same file (same path, a ?t= query): that is one copy, not two, so the path without the query decides.
7
7
  import { coded } from '../base/errorHints.js';
8
8
 
9
- export const VERSION = '2.1.0'; // kept equal to package.json by the "[guard] engine copies" spec
9
+ export const VERSION = '2.2.2'; // kept equal to package.json by the "[guard] engine copies" spec
10
10
 
11
11
  const KEY = Symbol.for('threedog.engine.copies');
12
12
 
@@ -329,6 +329,7 @@ export const loopMethods = {
329
329
  `engine.step(${String(seconds)}): seconds must be a finite number >= 0, e.g. engine.step(0.5) (real seconds; 1 / 60 is one fixed step)`);
330
330
  if (seconds === 0) return describe ? this.describe() : null; // 0 advances nothing (a tiny positive value still runs one fixed step)
331
331
  if (DEV && (this._inStart || this.session._busy)) warnOnce(coded('step-during-load', this._inStart ? STRINGS.stepStart : STRINGS.stepSession), 'step-during-load');
332
+ this._followBox(); // a viewport change while frozen / stepped: canvas, camera and UI root follow before this step reads them
332
333
  const n = Math.max(1, Math.round(seconds / STEP));
333
334
  this.stepBlend = 1; // step() takes the state to the end of each step, so the latest state is what cameras read and what gets drawn
334
335
  let since = 0;
@@ -324,7 +324,7 @@ export class Input {
324
324
  }
325
325
  /**
326
326
  * Why a game action cannot be read right now, for a driver about to press it or that pressed it and saw nothing happen; [] when it is readable. Every cause,
327
- * top down: an opaque input context above the action's own ('win-settings', 'dialogue'...), 'shadowed-by:<context>' (a pass-through context above binds
327
+ * top down: an opaque input context above the action's own ('ui-settings', 'dialogue'...), 'shadowed-by:<context>' (a pass-through context above binds
328
328
  * the same key), or 'context-off:<context>' alone (its own context is not on the stack); then the owners of the action's gate. Pushes and removes
329
329
  * count at once, as in holders. A real key is blocked the same way, so this is the game's rule, not the driver's.
330
330
  * Without an action: every opaque context, which is runState.blockedBy's input part (one list, so the two never disagree)
@@ -377,6 +377,6 @@ export class Input {
377
377
  }
378
378
 
379
379
  export const handRolled = [
380
- { kind: 'keys', seen: 'a raw keydown / keyup listener', use: "engine.input.define('jump', { label, keys }) in a module, the game binds keys with engine.input.bind (rebinding, contexts, gamepad); read engine.input.pressed(name) (recipe 58)", raw: /(?:^|[^\w.])(?:(?:window|document|self|globalThis|canvas|document\.body|[\w.]*domElement)\.)?(?:addEventListener\s*\(\s*['"]|on)key(?:down|up)\b/, yields: { kind: 'pause', raw: /['"]Escape['"]/ } },
381
- { kind: 'lock', seen: 'an input lock of its own', use: "engine.input.push('ride', { owner }) takes the keys and h.remove() gives them back: no key sticks, and describe().holds.input shows who holds them (recipe 07 §2b)", quiet: /\b(engine|e|eng|ctx)\.input\.(push|gate)\b|\blockInput\b/, code: /\b(?:let|var)\s+(?:input|controls?|keys)(?:Locked|Disabled|Enabled|Frozen)\s*=/i, tags: false },
380
+ { kind: 'keys', docRef: 'recipes/58-input.md §1', seen: 'a raw keydown / keyup listener', use: "engine.input.define('jump', { label, keys }) in a module, the game binds keys with engine.input.bind (rebinding, contexts, gamepad); read engine.input.pressed(name); a menu that must read keys while the world is frozen reads engine.input.pressedRaw(name) in a frame hook, or toggleOnKey(engine, win, action) for a window", notRaw: /\bcode\s*===?\s*['"]F\d+['"]/, raw: /(?:^|[^\w.])(?:(?:window|document|self|globalThis|canvas|document\.body|[\w.]*domElement)\.)?(?:addEventListener\s*\(\s*['"]|on)key(?:down|up)\b/, yields: { kind: 'pause', raw: /['"]Escape['"]/ } },
381
+ { kind: 'lock', docRef: 'recipes/07-flow-scenes-pause.md §2b', seen: 'an input lock of its own', use: "engine.input.push('ride', { owner }) takes the keys and h.remove() gives them back: no key sticks, and describe().holds.input shows who holds them", quiet: /\b(engine|e|eng|ctx)\.input\.(push|gate)\b|\blockInput\b/, code: /\b(?:let|var)\s+(?:input|controls?|keys)(?:Locked|Disabled|Enabled|Frozen)\s*=/i, tags: false },
382
382
  ];
@@ -68,7 +68,7 @@ export function inspectPerf(e, { top = 5 } = {}) {
68
68
  const unit = { textureMB: ' MB', cpuMs: ' ms', compileMs: ' ms (worst stall)', lights: ' point + spot' };
69
69
  const text = [
70
70
  measured ? `frame: ${values.drawCalls} draw calls (incl. shadow + post passes), ${fmtN(values.triangles)} triangles, ${values.programs == null ? 'programs not counted (WebGPU)' : values.programs + ' programs'}, ~${mb(texBytes)} textures `
71
- + `(${mats.textures}), ${e.halted ? 'JS ms and fps not measured (the loop is halted, only real-time running times them)' : `JS ${values.cpuMs ?? '-'} ms (median of ${fm?.n ?? 0} frames; last frame fixed ${r1(p.fixed ?? 0)} / frame ${r1(p.frame ?? 0)} / render ${r1(p.render ?? 0)}), fps ${Math.round(e.fps ?? 0)}`}`
71
+ + `(${mats.textures}), ${e.halted ? 'JS ms and fps not measured (the loop is halted, only real-time running times them; the draw counts are those of the last frame drawn, engine.step(1 / 60) draws a new one)' : `JS ${values.cpuMs ?? '-'} ms (median of ${fm?.n ?? 0} frames; last frame fixed ${r1(p.fixed ?? 0)} / frame ${r1(p.frame ?? 0)} / render ${r1(p.render ?? 0)}), fps ${Math.round(e.fps ?? 0)}`}`
72
72
  : `nothing measured yet: no draw has been counted, so draw calls, triangles, JS ms and compile stalls have no value. Draw a frame first (engine.step(1 / 60), or threedog step 1 / snap --play), then ask again. ~${mb(texBytes)} textures (${mats.textures})`,
73
73
  firstFrameLine(e.startup),
74
74
  values.gpuMemoryMB == null ? '' : `GPU memory ~${values.gpuMemoryMB} MB (${GPU_MEMORY})`,
@@ -10,7 +10,7 @@ const STRINGS = {
10
10
  actions: 'Can do (engine.ops): {list}',
11
11
  error: '[Error, gameplay frozen] {where}: {message}', errorAt: ' ({at})',
12
12
  errorHint: ' | Code: {code} | Fix: {fix} Read: {docs}', disabled: 'Disabled picture / ui modules (they threw): {list}', blockedModules: 'Blocked modules: {list}',
13
- halted: ', halted', headless: ', headless', notReady: ', still loading',
13
+ halted: ', halted', frozenBy: ', frozen by {who}', headless: ', headless', notReady: ', still loading',
14
14
  waiting: 'Loading: {waiting} ({pending} pending, {done}/{total} done)', loadFailed: 'Load failed{blocked}: {list}', blocked: ' (start blocked)',
15
15
  loadWarn: 'Loaded with missing references: {list}',
16
16
  audio: 'Audio: {list}',
@@ -94,7 +94,8 @@ function atPath(d, path) {
94
94
  export function describeText(d, { full = false, path, maxLines = 30, game = [] } = {}) {
95
95
  if (path) return atPath(d, path);
96
96
  const L = [], t = d.time;
97
- const flags = (t.halted ? STRINGS.halted : '') + (t.headless ? STRINGS.headless : '') + (d.loading.done ? '' : STRINGS.notReady);
97
+ // frozenBy comes from the describe object (not engine.runState): the freeze owners only; who halted the page is not listed, the bridge halts it always
98
+ const flags = (t.halted ? STRINGS.halted : '') + (t.frozenBy?.length ? fmt(STRINGS.frozenBy, { who: t.frozenBy.join(', ') }) : '') + (t.headless ? STRINGS.headless : '') + (d.loading.done ? '' : STRINGS.notReady);
98
99
  if (d.error) L.push(fmt(STRINGS.error, d.error) + (d.error.at ? fmt(STRINGS.errorAt, d.error) : '')
99
100
  + (d.error.fix ? fmt(STRINGS.errorHint, { code: d.error.code, fix: d.error.fix, docs: d.error.docs.join(', ') }) : ''));
100
101
  L.push(fmt(STRINGS.head, { s: t.real, flags }));
@@ -2024,8 +2024,7 @@ export const metadata = {
2024
2024
  "save",
2025
2025
  "values",
2026
2026
  "presets",
2027
- "sections",
2028
- "isOpen"
2027
+ "sections"
2029
2028
  ],
2030
2029
  "sections": [],
2031
2030
  "saves": [],
@@ -3997,31 +3996,52 @@ export const metadata = {
3997
3996
  "hints": {
3998
3997
  "animation": {
3999
3998
  "kind": "animation",
3999
+ "docRef": "recipes/13-animation.md §5",
4000
4000
  "seen": "an AnimationMixer of its own",
4001
- "use": "engine.assets.animate(model, { states }): states, crossfades, sync with game time and pause (recipe 13)",
4001
+ "use": "engine.assets.animate(model, { states }): states, crossfades, sync with game time and pause",
4002
4002
  "quiet": "/\\bassets\\.animate\\b/",
4003
4003
  "code": "/\\bnew\\s+(?:THREE\\.)?AnimationMixer\\s*\\(|\\bmixer\\.update\\s*\\(/i",
4004
4004
  "file": "packages/engine/core/assets/Animator.js"
4005
4005
  },
4006
4006
  "audio": {
4007
4007
  "kind": "audio",
4008
+ "docRef": "recipes/31-audio.md §2",
4008
4009
  "seen": "an AudioContext / Audio element of its own",
4009
- "use": "engine.audio: engine.audio.play(url, { bus, volume }) or named sounds, with buses and volume settings (recipe 31)",
4010
+ "use": "engine.audio: engine.audio.play(url, { bus, volume }) or named sounds, with buses and volume settings",
4010
4011
  "code": "/\\bnew\\s+(?:window\\.)?(?:AudioContext|webkitAudioContext)\\b|\\bnew\\s+Audio\\s*\\(/",
4011
4012
  "file": "packages/engine/core/audio/Audio.js"
4012
4013
  },
4014
+ "audiochain": {
4015
+ "kind": "audiochain",
4016
+ "docRef": "recipes/31-audio.md §2",
4017
+ "seen": "master taken apart and rewired by hand",
4018
+ "use": "engine.audio.addNode(bus, ctx => node): the engine puts your node in the chain and relinks it when buses change",
4019
+ "code": "/\\bmaster\\??\\.disconnect\\s*\\(/",
4020
+ "file": "packages/engine/core/audio/Audio.js"
4021
+ },
4022
+ "bump": {
4023
+ "kind": "bump",
4024
+ "docRef": "recipes/56-webgpu-tsl.md §\"The engine\"",
4025
+ "seen": "a bumpMap() call (it does nothing for a height computed in the shader)",
4026
+ "use": "detailBump(positionView, normal, height, strength, faceDirection) from 'threedog/tsl' turns a procedural height node into a bumped normal; bumpMap stays right for a real texture",
4027
+ "quiet": "/\\bdetailBump\\b/",
4028
+ "code": "/\\bbumpMap\\s*\\(/",
4029
+ "file": "packages/engine/render/fx/detail.tsl.js"
4030
+ },
4013
4031
  "collision": {
4014
4032
  "kind": "collision",
4015
4033
  "seen": "a hand-written box overlap",
4016
4034
  "use": "engine.collision.addBox / addCircle for walls and props (movement, rays and physics read them); engine.collision.walkable to ask",
4017
4035
  "quiet": "/\\b(engine|e|eng|ctx)\\.collision\\b/",
4018
- "code": "/Math\\.abs\\([^)]*\\)\\s*<=?[^&|;]*&&\\s*Math\\.abs\\([^)]*\\)\\s*<=?|[<>]=?\\s*[\\w.]*\\bmin[XYZ]?\\b[^;]*&&[^;]*[<>]=?\\s*[\\w.]*\\bmax[XYZ]?\\b/i",
4036
+ "notRaw": "/Math\\.abs\\([^)]*\\)\\s*<=?\\s*\\.?\\d/",
4037
+ "code": "/Math\\.abs\\([^)]*\\w\\s*-\\s*[\\w.(][^)]*\\)\\s*<=?[^&|;]*&&\\s*Math\\.abs\\([^)]*\\w\\s*-\\s*[\\w.(][^)]*\\)\\s*<=?|[<>]=?\\s*[\\w.]*\\bmin[XYZ]?\\b[^;]*&&[^;]*[<>]=?\\s*[\\w.]*\\bmax[XYZ]?\\b/i",
4019
4038
  "file": "packages/engine/modules/collision/Collision.js"
4020
4039
  },
4021
4040
  "dialogue": {
4022
4041
  "kind": "dialogue",
4042
+ "docRef": "recipes/02-npc.md",
4023
4043
  "seen": "a dialogue box of its own",
4024
- "use": "engine.dialogue.define(speaker, nodes) and the dialogue part: typing on game time, choices, input lock (recipe 02, recipe 26)",
4044
+ "use": "engine.dialogue.define(speaker, nodes) and the dialogue part: typing on game time, choices, input lock",
4025
4045
  "quiet": "/\\b(engine|e|eng|ctx)\\.dialogue\\b|\\bdialogue\\(\\s*[{)]/",
4026
4046
  "code": "/\\b(createElement|innerHTML|className|classList|getElementById|querySelector|\\.id)\\b/",
4027
4047
  "raw": "/(?:createElement|innerHTML|className|classList|getElementById|querySelector|\\.id\\b)[^,;{}]*(?:dialog(?:ue)?|speech|subtitle|textbox|conversation)|(?:dialog(?:ue)?|speech|subtitle|textbox|conversation)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\\.id\\b)/i",
@@ -4029,8 +4049,9 @@ export const metadata = {
4029
4049
  },
4030
4050
  "follow": {
4031
4051
  "kind": "follow",
4052
+ "docRef": "recipes/21-camera.md",
4032
4053
  "seen": "a camera follow of its own",
4033
- "use": "followCamera() or openWorld({ camera }): collision, smoothing and switching are handled; a shot of your own: engine.takeCamera(owner) (recipe 21)",
4054
+ "use": "followCamera() or openWorld({ camera }): collision, smoothing and switching are handled; a shot of your own: engine.takeCamera(owner)",
4034
4055
  "quiet": "/\\b(?:follow|firstPerson|fixed|rts)Camera\\(|\\bopenWorld\\(|\\b(engine|e|eng|ctx)\\.(takeCamera|cameraRig|setCamera)\\b/",
4035
4056
  "code": "/\\bcamera\\.position\\.(?:lerp|copy|set)\\s*\\(/",
4036
4057
  "raw": "/player|hero|target|character|avatar/i",
@@ -4069,8 +4090,8 @@ export const metadata = {
4069
4090
  "code": "/\\b(?:inventory|backpack|bag|pockets|inv)(?:Items|Slots|List|Contents|Data|Map|Counts?|s)?\\s*(?:[=:]\\s*\\(?\\s*(?:\\[\\s*\\]|\\{\\s*\\}|new Map\\b|new Set\\b)|\\.(?:push|splice|unshift|reduce)\\()/i",
4070
4091
  "near": [
4071
4092
  {
4072
- "re": "/[<>]=?\\s*(?:[\\w$]+\\.)*(?:capacity|cap|max\\w*|slots?|limit)\\w*\\b(?!\\s*\\()/i",
4073
- "lines": 3,
4093
+ "re": "/[<>]=?\\s*(?:[\\w$]+\\.)*[\\w$]*(?:capacity|cap|max|slots?|limit)\\w*\\b(?!\\s*\\()|\\b(?:sell|price|gold|coins?|shop)\\w*/i",
4094
+ "lines": 6,
4074
4095
  "on": "code"
4075
4096
  }
4076
4097
  ],
@@ -4079,8 +4100,10 @@ export const metadata = {
4079
4100
  },
4080
4101
  "keys": {
4081
4102
  "kind": "keys",
4103
+ "docRef": "recipes/58-input.md §1",
4082
4104
  "seen": "a raw keydown / keyup listener",
4083
- "use": "engine.input.define('jump', { label, keys }) in a module, the game binds keys with engine.input.bind (rebinding, contexts, gamepad); read engine.input.pressed(name) (recipe 58)",
4105
+ "use": "engine.input.define('jump', { label, keys }) in a module, the game binds keys with engine.input.bind (rebinding, contexts, gamepad); read engine.input.pressed(name); a menu that must read keys while the world is frozen reads engine.input.pressedRaw(name) in a frame hook, or toggleOnKey(engine, win, action) for a window",
4106
+ "notRaw": "/\\bcode\\s*===?\\s*['\"]F\\d+['\"]/",
4084
4107
  "raw": "/(?:^|[^\\w.])(?:(?:window|document|self|globalThis|canvas|document\\.body|[\\w.]*domElement)\\.)?(?:addEventListener\\s*\\(\\s*['\"]|on)key(?:down|up)\\b/",
4085
4108
  "yields": {
4086
4109
  "kind": "pause",
@@ -4105,8 +4128,9 @@ export const metadata = {
4105
4128
  },
4106
4129
  "loading": {
4107
4130
  "kind": "loading",
4131
+ "docRef": "recipes/07-flow-scenes-pause.md §1b",
4108
4132
  "seen": "a loading screen of its own",
4109
- "use": "engine.loading: tracks what is loading, shows progress and has a view you can replace (recipe 07)",
4133
+ "use": "engine.loading: tracks what is loading, shows progress and has a view you can replace",
4110
4134
  "quiet": "/\\bengine\\.loading\\b/",
4111
4135
  "code": "/\\b(createElement|innerHTML|className|classList|getElementById|querySelector|\\.id)\\b/",
4112
4136
  "raw": "/(?:createElement|innerHTML|className|classList|getElementById|querySelector|\\.id\\b)[^,;{}]*(?:loading|loader|load-?bar|progress-?bar)|(?:loading|loader|load-?bar|progress-?bar)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\\.id\\b)/i",
@@ -4114,8 +4138,9 @@ export const metadata = {
4114
4138
  },
4115
4139
  "lock": {
4116
4140
  "kind": "lock",
4141
+ "docRef": "recipes/07-flow-scenes-pause.md §2b",
4117
4142
  "seen": "an input lock of its own",
4118
- "use": "engine.input.push('ride', { owner }) takes the keys and h.remove() gives them back: no key sticks, and describe().holds.input shows who holds them (recipe 07 §2b)",
4143
+ "use": "engine.input.push('ride', { owner }) takes the keys and h.remove() gives them back: no key sticks, and describe().holds.input shows who holds them",
4119
4144
  "quiet": "/\\b(engine|e|eng|ctx)\\.input\\.(push|gate)\\b|\\blockInput\\b/",
4120
4145
  "code": "/\\b(?:let|var)\\s+(?:input|controls?|keys)(?:Locked|Disabled|Enabled|Frozen)\\s*=/i",
4121
4146
  "tags": false,
@@ -4130,8 +4155,9 @@ export const metadata = {
4130
4155
  },
4131
4156
  "particles": {
4132
4157
  "kind": "particles",
4158
+ "docRef": "recipes/64-particles.md",
4133
4159
  "seen": "a particle loop of its own",
4134
- "use": "engine.particles: emitters on game time, one draw call, budgets (recipe 64)",
4160
+ "use": "engine.particles: emitters on game time, one draw call, budgets",
4135
4161
  "quiet": "/\\b(engine|e|eng|ctx)\\.particles\\b|\\bparticles\\(\\s*[{)]/",
4136
4162
  "code": "/\\bfor\\s*\\([^)]*\\bof\\s+[\\w.]*(?:particles|sparks|embers)\\b|\\b(?:particles|sparks|embers)\\.(?:forEach|filter)\\s*\\(/i",
4137
4163
  "near": [
@@ -4144,8 +4170,9 @@ export const metadata = {
4144
4170
  },
4145
4171
  "pause": {
4146
4172
  "kind": "pause",
4173
+ "docRef": "recipes/07-flow-scenes-pause.md §1",
4147
4174
  "seen": "a pause or Esc handler of its own",
4148
- "use": "settings({ freezeWorld: true }): Esc stops every system and opens the menu (recipe 63); engine.freeze(why) for a pause with no menu",
4175
+ "use": "settings({ freezeWorld: true }): Esc stops every system and opens the menu; engine.freeze(why) for a pause with no menu",
4149
4176
  "quiet": "/\\bsettings\\(|\\bengine\\.(freeze|flow|settings)\\b|\\buiFocus\\(/",
4150
4177
  "code": "/\\b(?:let|var)\\s+(?:is|game)?paused\\s*=/i",
4151
4178
  "orRaw": "/(?:\\.key|\\.code)\\s*===?\\s*['\"]Escape['\"]/",
@@ -4154,32 +4181,36 @@ export const metadata = {
4154
4181
  },
4155
4182
  "physics": {
4156
4183
  "kind": "physics",
4184
+ "docRef": "recipes/11-physics.md §3",
4157
4185
  "seen": "a physics library of its own",
4158
- "use": "rigid(): bodies, joints and vehicles on the engine step, shared with collision and saves (recipe 11)",
4186
+ "use": "rigid(): bodies, joints and vehicles on the engine step, shared with collision and saves",
4159
4187
  "quiet": "/\\b(engine|e|eng|ctx)\\.rigid\\b|\\brigid\\(\\s*[{)]/",
4160
4188
  "raw": "/\\bfrom\\s+['\"](?:cannon-es|cannon|ammo\\.js|@dimforge\\/rapier3d(?:-compat)?|oimo|matter-js)['\"]/",
4161
4189
  "file": "packages/engine/modules/rigid/RigidBodies.js"
4162
4190
  },
4163
4191
  "picking": {
4164
4192
  "kind": "picking",
4193
+ "docRef": "recipes/19-shooting-picking.md",
4165
4194
  "seen": "a pointer-to-object raycast of its own",
4166
- "use": "engine.pick(x, y), or engine.raycast / engine.rays: colliders and moving things are in the same query (recipe 19)",
4195
+ "use": "engine.pick(x, y), or engine.raycast / engine.rays: colliders and moving things are in the same query",
4167
4196
  "quiet": "/\\b(engine|e|eng|ctx)\\.(rays|raycast|pick)\\b/",
4168
4197
  "code": "/\\.setFromCamera\\s*\\(/",
4169
4198
  "file": "packages/engine/core/scene/Rays.js"
4170
4199
  },
4171
4200
  "pool": {
4172
4201
  "kind": "pool",
4202
+ "docRef": "recipes/65-swarm.md",
4173
4203
  "seen": "a pool or list of many shots of its own",
4174
- "use": "engine.swarm: thousands of shots, crowds and debris in one draw, with reuse and hits (recipe 65)",
4204
+ "use": "engine.swarm: thousands of shots, crowds and debris in one draw, with reuse and hits",
4175
4205
  "quiet": "/\\b(engine|e|eng|ctx)\\.swarm\\b|\\bswarm\\(\\s*[{)]/",
4176
4206
  "code": "/(?:\\b(?:const|let|var)\\s+|\\bthis\\.)(?:pool|\\w*(?:bullet|projectile|shot|enemy|particle|mesh|object)pool|bullets|projectiles)\\s*=\\s*(?:\\[\\s*\\]|new Map\\b|new Set\\b)/i",
4177
4207
  "file": "packages/engine/modules/swarm/Swarm.js"
4178
4208
  },
4179
4209
  "quests": {
4180
4210
  "kind": "quests",
4211
+ "docRef": "recipes/04-quests.md §1",
4181
4212
  "seen": "a quest list of its own",
4182
- "use": "engine.quests (quests()): steps, rewards, markers and the log, saved with the game (recipe 04)",
4213
+ "use": "engine.quests (quests()): steps, rewards, markers and the log, saved with the game",
4183
4214
  "quiet": "/\\b(engine|e|eng|ctx)\\.quests\\b|\\bquests\\(\\s*[{)]/",
4184
4215
  "code": "/(?:\\b(?:const|let|var)\\s+|\\bthis\\.)(?:quests?|questLog|missions?|objectives?)(?:List|Log|Data|s)?\\s*=\\s*(?:\\[\\s*\\]|\\{\\s*\\}|new Map\\b)/i",
4185
4216
  "file": "packages/engine/modules/gameplay/Quests.js"
@@ -4189,29 +4220,40 @@ export const metadata = {
4189
4220
  "seen": "Math.random() in game code",
4190
4221
  "use": "engine.random (seeded: next / range / int / pick / chance; replays, tests and saves get the same numbers)",
4191
4222
  "code": "/\\bMath\\.random\\s*\\(/",
4192
- "notRaw": "/particle|spark|dust|confetti|debris|twinkle|flicker|jitter|smoke|puff|droplet|bubble|petal|glitter|wobble/i",
4223
+ "notRaw": "/particle|spark|dust|confetti|debris|twinkle|flicker|jitter|smoke|puff|droplet|bubble|petal|glitter|wobble|getChannelData/i",
4193
4224
  "gameplayOnly": true,
4194
4225
  "file": "packages/engine/core/base/Random.js"
4195
4226
  },
4196
4227
  "reach": {
4197
4228
  "kind": "reach",
4229
+ "docRef": "recipes/03-items-pickups.md",
4198
4230
  "seen": "a hand-made reach check for interacting",
4199
- "use": "engine.interactions.add(target, { ... }): prompt, range and the interact action are handled (recipe 20)",
4231
+ "use": "engine.interactions.add(target, { ... }): prompt, range and the interact action are handled",
4200
4232
  "quiet": "/\\b(engine|e|eng|ctx)\\.interactions\\b/",
4201
4233
  "code": "/(?:\\bdistanceTo(?:Squared)?\\(|\\bMath\\.hypot\\(|\\bdist(?:ance)?\\w*)[^;]*<=?\\s*[\\w.]/",
4202
4234
  "near": [
4203
4235
  {
4204
4236
  "re": "/KeyE|['\"]e['\"]|press e\\b|\\.hud\\.hint\\(/i",
4205
- "lines": 3,
4237
+ "lines": 6,
4206
4238
  "on": "raw"
4207
4239
  }
4208
4240
  ],
4209
4241
  "file": "packages/engine/modules/gameplay/Interactions.js"
4210
4242
  },
4243
+ "ready": {
4244
+ "kind": "ready",
4245
+ "docRef": "recipes/14-custom-module.md §1",
4246
+ "seen": "a ready / flush flag of your own (read from the URL or hung on window)",
4247
+ "use": "a module isReady(e) and engine.loading.track(name, promise): start() and shot wait for them, no flag to set",
4248
+ "quiet": "/\\bisReady\\b|\\bloading\\.track\\b/",
4249
+ "raw": "/URLSearchParams\\([^)]*\\)\\s*\\.get\\(\\s*['\"][^'\"]*(?:flush|ready|settle|finish)[^'\"]*['\"]|\\(?window\\)?\\.\\w+\\s*=\\s*\\{[^}]*\\b(?:finish|flush|ready|settle)\\w*\\b/i",
4250
+ "file": "packages/engine/core/engine/Loading.js"
4251
+ },
4211
4252
  "save": {
4212
4253
  "kind": "save",
4254
+ "docRef": "recipes/20-content-actions-save.md §4",
4213
4255
  "seen": "a save of its own in localStorage",
4214
- "use": "engine.saves: autosave(minutes), define('game', { version: 1, save, load }), and Continue on the start screen (recipe 63); versions, slots and a corrupt save are handled",
4256
+ "use": "engine.saves: autosave(minutes), define('game', { version: 1, save, load }), and Continue on the start screen; versions, slots and a corrupt save are handled",
4215
4257
  "quiet": "/\\bengine\\.saves\\b/",
4216
4258
  "code": "/\\blocalStorage\\.setItem\\s*\\(/",
4217
4259
  "notRaw": "/setItem\\s*\\(\\s*(?![^,)]*(?:save|progress))[^,)]*(?:volume|mute|lang|locale|theme|music|sfx|quality|sensitiv|brightness|fullscreen|tutorial|dismiss|setting|pref|option|keybind)/i",
@@ -4219,13 +4261,22 @@ export const metadata = {
4219
4261
  },
4220
4262
  "settings": {
4221
4263
  "kind": "settings",
4264
+ "docRef": "recipes/26-ui-parts.md §6",
4222
4265
  "seen": "a settings menu of its own",
4223
- "use": "engine.settings (settings()): volume, keys, quality and language in one menu that remembers itself; engine.settings.define adds your own (recipe 26)",
4266
+ "use": "engine.settings (settings()): volume, keys, quality and language in one menu that remembers itself; engine.settings.define adds your own",
4224
4267
  "quiet": "/\\bsettings\\(|\\bengine\\.settings\\b/",
4225
4268
  "code": "/\\b(createElement|innerHTML|className|classList|getElementById|querySelector|\\.id)\\b/",
4226
4269
  "raw": "/(?:createElement|innerHTML|className|classList|getElementById|querySelector|\\.id\\b)[^,;{}]*(?:settings|options-?(?:menu|panel|screen)|pause-?menu)|(?:settings|options|pause)-?(?:menu|panel|screen)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\\.id\\b)/i",
4227
4270
  "file": "packages/engine/modules/settings/Settings.js"
4228
4271
  },
4272
+ "sounds": {
4273
+ "kind": "sounds",
4274
+ "docRef": "recipes/31-audio.md §8",
4275
+ "seen": "a sound written straight into audio.config.sounds",
4276
+ "use": "createEngine({ audio: { sounds } }) or a content pack's sounds section: engine.audio reads them once, with voices and distance",
4277
+ "code": "/\\bconfig\\??\\.sounds\\s*(?:\\[|=(?!=))|\\bObject\\.assign\\(\\s*[\\w.?]*config\\??\\.sounds\\b/",
4278
+ "file": "packages/engine/core/audio/Audio.js"
4279
+ },
4229
4280
  "timers": {
4230
4281
  "kind": "timers",
4231
4282
  "seen": "setInterval / setTimeout used for game timing",
@@ -4236,8 +4287,9 @@ export const metadata = {
4236
4287
  },
4237
4288
  "tween": {
4238
4289
  "kind": "tween",
4290
+ "docRef": "recipes/13-animation.md §5",
4239
4291
  "seen": "a tween of its own",
4240
- "use": "await engine.timeline.tween(target, to, { duration, ease }): on game time, stops with pause (recipe 07)",
4292
+ "use": "await engine.timeline.tween(target, to, { duration, ease }): on game time, stops with pause",
4241
4293
  "quiet": "/\\b(engine|e|eng|ctx)\\.timeline\\b/",
4242
4294
  "code": "/\\b(?:elapsed|time|timer|age|t)\\s*\\/\\s*(?:\\w+\\.)?(?:dur|duration)\\b/i",
4243
4295
  "orRaw": "/\\bfrom\\s+['\"](?:gsap|@tweenjs\\/tween\\.js|tween\\.js|animejs)['\"]/",
package/core/ops/holds.js CHANGED
@@ -102,7 +102,7 @@ export const holdMethods = {
102
102
  * state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'halted' (the loop is stopped: a test, the bridge, a headless page)
103
103
  * | 'frozen' (gameplay stopped by the owners in `owners`: a menu, the page, an error) | 'running';
104
104
  * owners: every halt and freeze owner, so closing one part's menu can be told from a player's;
105
- * blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
105
+ * blockedBy: what keeps the player's input from driving the game: each opaque input context ('ui-settings', 'ui-title', 'dialogue', 'cutscene'...),
106
106
  * 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
107
107
  * @returns {{ state: 'loading' | 'title-frozen' | 'halted' | 'frozen' | 'running', owners: string[], blockedBy: string[] }}
108
108
  */
@@ -137,6 +137,7 @@ export class Stack {
137
137
  } else value = o.value ?? (this.kind === 'top' ? null : true); // any / one: optional data beside the hold; top: the holder's value
138
138
  if (layer === 'settings') this._restricts(op, value, `engine.mod('${at}', { owner: '${owner}', layer: 'settings', ${op}: ${JSON.stringify(value)} })`);
139
139
  if (this.per === true && o.id == null) throw fail(`engine.mod('${this.name}'): this point is per record, pass { id }, e.g. { owner: '${owner}', id: 'slime_3', ... }`);
140
+ if (!this.per && o.id != null) throw fail(`engine.mod('${at}'): '${this.name}' is not per record, so { id } would be kept but never read; define it as { per: 'optional' } to hold one value per id, or drop the id`);
140
141
  const clock = o.clock ?? 'real';
141
142
  if (o.for != null && !(o.for >= 0 && Number.isFinite(o.for))) throw fail(`engine.mod('${at}', { for }): for is seconds >= 0 on clock '${clock}', got ${JSON.stringify(o.for)}`);
142
143
  return { owner, layer, op, value, clock, at };
@@ -150,7 +151,11 @@ export class Stack {
150
151
  _fromSave(list, layerOf) {
151
152
  if (!Array.isArray(list)) throw fail(`'${this.name}': a list of entries, got ${shown(list)}`);
152
153
  const seen = new Map(); // id -> owner -> entry: the list's own conflict check
153
- return list.map(e => {
154
+ // An old save may hold an id on a point that is not per record: engine.mod accepted it, but value() never read it, so dropping it changes no value.
155
+ // Dropped here (not rejected in _entry) so one such entry does not refuse the whole list.
156
+ const stale = !this.per && list.some(e => e && typeof e === 'object' && e.id != null);
157
+ if (stale) warnOnce(`'${this.name}': a saved entry carried an id although the point is not per record; it never changed the value and was dropped. Define the point as { per: 'optional' } if the id matters.`);
158
+ return (stale ? list.filter(e => !(e && typeof e === 'object' && e.id != null)) : list).map(e => {
154
159
  if (!e || typeof e !== 'object') throw fail(`'${this.name}': an entry is an object, got ${shown(e)}`);
155
160
  const op = e.op, left = e.left == null ? undefined : Math.max(0, e.left); // a timer already due loads as due
156
161
  const o = { owner: e.owner, id: e.id ?? undefined, layer: layerOf(e.layer), clock: e.clock ?? 'real', for: left, ...(NUM_OPS.includes(op) ? { [op]: e.value } : {}) };