tools: name players through player.setname, and the character groups and four fault classes (#23)

This commit is contained in:
2026-11-15 12:01:30 +01:00
parent f134534c6c
commit c4b97ec16c
10 changed files with 405 additions and 132 deletions
+13 -13
View File
@@ -54,9 +54,9 @@ async function gmConnect(origin, gmKey) {
return { ...conn, scene: walls.scene }
}
async function namedPlayer(stateDir, gm, name) {
async function namedPlayer(origin, gm, name) {
const player = await createPlayer(gm.ws)
await namePlayer(stateDir, player.id, name)
await namePlayer(origin, player.key, name)
return player
}
@@ -114,7 +114,7 @@ test('explored round trip: a fresh connection gets the whole grid the server acc
const s = await startServer({ stateDir })
try {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(stateDir, gm, 'Alice')
const alice = await namedPlayer(s.origin, gm, 'Alice')
const tok = await visionToken(gm, alice, [200, 200])
const p = await openAs(s.origin, alice.key)
@@ -145,8 +145,8 @@ test('explored is strictly per player, before and after a restart', async () =>
let alice, bob, before
try {
const gm = await gmConnect(s.origin, gmKey)
alice = await namedPlayer(stateDir, gm, 'Alice')
bob = await namedPlayer(stateDir, gm, 'Bob')
alice = await namedPlayer(s.origin, gm, 'Alice')
bob = await namedPlayer(s.origin, gm, 'Bob')
const aliceTok = await visionToken(gm, alice, [200, 200])
const bobTok = await visionToken(gm, bob, [3800, 3800])
const a = await openAs(s.origin, alice.key)
@@ -188,7 +188,7 @@ test('restart: every player\'s explored area is identical before and after (SIGT
let alice, before
try {
const gm = await gmConnect(s.origin, gmKey)
alice = await namedPlayer(stateDir, gm, 'Alice')
alice = await namedPlayer(s.origin, gm, 'Alice')
const tok = await visionToken(gm, alice, [200, 200])
const p = await openAs(s.origin, alice.key)
await p.ws.waitText('hello')
@@ -222,7 +222,7 @@ test('restart: the explored grid survives a SIGKILL', async () => {
let alice, before
try {
const gm = await gmConnect(s.origin, gmKey)
alice = await namedPlayer(stateDir, gm, 'Alice')
alice = await namedPlayer(s.origin, gm, 'Alice')
const tok = await visionToken(gm, alice, [400, 400])
const p = await openAs(s.origin, alice.key)
await p.ws.waitText('hello')
@@ -255,7 +255,7 @@ test('a wall removal\'s newly explored cells are persisted, even after the wall
const s = await startServer({ stateDir })
try {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(stateDir, gm, 'Alice')
const alice = await namedPlayer(s.origin, gm, 'Alice')
// The wall goes in before Alice's token exists: explored only grows (5.1), so a token created
// on the far side first would legitimately have explored it already.
// A wall at x = 500 hides everything to the right of Alice (her circle reaches x = 600).
@@ -310,7 +310,7 @@ test('the store holds 512-byte chunks, and they decode to exactly the explored g
const s = await startServer({ stateDir })
try {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(stateDir, gm, 'Alice')
const alice = await namedPlayer(s.origin, gm, 'Alice')
const tok = await visionToken(gm, alice, [400, 400])
const p = await openAs(s.origin, alice.key)
await p.ws.waitText('hello')
@@ -342,7 +342,7 @@ test('write timing: a move\'s ack stays inside the 4.3 lock budget with explored
const s = await startServer({ stateDir })
try {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(stateDir, gm, 'Alice')
const alice = await namedPlayer(s.origin, gm, 'Alice')
// On the ring, so the first move is not a teleport across the map (5.5's step cap).
const tok = await visionToken(gm, alice, [2900, 2000])
const p = await openAs(s.origin, alice.key)
@@ -413,7 +413,7 @@ test('migration: a schema-4 DB (fixture) migrates under the real binary to the l
}
const s = await startServer({ stateDir })
try {
assert.match(s.log(), /db_ready .*schema_version=6 applied=2/, s.log())
assert.match(s.log(), /db_ready .*schema_version=7 applied=3/, s.log())
// The old data is served unchanged through the product surface.
const alice = { id: 2, key: 'ALIC-ALIC-ALIC-ALIC-ALIC' }
const conn = await openAs(s.origin, alice.key)
@@ -434,11 +434,11 @@ test('migration: a schema-4 DB (fixture) migrates under the real binary to the l
}
const db = new DatabaseSync(dbPath)
try {
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 6)
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 7)
assert.deepEqual(db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
.map(r => [Number(r.version), r.name]),
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'],
[6, 'token details']])
[6, 'token details'], [7, 'characters']])
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0)
assert.equal(db.prepare('SELECT name FROM player WHERE id = 2').get().name, 'Alice')
} finally {