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
+39 -8
View File
@@ -148,7 +148,7 @@ suite "server frames (6.1)":
check not h.hasKey("scene") # an unnamed player gets proto, role, me only (6.1)
check not h.hasKey("extra")
check h["t"].getStr == "hello"
check h["proto"].getInt == 1
check h["proto"].getInt == 2
check h["role"].getStr == "player"
check h["me"]["id"].getInt == 4
check h["me"]["name"].kind == JNull
@@ -211,25 +211,54 @@ suite "server frames (6.1)":
["revoked", "evicted", "proto-mismatch", "malformed-flood"]
suite "wall frames (6.1 `walls`, `wall`, `wall_gone`; GM only)":
test "one wall carries id, a, b, kind, open and flags in the 6.1 shape":
let w = wallObject(7, (10.0, 20.5), (300.0, 20.5), "door", true, %*{"locked": false})
test "one wall carries the typed record plus the derived kind in the proto-2 shape":
let w = wallObject(WallView(id: 7, a: (10.0, 20.5), b: (300.0, 20.5), thickness: 12.0,
position: "left", blocksSight: true, blocksMovement: true,
sightDir: "both", playerMarker: false, door: true, open: true,
secret: false, locked: true, height: 2.5, hasHeight: true,
label: "the king's window", hasLabel: true, kind: "door",
flags: %*{"locked": false}))
check w["id"].getInt == 7
check w["a"][0].getFloat == 10.0
check w["a"][1].getFloat == 20.5
check w["b"][0].getFloat == 300.0
check w["thickness"].getFloat == 12.0
check w["position"].getStr == "left"
check w["height"].getFloat == 2.5
check w["kind"].getStr == "door"
check w["blocks_sight"].getBool
check w["blocks_movement"].getBool
check w["sight_dir"].getStr == "both"
check w["player_marker"].getBool == false
check w["door"].getBool
check w["open"].getBool
check w["secret"].getBool == false
check w["locked"].getBool
check w["label"].getStr == "the king's window"
check w["flags"]["locked"].getBool == false
# an absent flags object is still an object on the wire
check wallObject(1, (0.0, 0.0), (1.0, 0.0), "wall", false, nil)["flags"].kind == JObject
# unset height/label are present as JSON null, and an absent flags object is still an object
let plain = wallObject(WallView(id: 1, a: (0.0, 0.0), b: (1.0, 0.0), position: "center",
blocksSight: true, blocksMovement: true, sightDir: "both",
kind: "wall"))
check plain["height"].kind == JNull
check plain["label"].kind == JNull
check plain["flags"].kind == JObject
test "`walls` is the full list plus the scene, `wall` is one upsert, `wall_gone` an id":
let snap = wallsFrame(1, @[wallObject(1, (0.0, 0.0), (9.0, 0.0), "wall", false, nil)])
let plain = WallView(id: 1, a: (0.0, 0.0), b: (9.0, 0.0), position: "center",
blocksSight: true, blocksMovement: true, sightDir: "both", kind: "wall")
let snap = wallsFrame(1, @[wallObject(plain)])
check snap["t"].getStr == "walls"
check snap["scene"].getInt == 1
check snap["walls"].len == 1
check snap["walls"][0]["id"].getInt == 1
let one = wallFrame(1, wallObject(2, (0.0, 5.0), (9.0, 5.0), "door", false, nil))
var doorView = plain
doorView.id = 2
doorView.a = (0.0, 5.0)
doorView.b = (9.0, 5.0)
doorView.door = true
doorView.kind = "door"
let one = wallFrame(1, wallObject(doorView))
check one["t"].getStr == "wall"
check one["scene"].getInt == 1
check one["id"].getInt == 2
@@ -240,7 +269,9 @@ suite "wall frames (6.1 `walls`, `wall`, `wall_gone`; GM only)":
check gone["id"].getInt == 2
test "the fan-out frames carry no n: the sender stamps it per recipient":
let plain = WallView(id: 1, a: (0.0, 0.0), b: (1.0, 1.0), position: "center",
blocksSight: true, blocksMovement: true, sightDir: "both", kind: "wall")
check not wallsFrame(1, @[]).hasKey("n")
check not wallFrame(1, wallObject(1, (0.0, 0.0), (1.0, 1.0), "wall", false, nil)).hasKey("n")
check not wallFrame(1, wallObject(plain)).hasKey("n")
check not wallGoneFrame(1, 1).hasKey("n")
check withN(wallGoneFrame(1, 1), 12)["n"].getInt == 12