fix(client): usable GM column and phone HUD (#89)

This commit is contained in:
2026-11-21 23:39:09 +01:00
parent f170b9c91a
commit e2295aa416
23 changed files with 521 additions and 75 deletions
+1
View File
@@ -13,6 +13,7 @@ test('GM token create defaults X/Y to the viewport centre', { timeout: 120000 },
await waitForVisible(page, '#signin') await waitForVisible(page, '#signin')
await signIn(page, gmKey) await signIn(page, gmKey)
await waitForVisible(page, '#stage canvas') await waitForVisible(page, '#stage canvas')
await page.click('#gm-token-create-section > summary')
await page.waitForFunction(() => { await page.waitForFunction(() => {
const x = document.querySelector('#token-x') const x = document.querySelector('#token-x')
const y = document.querySelector('#token-y') const y = document.querySelector('#token-y')
+3
View File
@@ -87,6 +87,9 @@ test('GM roster, keys and token panel drive the real server', { timeout: 240000
await waitForText(gm, '#gm-roster-list', /GM/) await waitForText(gm, '#gm-roster-list', /GM/)
await waitForText(gm, '#gm-roster-list', /connected/) await waitForText(gm, '#gm-roster-list', /connected/)
assert.equal(await gm.locator('#gm-panels').isVisible(), true) assert.equal(await gm.locator('#gm-panels').isVisible(), true)
// The create form and the 50-row token list start folded (M4 UX); open both for this flow.
await gm.click('#gm-token-create-section > summary')
await gm.click('#gm-token-list-section > summary')
// ---- key.create through the panel, key visible only in the GM DOM ---------------------- // ---- key.create through the panel, key visible only in the GM DOM ----------------------
await gm.click('#gm-key-create') await gm.click('#gm-key-create')
+3
View File
@@ -82,6 +82,9 @@ test('GM characters, reveals, encountered remove and who-sees-it', { timeout: 24
await signIn(gm, gmKey) await signIn(gm, gmKey)
await waitForVisible(gm, '#gm-panels') await waitForVisible(gm, '#gm-panels')
await waitForVisible(gm, '#gm-cast') await waitForVisible(gm, '#gm-cast')
// Characters and the per-player encountered lists start folded (M4 UX).
await gm.click('#gm-characters > summary')
await gm.click('#gm-encountered-section > summary')
// ---- character.create through the panel (owner defaults to the GM) -------------------- // ---- character.create through the panel (owner defaults to the GM) --------------------
await gm.fill('#character-name', 'a cloaked figure') await gm.fill('#character-name', 'a cloaked figure')
+3
View File
@@ -70,6 +70,9 @@ async function createSightedToken(origin, gmKey, player, { pos, name, radius, vi
await signIn(page, gmKey) await signIn(page, gmKey)
await waitForVisible(page, '#gm-panels') await waitForVisible(page, '#gm-panels')
await waitForText(page, '#gm-roster-list', new RegExp(name)) await waitForText(page, '#gm-roster-list', new RegExp(name))
// The create form and the token list start folded (M4 UX).
await page.click('#gm-token-create-section > summary')
await page.click('#gm-token-list-section > summary')
await page await page
.locator(`#token-controller option[value="${player.id}"]`) .locator(`#token-controller option[value="${player.id}"]`)
.waitFor({ state: 'attached', timeout: 20000 }) .waitFor({ state: 'attached', timeout: 20000 })
+3 -5
View File
@@ -16,11 +16,9 @@ test('e2e: headless chromium loads the real client build and the page reports h2
const errors = [] const errors = []
page.on('pageerror', error => errors.push(error.message)) page.on('pageerror', error => errors.push(error.message))
page.on('console', message => { page.on('console', message => {
// The boot probe's refused WebSocket upgrade is the expected no-session path (the browser // A fresh visitor no longer probes `/ws` before signing in (M4 UX), so a healthy load has
// logs it); it is not a page error. Everything else must be silent. // no refused-upgrade noise: every console error is a real error here.
if (message.type() === 'error' && !message.text().includes('WebSocket connection')) { if (message.type() === 'error') errors.push(message.text())
errors.push(message.text())
}
}) })
await page.goto(`${origin}/`, { waitUntil: 'load' }) await page.goto(`${origin}/`, { waitUntil: 'load' })
+3 -2
View File
@@ -260,8 +260,9 @@ test('clamps: player stops at 0.5 and 4, the GM goes below 0.5 and stops at 4',
await signIn(gmPage, gmKey) await signIn(gmPage, gmKey)
await waitForVisible(gmPage, canvas) await waitForVisible(gmPage, canvas)
await waitTilesReady(gmPage) await waitTilesReady(gmPage)
// 0.25 is below the player's 0.5 floor: the GM's survey zoom is not clamped there. // 0.25 is below the player's 0.5 floor: the GM's survey zoom is not clamped there. Wheel
await gmPage.mouse.move(80, 80) // over the left edge: the GM column (Walls first) now owns the right side of this tiny view.
await gmPage.mouse.move(20, 80)
await gmPage.mouse.wheel(0, 924) await gmPage.mouse.wheel(0, 924)
await gmPage.waitForFunction(() => { await gmPage.waitForFunction(() => {
const zoom = Number(document.querySelector('#stage canvas')?.dataset.zoom) const zoom = Number(document.querySelector('#stage canvas')?.dataset.zoom)
+3
View File
@@ -13,6 +13,9 @@ test('protocol mismatch: the client shows reload and does not reconnect', { time
const browser = await launchBrowser() const browser = await launchBrowser()
try { try {
const { page } = await newPage(browser) const { page } = await newPage(browser)
// The client only dials on boot when its session marker exists (M4 UX). This test is about
// the upgrade outcome, so tell the page a session may exist before it loads.
await page.addInitScript(() => localStorage.setItem('fff-vtt.session', '1'))
let sockets = 0 let sockets = 0
await page.routeWebSocket(/\/ws\?proto=2$/, ws => { await page.routeWebSocket(/\/ws\?proto=2$/, ws => {
sockets += 1 sockets += 1
+1 -1
View File
@@ -36,7 +36,7 @@ test('perf overlay: absent by default, `?perf=1` shows fps/frame/JS/tokens/zoom'
assert.match(text, /fps \d+\.\d/) assert.match(text, /fps \d+\.\d/)
assert.match(text, /frame p50 \d+\.\d p95 \d+\.\d ms/) assert.match(text, /frame p50 \d+\.\d p95 \d+\.\d ms/)
assert.match(text, /JS p50 \d+\.\d\d p95 \d+\.\d\d ms/) assert.match(text, /JS p50 \d+\.\d\d p95 \d+\.\d\d ms/)
assert.match(text, /tokens \d+/) assert.match(text, /tokens visible \d+ \/ total \d+/)
assert.match(text, /zoom \d+\.\d\d/) assert.match(text, /zoom \d+\.\d\d/)
await perf.context.close() await perf.context.close()
} finally { } finally {
+4 -3
View File
@@ -93,7 +93,8 @@ test('first sign-in asks once for a name and shows a taken name', { timeout: 120
await waitForVisible(page, '#hud') await waitForVisible(page, '#hud')
await waitForVisible(page, '#stage canvas') await waitForVisible(page, '#stage canvas')
await waitForText(page, '#me', /^Bob$/) await waitForText(page, '#me', /^Bob$/)
await waitForText(page, '#roster', /Bob/) // The HUD roster lists the other players; this connection's own name is #me.
await waitForText(page, '#roster', /GM/)
await waitForBadge(page, 'connected') await waitForBadge(page, 'connected')
await waitForHidden(page, '#name') await waitForHidden(page, '#name')
@@ -188,7 +189,7 @@ test('a killed server under a live player: badge reconnecting, then a full resyn
assert.equal(full('encountered')?.full, true, 'the encountered list comes back full') assert.equal(full('encountered')?.full, true, 'the encountered list comes back full')
assert.ok(after.some(frame => frame.t === 'token'), 'tokens come back') assert.ok(after.some(frame => frame.t === 'token'), 'tokens come back')
assert.ok(after.some(frame => frame.t === 'vision'), 'fog/vision comes back') assert.ok(after.some(frame => frame.t === 'vision'), 'fog/vision comes back')
assert.match(await page.textContent('#roster'), /Ann/) assert.match(await page.textContent('#roster'), /GM/)
assert.equal(await page.locator('#hud').isVisible(), true) assert.equal(await page.locator('#hud').isVisible(), true)
} finally { } finally {
if (restarted) await stopServer(restarted) if (restarted) await stopServer(restarted)
@@ -274,7 +275,7 @@ test('two connections of one player are both live and stay in sync', { timeout:
assert.equal(renamed.ok, true) assert.equal(renamed.ok, true)
gm.ws.close() gm.ws.close()
for (const view of [first, second]) { for (const view of [first, second]) {
await waitForText(view.page, '#roster', /Dee Two/) await waitForText(view.page, '#me', /Dee Two/)
await waitForBadge(view.page, 'connected') await waitForBadge(view.page, 'connected')
} }
} finally { } finally {
+6 -3
View File
@@ -70,17 +70,20 @@ test('GM and player: join -> canvas -> hello and roster; revoked returns to sign
await gmView.page.goto(`${origin}/`) await gmView.page.goto(`${origin}/`)
await waitForVisible(gmView.page, '#signin') await waitForVisible(gmView.page, '#signin')
await signIn(gmView.page, gmKey) await signIn(gmView.page, gmKey)
const gmRoster = await canvasAndRoster(gmView.page, ['GM', 'Alice']) // The HUD names this connection separately and lists the other players (no self row).
const gmRoster = await canvasAndRoster(gmView.page, ['Alice'])
assert.equal(await gmView.page.textContent('#role'), 'GM') assert.equal(await gmView.page.textContent('#role'), 'GM')
assert.match(gmRoster, /connected/) // Alice has a key but no live connection yet: the other-player row says offline.
assert.match(gmRoster, /offline/)
const playerView = await newPage(browser) const playerView = await newPage(browser)
await playerView.page.goto(`${origin}/`) await playerView.page.goto(`${origin}/`)
await waitForVisible(playerView.page, '#signin') await waitForVisible(playerView.page, '#signin')
await signIn(playerView.page, player.key) await signIn(playerView.page, player.key)
await canvasAndRoster(playerView.page, ['GM', 'Alice']) const playerRoster = await canvasAndRoster(playerView.page, ['GM'])
assert.equal(await playerView.page.textContent('#role'), 'Player') assert.equal(await playerView.page.textContent('#role'), 'Player')
assert.equal(await playerView.page.textContent('#me'), 'Alice') assert.equal(await playerView.page.textContent('#me'), 'Alice')
assert.match(playerRoster, /connected/)
// Story 10: the GM replaces the key, the server revokes the session, and the browser stops // Story 10: the GM replaces the key, the server revokes the session, and the browser stops
// at the sign-in door instead of hammering a dead socket. // at the sign-in door instead of hammering a dead socket.
+180
View File
@@ -0,0 +1,180 @@
// M4 UX dry-run (issue: GM panel and phone HUD usability). Real stack, real browser:
// - a 390x844 phone viewport keeps the HUD inside the screen (no clipped "…Pl…" row) and folds
// the player lists to two summary rows, with a capped scroll when opened;
// - the GM column puts Walls at the top, selection brings the token editor into view, and every
// long section collapses;
// - the rendered DOM has no duplicate ids (the old per-row `#gm-token-name` etc.).
import test from 'node:test'
import assert from 'node:assert/strict'
import { createPlayer, namePlayer, sleep } from '../../tools/lib.mjs'
import { openAs } from '../../tools/withserver.mjs'
import {
launchBrowser,
newPage,
signIn,
waitForText,
waitForVisible,
withStack,
} from './stack.mjs'
test('M4 UX: phone HUD, collapsible GM column, unique ids', { timeout: 240000 }, async () => {
await withStack(async ({ origin, gmKey }) => {
const browser = await launchBrowser()
const raw = await openAs(origin, gmKey)
const hello = await raw.ws.waitText('hello')
const scene = hello.scene?.id ?? (await raw.ws.waitText('walls')).scene
try {
// One named player with a sighted token (so the phone's encountered list has 20+ rows) and
// 49 NPCs, the playtest shape that made the column 8k px tall.
const alice = await createPlayer(raw.ws)
await namePlayer(origin, alice.key, 'Alice')
const own = await raw.ws.request({
t: 'token.create',
scene,
kind: 'pc',
pos: [960, 540],
descriptive_name: 'Alice',
actual_name: 'Alice',
controller: alice.id,
flags: { vision: true },
vision_radius: 5000,
radius: 20,
})
assert.equal(own.ok, true, JSON.stringify(own))
for (let i = 0; i < 49; i += 1) {
const ack = await raw.ws.request({
t: 'token.create',
scene,
kind: 'npc',
pos: [120 + (i % 7) * 240, 120 + Math.floor(i / 7) * 120],
descriptive_name: `T${i}`,
actual_name: `T${i}`,
})
assert.equal(ack.ok, true, JSON.stringify(ack))
}
// ---- phone -----------------------------------------------------------------------------
const phoneContext = await browser.newContext({
ignoreHTTPSErrors: true,
viewport: { width: 390, height: 844 },
})
const phone = await phoneContext.newPage()
await phone.goto(`${origin}/`)
await waitForVisible(phone, '#signin')
await signIn(phone, alice.key)
await waitForVisible(phone, '#hud')
await waitForText(phone, '#me', /^Alice$/)
await phone.waitForFunction(() => document.querySelectorAll('#encountered li').length > 20, null, {
timeout: 20000,
})
const hud = await phone.evaluate(() => {
const node = document.querySelector('#hud')
const rect = node.getBoundingClientRect()
return {
left: rect.left,
right: rect.right,
width: rect.width,
scrollWidth: node.scrollWidth,
clientWidth: node.clientWidth,
innerWidth: window.innerWidth,
children: [...node.children].map(child => {
const r = child.getBoundingClientRect()
return { id: child.id, left: r.left, right: r.right, height: r.height }
}),
}
})
assert.equal(hud.left, 0, 'the HUD starts at the left edge')
assert.ok(hud.right <= hud.innerWidth + 0.5, `the HUD ends inside the screen: ${JSON.stringify(hud)}`)
assert.ok(
hud.scrollWidth <= hud.clientWidth + 1,
`the HUD scrolls horizontally (clipped text): ${JSON.stringify(hud)}`,
)
for (const child of hud.children) {
if (child.height === 0) continue // a hidden span (e.g. #me when the name equals the role)
assert.ok(child.left >= 0, `${child.id} starts inside the screen`)
assert.ok(child.right <= hud.innerWidth + 0.5, `${child.id} ends inside the screen: ${JSON.stringify(child)}`)
}
const folded = await phone.evaluate(() => ({
characters: document.querySelector('#characters-panel')?.open,
encountered: document.querySelector('#encountered-panel')?.open,
}))
assert.equal(folded.characters, false, 'My characters starts folded on a phone')
assert.equal(folded.encountered, false, 'Encountered starts folded on a phone')
await phone.click('#encountered-panel > summary')
const cap = await phone.evaluate(() => {
const list = document.querySelector('#encountered')
const style = getComputedStyle(list)
return {
maxHeight: style.maxHeight,
overflowY: style.overflowY,
height: list.getBoundingClientRect().height,
}
})
assert.equal(cap.overflowY, 'auto', 'an opened list scrolls on its own')
assert.ok(parseFloat(cap.maxHeight) > 0 && parseFloat(cap.maxHeight) <= 300, `capped: ${cap.maxHeight}`)
assert.ok(cap.height <= parseFloat(cap.maxHeight) + 1, `the list is capped: ${JSON.stringify(cap)}`)
// ---- GM --------------------------------------------------------------------------------
const gmView = await newPage(browser)
const gm = gmView.page
await gm.goto(`${origin}/`)
await waitForVisible(gm, '#signin')
await signIn(gm, gmKey)
await waitForVisible(gm, '#gm-panels')
await waitForVisible(gm, '#gm-walls')
await waitForText(gm, '#gm-token-list-section > summary', /Tokens/)
// Walls are the first block in the column (reachable without scrolling past the lists).
const wallsTop = await gm.evaluate(() => {
const wall = document.querySelector('#gm-walls').getBoundingClientRect()
const panel = document.querySelector('#panels').getBoundingClientRect()
return { wall: wall.top, panel: panel.top, viewport: window.innerHeight }
})
assert.ok(wallsTop.wall < wallsTop.panel + 40, `Walls is at the top: ${JSON.stringify(wallsTop)}`)
assert.ok(wallsTop.wall < wallsTop.viewport / 2, `Walls is on the first screen: ${JSON.stringify(wallsTop)}`)
// Selecting a token (from the folded list) brings its editor into view.
await gm.click('#gm-token-list-section > summary')
const first = gm.locator('#gm-token-list li[data-token]').first()
const tokenId = await first.getAttribute('data-token')
await gm.click(`#gm-token-select-${tokenId}`)
await waitForVisible(gm, '#gm-token-editor')
const editor = await gm.evaluate(() => {
const node = document.querySelector('#gm-token-editor')
const rect = node.getBoundingClientRect()
return { top: rect.top, bottom: rect.bottom, viewport: window.innerHeight }
})
assert.ok(editor.top >= 0, `the selected token editor starts on screen: ${JSON.stringify(editor)}`)
assert.ok(
editor.bottom <= editor.viewport + 0.5,
`the selected token editor fits on one screen: ${JSON.stringify(editor)}`,
)
// Sections collapse: closing the token list hides its rows.
await gm.click('#gm-token-list-section > summary')
assert.equal(await gm.locator('#gm-token-list').isVisible(), false, 'the token list collapsed')
// ---- ids -------------------------------------------------------------------------------
const duplicates = await gm.evaluate(() => {
const seen = new Set()
const repeated = new Set()
for (const node of document.querySelectorAll('[id]')) {
if (seen.has(node.id)) repeated.add(node.id)
seen.add(node.id)
}
return [...repeated]
})
assert.deepEqual(duplicates, [], `duplicate DOM ids: ${duplicates.join(', ')}`)
await sleep(50)
await phoneContext.close()
await gmView.context.close()
} finally {
raw.ws.close()
await browser.close()
}
})
})
+43 -5
View File
@@ -11,9 +11,35 @@ import type { Stage } from './render/stage.ts'
import { createStage } from './render/stage.ts' import { createStage } from './render/stage.ts'
import type { RootState } from './reducer.ts' import type { RootState } from './reducer.ts'
import { setIntentSender } from './intents.ts' import { setIntentSender } from './intents.ts'
import { viewport } from './viewport.ts'
const KEY_REFUSED = 'Key not recognised.' const KEY_REFUSED = 'Key not recognised.'
/**
* A non-secret marker that this browser signed in once. The session cookie is HttpOnly, so the
* client cannot read it; without the marker every cold boot opened `/ws` before a session existed
* and the browser logged the refused upgrade on a perfectly healthy first load (M4 dry-run). The
* marker only decides whether to dial on boot; a stale marker still lands on sign-in as before.
*/
const SESSION_MARKER = 'fff-vtt.session'
function hadSession(): boolean {
try {
return localStorage.getItem(SESSION_MARKER) === '1'
} catch {
return true // storage blocked: keep the old probe rather than break returning sessions
}
}
function markSession(present: boolean): void {
try {
if (present) localStorage.setItem(SESSION_MARKER, '1')
else localStorage.removeItem(SESSION_MARKER)
} catch {
// A blocked localStorage is not worth breaking sign-in over.
}
}
/** Story 6: a refused name is shown with a reason, next to the prompt. */ /** Story 6: a refused name is shown with a reason, next to the prompt. */
const NAME_REFUSALS: Record<string, string> = { const NAME_REFUSALS: Record<string, string> = {
'name-taken': 'That name is taken. Choose another.', 'name-taken': 'That name is taken. Choose another.',
@@ -79,6 +105,7 @@ async function signIn(key: string): Promise<void> {
store.dispatch({ type: 'signin-failed', message: KEY_REFUSED }) store.dispatch({ type: 'signin-failed', message: KEY_REFUSED })
return return
} }
markSession(true)
client?.close() client?.close()
store.dispatch({ type: 'connecting' }) store.dispatch({ type: 'connecting' })
connect() connect()
@@ -152,12 +179,18 @@ function syncStage(state: RootState): void {
} }
store.subscribe(state => { store.subscribe(state => {
// A session the server ended (revoked, evicted) must not make the next cold boot dial `/ws`.
if (state.connection.phase === 'signin') markSession(false)
shell.render(state) shell.render(state)
syncStage(state) syncStage(state)
adminPanel.render(state) adminPanel.render(state)
castPanel.render(state) castPanel.render(state)
}) })
// The HUD's read-only zoom readout; `viewport` already publishes on every camera change.
shell.setZoom(viewport.state.camera.zoom)
viewport.subscribe(view => shell.setZoom(view.camera.zoom))
// Story 7: the badge distinguishes "no network at all" from "socket is reconnecting". The socket // Story 7: the badge distinguishes "no network at all" from "socket is reconnecting". The socket
// retries by itself, but a browser `online` event is the moment to skip the rest of the backoff. // retries by itself, but a browser `online` event is the moment to skip the rest of the backoff.
window.addEventListener('offline', () => { window.addEventListener('offline', () => {
@@ -168,9 +201,14 @@ window.addEventListener('online', () => {
client?.retryNow() client?.retryNow()
}) })
// Boot: show the neutral connecting screen and probe for a session. A visitor without a session // Boot: dial only when this browser may still hold a session; otherwise go straight to the door.
// gets a refused `/ws` upgrade and lands on the sign-in page; no map data is ever created. // A visitor without a session is never probed with a WS upgrade, so a healthy fresh load has no
// refused-connection noise in the console. No map data is ever created before a session.
store.dispatch({ type: 'network', online: navigator.onLine }) store.dispatch({ type: 'network', online: navigator.onLine })
store.dispatch({ type: 'connecting' }) if (hadSession()) {
shell.render(store.state) store.dispatch({ type: 'connecting' })
connect() shell.render(store.state)
connect()
} else {
store.dispatch({ type: 'signed-out' })
}
+29 -10
View File
@@ -18,6 +18,7 @@ import type { AdminToken } from '../slices/admin.ts'
import { adminTokens, selectedTokenId } from '../slices/admin.ts' import { adminTokens, selectedTokenId } from '../slices/admin.ts'
import { createVisionFields, updateVisionFields } from '../tokenPanel.ts' import { createVisionFields, updateVisionFields } from '../tokenPanel.ts'
import { viewport, viewportCentre } from '../viewport.ts' import { viewport, viewportCentre } from '../viewport.ts'
import { panelSection, revealInColumn, setSectionTitle } from './section.ts'
export interface AdminPanelHandlers { export interface AdminPanelHandlers {
send(t: string, fields?: Record<string, unknown>): Promise<AckFrame> send(t: string, fields?: Record<string, unknown>): Promise<AckFrame>
@@ -71,20 +72,24 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
root.append(heading) root.append(heading)
// ---- roster and keys ----------------------------------------------------------------------- // ---- roster and keys -----------------------------------------------------------------------
const rosterSection = element('section', 'gm-roster') // Collapsible, open by default: at most six players, so it stays short, but a GM can fold it.
const rosterTitle = element('h3', undefined, 'Roster') const roster = panelSection('gm-roster', 'Roster', true)
const rosterList = element('ul', 'gm-roster-list') const rosterList = element('ul', 'gm-roster-list')
const keyCreate = element('button', 'gm-key-create', 'Create player key') const keyCreate = element('button', 'gm-key-create', 'Create player key')
keyCreate.type = 'button' keyCreate.type = 'button'
const keyStatus = element('p', 'gm-key-status') const keyStatus = element('p', 'gm-key-status')
keyStatus.hidden = true keyStatus.hidden = true
keyStatus.setAttribute('role', 'status') keyStatus.setAttribute('role', 'status')
rosterSection.append(rosterTitle, rosterList, keyCreate, keyStatus) roster.body.append(rosterList, keyCreate, keyStatus)
// ---- token panel --------------------------------------------------------------------------- // ---- token panel ---------------------------------------------------------------------------
// Layout: the selected token's editor first (selection-driven, see refresh), then the create
// form and the long token list, both collapsed. That keeps the editor near the top of the column
// instead of underneath 50 rows.
const tokenSection = element('section', 'gm-tokens') const tokenSection = element('section', 'gm-tokens')
const tokenTitle = element('h3', undefined, 'Tokens')
const createForm = element('form', 'gm-token-create') const createForm = element('form', 'gm-token-create')
const createSection = panelSection('gm-token-create-section', 'New token')
createSection.body.append(createForm)
const kindInput = field('input', 'token-kind', 'Kind') const kindInput = field('input', 'token-kind', 'Kind')
kindInput.node.value = 'npc' kindInput.node.value = 'npc'
@@ -145,6 +150,8 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
) )
const tokenList = element('ul', 'gm-token-list') const tokenList = element('ul', 'gm-token-list')
const listSection = panelSection('gm-token-list-section', 'Tokens')
listSection.body.append(tokenList)
const editor = element('section', 'gm-token-editor') const editor = element('section', 'gm-token-editor')
editor.hidden = true editor.hidden = true
@@ -224,8 +231,8 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
resize, resize,
) )
tokenSection.append(tokenTitle, createForm, tokenList, editor, tokenError) tokenSection.append(editor, createSection.details, listSection.details, tokenError)
root.append(rosterSection, tokenSection) root.append(roster.details, tokenSection)
host.append(root) host.append(root)
// Secrets and local UI state. Never dispatched, never logged. // Secrets and local UI state. Never dispatched, never logged.
@@ -236,6 +243,7 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
let rosterSig = '' let rosterSig = ''
let tokenSig = '' let tokenSig = ''
let populatedFor: string | null = null let populatedFor: string | null = null
let lastSelected: string | null = null
let current: RootState | null = null let current: RootState | null = null
// The create form follows the viewport centre (#82) until the GM types a position: `autoPos` is // The create form follows the viewport centre (#82) until the GM types a position: `autoPos` is
// the pair this module last wrote, so a value the GM edited is never overwritten by a pan. // the pair this module last wrote, so a value the GM edited is never overwritten by a pan.
@@ -298,8 +306,10 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
...players.map(entry => { ...players.map(entry => {
const item = element('li') const item = element('li')
item.dataset['player'] = String(entry.id) item.dataset['player'] = String(entry.id)
const name = element('span', 'gm-roster-name', playerLabel(entry)) const name = element('span', undefined, playerLabel(entry))
const state = element('span', 'gm-roster-state', entry.connected ? 'connected' : 'offline') name.className = 'gm-roster-name'
const state = element('span', undefined, entry.connected ? 'connected' : 'offline')
state.className = 'gm-roster-state'
item.append(name, state) item.append(name, state)
if (entry.role !== 'gm') { if (entry.role !== 'gm') {
const keyCode = element('code', `gm-key-${entry.id}`) const keyCode = element('code', `gm-key-${entry.id}`)
@@ -358,8 +368,10 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
const item = element('li') const item = element('li')
item.dataset['token'] = token.id item.dataset['token'] = token.id
if (token.id === selected) item.dataset['selected'] = 'true' if (token.id === selected) item.dataset['selected'] = 'true'
const name = element('span', 'gm-token-name', token.name) const name = element('span', undefined, token.name)
const meta = element('span', 'gm-token-meta', tokenMeta(token, players)) name.className = 'gm-token-name'
const meta = element('span', undefined, tokenMeta(token, players))
meta.className = 'gm-token-meta'
const pick = element('button', `gm-token-select-${token.id}`, 'Select') const pick = element('button', `gm-token-select-${token.id}`, 'Select')
pick.type = 'button' pick.type = 'button'
pick.addEventListener('click', () => handlers.select(token.id)) pick.addEventListener('click', () => handlers.select(token.id))
@@ -412,10 +424,13 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
renderRoster(players) renderRoster(players)
} }
const token = tokens.find(entry => entry.id === selected) ?? null const token = tokens.find(entry => entry.id === selected) ?? null
const selectionChanged = selected !== lastSelected
lastSelected = selected
const nextTokenSig = JSON.stringify(tokens) + selected const nextTokenSig = JSON.stringify(tokens) + selected
if (nextTokenSig !== tokenSig) { if (nextTokenSig !== tokenSig) {
tokenSig = nextTokenSig tokenSig = nextTokenSig
renderTokenList(tokens, players, selected) renderTokenList(tokens, players, selected)
setSectionTitle(listSection, `Tokens (${tokens.length})`)
populateEditor(token, players) populateEditor(token, players)
if (token) { if (token) {
statusTitle.textContent = statusTitle.textContent =
@@ -429,6 +444,9 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
} }
renderControllerOptions(createController.node, players, createController.node.value || '') renderControllerOptions(createController.node, players, createController.node.value || '')
applyPositionDefault() applyPositionDefault()
// Selecting a token (in the list or on the board) brings its editor into the column's view;
// the list itself may be collapsed or scrolled far down.
if (token && selectionChanged) revealInColumn(editor)
} }
function setError(text: string | null): void { function setError(text: string | null): void {
@@ -688,6 +706,7 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
rosterSig = '' rosterSig = ''
tokenSig = '' tokenSig = ''
populatedFor = null populatedFor = null
lastSelected = null
root.hidden = true root.hidden = true
rosterList.replaceChildren() rosterList.replaceChildren()
tokenList.replaceChildren() tokenList.replaceChildren()
+10 -7
View File
@@ -14,6 +14,7 @@ import type { AdminToken } from '../slices/admin.ts'
import { adminTokens } from '../slices/admin.ts' import { adminTokens } from '../slices/admin.ts'
import type { CastCharacter } from '../slices/cast.ts' import type { CastCharacter } from '../slices/cast.ts'
import { castCharacters, encounteredOf, seenByOf } from '../slices/cast.ts' import { castCharacters, encounteredOf, seenByOf } from '../slices/cast.ts'
import { panelSection } from './section.ts'
export interface CastPanelHandlers { export interface CastPanelHandlers {
send(t: string, fields?: Record<string, unknown>): Promise<AckFrame> send(t: string, fields?: Record<string, unknown>): Promise<AckFrame>
@@ -69,8 +70,8 @@ export function mountCastPanel(host: HTMLElement, handlers: CastPanelHandlers):
root.hidden = true root.hidden = true
// ---- characters ---------------------------------------------------------------------------- // ---- characters ----------------------------------------------------------------------------
const characterSection = element('section', 'gm-characters') // Long (one editable block per character), so collapsed by default; the list gets its own scroll.
characterSection.append(element('h3', undefined, 'Characters')) const characters = panelSection('gm-characters', 'Characters')
const createForm = element('form', 'gm-character-create') const createForm = element('form', 'gm-character-create')
const createName = field('input', 'character-name', 'Descriptive name') const createName = field('input', 'character-name', 'Descriptive name')
@@ -94,25 +95,27 @@ export function mountCastPanel(host: HTMLElement, handlers: CastPanelHandlers):
const characterStatus = element('p', 'gm-character-status') const characterStatus = element('p', 'gm-character-status')
characterStatus.hidden = true characterStatus.hidden = true
characterStatus.setAttribute('role', 'status') characterStatus.setAttribute('role', 'status')
characterSection.append(createForm, characterList, characterStatus) characters.body.append(createForm, characterList, characterStatus)
// ---- encountered --------------------------------------------------------------------------- // ---- encountered ---------------------------------------------------------------------------
const encounteredSection = element('section', 'gm-encountered-section') // One list per player; collapsed and capped so a busy table cannot bury the rest of the column.
encounteredSection.append(element('h3', undefined, 'Encountered')) const encountered = panelSection('gm-encountered-section', 'Encountered')
const encounteredBox = element('div', 'gm-encountered') const encounteredBox = element('div', 'gm-encountered')
const encounteredStatus = element('p', 'gm-encountered-status') const encounteredStatus = element('p', 'gm-encountered-status')
encounteredStatus.hidden = true encounteredStatus.hidden = true
encounteredStatus.setAttribute('role', 'status') encounteredStatus.setAttribute('role', 'status')
encounteredSection.append(encounteredBox, encounteredStatus) encountered.body.append(encounteredBox, encounteredStatus)
// ---- who sees it --------------------------------------------------------------------------- // ---- who sees it ---------------------------------------------------------------------------
// Open near the top: it is the answer the GM checks most while moving tokens; its own list is
// capped (50 tokens) so it stays a glance, not a wall.
const seenSection = element('section', 'gm-seen') const seenSection = element('section', 'gm-seen')
seenSection.append(element('h3', undefined, 'Who sees it')) seenSection.append(element('h3', undefined, 'Who sees it'))
const seenHint = element('p', 'gm-seen-hint', 'M4 is binary per player: 100 % in sight, 0 % not.') const seenHint = element('p', 'gm-seen-hint', 'M4 is binary per player: 100 % in sight, 0 % not.')
const seenList = element('ul', 'gm-seen-list') const seenList = element('ul', 'gm-seen-list')
seenSection.append(seenHint, seenList) seenSection.append(seenHint, seenList)
root.append(characterSection, encounteredSection, seenSection) root.append(seenSection, characters.details, encountered.details)
host.append(root) host.append(root)
let active = false let active = false
+10 -9
View File
@@ -12,6 +12,7 @@ import { ownCharactersOf } from '../slices/characters.ts'
import type { CharacterView } from '../slices/characters.ts' import type { CharacterView } from '../slices/characters.ts'
import { encounteredOf } from '../slices/encountered.ts' import { encounteredOf } from '../slices/encountered.ts'
import type { EncounteredEntry } from '../slices/encountered.ts' import type { EncounteredEntry } from '../slices/encountered.ts'
import { panelSection } from './section.ts'
const NAME_FALLBACK = '(unnamed)' const NAME_FALLBACK = '(unnamed)'
@@ -85,23 +86,23 @@ export function mountListsPanel(host: HTMLElement, store: Store): () => void {
section.id = 'lists' section.id = 'lists'
section.hidden = true section.hidden = true
const charactersSection = document.createElement('section') // On a phone the HUD column is narrow and tall: both lists start folded so the map stays
charactersSection.id = 'characters-panel' // visible, and each list is height-capped with its own scroll when opened. A wide screen has the
const charactersTitle = text('h2', 'panel-title', 'My characters') // room, so the lists stay open there (the pre-M4 behaviour).
const wide = window.innerWidth >= 640
const charactersSection = panelSection('characters-panel', 'My characters', wide)
const charactersList = document.createElement('ul') const charactersList = document.createElement('ul')
charactersList.id = 'characters' charactersList.id = 'characters'
const charactersEmpty = text('p', 'empty', 'No characters yet.') const charactersEmpty = text('p', 'empty', 'No characters yet.')
charactersSection.append(charactersTitle, charactersEmpty, charactersList) charactersSection.body.append(charactersEmpty, charactersList)
const encounteredSection = document.createElement('section') const encounteredSection = panelSection('encountered-panel', 'Encountered', wide)
encounteredSection.id = 'encountered-panel'
const encounteredTitle = text('h2', 'panel-title', 'Encountered')
const encounteredList = document.createElement('ul') const encounteredList = document.createElement('ul')
encounteredList.id = 'encountered' encounteredList.id = 'encountered'
const encounteredEmpty = text('p', 'empty', 'Nobody met yet.') const encounteredEmpty = text('p', 'empty', 'Nobody met yet.')
encounteredSection.append(encounteredTitle, encounteredEmpty, encounteredList) encounteredSection.body.append(encounteredEmpty, encounteredList)
section.append(charactersSection, encounteredSection) section.append(charactersSection.details, encounteredSection.details)
host.append(section) host.append(section)
let signature = '' let signature = ''
+35
View File
@@ -0,0 +1,35 @@
// A collapsible GM/player panel section (M4 UX): native <details>/<summary>, so a long column
// collapses without custom state, keyboard handling or ARIA. Every string still goes through
// `textContent` (spec #63 decision 15).
//
// The section id stays on the <details> element, so existing selectors (`#gm-roster`, ...) keep
// working and tests can read `.open` or click the summary to toggle.
export interface PanelSection {
details: HTMLDetailsElement
summary: HTMLElement
body: HTMLDivElement
}
export function panelSection(id: string, title: string, open = false): PanelSection {
const details = document.createElement('details')
details.id = id
details.open = open
details.className = 'panel-section'
const summary = document.createElement('summary')
summary.textContent = title
const body = document.createElement('div')
body.className = 'panel-body'
details.append(summary, body)
return { details, summary, body }
}
/** Update a summary without touching the body (the count in "Tokens (50)"). */
export function setSectionTitle(section: PanelSection, title: string): void {
if (section.summary.textContent !== title) section.summary.textContent = title
}
/** The nearest scrollable ancestor's viewport; `scrollIntoView` would also scroll the page. */
export function revealInColumn(node: HTMLElement): void {
node.scrollIntoView({ block: 'nearest', inline: 'nearest' })
}
+8 -2
View File
@@ -19,6 +19,7 @@ import { restoreOf, selectedWallOf, undoOf, wallsOf } from '../slices/walls.ts'
import type { SightDir, WallPreset, WallSwitches, WallUndo } from '../wallEditor.ts' import type { SightDir, WallPreset, WallSwitches, WallUndo } from '../wallEditor.ts'
import type { PopulatedWall } from './wallSync.ts' import type { PopulatedWall } from './wallSync.ts'
import { shouldPopulate, wallFieldsSignature } from './wallSync.ts' import { shouldPopulate, wallFieldsSignature } from './wallSync.ts'
import { revealInColumn } from './section.ts'
import { import {
PRESETS, PRESETS,
buildAddFields, buildAddFields,
@@ -219,7 +220,9 @@ export function mountWallPanel(
undoButton.type = 'button' undoButton.type = 'button'
root.append(drawSection, selected, undoButton) root.append(drawSection, selected, undoButton)
host.append(root) // Walls sit at the top of the column: drawing is the GM's most frequent action and the selected
// wall's editor must be reachable without scrolling past the token/cast lists.
host.prepend(root)
let active = false let active = false
let current: RootState | null = null let current: RootState | null = null
@@ -617,7 +620,8 @@ export function mountWallPanel(
} }
selected.hidden = false selected.hidden = false
selectedTitle.textContent = `${wall.kind}` selectedTitle.textContent = `${wall.kind}`
if (populated?.id !== wall.id) { const newlySelected = populated?.id !== wall.id
if (newlySelected) {
populated = null populated = null
advancedOpen = false advancedOpen = false
advanced.hidden = true advanced.hidden = true
@@ -625,6 +629,8 @@ export function mountWallPanel(
hintLocked.hidden = true hintLocked.hidden = true
unlockButton.hidden = true unlockButton.hidden = true
setError(null) setError(null)
// A click on the board (or a freshly drawn wall) selects it; bring its editor to the top.
revealInColumn(selected)
} }
// Repopulate only when the server record changed: an ack dispatch carries the previous record // Repopulate only when the server record changed: an ack dispatch carries the previous record
// and must not undo the switch the GM just made while the authoritative frame is in flight. // and must not undo the switch the GM just made while the authoritative frame is in flight.
+14 -3
View File
@@ -92,13 +92,24 @@ function number(value: number | null, digits: number): string {
return value === null ? '—' : value.toFixed(digits) return value === null ? '—' : value.toFixed(digits)
} }
/** The overlay's one line of text. Everything here is a number or a fixed label. */ /**
export function formatSnapshot(snapshot: PerfSnapshot, tokens: number, zoom: number): string { * The overlay's one line of text. Everything here is a number or a fixed label.
*
* `tokens visible`/`total` say what the number counts: a player only receives tokens inside their
* sight (the total is then what that client knows), while the GM receives every token. The old bare
* `tokens 50` read as "the scene has 50" even when only two were drawn (M4 dry-run).
*/
export function formatSnapshot(
snapshot: PerfSnapshot,
visibleTokens: number,
totalTokens: number,
zoom: number,
): string {
return [ return [
`fps ${number(snapshot.fps, 1)}`, `fps ${number(snapshot.fps, 1)}`,
`frame p50 ${number(snapshot.frameP50, 1)} p95 ${number(snapshot.frameP95, 1)} ms`, `frame p50 ${number(snapshot.frameP50, 1)} p95 ${number(snapshot.frameP95, 1)} ms`,
`JS p50 ${number(snapshot.jsP50, 2)} p95 ${number(snapshot.jsP95, 2)} ms`, `JS p50 ${number(snapshot.jsP50, 2)} p95 ${number(snapshot.jsP95, 2)} ms`,
`tokens ${tokens}`, `tokens visible ${visibleTokens} / total ${totalTokens}`,
`zoom ${zoom.toFixed(2)}`, `zoom ${zoom.toFixed(2)}`,
].join(' · ') ].join(' · ')
} }
+11
View File
@@ -185,6 +185,17 @@ function onFrame(state: RootState, frame: ServerFrame): void {
state.connection.nameError = null state.connection.nameError = null
state.connection.attempt = 0 state.connection.attempt = 0
state.connection.retryDelayMs = null state.connection.retryDelayMs = null
} else if (frame.t === 'roster') {
// The HUD names this connection from `session.me`; a rename arrives as a roster broadcast, so
// keep `me.name` in step or the one visible name goes stale (the roster no longer repeats it).
const players = frame['players']
const me = state.session.me
if (me !== null && Array.isArray(players)) {
const self = (players as RosterEntry[]).find(entry => entry.id === me.id)
if (self && typeof self.name === 'string' && self.name !== me.name) {
state.session.me = { ...me, name: self.name }
}
}
} else if (isClosing(frame)) { } else if (isClosing(frame)) {
// DESIGN 6.5: the closing frame is the reason a browser cannot read from the close code. // DESIGN 6.5: the closing frame is the reason a browser cannot read from the close code.
const outcome = closeOutcome(frame.reason) const outcome = closeOutcome(frame.reason)
+6 -1
View File
@@ -11,6 +11,7 @@ import { UPDATE_PRIORITY } from 'pixi.js'
import type { Ticker } from 'pixi.js' import type { Ticker } from 'pixi.js'
import type { RenderModule } from '../stage.ts' import type { RenderModule } from '../stage.ts'
import { viewport } from '../../viewport.ts' import { viewport } from '../../viewport.ts'
import { adminTokens } from '../../slices/admin.ts'
import { tokensOf } from '../../slices/tokens.ts' import { tokensOf } from '../../slices/tokens.ts'
import { formatSnapshot, PerfWindow, perfEnabled } from '../../perf.ts' import { formatSnapshot, PerfWindow, perfEnabled } from '../../perf.ts'
@@ -49,7 +50,11 @@ export const renderModule: RenderModule = {
if (now - lastUpdate < UPDATE_EVERY_MS) return if (now - lastUpdate < UPDATE_EVERY_MS) return
lastUpdate = now lastUpdate = now
const snapshot = windowStats.snapshot(now) const snapshot = windowStats.snapshot(now)
node.textContent = formatSnapshot(snapshot, tokensOf(store.state).length, viewport.state.camera.zoom) const visible = tokensOf(store.state).length
// A player only ever receives tokens in sight, so its total is what it knows. The GM sees
// the whole table in the admin slice, which is the meaningful total there.
const total = store.state.session.role === 'gm' ? adminTokens(store.state).length : visible
node.textContent = formatSnapshot(snapshot, visible, total, viewport.state.camera.zoom)
} }
app.ticker.add(begin, undefined, UPDATE_PRIORITY.INTERACTION) app.ticker.add(begin, undefined, UPDATE_PRIORITY.INTERACTION)
+36 -16
View File
@@ -23,15 +23,17 @@ export interface Shell {
render(state: RootState): void render(state: RootState): void
setBusy(busy: boolean): void setBusy(busy: boolean): void
setNameBusy(busy: boolean): void setNameBusy(busy: boolean): void
/** The read-only zoom readout in the HUD (M4 dry-run: no visible zoom level otherwise). */
setZoom(zoom: number): void
} }
function element<K extends keyof HTMLElementTagNameMap>( function element<K extends keyof HTMLElementTagNameMap>(
tag: K, tag: K,
id: string, id?: string,
text?: string, text?: string,
): HTMLElementTagNameMap[K] { ): HTMLElementTagNameMap[K] {
const node = document.createElement(tag) const node = document.createElement(tag)
node.id = id if (id !== undefined) node.id = id
if (text !== undefined) node.textContent = text if (text !== undefined) node.textContent = text
return node return node
} }
@@ -109,8 +111,11 @@ export function mountShell(root: HTMLElement, handlers: ShellHandlers): Shell {
const me = element('span', 'me') const me = element('span', 'me')
const badge = element('span', 'badge', BADGE_TEXT.connected) const badge = element('span', 'badge', BADGE_TEXT.connected)
badge.dataset['state'] = 'connected' badge.dataset['state'] = 'connected'
const zoom = element('span', 'zoom')
const roster = element('ul', 'roster') const roster = element('ul', 'roster')
hud.append(role, scene, me, badge, roster) // One line: role, scene, own name, then the other players, then the connection state and zoom.
// The own roster row is omitted (see renderRoster): #me already names this connection.
hud.append(role, scene, me, roster, badge, zoom)
const fatal = element('section', 'fatal') const fatal = element('section', 'fatal')
fatal.hidden = true fatal.hidden = true
@@ -160,13 +165,18 @@ export function mountShell(root: HTMLElement, handlers: ShellHandlers): Shell {
for (const node of [boot, signin, hud, namePanel, fatal]) node.hidden = node !== active for (const node of [boot, signin, hud, namePanel, fatal]) node.hidden = node !== active
} }
function renderRoster(players: RosterEntry[]): void { function renderRoster(players: RosterEntry[], meId: number | null): void {
// A roster row for the connection itself duplicated the role/name line on a phone
// ("GM Scene GM Connected GM connected"); the HUD names the viewer once and lists the others.
const others = meId === null ? players : players.filter(entry => entry.id !== meId)
roster.replaceChildren( roster.replaceChildren(
...players.map(entry => { ...others.map(entry => {
const item = document.createElement('li') const item = document.createElement('li')
item.dataset['player'] = String(entry.id) item.dataset['player'] = String(entry.id)
const name = element('span', 'roster-name', rosterName(entry)) const name = element('span', undefined, rosterName(entry))
const state = element('span', 'roster-state', entry.connected ? 'connected' : 'offline') name.className = 'roster-name'
const state = element('span', undefined, entry.connected ? 'connected' : 'offline')
state.className = 'roster-state'
item.append(name, state) item.append(name, state)
return item return item
}), }),
@@ -195,6 +205,22 @@ export function mountShell(root: HTMLElement, handlers: ShellHandlers): Shell {
roster.replaceChildren() roster.replaceChildren()
} }
function setZoom(value: number): void {
zoom.textContent = `zoom ${value.toFixed(2)}`
}
/** One row: role, scene, this connection's name (once), the other players, badge, zoom. */
function renderHudLine(state: RootState): void {
const roleText = state.session.role === 'gm' ? 'GM' : 'Player'
const name = state.session.me?.name ?? ''
role.textContent = roleText
scene.textContent = state.session.scene?.name ?? ''
me.textContent = name
// "GM … GM" and a player literally named "Player" would say the same thing twice.
me.hidden = name === '' || name === roleText
renderRoster(rosterOf(state), state.session.me?.id ?? null)
}
function render(state: RootState): void { function render(state: RootState): void {
const phase = state.connection.phase const phase = state.connection.phase
const phaseChanged = phase !== prevPhase const phaseChanged = phase !== prevPhase
@@ -242,18 +268,12 @@ export function mountShell(root: HTMLElement, handlers: ShellHandlers): Shell {
} }
setNameBusy(false) setNameBusy(false)
showOnly(hud) showOnly(hud)
role.textContent = state.session.role === 'gm' ? 'GM' : 'Player' renderHudLine(state)
scene.textContent = state.session.scene?.name ?? ''
me.textContent = state.session.me?.name ?? ''
renderRoster(rosterOf(state))
break break
case 'reconnecting': case 'reconnecting':
// Keep the HUD (and the stale map) visible; only the badge changes. // Keep the HUD (and the stale map) visible; only the badge changes.
showOnly(hud) showOnly(hud)
role.textContent = state.session.role === 'gm' ? 'GM' : 'Player' renderHudLine(state)
scene.textContent = state.session.scene?.name ?? ''
me.textContent = state.session.me?.name ?? ''
renderRoster(rosterOf(state))
break break
case 'reload': case 'reload':
showOnly(fatal) showOnly(fatal)
@@ -266,5 +286,5 @@ export function mountShell(root: HTMLElement, handlers: ShellHandlers): Shell {
} }
} }
return { render, setBusy, setNameBusy } return { render, setBusy, setNameBusy, setZoom }
} }
+107 -7
View File
@@ -88,28 +88,52 @@ body {
left: 0; left: 0;
right: 0; right: 0;
display: flex; display: flex;
gap: 16px; flex-wrap: wrap;
column-gap: 16px;
row-gap: 2px;
align-items: baseline; align-items: baseline;
padding: 6px 12px; padding: 6px 12px;
background: rgb(0 0 0 / 65%); background: rgb(0 0 0 / 65%);
pointer-events: none; pointer-events: none;
font: 12px/1.4 ui-monospace, monospace; font: 12px/1.4 ui-monospace, monospace;
box-sizing: border-box;
}
/* The phone dry-run clipped "…Pl…" because the row could not wrap; these children may shrink and
the scene name ellipsises instead of pushing the badge off-screen. */
#hud > * {
min-width: 0;
}
#scene {
max-width: 40vw;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#zoom {
opacity: 0.7;
white-space: nowrap;
} }
#roster { #roster {
display: flex; display: flex;
gap: 12px; flex-wrap: wrap;
gap: 2px 12px;
margin: 0; margin: 0;
padding: 0; padding: 0;
list-style: none; list-style: none;
min-width: 0;
} }
#roster li { #roster li {
display: flex; display: flex;
gap: 4px; gap: 4px;
min-width: 0;
} }
#roster-state { .roster-state {
opacity: 0.6; opacity: 0.6;
} }
@@ -182,6 +206,25 @@ body {
opacity: 0.8; opacity: 0.8;
} }
/* Collapsible sections (M4 UX): native <details>; the summary is the section's only click target,
and an open section's body keeps the column's normal flow. */
.panel-section > summary {
cursor: pointer;
font-weight: 600;
opacity: 0.85;
padding: 2px 0;
}
.panel-section[open] > summary {
margin-bottom: 4px;
}
.panel-section > .panel-body {
display: flex;
flex-direction: column;
gap: 4px;
}
#gm-roster-list, #gm-roster-list,
#gm-token-list { #gm-token-list {
display: flex; display: flex;
@@ -192,6 +235,27 @@ body {
list-style: none; list-style: none;
} }
/* A long list gets its own scroll instead of stretching the column (50 tokens, a busy cast). */
#gm-token-list {
max-height: 220px;
overflow: auto;
}
#gm-character-list {
max-height: 360px;
overflow: auto;
}
#gm-seen-list {
max-height: 160px;
overflow: auto;
}
#gm-encountered {
max-height: 220px;
overflow: auto;
}
#gm-roster-list li, #gm-roster-list li,
#gm-token-list li { #gm-token-list li {
display: flex; display: flex;
@@ -207,7 +271,7 @@ body {
outline: 1px solid #7ee787; outline: 1px solid #7ee787;
} }
#gm-roster-state { .gm-roster-state {
opacity: 0.6; opacity: 0.6;
} }
@@ -266,7 +330,7 @@ body {
color: #ff8a8a; color: #ff8a8a;
} }
#gm-token-meta { .gm-token-meta {
flex-basis: 100%; flex-basis: 100%;
opacity: 0.7; opacity: 0.7;
word-break: break-word; word-break: break-word;
@@ -286,14 +350,25 @@ body {
pointer-events: none; pointer-events: none;
} }
#lists .panel-title { #lists summary {
margin: 0 0 2px; cursor: pointer;
pointer-events: auto;
font: 600 11px/1.2 system-ui, sans-serif; font: 600 11px/1.2 system-ui, sans-serif;
letter-spacing: 0.08em; letter-spacing: 0.08em;
text-transform: uppercase; text-transform: uppercase;
opacity: 0.65; opacity: 0.65;
} }
/* The list itself stays pointer-transparent so it never eats a pan; the body takes pointers only
while open (to scroll a capped list). */
#lists details > .panel-body {
pointer-events: none;
}
#lists details[open] > .panel-body {
pointer-events: auto;
}
#lists ul { #lists ul {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -301,6 +376,8 @@ body {
margin: 0 0 6px; margin: 0 0 6px;
padding: 0; padding: 0;
list-style: none; list-style: none;
max-height: 200px;
overflow: auto;
} }
#lists li { #lists li {
@@ -531,3 +608,26 @@ body {
color: #ff8a8a; color: #ff8a8a;
word-break: break-word; word-break: break-word;
} }
/* Phone (M4 dry-run, 390 px): the HUD wraps instead of clipping, and the player list column folds
to two summary rows so the map stays visible. The lists are capped and scroll when opened. */
@media (max-width: 640px) {
#hud {
column-gap: 8px;
padding: 4px 8px;
font-size: 11px;
}
#scene {
max-width: 38vw;
}
#panels {
top: 48px;
width: min(300px, 46vw);
}
#lists ul {
max-height: 28vh;
}
}
+2 -1
View File
@@ -56,12 +56,13 @@ describe('rolling window', () => {
const text = formatSnapshot( const text = formatSnapshot(
{ fps: 59.9, frameP50: 16.7, frameP95: 17.1, jsP50: null, jsP95: null, samples: 600 }, { fps: 59.9, frameP50: 16.7, frameP95: 17.1, jsP50: null, jsP95: null, samples: 600 },
50, 50,
50,
1.25, 1.25,
) )
expect(text).toContain('fps 59.9') expect(text).toContain('fps 59.9')
expect(text).toContain('frame p50 16.7 p95 17.1 ms') expect(text).toContain('frame p50 16.7 p95 17.1 ms')
expect(text).toContain('JS p50 — p95 — ms') expect(text).toContain('JS p50 — p95 — ms')
expect(text).toContain('tokens 50') expect(text).toContain('tokens visible 50 / total 50')
expect(text).toContain('zoom 1.25') expect(text).toContain('zoom 1.25')
}) })
}) })