feat(m4): playtest friction: perf overlay, fresh import, token seed (#82)

Opt-in ?perf=1 overlay (fps, frame p50/p95, JS p50/p95, tokens, zoom; no node or ticker work when off). fff-vtt import creates and migrates a fresh/empty state dir through the shared server startup path; devbox run serve gains --image. devbox run seed creates deterministic labelled NPC tokens over the real WS (idempotent rerun, --replace), and the GM token form defaults X/Y to the viewport centre.
This commit is contained in:
2026-11-21 17:20:05 +01:00
parent 356705823b
commit 9c7f9de910
20 changed files with 933 additions and 53 deletions
+37 -2
View File
@@ -17,6 +17,7 @@ import { rosterOf } from '../reducer.ts'
import type { AdminToken } from '../slices/admin.ts'
import { adminTokens, selectedTokenId } from '../slices/admin.ts'
import { createVisionFields, updateVisionFields } from '../tokenPanel.ts'
import { viewport, viewportCentre } from '../viewport.ts'
export interface AdminPanelHandlers {
send(t: string, fields?: Record<string, unknown>): Promise<AckFrame>
@@ -236,6 +237,37 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
let tokenSig = ''
let populatedFor: string | null = null
let current: RootState | null = null
// 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.
let autoPos: [number, number] | null = null
function viewportDefaultPosition(): [number, number] | null {
const scene = current?.session.scene
if (!scene) return null
const view = viewport.state
if (view.scene && view.size.width > 1 && view.size.height > 1) {
const [x, y] = viewportCentre(view.camera, view.size)
return [Math.round(x), Math.round(y)]
}
return [Math.round(scene.w / 2), Math.round(scene.h / 2)]
}
function applyPositionDefault(): void {
if (!active) return
const next = viewportDefaultPosition()
if (!next) return
const untouched =
autoPos === null ||
(xInput.node.value === String(autoPos[0]) && yInput.node.value === String(autoPos[1]))
const busy = document.activeElement === xInput.node || document.activeElement === yInput.node
if (untouched && !busy) {
xInput.node.value = String(next[0])
yInput.node.value = String(next[1])
}
autoPos = next
}
const unsubscribeViewport = viewport.subscribe(applyPositionDefault)
function showSecret(entry: RosterEntry): string {
if (!revealed.has(entry.id)) return ''
@@ -396,6 +428,7 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
}
}
renderControllerOptions(createController.node, players, createController.node.value || '')
applyPositionDefault()
}
function setError(text: string | null): void {
@@ -501,8 +534,9 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
const kind = kindInput.node.value.trim()
const name = nameInput.node.value.trim()
const actual = actualInput.node.value.trim()
const x = Number(xInput.node.value)
const y = Number(yInput.node.value)
const fallback = viewportDefaultPosition()
const x = xInput.node.value.trim() === '' && fallback ? fallback[0] : Number(xInput.node.value)
const y = yInput.node.value.trim() === '' && fallback ? fallback[1] : Number(yInput.node.value)
if (kind === '' || name === '' || actual === '' || !Number.isFinite(x) || !Number.isFinite(y)) {
setError('Kind, both names and a numeric position are required.')
return
@@ -674,6 +708,7 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
return {
render,
destroy() {
unsubscribeViewport()
keys.clear()
revealed.clear()
root.remove()