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:
@@ -16,6 +16,7 @@ import type { AckFrame, RosterEntry } from '../protocol.ts'
|
||||
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'
|
||||
|
||||
export interface AdminPanelHandlers {
|
||||
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.min = '0.1'
|
||||
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')
|
||||
createGmOnly.node.type = 'checkbox'
|
||||
const createController = field('select', 'token-controller', 'Controller')
|
||||
@@ -120,6 +132,10 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
yInput.node,
|
||||
radiusInput.label,
|
||||
radiusInput.node,
|
||||
createVision.label,
|
||||
createVision.node,
|
||||
createVisionRadius.label,
|
||||
createVisionRadius.node,
|
||||
createGmOnly.label,
|
||||
createGmOnly.node,
|
||||
createControllerLabel,
|
||||
@@ -138,6 +154,16 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
editActual.node.type = 'text'
|
||||
const editKind = field('input', 'token-edit-kind', 'Kind')
|
||||
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')
|
||||
editGmOnly.node.type = 'checkbox'
|
||||
const editController = field('select', 'token-edit-controller', 'Controller')
|
||||
@@ -176,6 +202,10 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
editActual.node,
|
||||
editKind.label,
|
||||
editKind.node,
|
||||
editVision.label,
|
||||
editVision.node,
|
||||
editVisionRadius.label,
|
||||
editVisionRadius.node,
|
||||
editGmOnly.label,
|
||||
editGmOnly.node,
|
||||
editController.label,
|
||||
@@ -328,6 +358,8 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
editName.node.value = token.descriptiveName ?? token.name
|
||||
editActual.node.value = token.actualName ?? token.name
|
||||
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
|
||||
renderControllerOptions(
|
||||
editController.node,
|
||||
@@ -385,6 +417,12 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
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> {
|
||||
try {
|
||||
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.')
|
||||
return
|
||||
}
|
||||
const vision = createVisionFields(createVision.node.checked, createVisionRadius.node.value)
|
||||
if (!vision.ok) {
|
||||
setError(vision.error)
|
||||
return
|
||||
}
|
||||
const controllerValue = createController.node.value
|
||||
const controller = controllerValue === '' ? null : Number(controllerValue)
|
||||
const ack = await request('token.create', {
|
||||
@@ -491,6 +534,7 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
radius,
|
||||
gm_only: createGmOnly.node.checked,
|
||||
controller,
|
||||
...vision.fields,
|
||||
})
|
||||
if (ack?.ok) {
|
||||
const created = ack as { id?: unknown }
|
||||
@@ -499,8 +543,8 @@ export function mountAdminPanel(host: HTMLElement, handlers: AdminPanelHandlers)
|
||||
}
|
||||
|
||||
async function saveToken(): Promise<void> {
|
||||
const selected = currentSelection()
|
||||
if (selected === null) return
|
||||
const token = currentToken()
|
||||
if (token === null) return
|
||||
setError(null)
|
||||
const name = editName.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.')
|
||||
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
|
||||
await request('token.update', {
|
||||
id: selected,
|
||||
...vision.fields,
|
||||
kind,
|
||||
descriptive_name: name,
|
||||
actual_name: actual,
|
||||
|
||||
Reference in New Issue
Block a user