@umicat/three-sdk 1.13.0 → 1.13.1

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.
@@ -16,4 +16,4 @@ export declare function viewportSize(umicat: ThreeUmicat): {
16
16
  * All in CSS pixels; all `0` when there is no fold, so a stylesheet that uses
17
17
  * them is correct on a flat screen too.
18
18
  */
19
- export declare function installDualScreen(umicat: ThreeUmicat): () => void;
19
+ export declare function installDualScreen(umicat: ThreeUmicat, canvas?: HTMLCanvasElement): () => void;
@@ -45,9 +45,10 @@ export function viewportSize(umicat) {
45
45
  * All in CSS pixels; all `0` when there is no fold, so a stylesheet that uses
46
46
  * them is correct on a flat screen too.
47
47
  */
48
- export function installDualScreen(umicat) {
48
+ export function installDualScreen(umicat, canvas) {
49
49
  return umicat.fold.subscribe((layout) => {
50
50
  publishVariables(layout);
51
+ placeCanvas(layout, canvas);
51
52
  placeControls(layout);
52
53
  // The game sizes its own renderer off a resize listener. Folding is a size
53
54
  // change as far as it is concerned, but no window resize accompanies it —
@@ -82,18 +83,52 @@ function publishVariables(layout) {
82
83
  * Done by moving the LAYER rather than each control, so every control the SDK
83
84
  * places — and any it grows later — follows for free.
84
85
  */
86
+ /**
87
+ * Constrains the canvas's CSS box to the upper panel.
88
+ *
89
+ * `viewportSize` alone is not enough, and the reason is a three.js argument
90
+ * nobody thinks about: `setSize(w, h, false)` — which every template uses —
91
+ * sizes the DRAWING BUFFER and deliberately leaves the CSS box alone, because
92
+ * normally the canvas is stretched to the window by a stylesheet. Shrink only
93
+ * the buffer and the result is the same full-screen picture at a lower
94
+ * resolution, which looks like nothing happened at all.
95
+ *
96
+ * Found by doing exactly that: the fold arrived, the buffer shrank, and the
97
+ * screenshot was unchanged.
98
+ *
99
+ * Defaults to the document's only canvas. A game with several passes its own.
100
+ */
101
+ function placeCanvas(layout, explicit) {
102
+ const canvas = explicit ?? document.querySelector('canvas');
103
+ if (!canvas)
104
+ return;
105
+ if (layout.dualScreen && layout.top) {
106
+ Object.assign(canvas.style, {
107
+ position: 'fixed',
108
+ left: `${layout.top.x}px`,
109
+ top: `${layout.top.y}px`,
110
+ width: `${layout.top.width}px`,
111
+ height: `${layout.top.height}px`,
112
+ });
113
+ }
114
+ else {
115
+ Object.assign(canvas.style, { position: '', left: '', top: '', width: '', height: '' });
116
+ }
117
+ }
85
118
  function placeControls(layout) {
86
119
  const root = document.querySelector(TOUCH_ROOT);
87
120
  if (!root)
88
121
  return; // desktop: the SDK mounts no touch layer at all
122
+ // Write the shorthand FIRST and the longhands after. `inset` sets all four
123
+ // edges, so assigning it last — which is what an object literal written in
124
+ // the obvious order does — silently wipes the `top` set two lines above and
125
+ // collapses the layer to nothing. The controls do not move; they vanish.
89
126
  if (layout.dualScreen && layout.bottom) {
90
- Object.assign(root.style, {
91
- top: `${layout.bottom.y}px`,
92
- bottom: '0px',
93
- inset: '',
94
- });
127
+ root.style.inset = '0';
128
+ root.style.top = `${layout.bottom.y}px`;
95
129
  }
96
130
  else {
97
- Object.assign(root.style, { inset: '0', top: '', bottom: '' });
131
+ root.style.inset = '0';
132
+ root.style.top = '';
98
133
  }
99
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umicat/three-sdk",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
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",