tools: name players through player.setname, and the character groups and four fault classes (#23)
This commit is contained in:
+20
-18
@@ -17,10 +17,10 @@ async function gmConnect(origin, gmKey) {
|
||||
return { ...conn, scene: walls.scene, walls }
|
||||
}
|
||||
|
||||
// A named player: naming is the harness fixture of lib.mjs until slice 8 brings player.setname.
|
||||
async function namedPlayer(stateDir, gm, name) {
|
||||
// A named player: the harness names it through `player.setname` (lib.mjs, slice 8 / #23).
|
||||
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
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ const tokenFrames = ws => ws.messages.filter(m => m.t === 'token')
|
||||
test('token.create: ack with the id, the token to the GM, invisible to a player out of range', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const player = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const player = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const p = await playerConnect(s.origin, player)
|
||||
|
||||
const ack = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||
@@ -73,7 +73,7 @@ test('token.create validation: the 6.1 table and the fields this slice cannot ho
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const scene = gm.scene
|
||||
const player = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const player = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const base = { kind: 'npc', pos: [100, 100], descriptive_name: 'a thing', actual_name: 'Thing' }
|
||||
const invalid = [
|
||||
{ ...base, descriptive_name: '' },
|
||||
@@ -118,8 +118,8 @@ test('token.create validation: the 6.1 table and the fields this slice cannot ho
|
||||
test('token.move: controller only, uniform nack, and one code for unknown and not-yours', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const bob = await namedPlayer(s.stateDir, gm, 'Bob')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const bob = await namedPlayer(s.origin, gm, 'Bob')
|
||||
const mine = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||
controller: alice.id, flags: { vision: true } })
|
||||
@@ -166,7 +166,7 @@ test('token.move: controller only, uniform nack, and one code for unknown and no
|
||||
test('token.update: controller, gm_only, names, flags and the codes of 6.5', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const own = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
|
||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||
controller: alice.id, flags: { vision: true } })
|
||||
@@ -219,7 +219,7 @@ test('token.update: controller, gm_only, names, flags and the codes of 6.5', asy
|
||||
test('token.remove: token_gone to whoever knew it, not-found after', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
|
||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||
controller: alice.id, flags: { vision: true } })
|
||||
@@ -239,7 +239,7 @@ test('token.remove: token_gone to whoever knew it, not-found after', async () =>
|
||||
test('connect resync: GM gets walls then every token; a player vision, explored, then its tokens', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const visible = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
|
||||
pos: [450, 400], descriptive_name: 'a wolf',
|
||||
actual_name: 'Fang' })
|
||||
@@ -262,7 +262,8 @@ test('connect resync: GM gets walls then every token; a player vision, explored,
|
||||
assert.deepEqual(hello.extra, {})
|
||||
assert.equal(hello.n, 1)
|
||||
const order = gm2.ws.messages.map(m => m.t)
|
||||
assert.deepEqual(order.slice(0, 2), ['hello', 'walls'])
|
||||
// 6.3 resync order: roster, walls, then every token (characters/encountered are slice 8).
|
||||
assert.deepEqual(order.slice(0, 3), ['hello', 'roster', 'walls'])
|
||||
assert.equal(order.filter(t => t === 'token').length, 3)
|
||||
assert.equal(order.includes('vision'), false, 'the GM never gets vision polygons')
|
||||
assert.equal(order.includes('explored'), false, 'the GM never gets explored cells')
|
||||
@@ -273,15 +274,16 @@ test('connect resync: GM gets walls then every token; a player vision, explored,
|
||||
const a = await playerConnect(s.origin, alice, 1)
|
||||
await sleep(150)
|
||||
const aOrder = a.ws.messages.map(m => m.t)
|
||||
assert.deepEqual(aOrder.slice(0, 3), ['hello', 'vision', 'explored'])
|
||||
const explored = a.ws.messages[2]
|
||||
// 6.3: hello, roster, the encountered list, then vision/explored and the tokens.
|
||||
assert.deepEqual(aOrder.slice(0, 5), ['hello', 'roster', 'encountered', 'vision', 'explored'])
|
||||
const explored = a.ws.messages[4]
|
||||
assert.equal(explored.full, true)
|
||||
assert.ok(Array.isArray(explored.rle))
|
||||
const ids = tokenFrames(a.ws).map(m => m.id).sort()
|
||||
assert.deepEqual(ids, [mine.id].sort(),
|
||||
'a player gets only what it controls or sees (its own token is far away: controlled)')
|
||||
assert.equal(ids.includes(far.id), false)
|
||||
const vision = a.ws.messages[1]
|
||||
const vision = a.ws.messages[3]
|
||||
assert.equal(vision.polys.length, 1)
|
||||
assert.equal(vision.polys[0].id, mine.id)
|
||||
for (const pt of vision.polys[0].pts) {
|
||||
@@ -294,7 +296,7 @@ test('connect resync: GM gets walls then every token; a player vision, explored,
|
||||
test('an unnamed player gets nothing but hello, and every intent is refused (6.1, 6.5 step 5)', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const player = await createPlayer(gm.ws) // no name: slice 8 brings player.setname
|
||||
const player = await createPlayer(gm.ws) // a fresh key: unnamed until player.setname
|
||||
const p = await playerConnect(s.origin, player)
|
||||
const hello = await p.ws.waitText('hello')
|
||||
assert.deepEqual(Object.keys(hello).sort(), ['me', 'n', 'proto', 'role', 't'])
|
||||
@@ -315,7 +317,7 @@ test('door closing pushes an overlapped token aside (5.5), and the push is a nor
|
||||
async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const door = await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 400], b: [500, 700],
|
||||
kind: 'door' })
|
||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
|
||||
@@ -350,7 +352,7 @@ test('restart: tokens, positions and controllers come back with the same view',
|
||||
let ids
|
||||
try {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const t1 = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||
controller: alice.id, flags: { vision: true } })
|
||||
@@ -384,7 +386,7 @@ test('restart: tokens, positions and controllers come back with the same view',
|
||||
test('player.remove hands the player\'s tokens to the GM (3.2)', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
||||
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||
controller: alice.id, flags: { vision: true } })
|
||||
|
||||
Reference in New Issue
Block a user