@umicat/three-sdk 1.31.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Input3D.js CHANGED
@@ -680,13 +680,27 @@ export class Input3D {
680
680
  }
681
681
  if (jumpBtn) {
682
682
  const jb = jumpBtn;
683
+ // Tracked by pointerId for the same reason the stick/look zone are —
684
+ // without it, a SECOND finger landing on (and releasing from) this
685
+ // same button clears `touchJump` unconditionally, even while the
686
+ // FIRST finger is still physically holding it down. The release
687
+ // handlers below used to take no event parameter at all and just
688
+ // zeroed the flag outright; they now only do that for the finger
689
+ // that actually set it.
690
+ let jumpId = null;
683
691
  on(jb, 'pointerdown', (e) => {
692
+ if (jumpId !== null)
693
+ return;
694
+ jumpId = e.pointerId;
684
695
  jb.setPointerCapture(e.pointerId);
685
696
  this.touchJump = true;
686
697
  this.beginPress('jump');
687
698
  });
688
699
  for (const ev of ['pointerup', 'pointercancel', 'lostpointercapture']) {
689
- on(jb, ev, () => { this.touchJump = false; });
700
+ on(jb, ev, (e) => { if (e.pointerId === jumpId) {
701
+ jumpId = null;
702
+ this.touchJump = false;
703
+ } });
690
704
  }
691
705
  }
692
706
  }
@@ -696,9 +710,17 @@ export class Input3D {
696
710
  el.addEventListener(ev, h);
697
711
  this.cleanups.push(() => el.removeEventListener(ev, h));
698
712
  };
713
+ // Same pointerId guard as the jump button above, scoped per-button (one
714
+ // `heldId` per `wireButton` call/element) — `touchHeld` is keyed by
715
+ // ACTION id, not pointer id, so without this a second finger tapping
716
+ // the same action button clears the first finger's still-held press.
717
+ let heldId = null;
699
718
  on('pointerdown', (e) => {
700
719
  // Cancels the selection gesture as well as the default press behaviour.
701
720
  e.preventDefault();
721
+ if (heldId !== null)
722
+ return;
723
+ heldId = e.pointerId;
702
724
  el.setPointerCapture(e.pointerId);
703
725
  this.touchHeld.add(id);
704
726
  this.beginPress(id);
@@ -706,7 +728,10 @@ export class Input3D {
706
728
  // pointercancel included: a system gesture steals the pointer with no `up`,
707
729
  // and the button would read as held for the rest of the run.
708
730
  for (const ev of ['pointerup', 'pointercancel', 'lostpointercapture']) {
709
- on(ev, () => { this.touchHeld.delete(id); });
731
+ on(ev, (e) => { if (e.pointerId === heldId) {
732
+ heldId = null;
733
+ this.touchHeld.delete(id);
734
+ } });
710
735
  }
711
736
  }
712
737
  }
@@ -1,6 +1,7 @@
1
1
  import { UmicatCore } from '@umicat/platform-sdk/core/UmicatCore.js';
2
2
  import { DialogueModule } from '@umicat/platform-sdk/dialogue/DialogueModule.js';
3
3
  import { HudBinding3DNamespace } from './hud3d/HudDynamicBinding3D.js';
4
+ import { setupRecordingListener } from './capture/RecordingManager.js';
4
5
  /** Kept in sync with package.json on each publish. */
5
6
  const SDK_VERSION = '0.0.1';
6
7
  /**
@@ -25,6 +26,18 @@ export class ThreeUmicat extends UmicatCore {
25
26
  static async init(options = {}) {
26
27
  const game = new ThreeUmicat(await UmicatCore.connect(SDK_VERSION, options));
27
28
  announceScaleMode();
29
+ // Recording is a PLATFORM capability, not game logic — the editor's Play
30
+ // tab offers the button to every game regardless of engine, so every game
31
+ // has to be able to answer. Phaser games get this for free because
32
+ // `createUmicatGame` installs it centrally; this package has no such
33
+ // wrapper, so before this the listener was wired by each game's own
34
+ // `main.ts` — the 3D template does it, and every game older than that line
35
+ // (Balaboo, for one) simply could not record, with no error to say why.
36
+ // Installing here covers them all on the next SDK update. Safe to call
37
+ // even though the template ALSO calls it: it is idempotent, and it
38
+ // resolves the canvas at record time, not now — there is no renderer yet
39
+ // at init.
40
+ setupRecordingListener();
28
41
  return game;
29
42
  }
30
43
  }
@@ -11,9 +11,16 @@ import type * as THREE from 'three';
11
11
  * Parent sends: 'stopRecording'
12
12
  * Game responds: { type: 'recordingComplete', data: string (base64 data URL), mimeType: string }
13
13
  *
14
+ * The renderer is OPTIONAL. Without one the canvas is found at record time,
15
+ * which is what makes a single install from `ThreeUmicat.init()` cover every
16
+ * 3D game — three-sdk has no `createUmicatGame`-style wrapper, so before this
17
+ * the listener had to be wired by each game's own `main.ts`, and games older
18
+ * than the template line that does it (Balaboo, for one) simply could not
19
+ * record. Calling it twice is a no-op.
20
+ *
14
21
  * `canvas.captureStream()` samples the compositor's output directly, so
15
22
  * unlike {@link "./ScreenshotManager.js".takeScreenshot}, it works whether
16
23
  * or not the renderer was constructed with `preserveDrawingBuffer` — but the
17
24
  * template sets it anyway, for the screenshot path.
18
25
  */
19
- export declare function setupRecordingListener(renderer: THREE.WebGLRenderer): void;
26
+ export declare function setupRecordingListener(renderer?: THREE.WebGLRenderer): void;
@@ -1,5 +1,32 @@
1
1
  let mediaRecorder = null;
2
2
  let recordedChunks = [];
3
+ /** One listener per WINDOW, whoever asks first. `ThreeUmicat.init()` installs
4
+ * it for every game; the 3D template ALSO calls this explicitly and older
5
+ * games may too. Two listeners would mean two MediaRecorders racing the same
6
+ * canvas on one 'startRecording'.
7
+ *
8
+ * Keyed on the window rather than held as a module-level flag, which is both
9
+ * more honest about what "once" means here and the difference between this
10
+ * being testable and not: a module latch makes every call after the first a
11
+ * no-op for the life of the process, so a suite that exercises more than one
12
+ * scenario silently tests nothing after its first case. */
13
+ const installedOn = new WeakSet();
14
+ /** The canvas to record, resolved LAZILY — at record time, not install time.
15
+ * That is what lets `ThreeUmicat.init()` install this: init runs at the top
16
+ * of a game's boot, long before the renderer (and its canvas) exist. An
17
+ * explicit renderer, when given, always wins.
18
+ *
19
+ * Picks the largest canvas when a game has more than one — a minimap or a
20
+ * thumbnail baker is a canvas too, and recording one of those instead of the
21
+ * game would be a silent, confusing failure. */
22
+ function resolveCanvas(renderer) {
23
+ if (renderer?.domElement)
24
+ return renderer.domElement;
25
+ const all = [...document.querySelectorAll('canvas')];
26
+ if (all.length === 0)
27
+ return null;
28
+ return all.reduce((best, c) => (c.width * c.height > best.width * best.height ? c : best), all[0]);
29
+ }
3
30
  /**
4
31
  * Sets up postMessage listeners for video recording of the renderer's
5
32
  * canvas. Same wire protocol as `@umicat/phaser-sdk`'s
@@ -12,18 +39,30 @@ let recordedChunks = [];
12
39
  * Parent sends: 'stopRecording'
13
40
  * Game responds: { type: 'recordingComplete', data: string (base64 data URL), mimeType: string }
14
41
  *
42
+ * The renderer is OPTIONAL. Without one the canvas is found at record time,
43
+ * which is what makes a single install from `ThreeUmicat.init()` cover every
44
+ * 3D game — three-sdk has no `createUmicatGame`-style wrapper, so before this
45
+ * the listener had to be wired by each game's own `main.ts`, and games older
46
+ * than the template line that does it (Balaboo, for one) simply could not
47
+ * record. Calling it twice is a no-op.
48
+ *
15
49
  * `canvas.captureStream()` samples the compositor's output directly, so
16
50
  * unlike {@link "./ScreenshotManager.js".takeScreenshot}, it works whether
17
51
  * or not the renderer was constructed with `preserveDrawingBuffer` — but the
18
52
  * template sets it anyway, for the screenshot path.
19
53
  */
20
54
  export function setupRecordingListener(renderer) {
55
+ if (installedOn.has(window))
56
+ return;
57
+ installedOn.add(window);
21
58
  window.addEventListener('message', (event) => {
22
59
  if (event.data === 'startRecording') {
23
60
  try {
24
- const canvas = renderer.domElement;
25
- if (!canvas)
61
+ const canvas = resolveCanvas(renderer);
62
+ if (!canvas) {
63
+ window.parent.postMessage({ type: 'recordingError', error: 'no canvas to record' }, '*');
26
64
  return;
65
+ }
27
66
  recordedChunks = [];
28
67
  const stream = canvas.captureStream(30);
29
68
  // Pick best available codec.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umicat/three-sdk",
3
- "version": "1.31.0",
3
+ "version": "1.32.0",
4
4
  "description": "Three.js runtime for Umicat games: the scene3d design format, its loader with physics, a kinematic character controller, and the Umicat platform via @umicat/platform-sdk.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",