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:
@@ -83,6 +83,8 @@ describe('GM token records', () => {
|
||||
statuses: [{ status: 'stuck', source: 'walls' }],
|
||||
descriptiveName: 'Rat',
|
||||
actualName: 'Giant Rat',
|
||||
flags: {},
|
||||
visionRadius: null,
|
||||
})
|
||||
|
||||
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', () => {
|
||||
const state = run({ type: 'connecting' }, hello(1), frame({ t: 'token', n: 2, id: 7 }))
|
||||
expect(adminTokens(state)).toEqual([])
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user