feat: GM characters, reveals, who-sees-it and seen_by (#75)
Server: GM token frames gain the additive, GM-only seen_by:[player ids], computed from each player's existing sight (PlayerVision.visibleTo) with no extra polygon pass. Leakcheck BannedAlways bans seen_by; a seenBy fault build is caught as exactly WALLDATA. proto stays 2 (6.2 additive). Client: new cast slice parses character/character_gone/encountered frames and seen_by; gmcast panel adds character create/rename/assign/remove, reveal to one/all, encountered forget (grey entries only) and the who-sees-it list (0/100 in M4). Mounted beside the #74 admin panel. Docs: DESIGN 5.9/6.1/6.2/7.4 record the round-1 shape and the no-bump call. Gates: devbox run test, client-test, e2e green; bench recorded.
This commit is contained in:
@@ -32,6 +32,7 @@ const FAULTS = {
|
||||
gmOnly: ['GMONLY_TOKEN', 'NO_REMOVE'],
|
||||
walls: ['WALLDATA'],
|
||||
wallHeight: ['WALLDATA'],
|
||||
seenBy: ['WALLDATA'], // #75: the GM-only who-sees-it field in a player token frame
|
||||
oneWay: ['ONEWAY'],
|
||||
markerEarly: ['MARKER_EARLY'],
|
||||
markerExtra: ['MARKER_EXTRA'],
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ const
|
||||
MarkerIdLength = 12
|
||||
MarkerIdAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
|
||||
BannedAlways = ["walls", "wall", "wall_gone", "a", "b", "open", "kind", "controller", "gm_only",
|
||||
"flags", "radius_own", "extra",
|
||||
"flags", "radius_own", "extra", "seen_by",
|
||||
# every wall field name (#54): geometry, switches, door settings, label
|
||||
"thickness", "position", "height", "blocks_sight", "blocks_movement", "sight_dir",
|
||||
"player_marker", "door", "secret", "locked", "label"]
|
||||
|
||||
@@ -383,6 +383,68 @@ test('restart: tokens, positions and controllers come back with the same view',
|
||||
}
|
||||
})
|
||||
|
||||
test('seen_by: the GM sees which players see each token (0/100); players never receive it', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const bob = await namedPlayer(s.origin, gm, 'Bob')
|
||||
const pa = await playerConnect(s.origin, alice)
|
||||
const pb = await playerConnect(s.origin, bob)
|
||||
const create = fields => gm.ws.request({ t: 'token.create', scene: gm.scene, ...fields })
|
||||
// One scout each: Alice at (400,400), Bob far away at (3900,3900). Both have sight, so the
|
||||
// `seen_by` lists below are the server's own per-player vision, not a second rule.
|
||||
const aScout = await create({ kind: 'pc', pos: [400, 400], descriptive_name: 'A',
|
||||
actual_name: 'A', controller: alice.id, flags: { vision: true } })
|
||||
const bScout = await create({ kind: 'pc', pos: [3900, 3900], descriptive_name: 'B',
|
||||
actual_name: 'B', controller: bob.id, flags: { vision: true } })
|
||||
// In Alice's sight, controlled by nobody.
|
||||
const near = await create({ kind: 'npc', pos: [500, 500], descriptive_name: 'near',
|
||||
actual_name: 'Near' })
|
||||
// In Alice's sight, controlled by Bob: both see it (sight plus control, 3.1).
|
||||
const bobs = await create({ kind: 'npc', pos: [300, 300], descriptive_name: 'bobs',
|
||||
actual_name: 'Bobs', controller: bob.id })
|
||||
// gm_only inside Alice's sight: nobody sees it.
|
||||
const hidden = await create({ kind: 'npc', pos: [450, 450], descriptive_name: 'hidden',
|
||||
actual_name: 'Hidden', gm_only: true })
|
||||
// gm_only, controlled by Alice: its controller always sees it.
|
||||
const hiddenMine = await create({ kind: 'npc', pos: [450, 550], descriptive_name: 'hidden mine',
|
||||
actual_name: 'Hidden Mine', gm_only: true,
|
||||
controller: alice.id })
|
||||
// Out of Alice's sight, controlled by Bob: its controller sees it.
|
||||
const far = await create({ kind: 'npc', pos: [3000, 3000], descriptive_name: 'far',
|
||||
actual_name: 'Far', controller: bob.id })
|
||||
|
||||
const seen = async id => {
|
||||
const frame = await gm.ws.waitFor(m => m.t === 'token' && m.id === id && Array.isArray(m.seen_by))
|
||||
return frame.seen_by
|
||||
}
|
||||
assert.deepEqual(await seen(aScout.id), [alice.id])
|
||||
assert.deepEqual(await seen(bScout.id), [bob.id])
|
||||
assert.deepEqual(await seen(near.id), [alice.id])
|
||||
assert.deepEqual(await seen(bobs.id), [alice.id, bob.id].sort((a, b) => a - b))
|
||||
assert.deepEqual(await seen(hidden.id), [], 'gm_only and uncontrolled: nobody sees it')
|
||||
assert.deepEqual(await seen(hiddenMine.id), [alice.id], 'a controller always sees its token')
|
||||
assert.deepEqual(await seen(far.id), [bob.id])
|
||||
|
||||
// A `gm_only` flip updates the list: control survives it, sight does not.
|
||||
assert.equal((await gm.ws.request({ t: 'token.update', id: bobs.id, gm_only: true })).ok, true)
|
||||
let flipped = null
|
||||
await gm.ws.waitFor(m => {
|
||||
if (m.t === 'token' && m.id === bobs.id && m.gm_only === true) flipped = m
|
||||
return flipped !== null
|
||||
})
|
||||
assert.deepEqual(flipped.seen_by, [bob.id])
|
||||
|
||||
// The only M4 wire change is GM-only: neither player socket ever receives the field.
|
||||
await sleep(150)
|
||||
for (const conn of [pa, pb]) {
|
||||
assert.equal(JSON.stringify(conn.ws.messages).includes('seen_by'), false,
|
||||
'seen_by reached a player wire')
|
||||
}
|
||||
pa.ws.close(); pb.ws.close(); gm.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
test('player.remove hands the player\'s tokens to the GM (3.2)', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
|
||||
Reference in New Issue
Block a user