feat(client): drag with prediction and rollback (#72)

Drag a controlled token (GM: any token) at <=20 Hz plus a final send on release;
the sprite follows the pointer while authoritative frames are ignored for drawing.
Uniform move nacks roll back with a short tween (on release if still dragging),
rate-limited acks drop quietly, and pending reqIds die with the connection.

- slices/move.ts: pure drag/pending/ack state machine at the reducer seam
- render/modules/drag.ts: canvas pointer input, capture-phase so token drag wins
  over pan/pinch (#69); sends via the new intents bridge
- tokens renderer draws the optimistic/confirmed position and tweens the rollback
- intents.ts + ws.send onReqId: one reqId-keyed sender for render modules
- e2e: drag persists after reload, wall refusal tween, GM move mid-drag,
  reconnect mid-drag dropping the pending map
This commit is contained in:
2026-11-21 09:41:03 +01:00
parent 4534ed6426
commit c7d5e2cc69
10 changed files with 1284 additions and 13 deletions
+19
View File
@@ -85,6 +85,25 @@ describe('protocol client', () => {
expect(client.pendingCount).toBe(0)
})
it('tells the caller the reqId after the frame left the socket (#72)', async () => {
const { client, socket } = connect()
const seen: number[] = []
const pending = client.send('token.move', { id: 'aaa', pos: [10, 20] }, reqId => {
// The callback runs only once the frame is on the wire, so recording it cannot outrun send.
expect(socket.sent).toHaveLength(1)
seen.push(reqId)
})
expect(seen).toEqual([1])
expect(JSON.parse(socket.sent[0] ?? '{}')).toMatchObject({
t: 'token.move',
reqId: 1,
id: 'aaa',
pos: [10, 20],
})
socket.receive({ t: 'ack', n: 1, reqId: 1, ok: true, pos: [10, 20] })
await expect(pending).resolves.toMatchObject({ ok: true })
})
it('keeps pending requests across a hello on a live connection (6.3)', async () => {
const { client, socket } = connect()
const pending = client.send('player.setname', { name: 'Ann' })