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:
+36
-5
@@ -14,8 +14,10 @@ import std/[json, monotimes, unicode]
|
||||
import geometry
|
||||
|
||||
const
|
||||
ProtoVersion* = 1
|
||||
## M3 ships proto 1 (DESIGN 6.2). The client announces it as `/ws?proto=N`.
|
||||
ProtoVersion* = 2
|
||||
## proto 2 is the wall-model build (DESIGN 6.2, ADR-0011, #54): the wall payloads carry the
|
||||
## typed geometry and switches, `kind` is output-only and the GM frames echo the full record.
|
||||
## The client announces it as `/ws?proto=N`.
|
||||
MaxInboundBytes* = 64 * 1024
|
||||
## DESIGN 6.4: mummy's `maxMessageLen`, inbound and cumulative across fragments.
|
||||
RatePerSecond* = 30
|
||||
@@ -211,10 +213,39 @@ proc rosterEntry*(id: int, name: JsonNode, role: string, colour: string,
|
||||
# `n`: they are the only frames fanned out to several recipients at once (every GM connection), and
|
||||
# each recipient gets its own number, added by the sender with `withN` right before the send.
|
||||
|
||||
proc wallObject*(id: int, a, b: Vec, kind: string, open: bool, flags: JsonNode): JsonNode =
|
||||
type
|
||||
WallView* = object
|
||||
## One wall as the GM's `wall`/`walls` frames show it (DESIGN 6.1, proto 2, #54). The typed
|
||||
## record plus the derived shape label; `height` and `label` are always present and null when
|
||||
## unset (the frame is GM-only, so their presence marks nothing). This is the narrow wire shape,
|
||||
## kept out of `world.nim` so the protocol shell stays free of storage imports.
|
||||
id*: int
|
||||
a*, b*: Vec
|
||||
thickness*: float
|
||||
position*: string
|
||||
blocksSight*, blocksMovement*: bool
|
||||
sightDir*: string
|
||||
playerMarker*, door*, open*, secret*, locked*: bool
|
||||
height*: float
|
||||
hasHeight*: bool ## false = full height (`height:null`)
|
||||
label*: string
|
||||
hasLabel*: bool ## false = no label (`label:null`)
|
||||
kind*: string ## the derived 5.8 shape label, output only
|
||||
flags*: JsonNode
|
||||
|
||||
proc wallObject*(w: WallView): JsonNode =
|
||||
## One wall as the wire shows it: the same shape inside `walls` and in a `wall` upsert.
|
||||
%*{"id": id, "a": [a.x, a.y], "b": [b.x, b.y], "kind": kind, "open": open,
|
||||
"flags": (if flags.isNil: newJObject() else: flags)}
|
||||
%*{
|
||||
"id": w.id, "a": [w.a.x, w.a.y], "b": [w.b.x, w.b.y],
|
||||
"thickness": w.thickness, "position": w.position,
|
||||
"height": (if w.hasHeight: %w.height else: newJNull()),
|
||||
"kind": w.kind,
|
||||
"blocks_sight": w.blocksSight, "blocks_movement": w.blocksMovement,
|
||||
"sight_dir": w.sightDir, "player_marker": w.playerMarker,
|
||||
"door": w.door, "open": w.open, "secret": w.secret, "locked": w.locked,
|
||||
"label": (if w.hasLabel: %w.label else: newJNull()),
|
||||
"flags": (if w.flags.isNil: newJObject() else: w.flags)
|
||||
}
|
||||
|
||||
proc wallsFrame*(scene: int, walls: seq[JsonNode]): JsonNode =
|
||||
## The GM snapshot of every wall in the scene (DESIGN 6.1 `walls`, 6.3: on connect and resync).
|
||||
|
||||
Reference in New Issue
Block a user