fix(client): read walls snapshot with the frame scene (#87)
The snapshot is {t:'walls', scene, walls:[{id, a, b, ...}]} per DESIGN 6.1:
scene lives on the frame, entries carry only the wall record. The client
required scene on each entry and dropped every snapshot wall, so a GM
reload/reconnect showed canvas.dataset.walls==='0' while the server still
blocked player sight.
Pass the enclosing frame's scene into wallViewFromFrame and keep an entry's
own scene as the tolerant fallback. The server already matched DESIGN, so
no wall wire shape changed.
Tests: client reducer from a real snapshot frame, WS pin that a snapshot
entry equals a wall delta record, and e2e reload plus server-restart.
The old e2e missed it because every wall test built walls in-session.
This commit is contained in:
@@ -63,6 +63,12 @@ const wallBody = (id: number, overrides: Record<string, unknown> = {}): Record<s
|
||||
...overrides,
|
||||
})
|
||||
|
||||
// DESIGN 6.1: a `walls` snapshot entry carries the wall fields only; `scene` is on the frame.
|
||||
const snapBody = (id: number, overrides: Record<string, unknown> = {}): Record<string, unknown> => {
|
||||
const { scene: _scene, ...entry } = wallBody(id, overrides)
|
||||
return entry
|
||||
}
|
||||
|
||||
const run = (...events: ReducerEvent[]): RootState =>
|
||||
events.reduce((state, event) => reduce(state, event), initialState())
|
||||
|
||||
@@ -76,7 +82,7 @@ describe('wall slice (DESIGN 6.1, GM only)', () => {
|
||||
const state = run(
|
||||
{ type: 'connecting' },
|
||||
hello(1),
|
||||
frame({ t: 'walls', n: 2, scene: 1, walls: [wallBody(1), wallBody(2, { a: [100, 200], b: [100, 400] })] }),
|
||||
frame({ t: 'walls', n: 2, scene: 1, walls: [snapBody(1), snapBody(2, { a: [100, 200], b: [100, 400] })] }),
|
||||
)
|
||||
expect(wallsOf(state).map(wall => wall.id)).toEqual([1, 2])
|
||||
expect(wallOf(state, 1)?.kind).toBe('wall')
|
||||
@@ -89,6 +95,31 @@ describe('wall slice (DESIGN 6.1, GM only)', () => {
|
||||
expect(wallsOf(gone).map(wall => wall.id)).toEqual([1])
|
||||
})
|
||||
|
||||
it('loads a real `walls` snapshot: scene on the frame, entries without scene (6.1)', () => {
|
||||
// The server's snapshot frame is `{t:'walls', scene, walls:[{id, a, b, ...}]}`; a delta is
|
||||
// `{t:'wall', scene, id, a, b, ...}`. This is the reload regression: the reducer must read the
|
||||
// frame's scene for every entry, not require `scene` on the entry itself.
|
||||
const snapshot = frame({
|
||||
t: 'walls',
|
||||
n: 2,
|
||||
scene: 7,
|
||||
walls: [snapBody(1), snapBody(2, { a: [100, 200], b: [100, 400] })],
|
||||
})
|
||||
const state = run({ type: 'connecting' }, hello(1), snapshot)
|
||||
expect(wallsOf(state).map(wall => wall.id)).toEqual([1, 2])
|
||||
expect(wallOf(state, 1)?.scene).toBe(7)
|
||||
expect(wallOf(state, 2)?.scene).toBe(7)
|
||||
|
||||
// An entry that still carries its own scene (an older/foreign snapshot) is tolerated.
|
||||
const explicit = run(
|
||||
{ type: 'connecting' },
|
||||
hello(1),
|
||||
frame({ t: 'walls', n: 2, scene: 7, walls: [wallBody(3, { scene: 3 })] }),
|
||||
)
|
||||
expect(wallOf(explicit, 3)?.scene).toBe(3)
|
||||
expect(wallOf(explicit, 3)).not.toBeNull()
|
||||
})
|
||||
|
||||
it('keeps selection while the wall exists and clears it on wall_gone or a snapshot without it', () => {
|
||||
const state = run(
|
||||
{ type: 'connecting' },
|
||||
|
||||
Reference in New Issue
Block a user