feat(walls): windows — see-through barrier, movement follows blocks_movement (#57)
- geometry.Wall carries the stored blocks_sight/blocks_movement switches; sight asks blocksSight, movement and the status rules ask blocks (open door passes both). - worldmap translates both switches; moverules only pushes on a movement barrier. - leakcheck and the tile oracle read blocks_sight independently. - Walls/token-details/tiles groups prove both forms, sight-through, stuck, push and the locked-window open refusal; existing scenes stay byte-identical. Ref #57 # Conflicts: # server/geometry.nim # server/world.nim # server/worldmap.nim # tools/leakcheck.nim
This commit is contained in:
+49
-6
@@ -56,11 +56,12 @@ async function addWall(gm, fields) {
|
||||
|
||||
// A named player who controls one token with vision at (300, 300), radius 400, and a wall at x=400
|
||||
// splitting the view. The player's explored grid is then produced by the server's own resync.
|
||||
async function sceneWithVision(s, gmKey, ngx) {
|
||||
// `wallFields` lets a test make that segment a see-through window without changing anything else.
|
||||
async function sceneWithVision(s, gmKey, ngx, wallFields = {}) {
|
||||
const gm = await gmConnect(ngx.origin, gmKey)
|
||||
const player = await createPlayer(gm.ws)
|
||||
await namePlayer(ngx.origin, player.key, 'Alice')
|
||||
const wall = await addWall(gm, { a: [400, 100], b: [400, 700] })
|
||||
const wall = await addWall(gm, { a: [400, 100], b: [400, 700], ...wallFields })
|
||||
const created = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
|
||||
pos: [300, 300], flags: { vision: true },
|
||||
vision_radius: 400, controller: player.id,
|
||||
@@ -111,11 +112,13 @@ function segGap(p, q, a, b) {
|
||||
return Math.min(segDist(p, a, b), segDist(q, a, b), segDist(a, p, q), segDist(b, p, q))
|
||||
}
|
||||
|
||||
function blockingWalls(wallsFrame) {
|
||||
// A wall blocks sight unless it is an open door (today's rule; the raw switches gain their
|
||||
// behaviour in the window/one-way rounds, #57/#58).
|
||||
function blockingWalls(wallsFrame, opts = {}) {
|
||||
// The oracle's own reading of the sight switches (#57): a wall blocks sight only while its
|
||||
// `blocks_sight` switch is on and it is not an open door. A window is see-through along its whole
|
||||
// drawn length. `ignoreBlocksSight` is the negative control: it restores the old
|
||||
// `door/open`-only rule, under which a window would wrongly block.
|
||||
return wallsFrame.walls
|
||||
.filter(w => !(w.door && w.open))
|
||||
.filter(w => (opts.ignoreBlocksSight || w.blocks_sight !== false) && !(w.door && w.open))
|
||||
.map(w => ({ a: { x: w.a[0], y: w.a[1] }, b: { x: w.b[0], y: w.b[1] } }))
|
||||
}
|
||||
|
||||
@@ -252,6 +255,46 @@ test('tile gate: leak check (d) matches the independent explored oracle', async
|
||||
})
|
||||
})
|
||||
|
||||
test('tile gate: a window is see-through along its drawn length (#57)', async () => {
|
||||
await withTileStack(async ({ s, gmKey, ngx, stateDir }) => {
|
||||
// A fixed window: the same segment as the solid-wall scenario, `blocks_sight:false` and no door,
|
||||
// so nothing about the change is a door opening. The token still sits 100 px west of it.
|
||||
const ctx = await sceneWithVision(s, gmKey, ngx,
|
||||
{ blocks_sight: false, blocks_movement: true })
|
||||
const scene = ctx.gm.ws.messages.find(m => m.t === 'hello' && m.scene).scene
|
||||
const cell = scene.cell
|
||||
const tile = scene.tile_size
|
||||
const frame = ctx.wallsFrame.walls[0]
|
||||
assert.equal(frame.kind, 'window')
|
||||
assert.equal(frame.blocks_sight, false)
|
||||
assert.equal(frame.blocks_movement, true)
|
||||
assert.equal(frame.door, false, 'the fixed form has no open state')
|
||||
|
||||
writeTileGrid(stateDir, { scene: scene.id, artVersion: ctx.artVersion, size: tile,
|
||||
x0: 0, x1: 31, y0: 0, y1: 31 })
|
||||
const o = { x: ctx.token.pos[0], y: ctx.token.pos[1] }
|
||||
const radius = ctx.token.vision_radius
|
||||
const seenThrough = blockingWalls(ctx.wallsFrame)
|
||||
const opaque = blockingWalls(ctx.wallsFrame, { ignoreBlocksSight: true })
|
||||
// Cells just east of x=400 are behind the drawn window. The oracle (own reading of
|
||||
// `blocks_sight`) can see them; a window treated as opaque could not, which is the control.
|
||||
for (const bx of [13, 14, 15]) {
|
||||
assert.equal(oracleCell({ o, radius, walls: seenThrough, cell, x: bx, y: 9 }).maybe, true,
|
||||
`cell ${bx},9 must be visible through the window`)
|
||||
assert.equal(oracleCell({ o, radius, walls: opaque, cell, x: bx, y: 9 }).maybe, false,
|
||||
`control: cell ${bx},9 must be hidden if the window wrongly blocked sight`)
|
||||
}
|
||||
// The gate agrees with the see-through oracle: those cells are allowed.
|
||||
const cookie = ctx.seenCtx.cookie
|
||||
for (const bx of [14, 15]) {
|
||||
const r = await getTile(ngx.origin, tileUrl(scene.id, ctx.artVersion, bx, 9), cookie)
|
||||
await r.arrayBuffer()
|
||||
assert.equal(r.status, 200, `tile ${bx},9 behind the window must be allowed`)
|
||||
}
|
||||
ctx.gm.ws.close(); ctx.seenCtx.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
test('tile gate: refusals, direct /_tiles, malformed and out-of-range paths', async () => {
|
||||
await withTileStack(async ({ s, gmKey, ngx, stateDir }) => {
|
||||
const ctx = await sceneWithVision(s, gmKey, ngx)
|
||||
|
||||
Reference in New Issue
Block a user