feat(walls): presets, label rule and one switch-set validation path (#55)
wall.add/wall.update now take a preset or raw switches, never both:
resolveWall expands the four 5.8 presets to switches before validating, so
a preset never touches geometry and preset+switch or preset+open is invalid.
A raw create starts from the wall defaults; a raw update patches only the
switches it names and {door:false} closes and de-secrets.
The switch-set invariants are enforced by that one path for add and update:
open/secret/locked without a door, a secret door that is open/one-way/not
opaque, open with secret or locked, and a direction with no sight to block
are all invalid. The DB gains the missing open+locked CHECK as the backstop,
and the now-redundant open/door parity test is gone from the server path.
A wall label is now the 6.5 text rule: trimmed, 1..64 code points, no control
characters, null clears, stored verbatim and GM-only. window/one_way presets
are accepted and expanded to their switch sets per DESIGN 5.8/6.1; their
player-facing behaviour stays with #57/#58.
Tests: WS black-box presets/patch semantics/every refusal/label round-trip;
Nim shape pins for expansion, invariants and the label rule.
Nim 385 / Node 117 green.
This commit is contained in:
+60
-1
@@ -276,6 +276,65 @@ suite "validation (DESIGN 6.1 `wall.*`)":
|
||||
check addWall(conn, sc, wall(4096, 4096, 0, 0)).isSome
|
||||
check sc.walls.len == 2
|
||||
|
||||
test "presets expand to switches only through the one resolve path (#55)":
|
||||
let base = defaultWall((0.0, 0.0), (10.0, 0.0))
|
||||
var sized = base
|
||||
sized.thickness = 12
|
||||
sized.position = wpLeft
|
||||
sized.height = some(3.0)
|
||||
sized.label = some("railing")
|
||||
check parsePreset("wall").get == pwWall
|
||||
check parsePreset("one_way").get == pwOneWay
|
||||
check parsePreset("terrain").isNone
|
||||
let window = resolveWall(sized, some(pwWindow), WallSwitches()).get
|
||||
check not window.blocksSight and window.blocksMovement
|
||||
check window.door and not window.open and window.playerMarker
|
||||
check window.thickness == 12 and window.position == wpLeft and window.height == some(3.0)
|
||||
check window.label == some("railing") # a preset never touches non-switch fields
|
||||
let oneWay = resolveWall(sized, some(pwOneWay), WallSwitches()).get
|
||||
check oneWay.sightDir == sdLeft and oneWay.blocksSight and not oneWay.door
|
||||
# preset xor raw switches: even a switch equal to the expansion is a mix
|
||||
check resolveWall(sized, some(pwDoor), WallSwitches(blocksSight: some(true))).isNone
|
||||
check resolveWall(sized, some(pwDoor), WallSwitches(open: some(true))).isNone
|
||||
|
||||
test "the switch-set invariants reject door-only settings on a non-door (#55)":
|
||||
let plain = defaultWall((0.0, 0.0), (10.0, 0.0))
|
||||
check resolveWall(plain, none(Preset), WallSwitches(open: some(true))).isNone
|
||||
check resolveWall(plain, none(Preset), WallSwitches(secret: some(true))).isNone
|
||||
check resolveWall(plain, none(Preset), WallSwitches(locked: some(true))).isNone
|
||||
check resolveWall(plain, none(Preset), WallSwitches(secret: some(false))).isSome
|
||||
# clearing door closes and de-secrets, but naming a true door-only switch with it is invalid
|
||||
var secretDoor = plain
|
||||
secretDoor.door = true
|
||||
secretDoor.secret = true
|
||||
let closed = resolveWall(secretDoor, none(Preset), WallSwitches(door: some(false))).get
|
||||
check not closed.door and not closed.open and not closed.secret and not closed.locked
|
||||
check resolveWall(secretDoor, none(Preset),
|
||||
WallSwitches(door: some(false), secret: some(true))).isNone
|
||||
# open excludes secret and locked; a direction needs sight to block
|
||||
var lockedDoor = plain
|
||||
lockedDoor.door = true
|
||||
lockedDoor.locked = true
|
||||
check resolveWall(lockedDoor, none(Preset), WallSwitches(open: some(true))).isNone
|
||||
check resolveWall(plain, none(Preset),
|
||||
WallSwitches(blocksSight: some(false), sightDir: some(sdLeft))).isNone
|
||||
|
||||
test "a label is 1..64 code points, trimmed and free of control characters (#55)":
|
||||
let (conn, d) = freshScene()
|
||||
defer:
|
||||
close(conn)
|
||||
removeDir(d)
|
||||
var sc = loadScene(conn).get
|
||||
var w = defaultWall((10.0, 10.0), (100.0, 10.0))
|
||||
w.label = some("x")
|
||||
check addWall(conn, sc, w).isSome
|
||||
w.label = some("é".repeat(64)) # code points, not bytes
|
||||
check addWall(conn, sc, w).isSome
|
||||
for bad in ["", " x", "x ", "x\ty", "x\u007fy", " ".repeat(3), "x".repeat(65)]:
|
||||
w.label = some(bad)
|
||||
check addWall(conn, sc, w).isNone
|
||||
check sc.walls.len == 2
|
||||
|
||||
test "a wall is never open: the stored row normalizes it":
|
||||
let (conn, d) = freshScene()
|
||||
defer:
|
||||
@@ -313,7 +372,7 @@ suite "validation (DESIGN 6.1 `wall.*`)":
|
||||
var sc = loadScene(conn).get
|
||||
let id = addWall(conn, sc, wall(10, 10, 100, 10)).get
|
||||
let before = wallById(sc, id).get
|
||||
let after = patched(before, WallPatch(b: some((300.0, 400.0))))
|
||||
let after = patched(before, WallPatch(b: some((300.0, 400.0)))).get
|
||||
check after.a == before.a
|
||||
check after.b == (300.0, 400.0)
|
||||
check after.door == before.door
|
||||
|
||||
Reference in New Issue
Block a user