82 lines
3.9 KiB
Nim
82 lines
3.9 KiB
Nim
## Player marker memory in process (DESIGN 5.8, 6.1, ADR-0015; #59/#60): the emission gate, the
|
|
## opaque per-player id, the fixed anchor, and the retraction rule. The wire, storage, resync and
|
|
## privacy are proven by tools/markers.test.mjs; this file pins the rule the mutation suite can
|
|
## mutate: a marker is memory, so only a cause change (wall gone, switch off, no longer a window,
|
|
## geometry moved) retracts it, and the signature is exactly those causes.
|
|
import std/[options, tables, unittest]
|
|
import geometry, markers, vision, world
|
|
|
|
proc sceneWith(walls: varargs[WallRec]): SceneRec =
|
|
SceneRec(id: 1, w: 4096, h: 4096, tileSize: 32, cell: 32, walls: @walls)
|
|
|
|
proc windowWall(id: int, a, b: Vec): WallRec =
|
|
## The `window` preset's switch set at the given geometry (an opening window, marker on).
|
|
result = defaultWall(a, b)
|
|
result.id = id
|
|
result.blocksSight = false
|
|
result.blocksMovement = true
|
|
result.door = true
|
|
result.playerMarker = true
|
|
|
|
proc poly(pts: varargs[Vec]): seq[Poly] =
|
|
@[Poly(tokenId: "tok000000001", pts: @pts)]
|
|
|
|
const Covered = @[(0.0, 0.0), (400.0, 0.0), (400.0, 400.0), (0.0, 400.0)]
|
|
|
|
suite "player markers (5.8, #59/#60)":
|
|
test "a marked window seen by any part of its extent mints one anchor marker":
|
|
var pv = PlayerVision(polys: poly(Covered))
|
|
let w = windowWall(1, (100.0, 100.0), (100.0, 300.0))
|
|
check syncMarkers(pv, sceneWith(w)) == 1
|
|
check pv.markers.len == 1
|
|
check pv.markers[1].id.len == 12
|
|
check (pv.markers[1].x, pv.markers[1].y) == (100, 200) # the drawn midpoint
|
|
check pv.markerFresh.len == 1 and pv.markerDead.len == 0
|
|
|
|
test "an untouched marker survives a refresh: it is memory, not current sight":
|
|
var pv = PlayerVision(polys: poly(Covered))
|
|
let sc = sceneWith(windowWall(1, (100.0, 100.0), (100.0, 300.0)))
|
|
check syncMarkers(pv, sc) == 1
|
|
let earned = pv.markers[1].id
|
|
pv.polys = poly(@[(2000.0, 2000.0), (2200.0, 2000.0), (2200.0, 2200.0)])
|
|
check syncMarkers(pv, sc) == 0 # walking away mints and retracts nothing
|
|
check pv.markers.hasKey(1) and pv.markers[1].id == earned
|
|
check pv.markerDead.len == 0
|
|
|
|
test "a geometry change retracts the marker and a re-earn gets a fresh id":
|
|
var pv = PlayerVision(polys: poly(Covered))
|
|
var w = windowWall(1, (100.0, 100.0), (100.0, 300.0))
|
|
check syncMarkers(pv, sceneWith(w)) == 1
|
|
let earned = pv.markers[1].id
|
|
w.thickness = 7 # thickness is a retraction cause
|
|
check syncMarkers(pv, sceneWith(w)) == 1
|
|
check pv.markerDead == @[earned]
|
|
check pv.markers[1].id != earned # a re-earned marker is a new id
|
|
check (pv.markers[1].x, pv.markers[1].y) == (100, 200)
|
|
|
|
test "a placement change retracts too; height and label never do":
|
|
var pv = PlayerVision(polys: poly(Covered))
|
|
var w = windowWall(1, (100.0, 100.0), (100.0, 300.0))
|
|
check syncMarkers(pv, sceneWith(w)) == 1
|
|
let earned = pv.markers[1].id
|
|
w.height = some(1.0) # no marker consequence
|
|
w.label = some("railing")
|
|
check syncMarkers(pv, sceneWith(w)) == 0
|
|
check pv.markers[1].id == earned
|
|
w.position = wpLeft # placement is a retraction cause
|
|
check syncMarkers(pv, sceneWith(w)) == 1
|
|
check pv.markerDead == @[earned]
|
|
|
|
test "a solid wall with the switch on mints nothing; clearing the switch retracts":
|
|
var pv = PlayerVision(polys: poly(Covered))
|
|
var solid = defaultWall((100.0, 100.0), (100.0, 300.0))
|
|
solid.id = 1
|
|
solid.playerMarker = true
|
|
check syncMarkers(pv, sceneWith(solid)) == 0 # a solid wall never qualifies as a window
|
|
var w = windowWall(2, (150.0, 100.0), (150.0, 300.0))
|
|
check syncMarkers(pv, sceneWith(solid, w)) == 1
|
|
let earned = pv.markers[2].id
|
|
w.playerMarker = false
|
|
check syncMarkers(pv, sceneWith(solid, w)) == 0
|
|
check pv.markerDead == @[earned]
|