feat(walls): proto 2 typed wall record, inert geometry, derived kind (#54)

wall.add/wall.update take thickness, position, height and the eight raw
switches; kind is output-only and the GM wall frames echo the full typed
record. Geometry is stored but inert (0/full/centre behaviour), and the
legacy kind/open wire adapter is gone. proto is bumped to 2 with the
harness default, and BannedAlways gains every wall field name with a
WALLDATA positive control.

Tests: schema-7 migrated scene vs the same walls authored via raw switches
gives byte-identical player frames, refusals and per-tile statuses.
Nim 382 / Node 113 green.
This commit is contained in:
2026-11-19 22:21:47 +01:00
parent c1b1e9cf91
commit 77fa2dfe4c
23 changed files with 852 additions and 318 deletions
+40 -21
View File
@@ -12,9 +12,9 @@ proc tmpDir(): string =
removeDir(result)
createDir(result)
proc wall(ax, ay, bx, by: float, kind = wkWall, open = false): WallRec =
proc wall(ax, ay, bx, by: float, door = false, open = false): WallRec =
result = defaultWall((ax, ay), (bx, by))
result.kind = kind
result.door = door
result.open = open
proc freshScene(): tuple[db: DbConn, dir: string] =
@@ -65,19 +65,37 @@ suite "field parsing (6.1 field notes)":
check parseVec(newJNull()).isNone
check parseVec(nil).isNone
test "kind, open and flags accept only their own shape":
check parseKind("wall").get == wkWall
check parseKind("door").get == wkDoor
check parseKind("window").isNone
check parseKind("").isNone
check parseKind("WALL").isNone
check parseOpen(nil).get == false # omitted = closed
check parseOpen(%true).get == true
check parseOpen(%1).isNone
test "position, sight_dir and flags accept only their own shape":
check parsePosition("center").get == wpCenter
check parsePosition("left").get == wpLeft
check parsePosition("right").get == wpRight
check parsePosition("middle").isNone
check parsePosition("").isNone
check parseSightDir("both").get == sdBoth
check parseSightDir("left").get == sdLeft
check parseSightDir("right").get == sdRight
check parseSightDir("any").isNone
check parseFlags(nil).get.kind == JObject # omitted = {}
check parseFlags(%*{"a": 1}).get["a"].getInt == 1
check parseFlags(%*[1]).isNone
test "kind is derived from the switches, never stored (5.8)":
check derivedKind(defaultWall((0.0, 0.0), (1.0, 0.0))) == "wall"
var door = defaultWall((0.0, 0.0), (1.0, 0.0))
door.door = true
check derivedKind(door) == "door"
var window = defaultWall((0.0, 0.0), (1.0, 0.0))
window.blocksSight = false
check derivedKind(window) == "window"
window.door = true
check derivedKind(window) == "window" # a fixed or opening window is still a window
var oneWay = defaultWall((0.0, 0.0), (1.0, 0.0))
oneWay.sightDir = sdLeft
check derivedKind(oneWay) == "one_way"
var custom = defaultWall((0.0, 0.0), (1.0, 0.0))
custom.blocksMovement = false
check derivedKind(custom) == "custom"
test "undefined and null are the same as an absent field":
check fieldOrNull(%*{"open": true}, "open").getBool
var withNull = newJObject()
@@ -141,11 +159,11 @@ suite "persistence (write-through, restart-identical)":
var north = defaultWall((0.0, 0.0), (4096.0, 0.0))
north.flags = %*{"note": "north"}
let id1 = addWall(conn, sc, north).get
let id2 = addWall(conn, sc, wall(100, 25, 300, 25, wkDoor)).get
let id2 = addWall(conn, sc, wall(100, 25, 300, 25, door = true)).get
check setDoor(conn, sc, id2, true) == waOk
var changed = defaultWall((0.0, 0.0), (2000.0, 0.0))
changed.id = id1
changed.kind = wkDoor
changed.door = true
changed.flags = %*{"note": "north wall"}
check updateWall(conn, sc, changed) == waOk
@@ -155,11 +173,11 @@ suite "persistence (write-through, restart-identical)":
check reloaded.walls[0].id == id1
check reloaded.walls[0].a == (0.0, 0.0)
check reloaded.walls[0].b == (2000.0, 0.0)
check reloaded.walls[0].kind == wkDoor # kind is updatable
check reloaded.walls[0].door # the door switch is updatable
check reloaded.walls[0].open == false
check reloaded.walls[0].flags["note"].getStr == "north wall"
check reloaded.walls[1].id == id2
check reloaded.walls[1].kind == wkDoor
check reloaded.walls[1].door
check reloaded.walls[1].open == true # an open door stays open
check reloaded.walls[1].flags.kind == JObject # flags default to {}
@@ -264,25 +282,25 @@ suite "validation (DESIGN 6.1 `wall.*`)":
close(conn)
removeDir(d)
var sc = loadScene(conn).get
let id = addWall(conn, sc, wall(10, 10, 100, 10, wkWall, open = true)).get
let id = addWall(conn, sc, wall(10, 10, 100, 10, open = true)).get
check wallById(sc, id).get.open == false
check loadScene(conn).get.walls[0].open == false
test "update keeps the row's id and open flag unless the kind changes":
test "update keeps the row's id and open flag unless the door switch is cleared":
let (conn, d) = freshScene()
defer:
close(conn)
removeDir(d)
var sc = loadScene(conn).get
let id = addWall(conn, sc, wall(10, 10, 100, 10, wkDoor)).get
let id = addWall(conn, sc, wall(10, 10, 100, 10, door = true)).get
check setDoor(conn, sc, id, true) == waOk
var w = wallById(sc, id).get
w.a = (20.0, 20.0)
check updateWall(conn, sc, w) == waOk
check wallById(sc, id).get.open == true # untouched by update
# door -> wall closes it (a wall is never open)
# clearing the door switch closes it (a non-door stores no door settings)
var back = wallById(sc, id).get
back.kind = wkWall
back.door = false
check updateWall(conn, sc, back) == waOk
check wallById(sc, id).get.open == false
check loadScene(conn).get.walls[0].open == false
@@ -298,7 +316,8 @@ suite "validation (DESIGN 6.1 `wall.*`)":
let after = patched(before, WallPatch(b: some((300.0, 400.0))))
check after.a == before.a
check after.b == (300.0, 400.0)
check after.kind == before.kind
check after.door == before.door
check after.thickness == before.thickness
check after.flags.kind == JObject
suite "lookup outcomes (main.nim's 6.5 mapping)":