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
@@ -8,7 +8,7 @@ import { keyed } from '../../core/input/inputPad.js'; // "E · Talk", the same
8
8
  /** @import { Engine } from '../../types/core' */
9
9
 
10
10
  export const CSS = `
11
- .threedog-hud{position:fixed;inset:0;pointer-events:none;z-index:12;font:13px/1.4 var(--threedog-font);color:var(--threedog-hud-fg)}
11
+ .threedog-hud{position:fixed;inset:0;pointer-events:none;z-index:var(--threedog-z-hud);font:13px/1.4 var(--threedog-font);color:var(--threedog-hud-fg)}
12
12
  .threedog-hud-stats{position:absolute;display:flex;flex-direction:column;gap:6px;--hx:calc(12px + env(safe-area-inset-left,0px));--hy:calc(12px + env(safe-area-inset-top,0px))}
13
13
  .threedog-hud-top-left,.threedog-hud-left,.threedog-hud-bottom-left{left:var(--hx)}
14
14
  .threedog-hud-top-right,.threedog-hud-right,.threedog-hud-bottom-right{right:calc(12px + env(safe-area-inset-right,0px));align-items:flex-end}
@@ -9,6 +9,8 @@
9
9
  // engine.music.intensity = 0.8 // stems fade in as it rises through their `at` range (0-1)
10
10
  // engine.music.stinger('win') // a short piece over the music; the music dips under it
11
11
  // engine.music.stop({ fade: 3 }) // fade out over 3 s
12
+ // A track may be made by the game's own nodes instead of a file: { generate({ ctx, output, start, end }) { ...; return { stop(at) {} }; } } (recipes/31 §4a);
13
+ // it goes through the same play / rules / fade / duck / stinger as a file track.
12
14
  //
13
15
  // Rules (checked about once a second; the highest-priority match wins; a new result must hold `hold` seconds before switching):
14
16
  // engine.music.rules([
@@ -44,7 +46,7 @@ export class Music {
44
46
  /** @internal */ this.engine = engine;
45
47
  const st = readParams('createEngine({ audio: { music } })', MUSIC_PARAMS, engine.audio.config.music); // core keeps this table for music() and does not read it, so its spelling is checked here
46
48
  /** @internal */ this.opts = { ...st, ...opts };
47
- /** Registered tracks @type {Map<string, { url?: string, volume?: number, loop?: boolean, stems?: { url: string, at?: number[], volume?: number }[] }>} */
49
+ /** Registered tracks @type {Map<string, Exclude<MusicTrack, string>>} */
48
50
  this.tracks = new Map();
49
51
  this._defineAll(st.tracks || {});
50
52
  this._defineAll(opts.tracks || {});
@@ -88,7 +90,7 @@ export class Music {
88
90
  }
89
91
 
90
92
  /**
91
- * Define a track: a url, or { url, volume, loop, stems }. The same name again replaces it
93
+ * Define a track: a url, { url, volume, loop, stems }, or { generate } (your own Web Audio nodes). The same name again replaces it
92
94
  * @example engine.music.define('town', '/music/town.ogg')
93
95
  * @param {string} name
94
96
  * @param {MusicTrack} track
@@ -96,7 +98,9 @@ export class Music {
96
98
  */
97
99
  define(name, track) {
98
100
  const tr = typeof track === 'string' ? { url: track } : { ...track };
99
- if (tr.url == null && !tr.stems?.length) throw codedError('music-track', `music track '${name}' needs url or stems, e.g. { url: '/music/${name}.ogg' }`, TypeError);
101
+ const file = tr.url != null || tr.stems?.length;
102
+ if (tr.generate != null && (file || typeof tr.generate !== 'function')) throw codedError('music-track', `music track '${name}': generate is a function and replaces url / stems, give one of them`, TypeError);
103
+ if (!file && tr.generate == null) throw codedError('music-track', `music track '${name}' needs url, stems or generate, e.g. { url: '/music/${name}.ogg' }`, TypeError);
100
104
  this.tracks.set(name, tr);
101
105
  }
102
106
  /** @internal */
@@ -152,6 +156,7 @@ export class Music {
152
156
  if (this._token !== token || this.playing !== slot) { g.disconnect(); return; } // another track was chosen while loading
153
157
  const t = ctx.currentTime + 0.02, loop = tr.loop !== false;
154
158
  bufs.forEach((buf, i) => { const src = ctx.createBufferSource(); src.buffer = buf; src.loop = loop; src.connect(parts[i].out); src.start(t); slot.srcs.push(src); });
159
+ if (tr.generate) { const gen = this._generate(tr, ctx, g, t); slot.srcs.push(gen.src); slot.stop = gen.stop; } // a throw lands in the catch below, like a file that fails to decode
155
160
  if (fade > 0) { g.gain.setValueAtTime(0, t); g.gain.linearRampToValueAtTime(vol, t + fade); }
156
161
  if (slot.srcs[0]) slot.srcs[0].onended = () => this._ended(slot); // a looping source ends only when a fade stops it
157
162
  }).catch(err => { warnOnce(err.message); if (this.playing === slot) this.playing = null; }); // a missing file is said once; the game goes on silent
@@ -176,9 +181,20 @@ export class Music {
176
181
  p.gain.gain.cancelScheduledValues(t);
177
182
  p.gain.gain.setValueAtTime(p.gain.gain.value, t);
178
183
  p.gain.gain.linearRampToValueAtTime(0, t + f);
184
+ p.stop?.(t + f); // a generated track's own nodes end with the fade; its marker source below frees the track
179
185
  for (const s of p.srcs) { try { s.stop(t + f + 0.05); } catch { /* already stopped */ } }
180
186
  if (p.srcs[0]) p.srcs[0].onended = () => this._ended(p); // free the nodes once the fade has really ended
181
187
  }
188
+ /**
189
+ * @internal Start a generated track: the game's generate() gets the track's gain node. A silent ConstantSource on that node stands for the track
190
+ * (srcs[0]): its `ended` is the one end every track has (fade done, or end() called), so generated tracks need no second lifetime path and no timer
191
+ */
192
+ _generate(tr, ctx, g, start) {
193
+ const src = ctx.createConstantSource(); src.offset.value = 0; src.connect(g);
194
+ const res = tr.generate({ ctx, output: g, start, end: () => src.stop() });
195
+ src.start(start);
196
+ return { src, stop: res?.stop?.bind(res) };
197
+ }
182
198
  /** @internal The one end of a track's nodes, natural or faded (a fade-out already took it off `playing`): free them, and if it is still the playing one, say the music ended */
183
199
  _ended(slot) {
184
200
  slot.gain.disconnect();
@@ -218,6 +234,7 @@ export class Music {
218
234
  const live = a.running && this._ensureOutput();
219
235
  this.engine.events.emit('music:stinger', { name, played: !!live });
220
236
  if (!live) return; // a one-shot piece is not worth queueing
237
+ if (tr.generate) return this._generatedStinger(tr, volume ?? tr.volume ?? 1, duck);
221
238
  a.play(tr.url, { bus: 'music', volume: volume ?? tr.volume ?? 1 }).then(h => {
222
239
  if (this._gone) { h.remove(); return; } // the file loaded after the module went
223
240
  this._stingers.add(h); h.source.addEventListener?.('ended', () => this._stingers.delete(h));
@@ -229,6 +246,21 @@ export class Music {
229
246
  }).catch(err => warnOnce(err.message));
230
247
  }
231
248
 
249
+ /** @internal a stinger made by generate(): same dip as a file's, but its length is unknown, so the background comes back when the piece ends */
250
+ _generatedStinger(tr, volume, duck) {
251
+ const a = this.engine.audio, ctx = a.ctx, g = ctx.createGain(), t = ctx.currentTime;
252
+ g.gain.value = volume; g.connect(a.buses.music);
253
+ const gen = this._generate(tr, ctx, g, t + 0.02);
254
+ const h = { remove: () => { gen.stop?.(ctx.currentTime); gen.src.stop(); } };
255
+ this._stingers.add(h);
256
+ const bed = this.output.gain;
257
+ if (duck < 1) { bed.cancelScheduledValues(t); bed.setValueAtTime(bed.value, t); bed.linearRampToValueAtTime(duck, t + 0.15); }
258
+ gen.src.onended = () => {
259
+ this._stingers.delete(h); g.disconnect();
260
+ const now = ctx.currentTime; bed.cancelScheduledValues(now); bed.setValueAtTime(bed.value, now); bed.linearRampToValueAtTime(1, now + 0.3);
261
+ };
262
+ }
263
+
232
264
  // ---------- rules ----------
233
265
  /**
234
266
  * Set the auto track rules (null turns them off). opts: hold how many seconds a new result must be stable before switching, fade switch fade seconds,
@@ -296,4 +296,4 @@ export function particles(opts = {}) {
296
296
  } };
297
297
  }
298
298
 
299
- export const handRolled = [{ kind: 'particles', seen: 'a particle loop of its own', use: 'engine.particles: emitters on game time, one draw call, budgets (recipe 64)', quiet: /\b(engine|e|eng|ctx)\.particles\b|\bparticles\(\s*[{)]/, code: /\bfor\s*\([^)]*\bof\s+[\w.]*(?:particles|sparks|embers)\b|\b(?:particles|sparks|embers)\.(?:forEach|filter)\s*\(/i, near: [{ re: /\.(?:life|age|ttl|vel\w*|v[xyz])\b/, lines: 5 }] }];
299
+ export const handRolled = [{ kind: 'particles', docRef: 'recipes/64-particles.md', seen: 'a particle loop of its own', use: 'engine.particles: emitters on game time, one draw call, budgets', quiet: /\b(engine|e|eng|ctx)\.particles\b|\bparticles\(\s*[{)]/, code: /\bfor\s*\([^)]*\bof\s+[\w.]*(?:particles|sparks|embers)\b|\b(?:particles|sparks|embers)\.(?:forEach|filter)\s*\(/i, near: [{ re: /\.(?:life|age|ttl|vel\w*|v[xyz])\b/, lines: 5 }] }];
@@ -613,4 +613,4 @@ export function rigid(opts = {}) {
613
613
  };
614
614
  }
615
615
 
616
- export const handRolled = [{ kind: 'physics', seen: 'a physics library of its own', use: 'rigid(): bodies, joints and vehicles on the engine step, shared with collision and saves (recipe 11)', quiet: /\b(engine|e|eng|ctx)\.rigid\b|\brigid\(\s*[{)]/, raw: /\bfrom\s+['"](?:cannon-es|cannon|ammo\.js|@dimforge\/rapier3d(?:-compat)?|oimo|matter-js)['"]/ }];
616
+ export const handRolled = [{ kind: 'physics', docRef: 'recipes/11-physics.md §3', seen: 'a physics library of its own', use: 'rigid(): bodies, joints and vehicles on the engine step, shared with collision and saves', quiet: /\b(engine|e|eng|ctx)\.rigid\b|\brigid\(\s*[{)]/, raw: /\bfrom\s+['"](?:cannon-es|cannon|ammo\.js|@dimforge\/rapier3d(?:-compat)?|oimo|matter-js)['"]/ }];
@@ -3,7 +3,7 @@
3
3
  // Changes apply at once and autosave to the browser (localStorage), restored on the next launch.
4
4
  //
5
5
  // engine.use(settings()); // install after other modules (so it sees terrain, audio, etc.)
6
- // engine.settings.open() / close() / toggle()
6
+ // engine.ui.open('settings') / close('settings') // the menu is the 'settings' UI part
7
7
  // engine.settings.set('shadows', false) // change a setting in code (also saved)
8
8
  // engine.settings.get('vol.music') // → 0.5
9
9
  // engine.settings.preset('low') // graphics preset: 'low' | 'medium' | 'high'
@@ -135,8 +135,10 @@ export class Settings extends SettingsView {
135
135
  id: 'settings', title: () => engine.t('settings.title'), hintAction: action,
136
136
  data: () => this._data(),
137
137
  render: (d, tools) => this._render(d, tools),
138
- onCancel: () => this._cancel(),
139
138
  });
139
+ // The window is the 'settings' UI part: ui.open / ui.close own the input context, focus entry and ui:open / ui:close, so the window's own toggle (its close
140
+ // button calls it) must only route there. Guarded by isOpen: dispose closes the window after the part may be gone, and ui.close throws on an unknown name.
141
+ this.win.toggle = on => { if (!on && engine.ui.isOpen('settings')) engine.ui.close('settings'); };
140
142
  const baseRefresh = this.win.refresh;
141
143
  this.win.refresh = () => { baseRefresh(); this._afterRefresh(); };
142
144
  this._bindDOM(this.win.el);
@@ -144,8 +146,8 @@ export class Settings extends SettingsView {
144
146
  track(this.win);
145
147
  // The back key (Esc) has one entry point: with an empty focus stack it opens the menu; while the menu is open the window's onCancel handles it
146
148
  this.focus = uiFocus(engine);
147
- track(this.focus.setRoot(() => this.open())); // unloaded, the back key must not open a window that left the page and hold the input behind it
148
- // The close button, the back key and code close() all go through the window's toggle, emitting ui:open / ui:close
149
+ track(this.focus.setRoot(() => engine.ui.open('settings'))); // unloaded, the back key must not open a window that left the page and hold the input behind it
150
+ // The close button, the back key and code all go through ui.close, emitting ui:open / ui:close
149
151
  track(engine.events.on('ui:open', id => { if (id === 'settings') this._pause(true); }));
150
152
  track(engine.events.on('ui:close', id => { if (id === 'settings') this._pause(false); }));
151
153
  track(engine.events.on('i18n:change', () => { if (this._ready) this.save(); }));
@@ -244,16 +246,20 @@ export class Settings extends SettingsView {
244
246
  return this;
245
247
  }
246
248
 
247
- get isOpen() { return this.win.open; }
248
249
  /** Action name waiting for a key press, or null @type {string | null} */
249
250
  get capturing() { return this._capturing?.action ?? null; }
250
251
  set capturing(action) {
251
252
  this._capturing?.hold.remove();
252
253
  this._capturing = action ? { action, hold: this.focus.push('settings-key', { cancel: () => this._cancel() }) } : null;
253
254
  }
254
- open() { if (!this.win.open) this.win.toggle(true); }
255
- close() { this.capturing = null; if (this.win.open) this.win.toggle(false); }
256
- toggle(on = !this.win.open) { on ? this.open() : this.close(); }
255
+ /** @internal The 'settings' UI part: ui.open shows it, ui.close hides it and drops a pending rebind from wherever it was closed */
256
+ _part() {
257
+ return {
258
+ show: () => { this.win.el.hidden = false; this.win.refresh(); },
259
+ hide: () => { this.capturing = null; this.win.el.hidden = true; },
260
+ el: this.win.el,
261
+ };
262
+ }
257
263
 
258
264
  /**
259
265
  * Put one setting (or, with no key, every setting) back to its default: the value the engine or the game's define() started with, before the player's saved ones.
@@ -383,7 +389,6 @@ export class Settings extends SettingsView {
383
389
  frame() {
384
390
  const inp = this.engine.input;
385
391
  if (this.capturing) {
386
- if (!this.win.open) { this.capturing = null; return; } // closed by its close button: a focus entry left here would hold the back key
387
392
  if (this._capturing.hold.fresh) return; // the confirm press that opened it is not the new key
388
393
  const code = [...inp.justPressed][0];
389
394
  // The back key is routed to _cancel by the UI focus stack (cancels rebinding); nothing to do here
@@ -393,13 +398,13 @@ export class Settings extends SettingsView {
393
398
  // When the menu key and the back key are the same (default Esc) the UI focus stack handles it all; with another key: close if open, open when the focus
394
399
  // stack is empty
395
400
  if (!inp.pressedRaw(this.action) || inp.pressedRaw('cancel')) return;
396
- if (this.win.open) this.close();
397
- else if (this.focus.top === null) this.open();
401
+ if (this.engine.ui.isOpen('settings')) this.engine.ui.close('settings');
402
+ else if (this.focus.top === null) this.engine.ui.open('settings');
398
403
  }
399
404
  /** Back key: cancel rebinding if one is in progress, otherwise close the menu */
400
405
  _cancel() {
401
406
  if (this.capturing) { this.capturing = null; this.win.refresh(); return; }
402
- this.close();
407
+ this.engine.ui.close('settings');
403
408
  }
404
409
  /**
405
410
  * freezeWorld: gameplay pauses while the menu is open. Pausing has one entry point: with flow installed it switches to flow's 'paused' state (back to the
@@ -433,7 +438,8 @@ export function settings(opts = {}) {
433
438
  name: 'settings', skipKind: 'none', type: 'ui', params: SETTINGS_PARAMS, options: opts, label: 'Settings', optional: ['flow', 'cameraRig'], stage: 'effects',
434
439
  install(e, ctx) {
435
440
  s = new Settings(e, opts, ctx.track);
436
- ctx.track(e.ui.titleItem('settings', { label: x => x.t('title.settings'), run: () => s.open() })); // the title screen's Settings button
441
+ ctx.track(e.ui.titleItem('settings', { label: x => x.t('title.settings'), run: e => e.ui.open('settings') })); // the title screen's Settings button
442
+ ctx.ui.define('settings', () => s._part(), { modal: { cancel: () => s._cancel() } });
437
443
  return s;
438
444
  },
439
445
  init() { s.init(); },
@@ -441,11 +447,11 @@ export function settings(opts = {}) {
441
447
  // the tracked ui:close listener went first, so what an open menu holds is given back here
442
448
  dispose() { s.capturing = null; s._pause(false); releaseLimits(s); },
443
449
  // the values the player chose (quality preset, volumes, ...) explain a picture or a sound level; open / tab / capturing say the menu holds the input
444
- describe() { return { open: s.isOpen, tab: s.current, capturing: s.capturing, values: { ...s.values } }; },
450
+ describe() { return { open: s.engine.ui.isOpen('settings'), tab: s.current, capturing: s.capturing, values: { ...s.values } }; },
445
451
  };
446
452
  }
447
453
 
448
454
  export const handRolled = [
449
- { kind: 'pause', seen: 'a pause or Esc handler of its own', use: 'settings({ freezeWorld: true }): Esc stops every system and opens the menu (recipe 63); engine.freeze(why) for a pause with no menu', quiet: /\bsettings\(|\bengine\.(freeze|flow|settings)\b|\buiFocus\(/, code: /\b(?:let|var)\s+(?:is|game)?paused\s*=/i, orRaw: /(?:\.key|\.code)\s*===?\s*['"]Escape['"]/, tags: false },
450
- { kind: 'settings', seen: 'a settings menu of its own', use: 'engine.settings (settings()): volume, keys, quality and language in one menu that remembers itself; engine.settings.define adds your own (recipe 26)', quiet: /\bsettings\(|\bengine\.settings\b/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, 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 },
455
+ { kind: 'pause', docRef: 'recipes/07-flow-scenes-pause.md §1', seen: 'a pause or Esc handler of its own', use: 'settings({ freezeWorld: true }): Esc stops every system and opens the menu; engine.freeze(why) for a pause with no menu', quiet: /\bsettings\(|\bengine\.(freeze|flow|settings)\b|\buiFocus\(/, code: /\b(?:let|var)\s+(?:is|game)?paused\s*=/i, orRaw: /(?:\.key|\.code)\s*===?\s*['"]Escape['"]/, tags: false },
456
+ { kind: 'settings', docRef: 'recipes/26-ui-parts.md §6', seen: 'a settings menu of its own', use: 'engine.settings (settings()): volume, keys, quality and language in one menu that remembers itself; engine.settings.define adds your own', quiet: /\bsettings\(|\bengine\.settings\b/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, 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 },
451
457
  ];
@@ -168,7 +168,7 @@ export const OPTIONAL_SECTIONS = {
168
168
  bind(el, e, s) {
169
169
  for (const b of el.querySelectorAll('[data-game]')) b.onclick = async () => {
170
170
  const act = b.dataset.game;
171
- s.close();
171
+ e.ui.close('settings');
172
172
  if (act === 'load') await e.session.load(b.dataset.slot); // a clean playthrough from the save, not a quick load onto this one
173
173
  else if (act === 'title') await e.session.quit();
174
174
  };
@@ -353,4 +353,4 @@ export function swarm() {
353
353
  dispose() { for (const s of [...list]) s.dispose(); list = []; } };
354
354
  }
355
355
 
356
- export const handRolled = [{ kind: 'pool', seen: 'a pool or list of many shots of its own', use: 'engine.swarm: thousands of shots, crowds and debris in one draw, with reuse and hits (recipe 65)', quiet: /\b(engine|e|eng|ctx)\.swarm\b|\bswarm\(\s*[{)]/, 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 }];
356
+ export const handRolled = [{ kind: 'pool', docRef: 'recipes/65-swarm.md', seen: 'a pool or list of many shots of its own', use: 'engine.swarm: thousands of shots, crowds and debris in one draw, with reuse and hits', quiet: /\b(engine|e|eng|ctx)\.swarm\b|\bswarm\(\s*[{)]/, 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 }];
@@ -346,4 +346,4 @@ export function timeline(opts = {}) {
346
346
  };
347
347
  }
348
348
 
349
- export const handRolled = [{ kind: 'tween', seen: 'a tween of its own', use: 'await engine.timeline.tween(target, to, { duration, ease }): on game time, stops with pause (recipe 07)', quiet: /\b(engine|e|eng|ctx)\.timeline\b/, code: /\b(?:elapsed|time|timer|age|t)\s*\/\s*(?:\w+\.)?(?:dur|duration)\b/i, orRaw: /\bfrom\s+['"](?:gsap|@tweenjs\/tween\.js|tween\.js|animejs)['"]/ }];
349
+ export const handRolled = [{ kind: 'tween', docRef: 'recipes/13-animation.md §5', seen: 'a tween of its own', use: 'await engine.timeline.tween(target, to, { duration, ease }): on game time, stops with pause', quiet: /\b(engine|e|eng|ctx)\.timeline\b/, code: /\b(?:elapsed|time|timer|age|t)\s*\/\s*(?:\w+\.)?(?:dur|duration)\b/i, orRaw: /\bfrom\s+['"](?:gsap|@tweenjs\/tween\.js|tween\.js|animejs)['"]/ }];
@@ -3,7 +3,7 @@ import { injectUICSS } from '../../ui/UI.js';
3
3
 
4
4
  export function buildLetterbox(t) {
5
5
  injectUICSS(`
6
- .threedog-letterbox{position:fixed;left:0;right:0;height:0;background:var(--threedog-letterbox-bg,var(--threedog-loading-bg));z-index:18;pointer-events:none;transition:height var(--threedog-letterbox-speed,.5s) ease}
6
+ .threedog-letterbox{position:fixed;left:0;right:0;height:0;background:var(--threedog-letterbox-bg,var(--threedog-loading-bg));z-index:var(--threedog-z-letterbox);pointer-events:none;transition:height var(--threedog-letterbox-speed,.5s) ease}
7
7
  .threedog-letterbox-top{top:0}.threedog-letterbox-bottom{bottom:0}
8
8
  .threedog-letterbox.is-on{height:var(--threedog-letterbox-size,11%)}
9
9
  .threedog-letterbox-skip{position:absolute;right:calc(16px + env(safe-area-inset-right,0px));bottom:12px;font:12px var(--threedog-font);color:var(--threedog-muted);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threedog",
3
- "version": "2.1.0",
3
+ "version": "2.2.2",
4
4
  "description": "Web 3D game engine on three.js, built to be driven by an AI. Start: npm install threedog three && npm install -D @threedog/tools && npx threedog init (writes the game and its CLAUDE.md). No built-in art",
5
5
  "license": "MIT",
6
6
  "repository": {
package/render/PostFX.js CHANGED
@@ -89,6 +89,11 @@ const SLOTS = ['scene', 'hdr', 'tone', 'ldr', 'final'];
89
89
  // slots one effect at a time: each replaces an engine stage (the scene render, the tone-mapping output), two replacements of one stage cannot both run
90
90
  const EXCLUSIVE = { scene: 'replace the scene render', tone: 'replace the tone-mapping output' };
91
91
  const ADD_KEYS = ['name', 'slot', 'order'];
92
+ // The keys and types of an effect object the game defines ({ name, create | node | fuse, ... }); checked in effectOf before the engine adds its own keys (_auto, output)
93
+ const EFFECT_SCHEMA = {
94
+ name: 'string', create: 'function?', node: 'function?', fuse: 'object?', slot: 'string?', order: 'number?', params: 'object?', enabled: 'bool?', update: 'function?',
95
+ needsDepth: 'bool?', needsBuffers: 'array?', backend: 'string?', skipOnLowTier: 'bool?', cheaper: 'object?', facts: 'function?', about: 'object?',
96
+ };
92
97
 
93
98
  export class PostFX {
94
99
  /**
@@ -512,7 +517,8 @@ function effectOf(post, x, { name, slot, order }) {
512
517
  return pick({ name: `${cls}#${n}`, slot: s, order: 1000 + n, create: () => x, _pass: x, _auto: slot == null && (s === 'hdr' || s === 'ldr') });
513
518
  }
514
519
  if (x && typeof x === 'object' && typeof x.name === 'string' && (typeof x.create === 'function' || typeof x.node === 'function' || (x.fuse && typeof x.fuse === 'object')))
515
- return name != null || slot != null || order != null ? pick(x) : x;
520
+ { try { readParams('engine.post.add(effect)', EFFECT_SCHEMA, x); } catch (e) { throw codedError('post-effect', e.message); } // same code as every other wrong effect shape
521
+ return name != null || slot != null || order != null ? pick(x) : x; }
516
522
  throw codedError('post-effect', 'engine.post.add(x): x is a three.js Pass (has render(); WebGL), a node function (input, ctx) => node (WebGPU), ' +
517
523
  "or an effect { name: 'myEffect', create: ctx => pass, node: (input, ctx) => node } / { name, fuse: { glsl } } (both renderers, see PostEffect)");
518
524
  }
@@ -66,3 +66,6 @@ export const detailBump = Fn(/** @param {[N<'vec3'>, N<'vec3'>, N<'float'>, N<'f
66
66
  const det = dot(sx, r1).mul(faceDir);
67
67
  return normalize(abs(det).mul(surfNorm).sub(float(k).mul(sign(det)).mul(dFdx(h).mul(r1).add(dFdy(h).mul(r2)))));
68
68
  });
69
+
70
+ // bumpMap() reads a texture's slope; given a height computed in a shader it bumps nothing and throws nothing. Quiet when the file already calls detailBump.
71
+ export const handRolled = [{ kind: 'bump', docRef: 'recipes/56-webgpu-tsl.md §"The engine"', seen: 'a bumpMap() call (it does nothing for a height computed in the shader)', 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", quiet: /\bdetailBump\b/, code: /\bbumpMap\s*\(/ }];
package/types/core.d.ts CHANGED
@@ -413,6 +413,8 @@ export interface SaveProvider {
413
413
  notAtomic?: string;
414
414
  /** Dev only: called once start() finished with this part's data in the new-game state, to warn about what should not be there yet (world: records placed by code) */
415
415
  checkNewGame?: (data: any) => void;
416
+ /** Show this part in saves.list() rows (`summary[key]`), read from the stored save and migrated: a title screen's level, gold or play time without loading the slot. Keep the part small */
417
+ summary?: boolean;
416
418
  /** This part's format version, default 1: raise it by 1 when what save() returns changes shape. A save with a newer version is refused */
417
419
  version?: number;
418
420
  /** Upgrade steps: old version -> data => data in the next version's shape, e.g. { 1: d => ({ ...d, beds: [] }) }.
@@ -436,8 +436,6 @@ export interface Settings {
436
436
  presets: Record<string, QualityPreset>;
437
437
  /** Tabs @experimental */
438
438
  sections: Map<string, any>;
439
- /** Whether the menu is open */
440
- readonly isOpen: boolean;
441
439
  /** Read a setting, e.g. get('vol.music') */
442
440
  get(key: string): any;
443
441
  /** Change a setting (takes effect immediately + saved) */
@@ -456,9 +454,6 @@ export interface Settings {
456
454
  }): this;
457
455
  /** Add a tab of your own, or a built-in / optional one by name: addSection('camera') */
458
456
  addSection(id: string, section?: SettingsSection): this;
459
- open(): void;
460
- close(): void;
461
- toggle(on?: boolean): void;
462
457
  /** Put one setting (or all, with no key) back to its default: the engine's start value, or the default the game gave define(). Keys: resetBindings */
463
458
  reset(key?: string): void;
464
459
  /** Restore all keys to defaults @experimental */
@@ -475,8 +470,12 @@ export interface Settings {
475
470
  // Music music()
476
471
  // ======================================================================
477
472
 
478
- /** Track: a path, or { url, volume 0-1, loop, stems }. Stems are extra layers started in sync; each fades in as music.intensity rises through its `at` range */
479
- export type MusicTrack = string | { url?: string; volume?: number; loop?: boolean; stems?: MusicStem[] };
473
+ /**
474
+ * Track: a path, { url, volume 0-1, loop, stems }, or { generate } (code only, replaces url / stems). Stems are extra layers started in sync; each fades in as music.intensity rises through its `at` range
475
+ */
476
+ export type MusicTrack = string | { url?: string; volume?: number; loop?: boolean; stems?: MusicStem[]; generate?: MusicGenerate };
477
+ /** `output`: the track's gain node; `start`: audio-clock time to begin; `end()` finishes the track; return { stop(at) } to hear when a fade-out ends */
478
+ export type MusicGenerate = (g: { ctx: AudioContext; output: AudioNode; start: number; end(): void }) => void | { stop?(at: number): void };
480
479
  /** A layer of a track: silent below at[0], full at at[1] and above (intensity 0-1) */
481
480
  export interface MusicStem { url: string; at?: number[]; volume?: number }
482
481
  /** Auto-selection condition: an object of condition keys ({ state: 'combat', time: 'night', zone: 'cave' }) or (e, music) => boolean */
@@ -37,6 +37,16 @@ export class Audio {
37
37
  owner?: string;
38
38
  remove(): void;
39
39
  };
40
+ /**
41
+ * Your Web Audio node in a bus's path, after volume and duck, before master and reverb, in call order ('master': before the speakers).
42
+ * `make(ctx)` returns the node; it runs once audio is unlocked; taps you add to it stay
43
+ * @param {string} bus
44
+ * @param {(ctx: AudioContext) => AudioNode} make
45
+ * @returns {{ remove(): void }} remove() takes the node out and links the path back (repeat calls do nothing)
46
+ */
47
+ addNode(bus: string, make: (ctx: AudioContext) => AudioNode): {
48
+ remove(): void;
49
+ };
40
50
  /**
41
51
  * Set a bus volume 0-1 ('master' for the total)
42
52
  * @param {string} bus
@@ -158,10 +158,15 @@ export class Saves {
158
158
  load(slot?: string, { turn }?: {
159
159
  turn?: object;
160
160
  }): Promise<boolean>;
161
- /** All slots, newest first (synchronous, reads the in-memory index) @returns {{ slot: string, savedAt: number }[]} */
161
+ /**
162
+ * All slots, newest first (synchronous). summary: the parts marked `summary: true` in saves.define, read from the stored save and migrated; {} if none.
163
+ * @returns {{ slot: string, savedAt: number, summary: Record<string, any> }[]}
164
+ * @example for (const { slot, summary } of engine.saves.list()) console.log(slot, summary.hero?.level);
165
+ */
162
166
  list(): {
163
167
  slot: string;
164
168
  savedAt: number;
169
+ summary: Record<string, any>;
165
170
  }[];
166
171
  /**
167
172
  * Delete a slot. Returns a Promise (disk write done); awaiting is optional. A newer save another tab wrote meanwhile is kept: the slot lists again, with a toast (save-stale).
@@ -9,23 +9,14 @@
9
9
  export function music(opts?: MusicOptions): ModuleDef<Music>;
10
10
  /** engine.music */
11
11
  export class Music {
12
- /** Registered tracks @type {Map<string, { url?: string, volume?: number, loop?: boolean, stems?: { url: string, at?: number[], volume?: number }[] }>} */
13
- tracks: Map<string, {
14
- url?: string;
15
- volume?: number;
16
- loop?: boolean;
17
- stems?: {
18
- url: string;
19
- at?: number[];
20
- volume?: number;
21
- }[];
22
- }>;
12
+ /** Registered tracks @type {Map<string, Exclude<MusicTrack, string>>} */
13
+ tracks: Map<string, Exclude<MusicTrack, string>>;
23
14
  /** Name of the track playing (or wanted) @type {string | null} */
24
15
  current: string | null;
25
16
  /** 0-1: how loud each stem of the playing track is (see the stems `at` range); fades in about half a second @type {number} */
26
17
  intensity: number;
27
18
  /**
28
- * Define a track: a url, or { url, volume, loop, stems }. The same name again replaces it
19
+ * Define a track: a url, { url, volume, loop, stems }, or { generate } (your own Web Audio nodes). The same name again replaces it
29
20
  * @example engine.music.define('town', '/music/town.ogg')
30
21
  * @param {string} name
31
22
  * @param {MusicTrack} track
@@ -111,5 +102,5 @@ export class Music {
111
102
  }
112
103
  import type { MusicOptions } from '../../../gameplay';
113
104
  import type { ModuleDef } from '../../../core';
114
- import type { MusicRule } from '../../../gameplay';
115
105
  import type { MusicTrack } from '../../../gameplay';
106
+ import type { MusicRule } from '../../../gameplay';
package/ui/Focus.js CHANGED
@@ -12,7 +12,7 @@
12
12
  // h.onTop this entry is the top of the stack (a window without a cursor over a dialogue never uses confirm, so consumed alone would let the dialogue advance)
13
13
  // h.fresh pushed this frame: the key press that opened it (E, Space) must not count as its own action
14
14
  // h.remove() pop (safe to call repeatedly)
15
- // f.setRoot(() => settings.open()) // what the back key does on an empty stack; returns a handle { remove() }
15
+ // f.setRoot(() => engine.ui.open('settings')) // what the back key does on an empty stack; returns a handle { remove() }
16
16
  // f.top top name or null; f.list() names from bottom to top; f.cursor { id, index } of the top entry when it has a nav, else null
17
17
  // Picture: none (behavior only); the cursor marks the selected DOM control with .is-cursor.
18
18
  import { stepCursor, forgetNav } from './cursor.js';
package/ui/Parts.js CHANGED
@@ -26,7 +26,7 @@ const DEV = {
26
26
  badPart: "ui part '{name}': the function must return an object { show, update, hide, dispose } (any may be omitted). Got {got}.",
27
27
  badVerb: "ui part '{name}': {verb} must be a function.",
28
28
  unknown: "engine.ui.set('{name}'): no UI part has that name. Known parts: {known}. (A module's parts exist only after engine.use(module).)",
29
- notModal: "engine.ui.open('{name}'): only full-screen parts can be opened ({known}).",
29
+ notModal: "engine.ui.{verb}('{name}'): only full-screen parts can be opened and closed ({known}).",
30
30
  };
31
31
  const kind = v => v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v;
32
32
 
@@ -87,7 +87,7 @@ export class UIParts {
87
87
  this.defs.set(name, d);
88
88
  return { remove: () => {
89
89
  if (this.defs.get(name) !== d) return;
90
- this.close(name);
90
+ this._close(name);
91
91
  this.live.get(name)?.dispose?.();
92
92
  this.live.delete(name); this.defs.delete(name);
93
93
  } };
@@ -155,6 +155,13 @@ export class UIParts {
155
155
  */
156
156
  create(name) { return this._make(name); }
157
157
 
158
+ /** @internal The full-screen definition of name; throws ui-misuse listing the known ones */
159
+ _modal(verb, name) {
160
+ const d = this.defs.get(name);
161
+ if (!d?.modal) throw codedError('ui-misuse', fmt(DEV.notModal, { verb, name, known: [...this.defs].filter(([, x]) => x.modal).map(([n]) => n).join(', ') }));
162
+ return d;
163
+ }
164
+
158
165
  /**
159
166
  * Open a full-screen part (the title screen): shows it, pushes the UI focus stack (Esc goes to it; the choice cursor moves over the controls inside the
160
167
  * part's el), locks gameplay input, emits ui:open.
@@ -164,8 +171,7 @@ export class UIParts {
164
171
  * @example engine.ui.open('title')
165
172
  */
166
173
  open(name, data) {
167
- const d = this.defs.get(name);
168
- if (!d?.modal) throw codedError('ui-misuse', fmt(DEV.notModal, { name, known: [...this.defs].filter(([, x]) => x.modal).map(([n]) => n).join(', ') }));
174
+ const d = this._modal('open', name);
169
175
  const p = this.get(name);
170
176
  if (!p) return false;
171
177
  if (this.opened.has(name)) return true;
@@ -177,17 +183,23 @@ export class UIParts {
177
183
  const fr = typeof m.freeze === 'function' ? m.freeze(e) : m.freeze;
178
184
  const freeze = fr ? e.freeze('ui-' + name, { kind: typeof fr === 'string' ? fr : undefined }) : null;
179
185
  this.opened.set(name, { freeze, focus: uiFocus(e).push('ui-' + name, { cancel: m.cancel ? () => m.cancel(e) : null, nav: () => p.el ?? null }), ctx: e.input.push('ui-' + name) }); // own opaque context: gameplay actions stop responding
180
- try { p.show(shown); } catch (err) { this.close(name); throw err; }
186
+ try { p.show(shown); } catch (err) { this._close(name); throw err; }
181
187
  e.events.emit('ui:open', name);
182
188
  return true;
183
189
  }
184
190
 
185
191
  /**
186
- * Close a full-screen part opened with open().
192
+ * Close a full-screen part opened with open(). A name that is not a full-screen part throws, like open().
187
193
  * @param {string} name
188
194
  * @returns {void}
189
195
  */
190
196
  close(name) {
197
+ this._modal('close', name);
198
+ this._close(name);
199
+ }
200
+
201
+ /** @internal Close without checking the name: define().remove and a failed show() reach parts that may not be full-screen or already gone */
202
+ _close(name) {
191
203
  const f = this.opened.get(name);
192
204
  if (!f) return;
193
205
  const e = this.engine;
@@ -198,7 +210,7 @@ export class UIParts {
198
210
  }
199
211
 
200
212
  /**
201
- * Whether a full-screen part is open
213
+ * Whether a full-screen part is open (false for a name nobody defined: a game may ask about a module it did not install)
202
214
  * @param {string} name
203
215
  * @returns {boolean}
204
216
  */
package/ui/defaults.js CHANGED
@@ -12,7 +12,7 @@ const STRINGS = {
12
12
  en: { 'title.start': 'Start', 'title.continue': 'Continue' },
13
13
  };
14
14
  const CSS = `
15
- .threedog-title{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;background:var(--threedog-loading-bg);color:var(--threedog-fg);z-index:80;font-family:var(--threedog-font)}
15
+ .threedog-title{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;background:var(--threedog-loading-bg);color:var(--threedog-fg);z-index:var(--threedog-z-title);font-family:var(--threedog-font)}
16
16
  .threedog-title-name{font-size:32px;font-weight:600;letter-spacing:.08em}
17
17
  .threedog-title-items{display:flex;flex-direction:column;gap:10px;min-width:200px}
18
18
  .threedog-title-items .threedog-btn{padding:8px 16px;font-size:16px}
package/ui/theme.js CHANGED
@@ -14,12 +14,18 @@ const DEFAULT_UI = {
14
14
  shadowSmall: '0 1px 2px rgba(0,0,0,.6)',
15
15
  };
16
16
 
17
+ // Game UI layers, low to high, in one place so a new part picks a slot instead of a number. title < window < toast < fade: a window opened from the title
18
+ // (Settings) must sit above it, and a toast above both. The tools' own panels (editor, gallery) are not part of the game and keep their own.
19
+ const LAYERS = { stick: 5, touch: 6, debug: 10, hud: 12, prompt: 15, letterbox: 18, dialogue: 20, title: 22, window: 25, toast: 35, fade: 90, loading: 100 };
20
+ const LAYER_VARS = Object.entries(LAYERS).map(([k, v]) => `--threedog-z-${k}:${v}`).join(';');
21
+
17
22
  const BASE_CSS = `
23
+ :root{${LAYER_VARS}}
18
24
  :where(.threedog-root > *){pointer-events:auto}
19
25
  .threedog-ui{font:14px/1.55 var(--threedog-font);color:var(--threedog-fg)}
20
26
  .threedog-win{box-sizing:border-box;overflow-wrap:anywhere;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:min(480px,calc(100% - 32px));
21
27
  max-height:min(70%,560px);overflow:auto;
22
- background:var(--threedog-bg);border:1px solid var(--threedog-line);border-radius:var(--threedog-radius);padding:16px 18px;z-index:25;
28
+ background:var(--threedog-bg);border:1px solid var(--threedog-line);border-radius:var(--threedog-radius);padding:16px 18px;z-index:var(--threedog-z-window);
23
29
  box-shadow:var(--threedog-shadow)}
24
30
  .threedog-win-head{margin:0 0 10px;font-size:16px;color:var(--threedog-accent);letter-spacing:.04em;display:flex;justify-content:space-between;
25
31
  align-items:center;gap:8px}
@@ -39,22 +45,22 @@ const BASE_CSS = `
39
45
  .threedog-steps{margin:6px 0 0;padding-left:20px}.threedog-step{color:var(--threedog-muted)}.threedog-step.is-current{color:var(--threedog-fg)}
40
46
  .threedog-step.is-done{color:var(--threedog-good)}
41
47
  .threedog-toasts{position:fixed;top:calc(16px + env(safe-area-inset-top,0px));left:50%;transform:translateX(-50%);display:flex;flex-direction:column;
42
- gap:6px;align-items:center;z-index:35;pointer-events:none}
48
+ gap:6px;align-items:center;z-index:var(--threedog-z-toast);pointer-events:none}
43
49
  .threedog-toast{background:var(--threedog-bg);border:1px solid var(--threedog-accent);border-radius:var(--threedog-radius-small);
44
50
  padding:6px 14px;animation:threedogIn .25s ease-out;transition:opacity .4s}
45
51
  .threedog-prompt{position:fixed;left:0;top:0;transform:translate(-50%,-100%);padding:6px 10px;border-radius:var(--threedog-radius-small);background:var(--threedog-bg);
46
- color:var(--threedog-fg);font:13px var(--threedog-font);cursor:pointer;z-index:15;white-space:nowrap}
52
+ color:var(--threedog-fg);font:13px var(--threedog-font);cursor:pointer;z-index:var(--threedog-z-prompt);white-space:nowrap}
47
53
  .threedog-prompt-hold{background:linear-gradient(90deg,var(--threedog-accent) calc(var(--progress,0)*100%),var(--threedog-bg) 0)}
48
54
  .threedog-dlg{box-sizing:border-box;overflow-wrap:anywhere;position:fixed;left:50%;transform:translateX(-50%);bottom:calc(24px + env(safe-area-inset-bottom,0px));
49
55
  width:min(640px,calc(100% - 32px));
50
56
  background:var(--threedog-bg);color:var(--threedog-fg);border:1px solid var(--threedog-line);border-radius:var(--threedog-radius);
51
- padding:14px 18px 16px;font:15px/1.6 var(--threedog-font);z-index:20;cursor:pointer}
57
+ padding:14px 18px 16px;font:15px/1.6 var(--threedog-font);z-index:var(--threedog-z-dialogue);cursor:pointer}
52
58
  .threedog-dlg-name{display:block;color:var(--threedog-accent);font-size:13px;margin-bottom:4px;letter-spacing:.05em;font-weight:700}
53
59
  .threedog-dlg-opts{display:flex;flex-direction:column;gap:6px;margin-top:10px}
54
60
  .threedog-dlg-opts .threedog-btn{text-align:left}
55
61
  .threedog-dlg-hint{position:absolute;right:14px;bottom:8px;font-size:12px;opacity:.6}
56
62
  .threedog-loading{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:var(--threedog-loading-bg);
57
- color:var(--threedog-fg);z-index:100;transition:opacity .6s;font-family:var(--threedog-font)}
63
+ color:var(--threedog-fg);z-index:var(--threedog-z-loading);transition:opacity .6s;font-family:var(--threedog-font)}
58
64
  .threedog-loading-box{display:flex;flex-direction:column;gap:14px;align-items:center;width:min(360px,80%)}
59
65
  .threedog-loading-title{font-weight:600;font-size:20px;letter-spacing:.08em}
60
66
  .threedog-loading-track{width:100%;height:4px;background:var(--threedog-line);border-radius:2px;overflow:hidden}
@@ -62,14 +68,14 @@ const BASE_CSS = `
62
68
  .threedog-loading-msg{font-size:13px;color:var(--threedog-muted);min-height:1.5em}
63
69
  .threedog-stick{position:fixed;left:calc(24px + env(safe-area-inset-left,0px));bottom:calc(28px + env(safe-area-inset-bottom,0px));width:110px;
64
70
  height:110px;border-radius:50%;
65
- background:var(--threedog-bg);opacity:.7;border:1px solid var(--threedog-line);touch-action:none;z-index:5}
71
+ background:var(--threedog-bg);opacity:.7;border:1px solid var(--threedog-line);touch-action:none;z-index:var(--threedog-z-stick)}
66
72
  .threedog-touch-bar{position:fixed;right:calc(16px + env(safe-area-inset-right,0px));bottom:calc(96px + env(safe-area-inset-bottom,0px));display:flex;
67
- flex-wrap:wrap-reverse;gap:10px;justify-content:flex-end;width:160px;z-index:6}
73
+ flex-wrap:wrap-reverse;gap:10px;justify-content:flex-end;width:160px;z-index:var(--threedog-z-touch)}
68
74
  .threedog-touch-btn{width:64px;height:64px;border-radius:50%;border:1px solid var(--threedog-line);background:var(--threedog-bg);
69
75
  color:var(--threedog-fg);font:600 13px var(--threedog-font);touch-action:none}
70
76
  .threedog-touch-btn:active{border-color:var(--threedog-accent)}
71
77
  .threedog-stick-knob{position:absolute;left:35px;top:35px;width:40px;height:40px;border-radius:50%;background:var(--threedog-accent)}
72
- .threedog-fade{position:fixed;inset:0;background:var(--threedog-fade-bg);opacity:var(--threedog-fade,0);pointer-events:none;z-index:90}
78
+ .threedog-fade{position:fixed;inset:0;background:var(--threedog-fade-bg);opacity:var(--threedog-fade,0);pointer-events:none;z-index:var(--threedog-z-fade)}
73
79
  .threedog-fade.is-on{pointer-events:auto}
74
80
  @keyframes threedogIn{from{transform:translateY(-8px);opacity:0}to{transform:none;opacity:1}}
75
81
  @media (prefers-reduced-motion:reduce){.threedog-toast{animation:none}}