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:
+77
-12
@@ -7,6 +7,7 @@ import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { createPlayer, join, namePlayer } from '../../tools/lib.mjs'
|
||||
import { openAs } from '../../tools/withserver.mjs'
|
||||
import { writeTileGrid } from '../../tools/tilefixture.mjs'
|
||||
import {
|
||||
launchBrowser,
|
||||
newPage,
|
||||
@@ -68,7 +69,7 @@ async function waitForHiddenRow(page, tokenId) {
|
||||
}
|
||||
|
||||
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 browser = await launchBrowser()
|
||||
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 ------------------------------
|
||||
const gmView = await newPage(browser)
|
||||
const gm = gmView.page
|
||||
await recordSockets(gm)
|
||||
await gm.goto(`${origin}/`)
|
||||
await waitForVisible(gm, '#signin')
|
||||
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/)
|
||||
|
||||
// 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).
|
||||
const scout = await raw.ws.request({
|
||||
t: 'token.create',
|
||||
// hidden by `gm_only` (a token the player controls is always visible, by 3.1). It is created
|
||||
// through the token panel with vision on (#78): no raw `flags`/`vision_radius` shortcut.
|
||||
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,
|
||||
kind: 'pc',
|
||||
pos: [400, 400],
|
||||
descriptive_name: 'Scout',
|
||||
actual_name: 'Scout',
|
||||
controller: aliceId,
|
||||
flags: { vision: true },
|
||||
artVersion: rawHello.scene.art_version,
|
||||
size: rawHello.scene.tile_size,
|
||||
x0: 0,
|
||||
x1: 60,
|
||||
y0: 0,
|
||||
y1: 60,
|
||||
})
|
||||
assert.equal(scout.ok, true)
|
||||
await waitTokenFrame(player, scout.id, frame => frame.mine === true)
|
||||
const wallSession = await join(origin, aliceKey)
|
||||
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 ---------------------------------------------------
|
||||
// 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-actual', 'Giant Rat')
|
||||
await gm.fill('#token-x', '460')
|
||||
await gm.fill('#token-y', '450')
|
||||
await gm.fill('#token-radius', '5')
|
||||
await gm.selectOption('#token-controller', '')
|
||||
await gm.click('#token-create-submit')
|
||||
const tokenRow = gm.locator('#gm-token-list li', { hasText: 'Rat' }).first()
|
||||
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 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 -------------
|
||||
// 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')
|
||||
|
||||
Reference in New Issue
Block a user