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
+3 -52
View File
@@ -9,6 +9,7 @@ import fs from 'node:fs'
import { DatabaseSync } from 'node:sqlite'
import { createPlayer, namePlayer, sleep } from './lib.mjs'
import { gmKeyOf, makeStateDir, openAs, startServer, stopServer } from './withserver.mjs'
import { V7_DDL, V7_WALLS } from './schema7fixture.mjs'
const CELL = 32
const cellOf = (x, y) => `${Math.floor(x / CELL)},${Math.floor(y / CELL)}`
@@ -261,8 +262,7 @@ test('a wall removal\'s newly explored cells are persisted, even after the wall
// A wall at x = 500 hides everything to the right of Alice (her circle reaches x = 600).
// Endpoints stay off the exact 64-gon rays: a ray through a wall endpoint is the documented
// boundary ambiguity of 5.4, not something this test is about.
const wall = await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 50], b: [500, 4000],
kind: 'wall' })
const wall = await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 50], b: [500, 4000] })
assert.equal(wall.ok, true, JSON.stringify(wall))
const tok = await visionToken(gm, alice, [200, 200])
const p = await openAs(s.origin, alice.key)
@@ -280,8 +280,7 @@ test('a wall removal\'s newly explored cells are persisted, even after the wall
assert.ok(revealed.has(cellOf(590, 200)), 'removing the wall revealed and persisted the right side')
// Put the wall back: the right side is out of sight again, so only the store can still have it.
assert.equal((await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 50], b: [500, 4000],
kind: 'wall' })).ok, true)
assert.equal((await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 50], b: [500, 4000] })).ok, true)
await sleep(150)
const afterReplace = await exploredSnapshot(s.origin, alice)
assert.deepEqual(sorted(afterReplace), sorted(revealed))
@@ -457,55 +456,7 @@ test('migration: a schema-4 DB (fixture) migrates under the real binary to the l
// empty props, a linked token with a hand-set height/eye_height, and two characters, one with a
// hand-set height. Step 8 must rebuild `wall`, drop `kind`, add `marker_seen` and backfill only
// the missing heights.
const V7_DDL = `
CREATE TABLE schema_migration (version INTEGER PRIMARY KEY, name TEXT NOT NULL, applied_at TEXT NOT NULL);
CREATE TABLE meta (k TEXT PRIMARY KEY, v TEXT NOT NULL);
CREATE TABLE player (id INTEGER PRIMARY KEY, name TEXT UNIQUE, role TEXT NOT NULL CHECK (role IN ('gm', 'player')), colour TEXT NOT NULL, created_at TEXT NOT NULL);
CREATE UNIQUE INDEX player_single_gm ON player(role) WHERE role = 'gm';
CREATE TABLE player_key (player_id INTEGER PRIMARY KEY REFERENCES player(id) ON DELETE CASCADE, secret TEXT NOT NULL, created_at TEXT NOT NULL);
CREATE TABLE session (id INTEGER PRIMARY KEY, player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE, token_hash TEXT NOT NULL UNIQUE, created_at TEXT NOT NULL, last_seen TEXT NOT NULL);
CREATE INDEX session_player ON session(player_id);
CREATE TABLE scene (id INTEGER PRIMARY KEY, name TEXT NOT NULL, w REAL NOT NULL, h REAL NOT NULL, tile_size INTEGER NOT NULL, cell INTEGER NOT NULL, grid_size REAL NOT NULL, vision_radius_default REAL NOT NULL, token_radius_default REAL NOT NULL, art_version INTEGER NOT NULL, active INTEGER NOT NULL DEFAULT 1, next_wall_id INTEGER NOT NULL DEFAULT 1, extra TEXT NOT NULL DEFAULT '{}');
CREATE TABLE wall (scene_id INTEGER NOT NULL REFERENCES scene(id) ON DELETE CASCADE, id INTEGER NOT NULL, ax REAL NOT NULL, ay REAL NOT NULL, bx REAL NOT NULL, by REAL NOT NULL, kind TEXT NOT NULL CHECK (kind IN ('wall', 'door')), open INTEGER NOT NULL DEFAULT 0 CHECK (open IN (0, 1)), flags TEXT NOT NULL DEFAULT '{}', PRIMARY KEY (scene_id, id));
CREATE TABLE entity (id TEXT PRIMARY KEY, scene_id INTEGER NOT NULL REFERENCES scene(id) ON DELETE CASCADE, kind TEXT NOT NULL, descriptive_name TEXT NOT NULL, actual_name TEXT NOT NULL, x REAL NOT NULL, y REAL NOT NULL, radius REAL, owner_player_id INTEGER REFERENCES player(id) ON DELETE SET NULL, gm_only INTEGER NOT NULL DEFAULT 0 CHECK (gm_only IN (0, 1)), vision_radius REAL, flags TEXT NOT NULL DEFAULT '{}', created_at TEXT NOT NULL, props_public TEXT NOT NULL DEFAULT '{}', props_owner TEXT NOT NULL DEFAULT '{}', props_gm TEXT NOT NULL DEFAULT '{}', character_id TEXT REFERENCES character(id), reveal_all INTEGER NOT NULL DEFAULT 0 CHECK (reveal_all IN (0, 1)));
CREATE TABLE explored_chunk (player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE, scene_id INTEGER NOT NULL REFERENCES scene(id) ON DELETE CASCADE, cx INTEGER NOT NULL, cy INTEGER NOT NULL, bits BLOB NOT NULL CHECK (length(bits) = 512), PRIMARY KEY (player_id, scene_id, cx, cy));
CREATE TABLE entity_status (entity_id TEXT NOT NULL REFERENCES entity(id) ON DELETE CASCADE, status TEXT NOT NULL CHECK (status IN ('stuck', 'squeezed')), source TEXT NOT NULL CHECK (source IN ('walls', 'GM')), PRIMARY KEY (entity_id, status, source));
CREATE TABLE character (id TEXT PRIMARY KEY, owner_player_id INTEGER NOT NULL REFERENCES player(id), descriptive_name TEXT NOT NULL, actual_name TEXT NOT NULL, reveal_all INTEGER NOT NULL DEFAULT 0 CHECK (reveal_all IN (0, 1)), props_public TEXT NOT NULL DEFAULT '{}', props_owner TEXT NOT NULL DEFAULT '{}', props_gm TEXT NOT NULL DEFAULT '{}', created_at TEXT NOT NULL);
CREATE INDEX character_owner ON character(owner_player_id);
CREATE TABLE name_reveal (player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE, subject_id TEXT NOT NULL, created_at TEXT NOT NULL, PRIMARY KEY (player_id, subject_id));
CREATE TABLE encountered (player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE, entity_id TEXT NOT NULL, character_id TEXT, descriptive_name TEXT NOT NULL, actual_name TEXT, created_at TEXT NOT NULL, PRIMARY KEY (player_id, entity_id));
CREATE INDEX encountered_character ON encountered(character_id);
INSERT INTO schema_migration VALUES (1, 'meta', '2026-11-15T00:00:00Z'), (2, 'auth', '2026-11-15T00:00:00Z'), (3, 'world', '2026-11-15T00:00:00Z'), (4, 'tokens', '2026-11-15T00:00:00Z'), (5, 'explored', '2026-11-15T00:00:00Z'), (6, 'token details', '2026-11-15T00:00:00Z'), (7, 'characters', '2026-11-15T00:00:00Z');
INSERT INTO scene (id, name, w, h, tile_size, cell, grid_size, vision_radius_default, token_radius_default, art_version, active, next_wall_id, extra) VALUES (1, 'Scene', 4096, 4096, 32, 32, 0, 400, 20, 1, 1, 5, '{}');
INSERT INTO player (id, name, role, colour, created_at) VALUES (1, 'GM', 'gm', '#6b7280', '2026-11-15T00:00:00Z');
INSERT INTO player (id, name, role, colour, created_at) VALUES (2, 'Alice', 'player', '#2563eb', '2026-11-15T00:00:00Z');
INSERT INTO player_key (player_id, secret, created_at) VALUES (2, 'ALIC-ALIC-ALIC-ALIC-ALIC', '2026-11-15T00:00:00Z');
INSERT INTO wall (scene_id, id, ax, ay, bx, by, kind, open, flags) VALUES
(1, 1, 0, 0, 4096, 0, 'wall', 0, '{"note":"north"}'),
(1, 2, 10, 10, 100, 10, 'wall', 1, '{}'),
(1, 3, 100, 100, 400, 100, 'door', 1, '{"a":1}'),
(1, 4, 500, 500, 900, 500, 'door', 0, '{}');
INSERT INTO character (id, owner_player_id, descriptive_name, actual_name, created_at, props_gm) VALUES
('char000000001', 1, 'Alice', 'Alice', '2026-11-15T00:00:00Z', '{}'),
('char000000002', 1, 'Bob', 'Bob', '2026-11-15T00:00:00Z', '{"height":1.5}');
INSERT INTO entity (id, scene_id, kind, descriptive_name, actual_name, x, y, owner_player_id, flags, created_at, props_gm, character_id) VALUES
('tok000000001', 1, 'pc', 'a wanderer', 'Wanderer', 400, 400, 2, '{"vision": true}', '2026-11-15T00:00:00Z', '{}', NULL),
('tok000000002', 1, 'pc', '', '', 800, 800, 2, '{"vision": true}', '2026-11-15T00:00:00Z', '{"height":2.5,"eye_height":2.0}', 'char000000001');
PRAGMA user_version = 7;
`
const V7_WALLS = [
{ id: 1, thickness: 0, position: 'center', blocks_sight: 1, blocks_movement: 1, sight_dir: 'both',
player_marker: 0, door: 0, open: 0, secret: 0, locked: 0, height: null, label: null,
flags: '{"note":"north"}' },
{ id: 2, thickness: 0, position: 'center', blocks_sight: 1, blocks_movement: 1, sight_dir: 'both',
player_marker: 0, door: 0, open: 0, secret: 0, locked: 0, height: null, label: null, flags: '{}' },
{ id: 3, thickness: 0, position: 'center', blocks_sight: 1, blocks_movement: 1, sight_dir: 'both',
player_marker: 0, door: 1, open: 1, secret: 0, locked: 0, height: null, label: null,
flags: '{"a":1}' },
{ id: 4, thickness: 0, position: 'center', blocks_sight: 1, blocks_movement: 1, sight_dir: 'both',
player_marker: 0, door: 1, open: 0, secret: 0, locked: 0, height: null, label: null, flags: '{}' },
]
function readWallRows(db) {
return db.prepare(`SELECT id, thickness, position, blocks_sight, blocks_movement, sight_dir,