castle-web-cli 0.4.229 → 0.4.231
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/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +860 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +126 -9
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +99 -14
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +406 -53
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +158 -8
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +149 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1035 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1518 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +117 -5
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +527 -5
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +187 -5
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,1035 @@
|
|
|
1
|
+
// The hub's own chrome: DOM drawn by the place, never by a game's content, so a
|
|
2
|
+
// game cannot hide or fake it (contract: "Hub-owned UI"). The door cover, the
|
|
3
|
+
// Back control, the declared HUD, actor labels and speech, the result ribbon,
|
|
4
|
+
// the avatar picker (with a Graphics row in a deck with device tiers), the NPC
|
|
5
|
+
// talk button and panel, a town's door list (jump to a door), the people here and the player's friends, each friend with
|
|
6
|
+
// where they are and Join, each player with Report (where the host takes
|
|
7
|
+
// reports), the pointers to friends out of sight,
|
|
8
|
+
// the Grab / Throw button (a place with `grab`, v1.3), the emote picker and
|
|
9
|
+
// the Sit / Stand button (a place with `idle`, v1.6), an arcade cabinet's
|
|
10
|
+
// board card (v1.7), and the frame-rate readout behind `?hubstats`.
|
|
11
|
+
|
|
12
|
+
import { cardMode, makeCardView, tapCard } from './cabinets.js';
|
|
13
|
+
import { guardScrollKeys } from './keys.js';
|
|
14
|
+
|
|
15
|
+
const Z = 2147480000;
|
|
16
|
+
|
|
17
|
+
function el(tag, style, parent = document.body) {
|
|
18
|
+
const node = document.createElement(tag);
|
|
19
|
+
Object.assign(node.style, style);
|
|
20
|
+
parent.appendChild(node);
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onLeaveParty = () => {}, onReportChat = () => {} }) {
|
|
25
|
+
const unguardKeys = guardScrollKeys();
|
|
26
|
+
// A desktop stage (a mouse, room to spare): NPC lines are narrower and the
|
|
27
|
+
// talk panel sits in the bottom-left corner, clear of the avatar. Phones
|
|
28
|
+
// and narrow stages keep the layout they were tuned on.
|
|
29
|
+
const desktopQuery = globalThis.matchMedia?.('(pointer: fine) and (min-width: 700px)') ?? null;
|
|
30
|
+
const desktop = () => desktopQuery?.matches === true;
|
|
31
|
+
const root = el('div', { position: 'fixed', inset: '0', pointerEvents: 'none', zIndex: String(Z), font: '600 15px/1.3 system-ui, sans-serif', color: '#fff' });
|
|
32
|
+
|
|
33
|
+
// The door cover: a dark warm field the door animation fades to, with the
|
|
34
|
+
// destination named in it. It sits over everything while a scene swaps.
|
|
35
|
+
const cover = el('div', { position: 'absolute', inset: '0', opacity: '0', background: 'radial-gradient(ellipse at center, #2a1d14 0%, #0b0806 70%)', display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'none' }, root);
|
|
36
|
+
const coverText = el('div', { opacity: '0.85', letterSpacing: '0.12em', textTransform: 'uppercase', fontSize: '14px', color: '#e9c48f' }, cover);
|
|
37
|
+
|
|
38
|
+
const back = el('button', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '12px', pointerEvents: 'auto', padding: '9px 16px 9px 12px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.35)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
|
|
39
|
+
back.textContent = '‹ Town';
|
|
40
|
+
back.addEventListener('pointerdown', (event) => {
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
onBack();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const hud = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: '0 1px 3px rgba(0,0,0,0.8)', display: 'none', maxWidth: '70vw' }, root);
|
|
46
|
+
const hudTitle = el('div', { fontSize: '13px', opacity: '0.85', letterSpacing: '0.06em', textTransform: 'uppercase' }, hud);
|
|
47
|
+
const hudBig = el('div', { fontSize: '56px', fontWeight: '800', lineHeight: '1.05' }, hud);
|
|
48
|
+
const hudText = el('div', { fontSize: '14px', fontWeight: '500' }, hud);
|
|
49
|
+
|
|
50
|
+
const labels = el('div', { position: 'absolute', inset: '0' }, root);
|
|
51
|
+
const labelNodes = new Map();
|
|
52
|
+
|
|
53
|
+
// An arcade cabinet's card (v1.7). By the cabinet it is a chip: the best
|
|
54
|
+
// score and whose it is (their photo in a circle, their frame drawn over it
|
|
55
|
+
// a little larger, the way classic decks draw an avatar), small enough that
|
|
56
|
+
// the cabinets and the town behind them stay in view. A tap on the chip
|
|
57
|
+
// opens the board: the classic deck's cover, title and label and its top
|
|
58
|
+
// scores. A tap on the board, or walking away, closes it. Over the labels,
|
|
59
|
+
// so a pad's words never cut through a row; it is never drawn during a
|
|
60
|
+
// trip, so the door cover needs not hide it.
|
|
61
|
+
const cabinet = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', boxSizing: 'border-box', background: 'rgba(18,14,24,0.92)', border: '1px solid rgba(255,255,255,0.18)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', font: '600 13px/1.25 system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
|
|
62
|
+
cabinet.dataset.hub = 'cabinet';
|
|
63
|
+
let cabinetKey = '';
|
|
64
|
+
// Whose board this player opened, if any: one at a time (`cabinets.js`).
|
|
65
|
+
const cabinetView = makeCardView();
|
|
66
|
+
cabinet.addEventListener('pointerdown', (event) => {
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
tapCard(cabinetView);
|
|
69
|
+
});
|
|
70
|
+
const picture = (parent, src, style) => {
|
|
71
|
+
const img = el('img', { display: 'block', objectFit: 'cover', ...style }, parent);
|
|
72
|
+
img.alt = '';
|
|
73
|
+
img.draggable = false;
|
|
74
|
+
img.src = src;
|
|
75
|
+
return img;
|
|
76
|
+
};
|
|
77
|
+
// A player's photo `size` pixels across, their frame over it.
|
|
78
|
+
function faceOf(parent, row, size, imageOf) {
|
|
79
|
+
const px = `${size}px`;
|
|
80
|
+
const face = el('div', { position: 'relative', width: px, height: px, flex: 'none' }, parent);
|
|
81
|
+
const photo = imageOf(row.photo);
|
|
82
|
+
if (photo) {
|
|
83
|
+
picture(face, photo, { width: px, height: px, borderRadius: '50%', background: '#2a2433' });
|
|
84
|
+
} else {
|
|
85
|
+
const blank = el('div', { width: px, height: px, borderRadius: '50%', background: '#4a4458', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: `${Math.round(size * 0.46)}px` }, face);
|
|
86
|
+
blank.textContent = String(row.username ?? '?').slice(0, 1).toUpperCase();
|
|
87
|
+
}
|
|
88
|
+
const frame = imageOf(row.frame);
|
|
89
|
+
if (frame) {
|
|
90
|
+
// The frame sits over the photo and is 30% larger than it.
|
|
91
|
+
picture(face, frame, { position: 'absolute', left: '-15%', top: '-15%', width: '130%', height: '130%', objectFit: 'contain', pointerEvents: 'none' });
|
|
92
|
+
}
|
|
93
|
+
return face;
|
|
94
|
+
}
|
|
95
|
+
// The chip: the best score. False when the cabinet has no score to show,
|
|
96
|
+
// and nothing is drawn (its pad already says what it plays).
|
|
97
|
+
function buildCabinetChip(card, imageOf) {
|
|
98
|
+
cabinet.replaceChildren();
|
|
99
|
+
const best = Array.isArray(card.top) ? card.top[0] : null;
|
|
100
|
+
if (!best) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
Object.assign(cabinet.style, { width: 'auto', padding: '3px 9px 3px 4px', borderRadius: '15px', pointerEvents: 'auto' });
|
|
104
|
+
cabinet.setAttribute('role', 'button');
|
|
105
|
+
cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: show the scores`);
|
|
106
|
+
const line = el('div', { display: 'flex', alignItems: 'center', gap: '7px', fontSize: '12px', whiteSpace: 'nowrap' }, cabinet);
|
|
107
|
+
faceOf(line, best, 20, imageOf);
|
|
108
|
+
const score = el('div', { fontWeight: '800', fontVariantNumeric: 'tabular-nums', maxWidth: '84px', overflow: 'hidden', textOverflow: 'ellipsis' }, line);
|
|
109
|
+
score.textContent = String(best.score ?? '');
|
|
110
|
+
const more = el('div', { opacity: '0.6', fontSize: '11px' }, line);
|
|
111
|
+
more.textContent = '▾';
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
function buildCabinetBoard(card, imageOf) {
|
|
115
|
+
cabinet.replaceChildren();
|
|
116
|
+
Object.assign(cabinet.style, { width: '204px', padding: '10px', borderRadius: '12px', pointerEvents: 'auto' });
|
|
117
|
+
cabinet.setAttribute('role', 'button');
|
|
118
|
+
cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: hide the scores`);
|
|
119
|
+
const head = el('div', { display: 'flex', gap: '10px', alignItems: 'center' }, cabinet);
|
|
120
|
+
const cover = imageOf(card.cover);
|
|
121
|
+
if (cover) {
|
|
122
|
+
picture(head, cover, { width: '54px', height: '76px', borderRadius: '6px', flex: 'none', background: '#2a2433' });
|
|
123
|
+
}
|
|
124
|
+
const words = el('div', { minWidth: '0', flex: '1' }, head);
|
|
125
|
+
const title = el('div', { fontSize: '15px', fontWeight: '800', overflow: 'hidden', display: '-webkit-box', webkitLineClamp: '2', webkitBoxOrient: 'vertical' }, words);
|
|
126
|
+
title.textContent = card.title || 'Arcade';
|
|
127
|
+
if (card.label) {
|
|
128
|
+
const label = el('div', { marginTop: '3px', fontSize: '11px', letterSpacing: '0.08em', textTransform: 'uppercase', color: '#e9c48f' }, words);
|
|
129
|
+
label.textContent = card.label;
|
|
130
|
+
}
|
|
131
|
+
const close = el('div', { alignSelf: 'flex-start', flex: 'none', width: '20px', height: '20px', borderRadius: '10px', background: 'rgba(255,255,255,0.14)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '13px', lineHeight: '1' }, head);
|
|
132
|
+
close.textContent = '×';
|
|
133
|
+
const top = Array.isArray(card.top) ? card.top.slice(0, 5) : [];
|
|
134
|
+
top.forEach((row, i) => {
|
|
135
|
+
const line = el('div', { display: 'flex', alignItems: 'center', gap: '9px', marginTop: i === 0 ? '10px' : '7px' }, cabinet);
|
|
136
|
+
const rank = el('div', { width: '10px', flex: 'none', textAlign: 'right', opacity: '0.6', fontSize: '12px' }, line);
|
|
137
|
+
rank.textContent = String(i + 1);
|
|
138
|
+
faceOf(line, row, 28, imageOf);
|
|
139
|
+
const name = el('div', { flex: '1', minWidth: '0', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, line);
|
|
140
|
+
name.textContent = String(row.username ?? '?');
|
|
141
|
+
const score = el('div', { flex: 'none', fontWeight: '800', fontVariantNumeric: 'tabular-nums' }, line);
|
|
142
|
+
score.textContent = String(row.score ?? '');
|
|
143
|
+
});
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const ribbon = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '6px', background: 'linear-gradient(#f2c94c, #d69e2e)', color: '#3b2600', fontSize: '13px', fontWeight: '800', whiteSpace: 'nowrap', boxShadow: '0 2px 6px rgba(0,0,0,0.4)' }, root);
|
|
148
|
+
|
|
149
|
+
const toast = el('div', { position: 'absolute', bottom: '64px', left: '50%', transform: 'translateX(-50%)', padding: '8px 14px', borderRadius: '8px', background: 'rgba(20,16,12,0.8)', fontSize: '14px', display: 'none' }, root);
|
|
150
|
+
|
|
151
|
+
// The avatar picker: one button, "Character", that opens the kit's
|
|
152
|
+
// characters under their own heading. (Four bare numbers read as rooms.)
|
|
153
|
+
const picker = el('div', { position: 'absolute', right: '10px', bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'none', flexDirection: 'column', alignItems: 'flex-end', gap: '6px', pointerEvents: 'auto' }, root);
|
|
154
|
+
picker.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
155
|
+
const pickerCard = el('div', { display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, picker);
|
|
156
|
+
el('div', { fontSize: '12px', opacity: '0.8' }, pickerCard).textContent = 'Your character';
|
|
157
|
+
const pickerRow = el('div', { display: 'flex', gap: '6px' }, pickerCard);
|
|
158
|
+
const pickerButtons = [];
|
|
159
|
+
let pickerOpen = false;
|
|
160
|
+
const setPickerOpen = (open) => {
|
|
161
|
+
pickerOpen = open;
|
|
162
|
+
pickerCard.style.display = open ? 'flex' : 'none';
|
|
163
|
+
};
|
|
164
|
+
for (let i = 0; i < avatarCount; i += 1) {
|
|
165
|
+
const button = el('button', { width: '34px', height: '34px', borderRadius: '17px', border: '2px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '700 13px system-ui', cursor: 'pointer' }, pickerRow);
|
|
166
|
+
button.textContent = String(i + 1);
|
|
167
|
+
button.setAttribute('aria-label', `Character ${i + 1}`);
|
|
168
|
+
button.addEventListener('pointerdown', (event) => {
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
setPickerOpen(false);
|
|
171
|
+
onAvatar(i);
|
|
172
|
+
});
|
|
173
|
+
pickerButtons.push(button);
|
|
174
|
+
}
|
|
175
|
+
const pickerToggle = el('button', { padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', cursor: 'pointer' }, picker);
|
|
176
|
+
pickerToggle.textContent = 'Character';
|
|
177
|
+
// Graphics: Auto / Low / High, under the characters, in a deck that has
|
|
178
|
+
// device tiers (`tiers.js`). Built on the first `setGraphics`, so a deck
|
|
179
|
+
// without them draws the card as it always was.
|
|
180
|
+
let graphics = null;
|
|
181
|
+
function buildGraphics() {
|
|
182
|
+
const row = el('div', { display: 'flex', alignItems: 'center', gap: '6px', marginTop: '2px' }, pickerCard);
|
|
183
|
+
el('div', { fontSize: '12px', opacity: '0.8', flex: '1' }, row).textContent = 'Graphics';
|
|
184
|
+
const buttons = new Map();
|
|
185
|
+
for (const [mode, text] of [['auto', 'Auto'], ['low', 'Low'], ['high', 'High']]) {
|
|
186
|
+
const button = el('button', { padding: '4px 9px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '600 12px system-ui, sans-serif', cursor: 'pointer' }, row);
|
|
187
|
+
button.textContent = text;
|
|
188
|
+
button.setAttribute('aria-label', `Graphics: ${text}`);
|
|
189
|
+
button.addEventListener('pointerdown', (event) => {
|
|
190
|
+
event.stopPropagation();
|
|
191
|
+
graphics.onPick(mode);
|
|
192
|
+
});
|
|
193
|
+
buttons.set(mode, button);
|
|
194
|
+
}
|
|
195
|
+
return { buttons, onPick: () => {} };
|
|
196
|
+
}
|
|
197
|
+
pickerToggle.addEventListener('pointerdown', (event) => {
|
|
198
|
+
event.stopPropagation();
|
|
199
|
+
setPickerOpen(!pickerOpen);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Talking to an NPC: a button when one is near, and a panel while a
|
|
203
|
+
// conversation is open. Keys typed here are the panel's, not the game's.
|
|
204
|
+
let talkHandlers = { open() {}, send() {}, end() {} };
|
|
205
|
+
const talkButton = el('button', { position: 'absolute', bottom: 'max(64px, calc(env(safe-area-inset-bottom) + 54px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 18px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
|
|
206
|
+
talkButton.addEventListener('pointerdown', (event) => {
|
|
207
|
+
event.stopPropagation();
|
|
208
|
+
talkHandlers.open();
|
|
209
|
+
});
|
|
210
|
+
const panel = el('div', { position: 'absolute', left: '50%', bottom: 'max(12px, env(safe-area-inset-bottom))', transform: 'translateX(-50%)', width: 'min(92vw, 420px)', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '10px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
211
|
+
const panelHead = el('div', { display: 'flex', alignItems: 'baseline', gap: '8px' }, panel);
|
|
212
|
+
const panelName = el('div', { fontWeight: '700', flex: '1' }, panelHead);
|
|
213
|
+
const panelEnd = el('button', { pointerEvents: 'auto', padding: '4px 10px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.35)', background: 'transparent', color: '#fff', font: '600 13px system-ui, sans-serif', cursor: 'pointer' }, panelHead);
|
|
214
|
+
panelEnd.textContent = 'Done';
|
|
215
|
+
panelEnd.addEventListener('pointerdown', (event) => {
|
|
216
|
+
event.stopPropagation();
|
|
217
|
+
talkHandlers.end();
|
|
218
|
+
});
|
|
219
|
+
const panelLog = el('div', { maxHeight: '28vh', overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '4px', fontSize: '14px', fontWeight: '500' }, panel);
|
|
220
|
+
// Not a <form>: castle.xyz plays a deck in a frame sandboxed without
|
|
221
|
+
// `allow-forms`, where a form's submission (Enter, or a submit button) is
|
|
222
|
+
// blocked before its submit event fires, so nothing would ever be said.
|
|
223
|
+
const panelForm = el('div', { display: 'flex', gap: '6px', margin: '0' }, panel);
|
|
224
|
+
const panelInput = el('input', { flex: '1', minWidth: '0', padding: '8px 10px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 15px system-ui, sans-serif' }, panelForm);
|
|
225
|
+
panelInput.maxLength = 280;
|
|
226
|
+
panelInput.placeholder = 'Say something…';
|
|
227
|
+
panelInput.enterKeyHint = 'send';
|
|
228
|
+
const panelSend = el('button', { padding: '8px 14px', borderRadius: '8px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 14px system-ui, sans-serif', cursor: 'pointer' }, panelForm);
|
|
229
|
+
panelSend.type = 'button';
|
|
230
|
+
panelSend.textContent = 'Say';
|
|
231
|
+
const submitTalk = () => {
|
|
232
|
+
const text = panelInput.value;
|
|
233
|
+
panelInput.value = '';
|
|
234
|
+
talkHandlers.send(text);
|
|
235
|
+
};
|
|
236
|
+
for (const type of ['keydown', 'keyup', 'keypress']) {
|
|
237
|
+
panelInput.addEventListener(type, (event) => event.stopPropagation());
|
|
238
|
+
}
|
|
239
|
+
panelInput.addEventListener('keydown', (event) => {
|
|
240
|
+
// An IME's own Enter (confirm) or Escape (cancel) belongs to the candidate;
|
|
241
|
+
// WebKit reports the confirming Enter as keyCode 229 with isComposing false.
|
|
242
|
+
if (event.isComposing || event.keyCode === 229) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (event.key === 'Enter') {
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
submitTalk();
|
|
248
|
+
} else if (event.key === 'Escape') {
|
|
249
|
+
event.preventDefault();
|
|
250
|
+
talkHandlers.end();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
panel.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
254
|
+
panelSend.addEventListener('click', (event) => {
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
submitTalk();
|
|
257
|
+
});
|
|
258
|
+
let talkOpen = false;
|
|
259
|
+
const layoutPanel = () => {
|
|
260
|
+
const wide = desktop();
|
|
261
|
+
Object.assign(panel.style, wide
|
|
262
|
+
? { left: '10px', transform: 'none', width: '340px' }
|
|
263
|
+
: { left: '50%', transform: 'translateX(-50%)', width: 'min(92vw, 420px)' });
|
|
264
|
+
panelLog.style.maxHeight = wide ? 'min(28vh, 220px)' : '28vh';
|
|
265
|
+
};
|
|
266
|
+
layoutPanel();
|
|
267
|
+
desktopQuery?.addEventListener?.('change', layoutPanel);
|
|
268
|
+
|
|
269
|
+
// Grab / Throw (v1.3): a big thumb button bottom right, above the avatar
|
|
270
|
+
// picker, shown while there is something to grab or something held.
|
|
271
|
+
let grabHandler = () => {};
|
|
272
|
+
const grabButton = el('button', { position: 'absolute', right: '14px', bottom: 'max(60px, calc(env(safe-area-inset-bottom) + 50px))', width: '76px', height: '76px', borderRadius: '38px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.55)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '800 16px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
|
|
273
|
+
grabButton.addEventListener('pointerdown', (event) => {
|
|
274
|
+
event.stopPropagation();
|
|
275
|
+
event.preventDefault();
|
|
276
|
+
grabHandler();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Idle play (v1.6): an emote button above Grab that opens a row of emotes
|
|
280
|
+
// to its left, and Sit / Stand at the bottom centre, above Talk.
|
|
281
|
+
let emoteHandler = () => {};
|
|
282
|
+
let sitHandler = () => {};
|
|
283
|
+
const emoteBottom = 'max(146px, calc(env(safe-area-inset-bottom) + 136px))';
|
|
284
|
+
const emoteButton = el('button', { position: 'absolute', right: '20px', bottom: emoteBottom, width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '24px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
|
|
285
|
+
emoteButton.textContent = '☺';
|
|
286
|
+
emoteButton.setAttribute('aria-label', 'Emote');
|
|
287
|
+
const emoteRow = el('div', { position: 'absolute', right: '80px', bottom: emoteBottom, display: 'none', gap: '6px', pointerEvents: 'auto', padding: '4px', borderRadius: '28px', background: 'rgba(20,16,12,0.78)' }, root);
|
|
288
|
+
emoteRow.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
289
|
+
let emotesOpen = false;
|
|
290
|
+
let emotesKey = '';
|
|
291
|
+
const setEmotesOpen = (open) => {
|
|
292
|
+
emotesOpen = open;
|
|
293
|
+
emoteRow.style.display = open ? 'flex' : 'none';
|
|
294
|
+
};
|
|
295
|
+
emoteButton.addEventListener('pointerdown', (event) => {
|
|
296
|
+
event.stopPropagation();
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
setEmotesOpen(!emotesOpen);
|
|
299
|
+
});
|
|
300
|
+
// Quick reactions and phrases (v1.11): a speech button beside the emote
|
|
301
|
+
// button opens a small card, a row of emoji over the place's phrases; and
|
|
302
|
+
// the feed of what was just said, small, above the dock.
|
|
303
|
+
let sayHandler = () => {};
|
|
304
|
+
const sayButton = el('button', { position: 'absolute', right: '20px', bottom: 'max(206px, calc(env(safe-area-inset-bottom) + 196px))', width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '22px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
|
|
305
|
+
sayButton.textContent = '💬';
|
|
306
|
+
sayButton.setAttribute('aria-label', 'Quick chat');
|
|
307
|
+
const sayCard = el('div', { position: 'absolute', right: '80px', bottom: 'max(146px, calc(env(safe-area-inset-bottom) + 136px))', width: 'min(70vw, 236px)', display: 'none', flexDirection: 'column', gap: '6px', pointerEvents: 'auto', padding: '8px', borderRadius: '14px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
308
|
+
sayCard.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
309
|
+
let sayOpen = false;
|
|
310
|
+
let sayKey = '';
|
|
311
|
+
let sayInput = null;
|
|
312
|
+
let sayNote = null;
|
|
313
|
+
const setSayOpen = (open) => {
|
|
314
|
+
sayOpen = open;
|
|
315
|
+
sayCard.style.display = open ? 'flex' : 'none';
|
|
316
|
+
};
|
|
317
|
+
sayButton.addEventListener('pointerdown', (event) => {
|
|
318
|
+
event.stopPropagation();
|
|
319
|
+
event.preventDefault();
|
|
320
|
+
setSayOpen(!sayOpen);
|
|
321
|
+
setEmotesOpen(false);
|
|
322
|
+
});
|
|
323
|
+
const feed = el('div', { position: 'absolute', left: '10px', bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: '0 1px 3px rgba(0,0,0,0.85)', opacity: '0.92' }, root);
|
|
324
|
+
let feedKey = '';
|
|
325
|
+
const sitButton = el('button', { position: 'absolute', bottom: 'max(112px, calc(env(safe-area-inset-bottom) + 102px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 22px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer', touchAction: 'manipulation' }, root);
|
|
326
|
+
sitButton.addEventListener('pointerdown', (event) => {
|
|
327
|
+
event.stopPropagation();
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
sitHandler();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Bottom left: the town's Doors, then People, side by side -- or People
|
|
333
|
+
// above Doors where a narrow screen leaves no room beside the avatar picker.
|
|
334
|
+
const dock = el('div', { position: 'absolute', left: '10px', bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'flex', flexWrap: 'wrap-reverse', alignItems: 'flex-start', gap: '6px', maxWidth: 'calc(100vw - 130px)' }, root);
|
|
335
|
+
// A list opens just above the dock, however tall the dock is.
|
|
336
|
+
const aboveDock = (list) => {
|
|
337
|
+
list.style.bottom = `calc(max(10px, env(safe-area-inset-bottom)) + ${dock.offsetHeight + 6}px)`;
|
|
338
|
+
};
|
|
339
|
+
const doorsButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
|
|
340
|
+
doorsButton.textContent = 'Doors';
|
|
341
|
+
// The town's doors: the list opens above the dock, one list at a time, and
|
|
342
|
+
// Go puts the player in front of that door.
|
|
343
|
+
const doorsList = el('div', { position: 'absolute', left: '10px', bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
344
|
+
doorsList.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
345
|
+
let doorsOpen = false;
|
|
346
|
+
let doorsKey = '';
|
|
347
|
+
function closeDoors() {
|
|
348
|
+
doorsOpen = false;
|
|
349
|
+
doorsList.style.display = 'none';
|
|
350
|
+
}
|
|
351
|
+
doorsButton.addEventListener('pointerdown', (event) => {
|
|
352
|
+
event.stopPropagation();
|
|
353
|
+
doorsOpen = !doorsOpen;
|
|
354
|
+
aboveDock(doorsList);
|
|
355
|
+
doorsList.style.display = doorsOpen ? 'flex' : 'none';
|
|
356
|
+
closePeople();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// The other players here, each with Report behind a confirm. Hub chrome
|
|
360
|
+
// only: a game's content cannot draw, hide or press it.
|
|
361
|
+
const peopleButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
|
|
362
|
+
const peopleList = el('div', { position: 'absolute', left: '10px', bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
363
|
+
peopleList.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
364
|
+
let peopleOpen = false;
|
|
365
|
+
let peopleKey = '';
|
|
366
|
+
function closePeople() {
|
|
367
|
+
peopleOpen = false;
|
|
368
|
+
peopleList.style.display = 'none';
|
|
369
|
+
}
|
|
370
|
+
peopleButton.addEventListener('pointerdown', (event) => {
|
|
371
|
+
event.stopPropagation();
|
|
372
|
+
peopleOpen = !peopleOpen;
|
|
373
|
+
aboveDock(peopleList);
|
|
374
|
+
peopleList.style.display = peopleOpen ? 'flex' : 'none';
|
|
375
|
+
closeDoors();
|
|
376
|
+
});
|
|
377
|
+
const smallButton = (parent, text, primary) => {
|
|
378
|
+
const button = el('button', { padding: '5px 12px', borderRadius: '12px', border: primary ? 'none' : '1px solid rgba(255,255,255,0.35)', background: primary ? '#e9c48f' : 'transparent', color: primary ? '#2b2118' : '#fff', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, parent);
|
|
379
|
+
button.textContent = text;
|
|
380
|
+
return button;
|
|
381
|
+
};
|
|
382
|
+
// One row: the name, with where they are under it in a town, and the
|
|
383
|
+
// row's actions (`person.actions`, [{ id, text }]): the first beside the
|
|
384
|
+
// name, the rest behind a "more" button on a line under it. Report asks
|
|
385
|
+
// first: the question, then Report / Cancel. Returns the node its `where`
|
|
386
|
+
// words live in, so they change without the row being rebuilt.
|
|
387
|
+
function personRow(person) {
|
|
388
|
+
const box = el('div', { display: 'flex', flexDirection: 'column', gap: '4px' }, peopleList);
|
|
389
|
+
let whereNode = null;
|
|
390
|
+
let more = false;
|
|
391
|
+
const act = (parent, action, primary) => {
|
|
392
|
+
smallButton(parent, action.text, primary).addEventListener('pointerdown', (event) => {
|
|
393
|
+
event.stopPropagation();
|
|
394
|
+
if (action.id === 'report') {
|
|
395
|
+
draw(true);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
closePeople();
|
|
399
|
+
onPerson(person, action.id);
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
const draw = (confirming) => {
|
|
403
|
+
box.replaceChildren();
|
|
404
|
+
const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, box);
|
|
405
|
+
const words = el('div', { flex: '1', minWidth: '0' }, row);
|
|
406
|
+
const name = el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
|
|
407
|
+
const who = person.username ?? 'this player';
|
|
408
|
+
name.textContent = confirming ? `Report ${who}?` : `${person.mark ?? ''}${who}`;
|
|
409
|
+
whereNode = null;
|
|
410
|
+
if (confirming) {
|
|
411
|
+
smallButton(row, 'Report', true).addEventListener('pointerdown', (event) => {
|
|
412
|
+
event.stopPropagation();
|
|
413
|
+
closePeople();
|
|
414
|
+
draw(false);
|
|
415
|
+
onReport(person);
|
|
416
|
+
});
|
|
417
|
+
smallButton(row, 'Cancel', false).addEventListener('pointerdown', (event) => {
|
|
418
|
+
event.stopPropagation();
|
|
419
|
+
draw(false);
|
|
420
|
+
});
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (person.where) {
|
|
424
|
+
whereNode = el('div', { fontSize: '12px', fontWeight: '500', opacity: '0.75', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
|
|
425
|
+
whereNode.textContent = person.where;
|
|
426
|
+
}
|
|
427
|
+
const [first, ...rest] = person.actions ?? [];
|
|
428
|
+
if (first) {
|
|
429
|
+
act(row, first, first.id !== 'report' && first.id !== 'find');
|
|
430
|
+
}
|
|
431
|
+
if (rest.length) {
|
|
432
|
+
const toggle = smallButton(row, '⋯', false);
|
|
433
|
+
toggle.setAttribute('aria-label', `More for ${who}`);
|
|
434
|
+
toggle.style.padding = '5px 8px';
|
|
435
|
+
toggle.addEventListener('pointerdown', (event) => {
|
|
436
|
+
event.stopPropagation();
|
|
437
|
+
more = !more;
|
|
438
|
+
draw(false);
|
|
439
|
+
});
|
|
440
|
+
if (more) {
|
|
441
|
+
const line = el('div', { display: 'flex', justifyContent: 'flex-end', gap: '6px' }, box);
|
|
442
|
+
for (const action of rest) {
|
|
443
|
+
act(line, action, false);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
draw(false);
|
|
449
|
+
return { setWhere: (text) => whereNode && whereNode.textContent !== text && (whereNode.textContent = text) };
|
|
450
|
+
}
|
|
451
|
+
const peopleRows = new Map();
|
|
452
|
+
|
|
453
|
+
// Pointers to friends out of sight (a town): a small chip over a friend far
|
|
454
|
+
// off, or at the screen's edge with an arrow when they are off screen.
|
|
455
|
+
const pointers = el('div', { position: 'absolute', inset: '0' }, root);
|
|
456
|
+
const pointerNodes = new Map();
|
|
457
|
+
|
|
458
|
+
// A question put to the player (v1.10): an invitation to a party, a door
|
|
459
|
+
// their party wants to go through. One at a time, under the HUD.
|
|
460
|
+
const askCard = el('div', { position: 'absolute', top: 'max(92px, calc(env(safe-area-inset-top) + 80px))', left: '50%', transform: 'translateX(-50%)', width: 'min(86vw, 320px)', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', alignItems: 'center', gap: '8px', padding: '8px 10px', borderRadius: '12px', background: 'rgba(20,16,12,0.9)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', fontSize: '14px' }, root);
|
|
461
|
+
askCard.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
462
|
+
let askKey = '';
|
|
463
|
+
let askNow = null;
|
|
464
|
+
// Standing by someone who is not in the player's party: invite them.
|
|
465
|
+
let nearHandler = () => {};
|
|
466
|
+
const nearButton = el('button', { position: 'absolute', bottom: 'max(160px, calc(env(safe-area-inset-bottom) + 150px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '6px 14px', borderRadius: '16px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '600 13px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', maxWidth: '80vw', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, root);
|
|
467
|
+
nearButton.addEventListener('pointerdown', (event) => {
|
|
468
|
+
event.stopPropagation();
|
|
469
|
+
event.preventDefault();
|
|
470
|
+
nearHandler();
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const stats = el('div', { position: 'absolute', right: '8px', top: 'max(8px, env(safe-area-inset-top))', font: '11px/1.3 ui-monospace, monospace', opacity: '0.7', textAlign: 'right', whiteSpace: 'pre' }, root);
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
setCover(alpha, text) {
|
|
477
|
+
cover.style.opacity = String(alpha);
|
|
478
|
+
cover.style.pointerEvents = alpha > 0.05 ? 'auto' : 'none';
|
|
479
|
+
if (text !== undefined && coverText.textContent !== text) {
|
|
480
|
+
coverText.textContent = text;
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
showBack(show, label = 'Back') {
|
|
484
|
+
back.style.display = show ? 'block' : 'none';
|
|
485
|
+
const text = `‹ ${label}`;
|
|
486
|
+
if (back.textContent !== text) {
|
|
487
|
+
back.textContent = text;
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
setHud(spec, timerSeconds) {
|
|
491
|
+
if (!spec) {
|
|
492
|
+
hud.style.display = 'none';
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
hud.style.display = 'block';
|
|
496
|
+
hudTitle.textContent = spec.title ?? '';
|
|
497
|
+
const big = spec.big ?? (timerSeconds !== null ? timerSeconds.toFixed(1) : '');
|
|
498
|
+
hudBig.textContent = big;
|
|
499
|
+
hudBig.style.display = big ? 'block' : 'none';
|
|
500
|
+
hudText.textContent = spec.text ?? '';
|
|
501
|
+
},
|
|
502
|
+
// `items` is [{ id, x, y, text, speech, npc, color }] in CSS pixels (a
|
|
503
|
+
// `color` is a player's mark); anything not
|
|
504
|
+
// listed is removed.
|
|
505
|
+
setLabels(items) {
|
|
506
|
+
const seen = new Set();
|
|
507
|
+
for (const item of items) {
|
|
508
|
+
seen.add(item.id);
|
|
509
|
+
let node = labelNodes.get(item.id);
|
|
510
|
+
if (!node) {
|
|
511
|
+
node = el('div', { position: 'absolute', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '12px', background: 'rgba(15,12,10,0.7)', whiteSpace: 'nowrap', fontSize: '14px' }, labels);
|
|
512
|
+
labelNodes.set(item.id, node);
|
|
513
|
+
}
|
|
514
|
+
// An NPC's line is kept on screen: a reply over one at the edge of the
|
|
515
|
+
// view would otherwise be cut off mid-sentence. Other labels are
|
|
516
|
+
// placed as they always were.
|
|
517
|
+
let x = item.x;
|
|
518
|
+
if (item.npc) {
|
|
519
|
+
const half = node.offsetWidth / 2;
|
|
520
|
+
x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
|
|
521
|
+
}
|
|
522
|
+
node.style.left = `${x}px`;
|
|
523
|
+
node.style.top = `${item.y}px`;
|
|
524
|
+
if (item.speech) {
|
|
525
|
+
node.style.background = 'rgba(255,250,240,0.94)';
|
|
526
|
+
node.style.color = '#2b2118';
|
|
527
|
+
node.style.whiteSpace = 'normal';
|
|
528
|
+
if (item.npc) {
|
|
529
|
+
// Its own width, not what is left of the screen to its right.
|
|
530
|
+
node.style.width = 'max-content';
|
|
531
|
+
}
|
|
532
|
+
node.style.maxWidth = item.npc && desktop() ? 'min(62vw, 320px)' : '62vw';
|
|
533
|
+
node.style.fontSize = '13px';
|
|
534
|
+
node.style.fontWeight = '500';
|
|
535
|
+
}
|
|
536
|
+
if (item.emote && node.dataset.emote !== '1') {
|
|
537
|
+
// An emote's emoji over a player: large, on nothing.
|
|
538
|
+
node.dataset.emote = '1';
|
|
539
|
+
node.style.background = 'transparent';
|
|
540
|
+
node.style.fontSize = '30px';
|
|
541
|
+
node.style.padding = '0';
|
|
542
|
+
node.style.textShadow = '0 2px 4px rgba(0,0,0,0.5)';
|
|
543
|
+
}
|
|
544
|
+
if (item.opacity !== undefined) {
|
|
545
|
+
node.style.opacity = String(item.opacity);
|
|
546
|
+
}
|
|
547
|
+
if (item.color && node.dataset.color !== item.color) {
|
|
548
|
+
// A player's mark: the place's colour, its words in whichever of
|
|
549
|
+
// black or white reads on it.
|
|
550
|
+
node.dataset.color = item.color;
|
|
551
|
+
node.style.background = item.color;
|
|
552
|
+
node.style.color = readableOn(item.color);
|
|
553
|
+
node.style.fontWeight = '700';
|
|
554
|
+
node.style.border = '2px solid rgba(255,255,255,0.85)';
|
|
555
|
+
}
|
|
556
|
+
if (node.textContent !== item.text) {
|
|
557
|
+
node.textContent = item.text;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
for (const [id, node] of labelNodes) {
|
|
561
|
+
if (!seen.has(id)) {
|
|
562
|
+
node.remove();
|
|
563
|
+
labelNodes.delete(id);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
// `item` is { id, rev, card, x, y, opacity } in CSS pixels, or null for no
|
|
568
|
+
// card; `imageOf(value)` is a picture's `src`, or null for none.
|
|
569
|
+
setCabinet(item, imageOf) {
|
|
570
|
+
const open = cardMode(cabinetView, item ? item.id : null) === 'board';
|
|
571
|
+
if (!item) {
|
|
572
|
+
cabinet.style.display = 'none';
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
const key = `${item.id}:${item.rev}:${open ? 'board' : 'chip'}`;
|
|
576
|
+
if (key !== cabinetKey) {
|
|
577
|
+
cabinetKey = key;
|
|
578
|
+
cabinet.dataset.drawn = (open ? buildCabinetBoard : buildCabinetChip)(item.card, imageOf) ? (open ? 'board' : 'chip') : '';
|
|
579
|
+
}
|
|
580
|
+
if (!cabinet.dataset.drawn) {
|
|
581
|
+
cabinet.style.display = 'none';
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
cabinet.style.display = 'block';
|
|
585
|
+
// Kept on screen: a card over a cabinet at the edge of the view.
|
|
586
|
+
const half = cabinet.offsetWidth / 2;
|
|
587
|
+
cabinet.style.left = `${Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6)}px`;
|
|
588
|
+
cabinet.style.top = `${Math.max(item.y, cabinet.offsetHeight + 6)}px`;
|
|
589
|
+
// A board the player asked for is read whole, wherever they stand by it.
|
|
590
|
+
cabinet.style.opacity = String(open ? 1 : item.opacity);
|
|
591
|
+
},
|
|
592
|
+
setRibbon(pos, text) {
|
|
593
|
+
if (!pos) {
|
|
594
|
+
ribbon.style.display = 'none';
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
ribbon.style.display = 'block';
|
|
598
|
+
ribbon.style.left = `${pos.x}px`;
|
|
599
|
+
ribbon.style.top = `${pos.y}px`;
|
|
600
|
+
if (ribbon.textContent !== text) {
|
|
601
|
+
ribbon.textContent = text;
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
setToast(text) {
|
|
605
|
+
toast.style.display = text ? 'block' : 'none';
|
|
606
|
+
if (text && toast.textContent !== text) {
|
|
607
|
+
toast.textContent = text;
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
showPicker(show, selected) {
|
|
611
|
+
picker.style.display = show ? 'flex' : 'none';
|
|
612
|
+
if (!show) {
|
|
613
|
+
setPickerOpen(false);
|
|
614
|
+
}
|
|
615
|
+
pickerButtons.forEach((button, i) => {
|
|
616
|
+
button.style.borderColor = i === selected ? '#f2c94c' : 'rgba(255,255,255,0.4)';
|
|
617
|
+
});
|
|
618
|
+
},
|
|
619
|
+
// The Graphics row: `mode` is the one picked ('auto', 'low' or 'high').
|
|
620
|
+
setGraphics(mode, onPick) {
|
|
621
|
+
graphics ??= buildGraphics();
|
|
622
|
+
graphics.onPick = onPick;
|
|
623
|
+
for (const [m, button] of graphics.buttons) {
|
|
624
|
+
button.style.borderColor = m === mode ? '#f2c94c' : 'rgba(255,255,255,0.4)';
|
|
625
|
+
button.setAttribute('aria-pressed', String(m === mode));
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
onTalk(handlers) {
|
|
629
|
+
talkHandlers = handlers;
|
|
630
|
+
},
|
|
631
|
+
onGrab(handler) {
|
|
632
|
+
grabHandler = handler;
|
|
633
|
+
},
|
|
634
|
+
onEmote(handler) {
|
|
635
|
+
emoteHandler = handler;
|
|
636
|
+
},
|
|
637
|
+
onSay(handler) {
|
|
638
|
+
sayHandler = handler;
|
|
639
|
+
},
|
|
640
|
+
onSit(handler) {
|
|
641
|
+
sitHandler = handler;
|
|
642
|
+
},
|
|
643
|
+
// `emotes` is [[id, emoji]] to offer, or null to hide the picker.
|
|
644
|
+
setEmotes(emotes) {
|
|
645
|
+
const show = Array.isArray(emotes) && emotes.length > 0;
|
|
646
|
+
emoteButton.style.display = show ? 'block' : 'none';
|
|
647
|
+
if (!show) {
|
|
648
|
+
setEmotesOpen(false);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const key = emotes.map(([id]) => id).join('|');
|
|
652
|
+
if (key === emotesKey) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
emotesKey = key;
|
|
656
|
+
emoteRow.replaceChildren();
|
|
657
|
+
for (const [id, emoji] of emotes) {
|
|
658
|
+
const button = el('button', { width: '44px', height: '44px', borderRadius: '22px', border: 'none', background: 'transparent', font: '26px system-ui, sans-serif', cursor: 'pointer', padding: '0', touchAction: 'manipulation' }, emoteRow);
|
|
659
|
+
button.textContent = emoji;
|
|
660
|
+
button.setAttribute('aria-label', id);
|
|
661
|
+
button.addEventListener('pointerdown', (event) => {
|
|
662
|
+
event.stopPropagation();
|
|
663
|
+
event.preventDefault();
|
|
664
|
+
setEmotesOpen(false);
|
|
665
|
+
emoteHandler(id);
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
// `say` is { reactions: [emoji], phrases: [[id, words]] } to offer, or
|
|
670
|
+
// null to hide the button; a pick calls the handler with { r } or { p }.
|
|
671
|
+
setSay(say) {
|
|
672
|
+
sayButton.style.display = say ? 'block' : 'none';
|
|
673
|
+
if (!say) {
|
|
674
|
+
setSayOpen(false);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const chat = say.chat ?? null;
|
|
678
|
+
const key = `${say.reactions.join('')}|${say.phrases.map(([id]) => id).join(',')}|${chat ? (chat.input ? 1 : 0) : '-'}`;
|
|
679
|
+
// Whom chat reaches changes as people come and go: only its words are
|
|
680
|
+
// rewritten, so a line being typed is not lost.
|
|
681
|
+
if (key === sayKey && sayNote && chat && sayNote.textContent !== (chat.note ?? '')) {
|
|
682
|
+
sayNote.textContent = chat.note ?? '';
|
|
683
|
+
}
|
|
684
|
+
if (key === sayKey) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
sayKey = key;
|
|
688
|
+
sayCard.replaceChildren();
|
|
689
|
+
const pick = (node, what) =>
|
|
690
|
+
node.addEventListener('pointerdown', (event) => {
|
|
691
|
+
event.stopPropagation();
|
|
692
|
+
event.preventDefault();
|
|
693
|
+
setSayOpen(false);
|
|
694
|
+
sayHandler(what);
|
|
695
|
+
});
|
|
696
|
+
const row = el('div', { display: 'flex', justifyContent: 'space-between' }, sayCard);
|
|
697
|
+
say.reactions.forEach((emoji, r) => {
|
|
698
|
+
const button = el('button', { width: '34px', height: '34px', border: 'none', background: 'transparent', font: '22px system-ui, sans-serif', cursor: 'pointer', padding: '0', touchAction: 'manipulation' }, row);
|
|
699
|
+
button.textContent = emoji;
|
|
700
|
+
button.setAttribute('aria-label', `React ${emoji}`);
|
|
701
|
+
pick(button, { r });
|
|
702
|
+
});
|
|
703
|
+
const lines = el('div', { display: 'flex', flexWrap: 'wrap', gap: '5px' }, sayCard);
|
|
704
|
+
for (const [id, words] of say.phrases) {
|
|
705
|
+
const button = smallButton(lines, words, false);
|
|
706
|
+
button.style.fontWeight = '600';
|
|
707
|
+
pick(button, { p: id });
|
|
708
|
+
}
|
|
709
|
+
// Free-text chat (v1.12), where the host has it: whom it reaches, or
|
|
710
|
+
// why it reaches nobody, and the field. Not a <form> (see the talk panel).
|
|
711
|
+
sayInput = null;
|
|
712
|
+
sayNote = null;
|
|
713
|
+
if (!chat) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
sayNote = el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, sayCard);
|
|
717
|
+
sayNote.textContent = chat.note ?? '';
|
|
718
|
+
const line = el('div', { display: 'flex', gap: '6px', opacity: chat.input ? '1' : '0.5' }, sayCard);
|
|
719
|
+
const input = el('input', { flex: '1', minWidth: '0', padding: '7px 9px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 14px system-ui, sans-serif' }, line);
|
|
720
|
+
input.maxLength = 200;
|
|
721
|
+
input.placeholder = 'Message…';
|
|
722
|
+
// Shown even when it cannot be used, so chat can be found; the note says why.
|
|
723
|
+
input.disabled = !chat.input;
|
|
724
|
+
input.enterKeyHint = 'send';
|
|
725
|
+
sayInput = input;
|
|
726
|
+
const send = () => {
|
|
727
|
+
const text = input.value.trim();
|
|
728
|
+
if (!text) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
input.value = '';
|
|
732
|
+
input.blur();
|
|
733
|
+
setSayOpen(false);
|
|
734
|
+
sayHandler({ text });
|
|
735
|
+
};
|
|
736
|
+
for (const type of ['keydown', 'keyup', 'keypress']) {
|
|
737
|
+
input.addEventListener(type, (event) => event.stopPropagation());
|
|
738
|
+
}
|
|
739
|
+
input.addEventListener('keydown', (event) => {
|
|
740
|
+
if (event.isComposing || event.keyCode === 229) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (event.key === 'Enter') {
|
|
744
|
+
event.preventDefault();
|
|
745
|
+
send();
|
|
746
|
+
} else if (event.key === 'Escape') {
|
|
747
|
+
event.preventDefault();
|
|
748
|
+
input.blur();
|
|
749
|
+
setSayOpen(false);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
const button = el('button', { padding: '7px 12px', borderRadius: '8px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, line);
|
|
753
|
+
button.type = 'button';
|
|
754
|
+
button.textContent = 'Send';
|
|
755
|
+
button.disabled = !chat.input;
|
|
756
|
+
button.addEventListener('click', (event) => {
|
|
757
|
+
event.preventDefault();
|
|
758
|
+
send();
|
|
759
|
+
});
|
|
760
|
+
},
|
|
761
|
+
// Whether the chat field has the keyboard (the game's keys are its own).
|
|
762
|
+
chatFocused: () => sayInput !== null && document.activeElement === sayInput,
|
|
763
|
+
// The lines of what was just said, oldest first; hidden while a list is open.
|
|
764
|
+
// Each is `{ text, id }`; a line with an `id` is another player's chat
|
|
765
|
+
// message: a tap on it asks whether to report it.
|
|
766
|
+
setFeed(lines) {
|
|
767
|
+
const shown = doorsOpen || peopleOpen ? [] : lines;
|
|
768
|
+
const key = shown.map((line) => `${line.id ?? ''}:${line.text}`).join('\n');
|
|
769
|
+
if (key === feedKey) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
feedKey = key;
|
|
773
|
+
feed.replaceChildren();
|
|
774
|
+
for (const line of shown) {
|
|
775
|
+
const node = el('div', {}, feed);
|
|
776
|
+
node.textContent = line.text;
|
|
777
|
+
if (!line.id) {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
node.style.pointerEvents = 'auto';
|
|
781
|
+
node.style.cursor = 'pointer';
|
|
782
|
+
node.addEventListener('pointerdown', (event) => {
|
|
783
|
+
event.stopPropagation();
|
|
784
|
+
node.replaceChildren();
|
|
785
|
+
node.style.display = 'flex';
|
|
786
|
+
node.style.gap = '6px';
|
|
787
|
+
node.style.alignItems = 'center';
|
|
788
|
+
el('span', {}, node).textContent = 'Report this message?';
|
|
789
|
+
smallButton(node, 'Report', true).addEventListener('pointerdown', (e) => {
|
|
790
|
+
e.stopPropagation();
|
|
791
|
+
node.remove();
|
|
792
|
+
onReportChat(line);
|
|
793
|
+
});
|
|
794
|
+
smallButton(node, 'Cancel', false).addEventListener('pointerdown', (e) => {
|
|
795
|
+
e.stopPropagation();
|
|
796
|
+
feedKey = '';
|
|
797
|
+
});
|
|
798
|
+
}, { once: true });
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
// The Sit / Stand button's word, or null to hide it.
|
|
802
|
+
sitPrompt(text) {
|
|
803
|
+
sitButton.style.display = text ? 'block' : 'none';
|
|
804
|
+
if (text && sitButton.textContent !== text) {
|
|
805
|
+
sitButton.textContent = text;
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
// The Grab button's word ("Grab" or "Throw"), or null to hide it.
|
|
809
|
+
grabPrompt(text) {
|
|
810
|
+
grabButton.style.display = text ? 'block' : 'none';
|
|
811
|
+
if (text && grabButton.textContent !== text) {
|
|
812
|
+
grabButton.textContent = text;
|
|
813
|
+
grabButton.style.background = text === 'Throw' ? 'rgba(233,196,143,0.92)' : 'rgba(20,16,12,0.78)';
|
|
814
|
+
grabButton.style.color = text === 'Throw' ? '#2b2118' : '#fff';
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
// The Talk button, for the NPC named, or hidden.
|
|
818
|
+
talkPrompt(name) {
|
|
819
|
+
const show = Boolean(name) && !talkOpen;
|
|
820
|
+
talkButton.style.display = show ? 'block' : 'none';
|
|
821
|
+
const text = show ? `Talk to ${name}` : '';
|
|
822
|
+
if (show && talkButton.textContent !== text) {
|
|
823
|
+
talkButton.textContent = text;
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
openTalk(name) {
|
|
827
|
+
talkOpen = true;
|
|
828
|
+
panelName.textContent = name;
|
|
829
|
+
panelLog.replaceChildren();
|
|
830
|
+
panel.style.display = 'flex';
|
|
831
|
+
talkButton.style.display = 'none';
|
|
832
|
+
// With a keyboard, typing goes straight to the panel; a touch screen
|
|
833
|
+
// waits for a tap on the field rather than throwing up its keyboard.
|
|
834
|
+
if (globalThis.matchMedia?.('(pointer: fine)').matches) {
|
|
835
|
+
panelInput.focus({ preventScroll: true });
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
closeTalk() {
|
|
839
|
+
talkOpen = false;
|
|
840
|
+
panel.style.display = 'none';
|
|
841
|
+
panelInput.blur();
|
|
842
|
+
},
|
|
843
|
+
// `note`, when given, is a small caption under the line (a scripted reply).
|
|
844
|
+
talkLine(who, text, note = null) {
|
|
845
|
+
const line = el('div', { alignSelf: who === 'me' ? 'flex-end' : 'flex-start', maxWidth: '85%', padding: '5px 9px', borderRadius: '10px', background: who === 'me' ? 'rgba(233,196,143,0.25)' : 'rgba(255,250,240,0.94)', color: who === 'me' ? '#fff' : '#2b2118' }, panelLog);
|
|
846
|
+
line.textContent = text;
|
|
847
|
+
if (note) {
|
|
848
|
+
el('div', { fontSize: '11px', fontStyle: 'italic', opacity: '0.65', marginTop: '2px' }, line).textContent = note;
|
|
849
|
+
}
|
|
850
|
+
panelLog.scrollTop = panelLog.scrollHeight;
|
|
851
|
+
},
|
|
852
|
+
talkWaiting(waiting) {
|
|
853
|
+
panelSend.disabled = waiting;
|
|
854
|
+
panelSend.style.opacity = waiting ? '0.5' : '1';
|
|
855
|
+
panelSend.textContent = waiting ? '…' : 'Say';
|
|
856
|
+
},
|
|
857
|
+
talkFocused() {
|
|
858
|
+
return document.activeElement === panelInput;
|
|
859
|
+
},
|
|
860
|
+
// `doors` is [{ id, title }] to offer, or null for none; `goText` is the
|
|
861
|
+
// word on each one's button ("Go", or "Go together" in a party).
|
|
862
|
+
setDoors(doors, goText = 'Go') {
|
|
863
|
+
const show = Array.isArray(doors) && doors.length > 0;
|
|
864
|
+
doorsButton.style.display = show ? 'block' : 'none';
|
|
865
|
+
if (!show) {
|
|
866
|
+
closeDoors();
|
|
867
|
+
doorsKey = '';
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
const key = `${goText}#${doors.map((d) => `${d.id}:${d.title ?? ''}:${d.featured ? 'f' : ''}${d.solo ? 's' : ''}${d.need ?? ''}`).join('|')}`;
|
|
871
|
+
if (key === doorsKey) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
doorsKey = key;
|
|
875
|
+
doorsList.replaceChildren();
|
|
876
|
+
for (const door of doors) {
|
|
877
|
+
const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsList);
|
|
878
|
+
// The title on a line of its own, with one short word under it on what
|
|
879
|
+
// the door takes (a solo game, how many it needs): beside the button
|
|
880
|
+
// they squeezed the title to a few letters.
|
|
881
|
+
const words = el('div', { flex: '1', minWidth: '0' }, row);
|
|
882
|
+
const name = el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
|
|
883
|
+
name.textContent = `${door.featured ? '★ ' : ''}${door.title ?? door.id}`;
|
|
884
|
+
const takes = door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
|
|
885
|
+
if (takes) {
|
|
886
|
+
el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, words).textContent = takes;
|
|
887
|
+
}
|
|
888
|
+
const go = el('button', { padding: '5px 12px', borderRadius: '12px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, row);
|
|
889
|
+
// A party cannot go together through a door that takes one player.
|
|
890
|
+
go.textContent = door.solo ? 'Go' : goText;
|
|
891
|
+
go.style.flex = 'none';
|
|
892
|
+
go.addEventListener('pointerdown', (event) => {
|
|
893
|
+
event.stopPropagation();
|
|
894
|
+
closeDoors();
|
|
895
|
+
onJumpDoor(door);
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
|
|
900
|
+
// `people` is the People list's rows, [{ key, playerId, userId, username,
|
|
901
|
+
// mark, where, actions }] (`mark` a sign before the name, `actions`
|
|
902
|
+
// [{ id, text }], the first drawn beside the name), or null for no People
|
|
903
|
+
// button; `party` is the line over them for a player in a party.
|
|
904
|
+
setPeople(people, party = null) {
|
|
905
|
+
const show = Array.isArray(people) && people.length > 0;
|
|
906
|
+
peopleButton.style.display = show ? 'block' : 'none';
|
|
907
|
+
if (!show) {
|
|
908
|
+
closePeople();
|
|
909
|
+
peopleKey = '';
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
// Everyone in this place, the player too: a count of the others read as
|
|
913
|
+
// one short beside the avatars on screen. Friends elsewhere are rows of
|
|
914
|
+
// the list, not people here.
|
|
915
|
+
const label = `People · ${people.filter((p) => p.playerId).length + 1}`;
|
|
916
|
+
if (peopleButton.textContent !== label) {
|
|
917
|
+
peopleButton.textContent = label;
|
|
918
|
+
}
|
|
919
|
+
const key = `${party ?? ''}#${people.map((p) => `${p.key}:${p.username ?? ''}:${p.mark ?? ''}:${(p.actions ?? []).map((a) => a.text).join(',')}:${p.door ?? ''}:${p.where ? 1 : 0}`).join('|')}`;
|
|
920
|
+
if (key !== peopleKey) {
|
|
921
|
+
peopleKey = key;
|
|
922
|
+
peopleList.replaceChildren();
|
|
923
|
+
peopleRows.clear();
|
|
924
|
+
if (party) {
|
|
925
|
+
// The player's party: how many, and the way out of it.
|
|
926
|
+
const head = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '4px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, peopleList);
|
|
927
|
+
el('div', { flex: '1', fontSize: '12px', opacity: '0.8' }, head).textContent = party;
|
|
928
|
+
smallButton(head, 'Leave party', false).addEventListener('pointerdown', (event) => {
|
|
929
|
+
event.stopPropagation();
|
|
930
|
+
onLeaveParty();
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
for (const person of people) {
|
|
934
|
+
peopleRows.set(person.key, personRow(person));
|
|
935
|
+
}
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
for (const person of people) {
|
|
939
|
+
if (person.where) {
|
|
940
|
+
peopleRows.get(person.key)?.setWhere(person.where);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
// `items` is [{ id, x, y, text, angle }] in CSS pixels; `angle` (radians
|
|
945
|
+
// on screen) is the way an edge chip's arrow points, null for a chip over
|
|
946
|
+
// the friend themself. Anything not listed is removed.
|
|
947
|
+
setPointers(items) {
|
|
948
|
+
const seen = new Set();
|
|
949
|
+
for (const item of items) {
|
|
950
|
+
seen.add(item.id);
|
|
951
|
+
let node = pointerNodes.get(item.id);
|
|
952
|
+
if (!node) {
|
|
953
|
+
const chip = el('div', { position: 'absolute', display: 'flex', alignItems: 'center', gap: '4px', padding: '2px 8px', borderRadius: '10px', background: 'rgba(233,196,143,0.92)', color: '#2b2118', font: '700 11px/1.3 system-ui, sans-serif', whiteSpace: 'nowrap', boxShadow: '0 1px 4px rgba(0,0,0,0.4)' }, pointers);
|
|
954
|
+
const arrow = el('span', { display: 'inline-block', fontSize: '10px' }, chip);
|
|
955
|
+
arrow.textContent = '➤';
|
|
956
|
+
const words = el('span', {}, chip);
|
|
957
|
+
node = { chip, arrow, words };
|
|
958
|
+
pointerNodes.set(item.id, node);
|
|
959
|
+
}
|
|
960
|
+
const edge = item.angle !== null && item.angle !== undefined;
|
|
961
|
+
node.arrow.style.display = edge ? 'inline-block' : 'none';
|
|
962
|
+
if (edge) {
|
|
963
|
+
node.arrow.style.transform = `rotate(${item.angle}rad)`;
|
|
964
|
+
}
|
|
965
|
+
if (node.words.textContent !== item.text) {
|
|
966
|
+
node.words.textContent = item.text;
|
|
967
|
+
}
|
|
968
|
+
// Kept whole on screen; over a friend it sits above their head.
|
|
969
|
+
const half = node.chip.offsetWidth / 2;
|
|
970
|
+
const x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
|
|
971
|
+
node.chip.style.transform = edge ? 'translate(-50%, -50%)' : 'translate(-50%, -100%)';
|
|
972
|
+
node.chip.style.left = `${x}px`;
|
|
973
|
+
node.chip.style.top = `${item.y}px`;
|
|
974
|
+
}
|
|
975
|
+
for (const [id, node] of pointerNodes) {
|
|
976
|
+
if (!seen.has(id)) {
|
|
977
|
+
node.chip.remove();
|
|
978
|
+
pointerNodes.delete(id);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
// `ask` is { key, text, yes, no } (the words and the two buttons'), or
|
|
983
|
+
// null for none; an answer goes to `onAsk(ask, true | false)`.
|
|
984
|
+
setAsk(ask) {
|
|
985
|
+
askNow = ask;
|
|
986
|
+
askCard.style.display = ask ? 'flex' : 'none';
|
|
987
|
+
if (!ask || ask.key === askKey) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
askKey = ask.key;
|
|
991
|
+
askCard.replaceChildren();
|
|
992
|
+
el('div', { flex: '1', minWidth: '0', fontWeight: '600' }, askCard).textContent = ask.text;
|
|
993
|
+
for (const [text, answer] of [[ask.yes, true], [ask.no, false]]) {
|
|
994
|
+
smallButton(askCard, text, answer).addEventListener('pointerdown', (event) => {
|
|
995
|
+
event.stopPropagation();
|
|
996
|
+
askCard.style.display = 'none';
|
|
997
|
+
onAsk(askNow, answer);
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
},
|
|
1001
|
+
// The invite button for the player stood beside (`text` its words), or
|
|
1002
|
+
// null to hide it; a press calls `handler`.
|
|
1003
|
+
nearPrompt(text, handler) {
|
|
1004
|
+
// Never over an open card or list: it sits where the speech card's field is.
|
|
1005
|
+
const show = Boolean(text) && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen;
|
|
1006
|
+
nearButton.style.display = show ? 'block' : 'none';
|
|
1007
|
+
if (text) {
|
|
1008
|
+
nearHandler = handler;
|
|
1009
|
+
if (nearButton.textContent !== text) {
|
|
1010
|
+
nearButton.textContent = text;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
},
|
|
1014
|
+
// Whether the People list is open (its rows' places are asked for then).
|
|
1015
|
+
peopleOpen: () => peopleOpen,
|
|
1016
|
+
setStats(text) {
|
|
1017
|
+
stats.style.display = text ? 'block' : 'none';
|
|
1018
|
+
if (stats.textContent !== text) {
|
|
1019
|
+
stats.textContent = text;
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
1022
|
+
dispose() {
|
|
1023
|
+
unguardKeys();
|
|
1024
|
+
desktopQuery?.removeEventListener?.('change', layoutPanel);
|
|
1025
|
+
root.remove();
|
|
1026
|
+
},
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// Black or white, whichever reads on a `#rrggbb` background.
|
|
1031
|
+
function readableOn(color) {
|
|
1032
|
+
const n = parseInt(color.slice(1), 16);
|
|
1033
|
+
const lum = 0.299 * ((n >> 16) & 255) + 0.587 * ((n >> 8) & 255) + 0.114 * (n & 255);
|
|
1034
|
+
return lum > 150 ? '#14110f' : '#ffffff';
|
|
1035
|
+
}
|