feat(client): GM token panel sets vision and vision radius (#78)

Token create and edit now carry flags.vision and vision_radius; edits merge
only the vision key into the stored flags. A new token keeps DESIGN 8's
flags '{}' default (vision off, radius = scene default). The fog e2e authors
its sighted token through the GM panel, and the admin e2e proves the panel
round-trip plus an explored 200 / unexplored 403 tile probe.

Refs #78
This commit is contained in:
2026-11-21 15:43:13 +01:00
parent fcd90529b6
commit bacf2e1412
9 changed files with 387 additions and 27 deletions
+77 -12
View File
@@ -7,6 +7,7 @@ import test from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { createPlayer, join, namePlayer } from '../../tools/lib.mjs' import { createPlayer, join, namePlayer } from '../../tools/lib.mjs'
import { openAs } from '../../tools/withserver.mjs' import { openAs } from '../../tools/withserver.mjs'
import { writeTileGrid } from '../../tools/tilefixture.mjs'
import { import {
launchBrowser, launchBrowser,
newPage, newPage,
@@ -68,7 +69,7 @@ async function waitForHiddenRow(page, tokenId) {
} }
test('GM roster, keys and token panel drive the real server', { timeout: 240000 }, async () => { test('GM roster, keys and token panel drive the real server', { timeout: 240000 }, async () => {
await withStack(async ({ origin, gmKey, server }) => { await withStack(async ({ origin, gmKey, server, stateDir }) => {
const keys = [] const keys = []
const browser = await launchBrowser() const browser = await launchBrowser()
const raw = await openAs(origin, gmKey) const raw = await openAs(origin, gmKey)
@@ -78,6 +79,7 @@ test('GM roster, keys and token panel drive the real server', { timeout: 240000
// ---- sign in as GM and see the roster with connected state ------------------------------ // ---- sign in as GM and see the roster with connected state ------------------------------
const gmView = await newPage(browser) const gmView = await newPage(browser)
const gm = gmView.page const gm = gmView.page
await recordSockets(gm)
await gm.goto(`${origin}/`) await gm.goto(`${origin}/`)
await waitForVisible(gm, '#signin') await waitForVisible(gm, '#signin')
await signIn(gm, gmKey) await signIn(gm, gmKey)
@@ -142,26 +144,69 @@ test('GM roster, keys and token panel drive the real server', { timeout: 240000
await waitForText(gm, '#gm-roster-list', /connected/) await waitForText(gm, '#gm-roster-list', /connected/)
// A scout gives the player a real line of sight, so a GM-controlled token can be shown and // A scout gives the player a real line of sight, so a GM-controlled token can be shown and
// hidden by `gm_only` (a token the player controls is always visible, by 3.1). // hidden by `gm_only` (a token the player controls is always visible, by 3.1). It is created
const scout = await raw.ws.request({ // through the token panel with vision on (#78): no raw `flags`/`vision_radius` shortcut.
t: 'token.create', await waitForVisible(gm, '#token-controller')
await gm
.locator(`#token-controller option[value="${aliceId}"]`)
.waitFor({ state: 'attached', timeout: 20000 })
await gm.fill('#token-kind', 'pc')
await gm.fill('#token-name', 'Scout')
await gm.fill('#token-actual', 'Scout')
await gm.fill('#token-x', '400')
await gm.fill('#token-y', '400')
await gm.fill('#token-radius', '20')
await gm.check('#token-vision')
await gm.fill('#token-vision-radius', '400')
await gm.selectOption('#token-controller', String(aliceId))
await gm.click('#token-create-submit')
const scoutRow = gm.locator('#gm-token-list li', { hasText: 'Scout' }).first()
await scoutRow.waitFor({ state: 'visible', timeout: 20000 })
const scoutId = await scoutRow.getAttribute('data-token')
assert.ok(scoutId, 'the panel-created scout has no id')
await waitTokenFrame(player, scoutId, frame => frame.mine === true)
// AC #78: the GM's `token` frame carries the same flags.vision and vision_radius after the ack.
const scoutFrame = await waitTokenFrame(
gm,
scoutId,
frame => frame.flags?.vision === true && frame.vision_radius === 400,
)
assert.equal(scoutFrame.flags.vision, true)
assert.equal(scoutFrame.vision_radius, 400)
// AC #78: the panel-created sight explores the player's set, without wire poking: an
// explored tile answers 200 and an unexplored one 403 for that player.
writeTileGrid(stateDir, {
scene, scene,
kind: 'pc', artVersion: rawHello.scene.art_version,
pos: [400, 400], size: rawHello.scene.tile_size,
descriptive_name: 'Scout', x0: 0,
actual_name: 'Scout', x1: 60,
controller: aliceId, y0: 0,
flags: { vision: true }, y1: 60,
}) })
assert.equal(scout.ok, true) const wallSession = await join(origin, aliceKey)
await waitTokenFrame(player, scout.id, frame => frame.mine === true) const tileStatus = async (x, y) =>
(await fetch(`${origin}/tiles/${scene}/v${rawHello.scene.art_version}/${x}_${y}.png`, {
headers: { cookie: wallSession.cookie },
})).status
await player.waitForFunction(
() => (window.__wsLog?.frames ?? []).some(frame => frame.t === 'vision'),
null,
{ timeout: 20000 },
)
assert.equal(await tileStatus(12, 12), 200, 'the explored tile is allowed')
assert.equal(await tileStatus(30, 30), 403, 'the unexplored tile is refused')
// ---- token.create through the panel --------------------------------------------------- // ---- token.create through the panel ---------------------------------------------------
// Vision off by default (DESIGN 8 `flags: '{}'`): clear the scout's controls explicitly.
await gm.uncheck('#token-vision')
await gm.fill('#token-vision-radius', '')
await gm.fill('#token-name', 'Rat') await gm.fill('#token-name', 'Rat')
await gm.fill('#token-actual', 'Giant Rat') await gm.fill('#token-actual', 'Giant Rat')
await gm.fill('#token-x', '460') await gm.fill('#token-x', '460')
await gm.fill('#token-y', '450') await gm.fill('#token-y', '450')
await gm.fill('#token-radius', '5') await gm.fill('#token-radius', '5')
await gm.selectOption('#token-controller', '')
await gm.click('#token-create-submit') await gm.click('#token-create-submit')
const tokenRow = gm.locator('#gm-token-list li', { hasText: 'Rat' }).first() const tokenRow = gm.locator('#gm-token-list li', { hasText: 'Rat' }).first()
await tokenRow.waitFor({ state: 'visible', timeout: 20000 }) await tokenRow.waitFor({ state: 'visible', timeout: 20000 })
@@ -183,6 +228,26 @@ test('GM roster, keys and token panel drive the real server', { timeout: 240000
await waitTokenFrame(player, tokenId, frame => frame.name === 'Big Rat') await waitTokenFrame(player, tokenId, frame => frame.name === 'Big Rat')
await waitForText(gm, '#gm-token-list', /Big Rat/) await waitForText(gm, '#gm-token-list', /Big Rat/)
// ---- edit: vision and its radius round-trip through the panel (#78) -------------------
await gm.check('#token-edit-vision')
await gm.fill('#token-edit-vision-radius', '250')
await gm.click('#token-save')
const visionOn = await waitTokenFrame(
gm,
tokenId,
frame => frame.flags?.vision === true && frame.vision_radius === 250,
)
assert.equal(visionOn.flags.vision, true)
await gm.uncheck('#token-edit-vision')
await gm.fill('#token-edit-vision-radius', '')
await gm.click('#token-save')
const visionOff = await waitTokenFrame(
gm,
tokenId,
frame => frame.flags?.vision === false && frame.vision_radius === null,
)
assert.equal(visionOff.flags.vision, false)
// ---- gm_only hides the token from the player, clearing it reveals it again ------------- // ---- gm_only hides the token from the player, clearing it reveals it again -------------
// A controlled token is always visible (3.1), so hand it back to the GM while it is hidden. // A controlled token is always visible (3.1), so hand it back to the GM while it is hidden.
await gm.check('#token-edit-gm-only') await gm.check('#token-edit-gm-only')
+60 -12
View File
@@ -12,7 +12,14 @@ import assert from 'node:assert/strict'
import { createPlayer, namePlayer } from '../../tools/lib.mjs' import { createPlayer, namePlayer } from '../../tools/lib.mjs'
import { openAs } from '../../tools/withserver.mjs' import { openAs } from '../../tools/withserver.mjs'
import { writeTileGrid } from '../../tools/tilefixture.mjs' import { writeTileGrid } from '../../tools/tilefixture.mjs'
import { launchBrowser, signIn, waitForVisible, withStack, sleep } from './stack.mjs' import {
launchBrowser,
signIn,
waitForText,
waitForVisible,
withStack,
sleep,
} from './stack.mjs'
import { differs, luminance, probe } from './pixels.mjs' import { differs, luminance, probe } from './pixels.mjs'
const SCENE = { w: 4096, h: 4096, tile: 32, cell: 32 } const SCENE = { w: 4096, h: 4096, tile: 32, cell: 32 }
@@ -45,6 +52,48 @@ async function gmWorld(origin, gmKey) {
return { ...gm, hello, scene: hello.scene ?? walls.scene } return { ...gm, hello, scene: hello.scene ?? walls.scene }
} }
/**
* Create the player's sighted token through the GM token panel (#78): the fog test's world is
* authored the way a GM authors it, with no raw `flags`/`vision_radius` on a wire `token.create`.
* Returns the new token id.
*/
async function createSightedToken(origin, gmKey, player, { pos, name, radius, visionRadius }) {
const browser = await launchBrowser()
try {
const context = await browser.newContext({
ignoreHTTPSErrors: true,
viewport: { width: 900, height: 900 },
})
const page = await context.newPage()
await page.goto(`${origin}/`)
await waitForVisible(page, '#signin')
await signIn(page, gmKey)
await waitForVisible(page, '#gm-panels')
await waitForText(page, '#gm-roster-list', new RegExp(name))
await page
.locator(`#token-controller option[value="${player.id}"]`)
.waitFor({ state: 'attached', timeout: 20000 })
await page.fill('#token-kind', 'pc')
await page.fill('#token-name', name)
await page.fill('#token-actual', name)
await page.fill('#token-x', String(pos[0]))
await page.fill('#token-y', String(pos[1]))
await page.fill('#token-radius', String(radius))
await page.check('#token-vision')
await page.fill('#token-vision-radius', String(visionRadius))
await page.selectOption('#token-controller', String(player.id))
await page.click('#token-create-submit')
const row = page.locator('#gm-token-list li', { hasText: name }).first()
await row.waitFor({ state: 'visible', timeout: 20000 })
const id = await row.getAttribute('data-token')
assert.ok(id, 'the panel-created token has no id')
await context.close()
return id
} finally {
await browser.close()
}
}
/** One player, one sighted token and the three walls; returns the wall ids. */ /** One player, one sighted token and the three walls; returns the wall ids. */
async function fogWorld(origin, gmKey, stateDir) { async function fogWorld(origin, gmKey, stateDir) {
const gm = await gmWorld(origin, gmKey) const gm = await gmWorld(origin, gmKey)
@@ -81,20 +130,19 @@ async function fogWorld(origin, gmKey, stateDir) {
}) })
assert.equal(secret.ok, true, JSON.stringify(secret)) assert.equal(secret.ok, true, JSON.stringify(secret))
const token = await gm.ws.request({ const tokenId = await createSightedToken(origin, gmKey, player, {
t: 'token.create',
scene: scene.id,
kind: 'pc',
pos: [2048, 2048], pos: [2048, 2048],
descriptive_name: 'Ann', name: 'Ann',
actual_name: 'Ann',
controller: player.id,
flags: { vision: true },
vision_radius: 300,
radius: 20, radius: 20,
visionRadius: 300,
}) })
assert.equal(token.ok, true, JSON.stringify(token)) // The GM's own frame confirms the panel round-trip before the pixel probes rely on the sight.
return { gm, player, scene, windowId: window.id, playerId: player.id } await gm.ws.waitFor(
frame => frame.t === 'token' && frame.id === tokenId &&
frame.flags?.vision === true && frame.vision_radius === 300,
20000,
)
return { gm, player, scene, tokenId, windowId: window.id, playerId: player.id }
} }
/** Canvas rect plus the world container's transform (#69): `screen = world * zoom + camera.xy`. */ /** Canvas rect plus the world container's transform (#69): `screen = world * zoom + camera.xy`. */
+57 -3
View File
@@ -16,6 +16,7 @@ import type { AckFrame, RosterEntry } from '../protocol.ts'
import { rosterOf } from '../reducer.ts' import { rosterOf } from '../reducer.ts'
import type { AdminToken } from '../slices/admin.ts' 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'
export interface AdminPanelHandlers { export interface AdminPanelHandlers {
send(t: string, fields?: Record<string, unknown>): Promise<AckFrame> send(t: string, fields?: Record<string, unknown>): Promise<AckFrame>
@@ -101,6 +102,17 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
radiusInput.node.type = 'number' radiusInput.node.type = 'number'
radiusInput.node.min = '0.1' radiusInput.node.min = '0.1'
radiusInput.node.step = 'any' radiusInput.node.step = 'any'
// DESIGN 8 defaults a new token's `flags` to `{}`: vision is off until the GM turns it on.
const createVision = field('input', 'token-vision', 'Vision')
createVision.node.type = 'checkbox'
const createVisionRadius = field(
'input',
'token-vision-radius',
'Vision radius (blank = scene default)',
)
createVisionRadius.node.type = 'number'
createVisionRadius.node.min = '0.1'
createVisionRadius.node.step = 'any'
const createGmOnly = field('input', 'token-gm-only', 'GM only') const createGmOnly = field('input', 'token-gm-only', 'GM only')
createGmOnly.node.type = 'checkbox' createGmOnly.node.type = 'checkbox'
const createController = field('select', 'token-controller', 'Controller') const createController = field('select', 'token-controller', 'Controller')
@@ -120,6 +132,10 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
yInput.node, yInput.node,
radiusInput.label, radiusInput.label,
radiusInput.node, radiusInput.node,
createVision.label,
createVision.node,
createVisionRadius.label,
createVisionRadius.node,
createGmOnly.label, createGmOnly.label,
createGmOnly.node, createGmOnly.node,
createControllerLabel, createControllerLabel,
@@ -138,6 +154,16 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
editActual.node.type = 'text' editActual.node.type = 'text'
const editKind = field('input', 'token-edit-kind', 'Kind') const editKind = field('input', 'token-edit-kind', 'Kind')
editKind.node.type = 'text' editKind.node.type = 'text'
const editVision = field('input', 'token-edit-vision', 'Vision')
editVision.node.type = 'checkbox'
const editVisionRadius = field(
'input',
'token-edit-vision-radius',
'Vision radius (blank = scene default)',
)
editVisionRadius.node.type = 'number'
editVisionRadius.node.min = '0.1'
editVisionRadius.node.step = 'any'
const editGmOnly = field('input', 'token-edit-gm-only', 'GM only') const editGmOnly = field('input', 'token-edit-gm-only', 'GM only')
editGmOnly.node.type = 'checkbox' editGmOnly.node.type = 'checkbox'
const editController = field('select', 'token-edit-controller', 'Controller') const editController = field('select', 'token-edit-controller', 'Controller')
@@ -176,6 +202,10 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
editActual.node, editActual.node,
editKind.label, editKind.label,
editKind.node, editKind.node,
editVision.label,
editVision.node,
editVisionRadius.label,
editVisionRadius.node,
editGmOnly.label, editGmOnly.label,
editGmOnly.node, editGmOnly.node,
editController.label, editController.label,
@@ -328,6 +358,8 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
editName.node.value = token.descriptiveName ?? token.name editName.node.value = token.descriptiveName ?? token.name
editActual.node.value = token.actualName ?? token.name editActual.node.value = token.actualName ?? token.name
editKind.node.value = token.kind ?? '' editKind.node.value = token.kind ?? ''
editVision.node.checked = token.flags['vision'] === true
editVisionRadius.node.value = token.visionRadius === null ? '' : String(token.visionRadius)
editGmOnly.node.checked = token.gmOnly editGmOnly.node.checked = token.gmOnly
renderControllerOptions( renderControllerOptions(
editController.node, editController.node,
@@ -385,6 +417,12 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
return current ? selectedTokenId(current) : null return current ? selectedTokenId(current) : null
} }
function currentToken(): AdminToken | null {
const selected = currentSelection()
if (selected === null || !current) return null
return adminTokens(current).find(token => token.id === selected) ?? null
}
async function request(t: string, fields: Record<string, unknown> = {}): Promise<AckFrame | null> { async function request(t: string, fields: Record<string, unknown> = {}): Promise<AckFrame | null> {
try { try {
const ack = await handlers.send(t, fields) const ack = await handlers.send(t, fields)
@@ -480,6 +518,11 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
setError('Radius must be a positive number or blank.') setError('Radius must be a positive number or blank.')
return return
} }
const vision = createVisionFields(createVision.node.checked, createVisionRadius.node.value)
if (!vision.ok) {
setError(vision.error)
return
}
const controllerValue = createController.node.value const controllerValue = createController.node.value
const controller = controllerValue === '' ? null : Number(controllerValue) const controller = controllerValue === '' ? null : Number(controllerValue)
const ack = await request('token.create', { const ack = await request('token.create', {
@@ -491,6 +534,7 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
radius, radius,
gm_only: createGmOnly.node.checked, gm_only: createGmOnly.node.checked,
controller, controller,
...vision.fields,
}) })
if (ack?.ok) { if (ack?.ok) {
const created = ack as { id?: unknown } const created = ack as { id?: unknown }
@@ -499,8 +543,8 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
} }
async function saveToken(): Promise<void> { async function saveToken(): Promise<void> {
const selected = currentSelection() const token = currentToken()
if (selected === null) return if (token === null) return
setError(null) setError(null)
const name = editName.node.value.trim() const name = editName.node.value.trim()
const actual = editActual.node.value.trim() const actual = editActual.node.value.trim()
@@ -509,9 +553,19 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
setError('Kind and both names are required.') setError('Kind and both names are required.')
return return
} }
const vision = updateVisionFields(
token.id,
token.flags,
editVision.node.checked,
editVisionRadius.node.value,
)
if (!vision.ok) {
setError(vision.error)
return
}
const controllerValue = editController.node.value const controllerValue = editController.node.value
await request('token.update', { await request('token.update', {
id: selected, ...vision.fields,
kind, kind,
descriptive_name: name, descriptive_name: name,
actual_name: actual, actual_name: actual,
+7
View File
@@ -31,6 +31,8 @@ export interface AdminToken {
statuses: AdminStatus[] statuses: AdminStatus[]
descriptiveName: string | null descriptiveName: string | null
actualName: string | null actualName: string | null
/** Free-form GM flags (DESIGN 8); the panel merges `vision` into this object on save. */
flags: Record<string, unknown>
visionRadius: number | null visionRadius: number | null
radiusOwn: number | null radiusOwn: number | null
} }
@@ -60,6 +62,10 @@ function finiteOrNull(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) ? value : null return typeof value === 'number' && Number.isFinite(value) ? value : null
} }
function flagsObject(value: unknown): Record<string, unknown> {
return isRecord(value) ? { ...value } : {}
}
function parseStatuses(value: unknown): AdminStatus[] { function parseStatuses(value: unknown): AdminStatus[] {
if (!Array.isArray(value)) return [] if (!Array.isArray(value)) return []
const out: AdminStatus[] = [] const out: AdminStatus[] = []
@@ -107,6 +113,7 @@ export function tokenFromFrame(frame: ServerFrame): AdminToken | null {
descriptiveName: descriptiveName:
typeof frame['descriptive_name'] === 'string' ? frame['descriptive_name'] : null, typeof frame['descriptive_name'] === 'string' ? frame['descriptive_name'] : null,
actualName: typeof frame['actual_name'] === 'string' ? frame['actual_name'] : null, actualName: typeof frame['actual_name'] === 'string' ? frame['actual_name'] : null,
flags: flagsObject(frame['flags']),
visionRadius: finiteOrNull(frame['vision_radius']), visionRadius: finiteOrNull(frame['vision_radius']),
radiusOwn: finiteOrNull(frame['radius_own']), radiusOwn: finiteOrNull(frame['radius_own']),
} }
+78
View File
@@ -0,0 +1,78 @@
// The GM token panel's pure half (T11/#74, #78): local validation of the vision controls and the
// fields the panel sends for `token.create` / `token.update` (DESIGN 6.1, 8). No DOM, no socket.
//
// `flags` is free-form (DESIGN 8): an edit writes only the `vision` key and copies every other key
// from the current GM `token` frame, so future GM flags survive a save. A new token keeps the
// DESIGN 8 default (`flags: '{}'`): vision off means no `flags` field is sent at all.
//
// `vision_radius` is also the player's move step cap (DESIGN 5.5), so the panel validates it like
// the token radius: blank = scene default (`null`), anything else must be > 0 and finite.
/** The vision part of a `token.create` / `token.update` payload. */
export interface VisionFields {
/** Present only when the panel writes a flag (create with vision on, or any edit). */
flags?: Record<string, unknown>
vision_radius: number | null
}
export type VisionFieldsResult =
| { ok: true; fields: VisionFields }
| { ok: false; error: string }
export type VisionUpdateResult =
| { ok: true; fields: { id: string; flags: Record<string, unknown>; vision_radius: number | null } }
| { ok: false; error: string }
type RadiusResult = { ok: true; value: number | null } | { ok: false; error: string }
/** Blank is the scene default; non-finite and non-positive values are refused before the wire. */
export function parseVisionRadius(raw: string): RadiusResult {
const text = raw.trim()
if (text === '') return { ok: true, value: null }
const value = Number(text)
if (!Number.isFinite(value) || value <= 0) {
return {
ok: false,
error: 'Vision radius must be a positive number or blank for the scene default.',
}
}
return { ok: true, value }
}
/** Copy `flags` and set only `vision`; every other GM flag survives (DESIGN 8). */
export function withVisionFlag(
flags: Record<string, unknown>,
vision: boolean,
): Record<string, unknown> {
return { ...flags, vision }
}
/**
* `token.create` vision fields. Vision off sends no `flags`, so the server keeps its DESIGN 8
* default (`{}`); vision on carries only the one key.
*/
export function createVisionFields(vision: boolean, rawRadius: string): VisionFieldsResult {
const radius = parseVisionRadius(rawRadius)
if (!radius.ok) return radius
return {
ok: true,
fields: vision
? { flags: { vision: true }, vision_radius: radius.value }
: { vision_radius: radius.value },
}
}
/** `token.update` vision fields: the stored flags are the base, never a rebuilt object. */
export function updateVisionFields(
id: string,
flags: Record<string, unknown>,
vision: boolean,
rawRadius: string,
): VisionUpdateResult {
const radius = parseVisionRadius(rawRadius)
if (!radius.ok) return radius
return {
ok: true,
fields: { id, flags: withVisionFlag(flags, vision), vision_radius: radius.value },
}
}
+19
View File
@@ -83,6 +83,8 @@ describe('GM token records', () => {
statuses: [{ status: 'stuck', source: 'walls' }], statuses: [{ status: 'stuck', source: 'walls' }],
descriptiveName: 'Rat', descriptiveName: 'Rat',
actualName: 'Giant Rat', actualName: 'Giant Rat',
flags: {},
visionRadius: null,
}) })
const changed = reduce( const changed = reduce(
@@ -107,6 +109,23 @@ describe('GM token records', () => {
}) })
}) })
it('keeps the free-form flags and the vision radius the panel edits (#78)', () => {
const state = run(
{ type: 'connecting' },
hello(1),
gmToken('abc', { flags: { vision: true, note: 'kept' }, vision_radius: 300 }),
)
expect(tokenOf(state, 'abc')).toMatchObject({
flags: { vision: true, note: 'kept' },
visionRadius: 300,
})
const changed = reduce(state, gmToken('abc', { flags: { vision: false }, vision_radius: null }))
expect(tokenOf(changed, 'abc')).toMatchObject({
flags: { vision: false },
visionRadius: null,
})
})
it('ignores a malformed token frame instead of inventing a row', () => { it('ignores a malformed token frame instead of inventing a row', () => {
const state = run({ type: 'connecting' }, hello(1), frame({ t: 'token', n: 2, id: 7 })) const state = run({ type: 'connecting' }, hello(1), frame({ t: 'token', n: 2, id: 7 }))
expect(adminTokens(state)).toEqual([]) expect(adminTokens(state)).toEqual([])
+79
View File
@@ -0,0 +1,79 @@
// #78 token panel seam: the vision controls' local rules and the exact `flags`/`vision_radius`
// fields the panel sends. Pure, no DOM, no socket. `flags` is free-form (DESIGN 8), so an edit must
// copy the stored object and change only `vision`; a new token keeps the `{}` default.
import { describe, expect, it } from 'vitest'
import {
createVisionFields,
parseVisionRadius,
updateVisionFields,
withVisionFlag,
} from '../src/tokenPanel.ts'
describe('vision radius', () => {
it('treats blank as the scene default and accepts any finite positive number', () => {
expect(parseVisionRadius('')).toEqual({ ok: true, value: null })
expect(parseVisionRadius(' ')).toEqual({ ok: true, value: null })
expect(parseVisionRadius('300')).toEqual({ ok: true, value: 300 })
expect(parseVisionRadius(' 12.5 ')).toEqual({ ok: true, value: 12.5 })
})
it('refuses zero, negative, non-finite and non-numeric values like the radius field', () => {
for (const raw of ['0', '-1', 'abc', 'Infinity', 'NaN']) {
const result = parseVisionRadius(raw)
expect(result.ok).toBe(false)
if (!result.ok) expect(result.error).toMatch(/positive number or blank/)
}
})
})
describe('create fields', () => {
it('sends only the vision key when vision is on, plus the radius', () => {
expect(createVisionFields(true, '300')).toEqual({
ok: true,
fields: { flags: { vision: true }, vision_radius: 300 },
})
expect(createVisionFields(true, '')).toEqual({
ok: true,
fields: { flags: { vision: true }, vision_radius: null },
})
})
it('sends no flags when vision is off, keeping the DESIGN 8 `{}` default', () => {
expect(createVisionFields(false, '')).toEqual({
ok: true,
fields: { vision_radius: null },
})
})
it('refuses a bad radius before the intent leaves the client', () => {
const result = createVisionFields(true, '0')
expect(result.ok).toBe(false)
})
})
describe('update fields', () => {
it('copies the stored flags and writes only vision, so other GM flags survive', () => {
expect(updateVisionFields('abc', { blocks_move: true, note: 'x' }, false, '250')).toEqual({
ok: true,
fields: {
id: 'abc',
flags: { blocks_move: true, note: 'x', vision: false },
vision_radius: 250,
},
})
expect(withVisionFlag({ vision: true, other: 1 }, true)).toEqual({ vision: true, other: 1 })
})
it('clears the radius back to the scene default with null', () => {
expect(updateVisionFields('abc', { vision: true }, true, '')).toEqual({
ok: true,
fields: { id: 'abc', flags: { vision: true }, vision_radius: null },
})
})
it('refuses a non-positive radius on edit too', () => {
const result = updateVisionFields('abc', {}, true, '-5')
expect(result.ok).toBe(false)
})
})
+6
View File
@@ -864,6 +864,12 @@ top-level object is depth 1). At a cap is accepted; over is `invalid` and applie
live next to the property caps and are read from one shared validator; token `flags`, props and live next to the property caps and are read from one shared validator; token `flags`, props and
stored values above a cap are out of scope. See current 6.1. stored values above a cap are out of scope. See current 6.1.
Owner also decided 2026-11-21 [FIXED (owner-delegated, 2026-11-21, #78)]: a new token's `flags`
stays the §8 default `'{}'`, so the GM token panel's Vision checkbox starts unchecked and its vision
radius starts blank (scene default), on create and on edit. No wire default changed; the panel
follows the existing `'{}'` reading rather than choosing "vision on for a player-controlled token".
See current 8.
## D. Superseded statements removed from the current spec ## D. Superseded statements removed from the current spec
Each entry quotes the superseded statement (excerpt) and names the surviving rule. Each entry quotes the superseded statement (excerpt) and names the surviving rule.
+4
View File
@@ -2090,6 +2090,10 @@ copy/export stable).
said "the server never interprets props in v1". Property writes are GM-only in v1 (6.1, #11); said "the server never interprets props in v1". Property writes are GM-only in v1 (6.1, #11);
the writable-by role and a default value are deferred to the FFF seam (9, post-v1), not part of the writable-by role and a default value are deferred to the FFF seam (9, post-v1), not part of
this registry. this registry.
- **New-token vision default [FIXED (owner-delegated), 2026-11-21, #78].** A new token's `flags`
stays `'{}'`, so it sees nothing until the GM turns vision on: the token panel's Vision checkbox
starts unchecked and its vision radius starts blank (the scene default), on create and on edit.
No wire default changed; the GM panel matches §8's `'{}'` default rather than adding one.
- **Character [FIXED, owner decision 2026-11-10, #14]**: own record, separate from tokens. Fields - **Character [FIXED, owner decision 2026-11-10, #14]**: own record, separate from tokens. Fields
(indicative): `id` (random, same format as token ids), `owner` (exactly one player id; the GM is a (indicative): `id` (random, same format as token ids), `owner` (exactly one player id; the GM is a
player, so GM ownership = the GM's player id; the GM reassigns), `descriptive_name`, `actual_name` player, so GM ownership = the GM's player id; the GM reassigns), `descriptive_name`, `actual_name`