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
+60 -12
View File
@@ -12,7 +12,14 @@ import assert from 'node:assert/strict'
import { createPlayer, namePlayer } from '../../tools/lib.mjs'
import { openAs } from '../../tools/withserver.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'
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 }
}
/**
* 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. */
async function fogWorld(origin, gmKey, stateDir) {
const gm = await gmWorld(origin, gmKey)
@@ -81,20 +130,19 @@ async function fogWorld(origin, gmKey, stateDir) {
})
assert.equal(secret.ok, true, JSON.stringify(secret))
const token = await gm.ws.request({
t: 'token.create',
scene: scene.id,
kind: 'pc',
const tokenId = await createSightedToken(origin, gmKey, player, {
pos: [2048, 2048],
descriptive_name: 'Ann',
actual_name: 'Ann',
controller: player.id,
flags: { vision: true },
vision_radius: 300,
name: 'Ann',
radius: 20,
visionRadius: 300,
})
assert.equal(token.ok, true, JSON.stringify(token))
return { gm, player, scene, windowId: window.id, playerId: player.id }
// The GM's own frame confirms the panel round-trip before the pixel probes rely on the sight.
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`. */