diff --git a/README.md b/README.md
index b62f95b..01cf212 100644
--- a/README.md
+++ b/README.md
@@ -357,7 +357,7 @@ It plays itself, so all of this is optional.
| scroll wheel | zoom |
| `Tab` | take the controls / give them back |
| `Esc` | give them back |
-| `P` | photo mode — freezes the world, you can still look and move |
+| `P` or `Space` | photo mode — freezes the world, you can still look and move (also the Pause button in the top bar) |
| `1` `2` `3` `4` | world: CyberCity, Frontier, Moonwalk, Edo (gamepad: `Y` / triangle cycles) |
| `T` | step the time of day (`Shift`+`T` steps back) |
| `Y` | stop / restart the automatic day cycle |
@@ -365,7 +365,7 @@ It plays itself, so all of this is optional.
| `[` `]` | cycle weather |
| `N` | new seed |
| `F` | fullscreen |
-| `H` | show the controls |
+| `?` or `H` | the help screen: every key, the touch gestures, and it pauses the city while open (also Help in the top bar) |
The weather presets are `clear, drizzle, rain, downpour, mist, storm` in the city,
`blazing, breeze, dust, squall, overcast, thunder` on the frontier, `clear, haze, tsuyu, shower,
diff --git a/build.js b/build.js
index 93cc2a8..ea7b9e1 100644
--- a/build.js
+++ b/build.js
@@ -319,11 +319,15 @@ for (const need of ['var CC', 'CC.City', 'CC.Surf', 'CC.Cast', 'CC.Canvas', 'CC.
/* The page is black before a single pixel of city is drawn — html, body and canvas all — so that
* entering fullscreen never flashes white and never shows a seam at an edge the canvas overhangs.
* The hint is CSS-only on purpose: it fades itself out and no JavaScript ever has to know it
- * existed, which keeps main.js free of anything resembling UI. */
-/* The baseline head block (description, canonical, Open Graph, JSON-LD) is written into
- * index.html by Carino-Systems/baseline/apply.py, between two marker comments. This build
- * regenerates index.html from scratch, so it carries that block over from the previous
- * output instead of dropping it. */
+ * existed, which keeps main.js free of anything resembling UI. Its wording is picked by
+ * (pointer: coarse) in CSS, so a phone reads "tap" from the first frame.
+ *
+ * The fleet chrome sits around the city, never in it: carino-ui.css (tokens and components,
+ * linked before the page's own style), carino-navbar.js with data-immersive (it slides away in
+ * fullscreen or after 3 s idle), carino-lang.js + i18n.js, and ui.js, which owns the help
+ * overlay and the pause button and talks to main.js only through window events. The body is
+ * Branding's play column: the navbar on top, .play-stage taking every remaining pixel, the
+ * canvas inside it. None of those files is part of the bundle. */
const PREV = fs.existsSync(OUT) ? fs.readFileSync(OUT, 'utf8') : '';
const BASELINE = (PREV.match(/\n/) || [''])[0];
@@ -336,41 +340,94 @@ const HTML = `
Four worlds drawn in text characters. Leave it alone and it walks itself; take the camera whenever you like. Opening this pauses the city.
+
+
Touch
+
Left half of the screen walks, right half looks. Tap the city for fullscreen.
+
+
+
WASD
Walk
+
←→↑↓
Look (or drag)
+
ShiftC
Run, crouch
+
1–4
Change world
+
[]
Change the weather
+
TY
Time of day, stop the clock
+
N
New city
+
Tab
Take or give back the camera
+
PSpace
Pause
+
F
Fullscreen
+
?H
Help
+
Esc
Close
+
+
No sound. Nothing is sent anywhere.
+
+
+
+
+
+
+
@@ -3577,6 +3626,11 @@ W("surf_west.js");
hintClose = t + HINT_IN + HINT_HOLD;
}
+ function setPaused(v) {
+ paused = v ? 1 : 0; Control.paused = paused;
+ if (hooksRef && hooksRef.paused) hooksRef.paused(paused);
+ }
+
var el = null;
var hooksRef = null;
@@ -3615,9 +3669,13 @@ W("surf_west.js");
hooks && hooks.now ? hooks.now() : 0); idle = 0;
if (doc.exitPointerLock) doc.exitPointerLock();
break;
- case 'KeyH': hintToggle(hooks && hooks.now ? hooks.now() : 0); break;
- case 'KeyP': paused = paused ? 0 : 1; Control.paused = paused; break;
+ case 'KeyH':
+ hintToggle(hooks && hooks.now ? hooks.now() : 0);
+ if (hooks && hooks.help) hooks.help();
+ break;
+
+ case 'KeyP': case 'Space': setPaused(!paused); e.preventDefault(); break;
case 'KeyF': if (hooks && hooks.fullscreen) hooks.fullscreen(); break;
case 'KeyN': if (hooks && hooks.reseed) hooks.reseed(); break;
@@ -3633,6 +3691,10 @@ W("surf_west.js");
default: hit = 0;
}
+ if (!hit && h === '?') {
+ if (hooks && hooks.help) hooks.help(); else hintToggle(hooks && hooks.now ? hooks.now() : 0);
+ hit = 2;
+ }
var dg = /^Digit[1-9]$/.test(c) ? parseInt(c.slice(5), 10)
: (h && h.length === 1 && h >= '1' && h <= '9' ? h.charCodeAt(0) - 48 : 0);
if (!hit && dg) {
@@ -3657,6 +3719,11 @@ W("surf_west.js");
win.addEventListener('keydown', function (e) {
if (e.metaKey || e.ctrlKey && e.code !== 'ControlLeft' || e.altKey) return;
+
+ if (hooks && hooks.blocked && hooks.blocked()) return;
+ var tg = e.target;
+ if (tg && (tg.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(tg.tagName || ''))) return;
+ if (e.code === 'Space' && tg && /^(BUTTON|A)$/.test(tg.tagName || '')) return;
if (e.repeat) { K.any = 1; return; }
if (set(e, 1) && e.code !== 'Tab') { }
});
@@ -3682,7 +3749,7 @@ W("surf_west.js");
if (!isTouch(e)) { mouseDrag = 1; mlx = e.clientX; mly = e.clientY; return; }
Control.touch = 1;
- var w = win.innerWidth || el.clientWidth || 800;
+ var w = el.clientWidth || win.innerWidth || 800;
if (e.clientX < w * 0.5) {
if (stickId < 0) { stickId = e.pointerId; stickX0 = e.clientX; stickY0 = e.clientY; }
} else if (lookId < 0) { lookId = e.pointerId; llx = e.clientX; lly = e.clientY; }
@@ -3755,6 +3822,7 @@ W("surf_west.js");
touch: 0,
paused: 0,
+ setPaused: function (v) { setPaused(v); },
hintAlpha: hintAlpha,
@@ -3770,6 +3838,7 @@ W("surf_west.js");
seedWanted = 0; padWorld = 0;
paused = 0; Control.paused = 0;
+ if (hooksRef && hooksRef.paused) hooksRef.paused(0);
hintOpen = 0; hintClose = HINT_IN + HINT_HOLD;
}
};
@@ -11969,9 +12038,16 @@ W("elements/west_town.js");
return w * zoom;
}
+ function stageSize() {
+ var p = canvas && canvas.parentNode;
+ var w = p && p.clientWidth, h = p && p.clientHeight;
+ return (w > 0 && h > 0) ? [w, h] : [window.innerWidth, window.innerHeight];
+ }
+
function layout() {
- var vw = Math.max(window.innerWidth || 320, 200);
- var vh = Math.max(window.innerHeight || 240, 160);
+ var sz = stageSize();
+ var vw = Math.max(sz[0] || 320, 200);
+ var vh = Math.max(sz[1] || 240, 160);
var dpr = Math.min(window.devicePixelRatio || 1, 2);
@@ -12104,6 +12180,15 @@ W("elements/west_town.js");
adapt(nowMs() - t0, now);
}
+ var modalOpen = false;
+ function emit(name, detail) {
+ try { window.dispatchEvent(new CustomEvent(name, { detail: detail })); } catch (err) { }
+ }
+
+ function onStage(e) {
+ var t = e && e.target;
+ return !modalOpen && !!e && !(t && t.closest && t.closest('#carinoNav, .modal-scrim, [data-carino-actions]'));
+ }
var rzT = 0;
function onResize() {
window.clearTimeout(rzT);
@@ -12131,6 +12216,9 @@ W("elements/west_town.js");
document.body.appendChild(canvas);
}
+ try {
+ if (CC.Control && window.matchMedia && window.matchMedia('(pointer: coarse)').matches) CC.Control.touch = 1;
+ } catch (err) { }
var mq = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)');
CC.reducedMotion = !!(mq && mq.matches);
if (mq && mq.addEventListener)
@@ -12155,6 +12243,14 @@ W("elements/west_town.js");
window.addEventListener('resize', onResize, { passive: true });
window.addEventListener('orientationchange', onResize, { passive: true });
+
+ if (typeof ResizeObserver === 'function' && canvas.parentNode && canvas.parentNode.nodeType === 1)
+ new ResizeObserver(onResize).observe(canvas.parentNode);
+ window.addEventListener('carino:navbar', onResize);
+ window.addEventListener('cybercity:modal', function (e) { modalOpen = !!(e && e.detail && e.detail.open); });
+ window.addEventListener('cybercity:pause', function (e) {
+ if (CC.Control && CC.Control.setPaused) CC.Control.setPaused(!!(e && e.detail && e.detail.paused));
+ });
document.addEventListener('fullscreenchange', onResize);
document.addEventListener('webkitfullscreenchange', onResize);
@@ -12166,9 +12262,9 @@ W("elements/west_town.js");
if (ns !== null && ns !== seed) moved = 1;
if (moved) build(ns === null ? seed : ns);
});
- window.addEventListener('pointerdown', goFullscreen, { passive: true });
+ window.addEventListener('pointerdown', function (e) { if (onStage(e)) goFullscreen(); }, { passive: true });
window.addEventListener('keydown', function (e) {
- if (!e.metaKey && !e.ctrlKey && !e.altKey) goFullscreen();
+ if (!e.metaKey && !e.ctrlKey && !e.altKey && onStage(e) && e.key !== 'Escape') goFullscreen();
});
if (CC.Control && CC.Control.attach) {
@@ -12176,6 +12272,9 @@ W("elements/west_town.js");
city: function () { return city; },
now: function () { return simT; },
fullscreen: goFullscreen,
+ help: function () { emit('cybercity:help', {}); },
+ blocked: function () { return modalOpen; },
+ paused: function (p) { emit('cybercity:paused', { paused: !!p }); },
reseed: function () {
var ns = (Math.random() * 4294967296) >>> 0;
seed = ns;
@@ -12192,8 +12291,8 @@ W("elements/west_town.js");
worldName: function () { return CC.World ? CC.World.name : ''; }
});
- window.addEventListener('pointerdown', function () {
- if (CC.Control.requestLook) CC.Control.requestLook();
+ window.addEventListener('pointerdown', function (e) {
+ if (onStage(e) && CC.Control.requestLook) CC.Control.requestLook();
}, { passive: true });
}
@@ -12217,5 +12316,9 @@ W("elements/west_town.js");
})();
+
+
+
+
diff --git a/src/control.js b/src/control.js
index 56d9704..fc7a5a6 100644
--- a/src/control.js
+++ b/src/control.js
@@ -476,6 +476,13 @@
hintClose = t + HINT_IN + HINT_HOLD;
}
+ /* Photo mode on and off, from P, Space or the page's pause button. hooksRef.paused hears every
+ * change so the page's own button and overlay can follow it. */
+ function setPaused(v) {
+ paused = v ? 1 : 0; Control.paused = paused;
+ if (hooksRef && hooksRef.paused) hooksRef.paused(paused);
+ }
+
/* ---- DOM ------------------------------------------------------------------------------------
* Everything below this line is skipped entirely when there is no window, which is what keeps
* the offline reference frame honest. */
@@ -519,13 +526,18 @@
hooks && hooks.now ? hooks.now() : 0); idle = 0;
if (doc.exitPointerLock) doc.exitPointerLock();
break;
- case 'KeyH': hintToggle(hooks && hooks.now ? hooks.now() : 0); break;
+ /* H (and ?) toggle the stencil hint as they always did, and also open the page's DOM
+ * help overlay when main.js wires one: the translated, readable twin of the stencil. */
+ case 'KeyH':
+ hintToggle(hooks && hooks.now ? hooks.now() : 0);
+ if (hooks && hooks.help) hooks.help();
+ break;
/* Photo mode. The flag is all this file owns — main.js reads Control.paused and stops
* stepping the world; what happens HERE is that the autopilot's clock is frozen with it
* (see update), so the pose under a paused city holds still whether or not a viewer is
* driving. Look and walk both keep working, which is the point: a still is something
* you compose, not something you take by accident. */
- case 'KeyP': paused = paused ? 0 : 1; Control.paused = paused; break;
+ case 'KeyP': case 'Space': setPaused(!paused); e.preventDefault(); break;
case 'KeyF': if (hooks && hooks.fullscreen) hooks.fullscreen(); break;
case 'KeyN': if (hooks && hooks.reseed) hooks.reseed(); break;
/* ---- the clock ------------------------------------------------------------------------
@@ -563,6 +575,11 @@
* for Digit1 on a US layout, '"' on a UK one, and so on), so the key path cannot read the
* digit and only the code path handles the weather — which is why the shifted branch is
* code-only and the unshifted one keeps both. */
+ // ? by the character it types, whatever key makes it on this layout.
+ if (!hit && h === '?') {
+ if (hooks && hooks.help) hooks.help(); else hintToggle(hooks && hooks.now ? hooks.now() : 0);
+ hit = 2;
+ }
var dg = /^Digit[1-9]$/.test(c) ? parseInt(c.slice(5), 10)
: (h && h.length === 1 && h >= '1' && h <= '9' ? h.charCodeAt(0) - 48 : 0);
if (!hit && dg) {
@@ -608,6 +625,12 @@
win.addEventListener('keydown', function (e) {
if (e.metaKey || e.ctrlKey && e.code !== 'ControlLeft' || e.altKey) return;
+ /* A dialog over the stage (the help overlay) owns the keyboard until it closes, a text field
+ * keeps its keys, and Space on a focused button presses the button, not photo mode. */
+ if (hooks && hooks.blocked && hooks.blocked()) return;
+ var tg = e.target;
+ if (tg && (tg.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(tg.tagName || ''))) return;
+ if (e.code === 'Space' && tg && /^(BUTTON|A)$/.test(tg.tagName || '')) return;
if (e.repeat) { K.any = 1; return; }
if (set(e, 1) && e.code !== 'Tab') { /* handled */ }
});
@@ -646,12 +669,12 @@
if (el.setPointerCapture) { try { el.setPointerCapture(e.pointerId); } catch (err) {} }
if (!isTouch(e)) { mouseDrag = 1; mlx = e.clientX; mly = e.clientY; return; }
/* The one bit elements/hud.js needs to know: this viewer has a thumb, not a keyboard, so the
- * hint must talk about halves of the screen rather than about WASD. It is latched on the
- * FIRST touch and never cleared — a device does not stop having a touchscreen, and clearing
+ * hint must talk about halves of the screen rather than about WASD. It is set at boot (main.js)
+ * on a coarse pointer, else latched on the FIRST touch, and never cleared — a device does not stop having a touchscreen, and clearing
* it in reset() would make N (which a touch viewer cannot press anyway) rewrite the hint.
* Never set without a DOM, so the offline reference frame keeps the keyboard wording. */
Control.touch = 1;
- var w = win.innerWidth || el.clientWidth || 800;
+ var w = el.clientWidth || win.innerWidth || 800;
if (e.clientX < w * 0.5) {
if (stickId < 0) { stickId = e.pointerId; stickX0 = e.clientX; stickY0 = e.clientY; }
} else if (lookId < 0) { lookId = e.pointerId; llx = e.clientX; lly = e.clientY; }
@@ -738,6 +761,7 @@
/* Photo mode, published for main.js to read. This file only owns the flag — see the KeyP
* case for what still has to happen at the other end. */
paused: 0,
+ setPaused: function (v) { setPaused(v); },
/* The hint overlay's envelope, as a pure function of the simulation clock. elements/hud.js is
* the only caller; it gets t handed to its draw() and asks here rather than keeping a clock of
* its own, so that H and the eight-second timer have exactly one implementation. */
@@ -758,6 +782,7 @@
/* N rebuilds the city and calls through here, and a new city that arrives paused is a viewer
* staring at a still they did not ask for. */
paused = 0; Control.paused = 0;
+ if (hooksRef && hooksRef.paused) hooksRef.paused(0);
hintOpen = 0; hintClose = HINT_IN + HINT_HOLD;
}
};
diff --git a/src/elements/ads.js b/src/elements/ads.js
index 8e80dfe..cc3f926 100644
--- a/src/elements/ads.js
+++ b/src/elements/ads.js
@@ -1,4 +1,5 @@
/* CyberCity ads — storey-scale lit media bolted to the building faces. Layer 34.
+ * Diegetic signage drawn into the city, not advertising: no third-party content, no network.
*
* WHAT THIS IS AND WHAT IT IS NOT. elements/signage.js owns everything at SHOPFRONT scale: the
* tubes over a door (neon, 30), the junction heads (31), the translucent panels (holo, 33) and the
diff --git a/src/main.js b/src/main.js
index 0b31580..b8f09fa 100644
--- a/src/main.js
+++ b/src/main.js
@@ -98,9 +98,19 @@
return w * zoom;
}
+ /* The stage the canvas sits in: everything under the fleet navbar, or the whole screen once the
+ * navbar has slid away (fullscreen, or idle). Without a laid-out parent (the DOM shim) it is
+ * the window, as it always was. */
+ function stageSize() {
+ var p = canvas && canvas.parentNode;
+ var w = p && p.clientWidth, h = p && p.clientHeight;
+ return (w > 0 && h > 0) ? [w, h] : [window.innerWidth, window.innerHeight];
+ }
+
function layout() {
- var vw = Math.max(window.innerWidth || 320, 200);
- var vh = Math.max(window.innerHeight || 240, 160);
+ var sz = stageSize();
+ var vw = Math.max(sz[0] || 320, 200);
+ var vh = Math.max(sz[1] || 240, 160);
/* Capped at 2. A phone at dpr 3 would triple the fill rate of the bloom taps to sharpen glyphs
* that are already sub-pixel-crisp at 2, and the bloom is where the frame budget goes. */
var dpr = Math.min(window.devicePixelRatio || 1, 2);
@@ -331,7 +341,24 @@
/* ---- DOM plumbing --------------------------------------------------------------------------
* Kept to the minimum the contract allows main to own: one canvas, one resize, one fullscreen
* gesture. The fade-out hint is pure CSS in index.html precisely so no code here has to know
- * about it or ever remove it. */
+ * about it or ever remove it. The fleet chrome (navbar, help overlay, pause button) lives in
+ * ui.js and talks to this file only through four window events, so the bundle still leaks
+ * nothing to window:
+ * cybercity:help main -> ui H or ? was pressed; open the help overlay
+ * cybercity:paused main -> ui photo mode changed, detail {paused}
+ * cybercity:pause ui -> main set photo mode, detail {paused}
+ * cybercity:modal ui -> main a dialog opened or closed, detail {open}; while open the
+ * keys belong to the dialog and nothing goes fullscreen */
+ var modalOpen = false;
+ function emit(name, detail) {
+ try { window.dispatchEvent(new CustomEvent(name, { detail: detail })); } catch (err) { }
+ }
+ /* A gesture on the city (the canvas) asks for fullscreen and the mouse-look; one on the navbar,
+ * a dialog or a button is about that control and asks for neither. */
+ function onStage(e) {
+ var t = e && e.target;
+ return !modalOpen && !!e && !(t && t.closest && t.closest('#carinoNav, .modal-scrim, [data-carino-actions]'));
+ }
var rzT = 0;
function onResize() {
window.clearTimeout(rzT);
@@ -368,6 +395,11 @@
}
/* Before ANY module initialises: elements read CC.reducedMotion at init time as well as in
* update, so setting it after boot would leave half the city un-damped. */
+ /* A coarse pointer means a thumb, so the stencil hint speaks touch from its first frame rather
+ * than after the first tap. Asked before the motion query, which is the one kept live. */
+ try {
+ if (CC.Control && window.matchMedia && window.matchMedia('(pointer: coarse)').matches) CC.Control.touch = 1;
+ } catch (err) { }
var mq = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)');
CC.reducedMotion = !!(mq && mq.matches);
if (mq && mq.addEventListener)
@@ -399,6 +431,15 @@
window.addEventListener('resize', onResize, { passive: true });
window.addEventListener('orientationchange', onResize, { passive: true });
+ /* The stage also changes size with no window event: the navbar sliding away or back
+ * (carino:navbar), or arriving at all after boot. */
+ if (typeof ResizeObserver === 'function' && canvas.parentNode && canvas.parentNode.nodeType === 1)
+ new ResizeObserver(onResize).observe(canvas.parentNode);
+ window.addEventListener('carino:navbar', onResize);
+ window.addEventListener('cybercity:modal', function (e) { modalOpen = !!(e && e.detail && e.detail.open); });
+ window.addEventListener('cybercity:pause', function (e) {
+ if (CC.Control && CC.Control.setPaused) CC.Control.setPaused(!!(e && e.detail && e.detail.paused));
+ });
document.addEventListener('fullscreenchange', onResize);
// goFullscreen already reaches for the webkit entry point; without its event too, a Safari
// that DID go fullscreen would keep drawing at the old grid until something else resized it.
@@ -414,9 +455,9 @@
if (ns !== null && ns !== seed) moved = 1; // same reason: navigating to #0 is a real move
if (moved) build(ns === null ? seed : ns);
});
- window.addEventListener('pointerdown', goFullscreen, { passive: true });
+ window.addEventListener('pointerdown', function (e) { if (onStage(e)) goFullscreen(); }, { passive: true });
window.addEventListener('keydown', function (e) {
- if (!e.metaKey && !e.ctrlKey && !e.altKey) goFullscreen();
+ if (!e.metaKey && !e.ctrlKey && !e.altKey && onStage(e) && e.key !== 'Escape') goFullscreen();
});
/* The keys. `hooks` is how control.js reaches back into main without importing it — it owns
@@ -426,6 +467,9 @@
city: function () { return city; },
now: function () { return simT; },
fullscreen: goFullscreen,
+ help: function () { emit('cybercity:help', {}); },
+ blocked: function () { return modalOpen; },
+ paused: function (p) { emit('cybercity:paused', { paused: !!p }); },
reseed: function () {
var ns = (Math.random() * 4294967296) >>> 0;
seed = ns;
@@ -447,8 +491,8 @@
});
/* Pointer lock is a mouse-look, and a mouse-look nobody asked for is a trap: it is only
* requested on a real click, which is also the gesture that goes fullscreen. */
- window.addEventListener('pointerdown', function () {
- if (CC.Control.requestLook) CC.Control.requestLook();
+ window.addEventListener('pointerdown', function (e) {
+ if (onStage(e) && CC.Control.requestLook) CC.Control.requestLook();
}, { passive: true });
}
diff --git a/tools/domshim.cjs b/tools/domshim.cjs
index ad30619..799095f 100644
--- a/tools/domshim.cjs
+++ b/tools/domshim.cjs
@@ -63,6 +63,13 @@ while ((t = TAG.exec(html))) {
if (/\btype\s*=\s*["']?application\/ld\+json/i.test(attrs)) { JSON.parse(t[2]); continue; }
if (/\btype\s*=/i.test(attrs)) throw new Error('domshim: unexpected