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
+9 -1
View File
@@ -187,8 +187,15 @@ export class ProtocolClient {
* Send one intent and resolve with its single `ack` (DESIGN 6 Conventions: exactly one ack per
* readable intent, whatever the outcome). Pending reqIds die with the connection (6.3), and a
* `hello` on a live connection does not drop them.
*
* `onReqId` is told the request id once the frame has left the socket, so a caller that must
* match the ack itself (the drag's `token.move`, #72) can record it before the reply can arrive.
*/
send(t: string, fields: Record<string, unknown> = {}): Promise<AckFrame> {
send(
t: string,
fields: Record<string, unknown> = {},
onReqId?: (reqId: number) => void,
): Promise<AckFrame> {
const socket = this.#socket
if (this.#state !== 'open' || !socket) {
return Promise.reject(new Error('not connected'))
@@ -199,6 +206,7 @@ export class ProtocolClient {
this.#pending.set(reqId, { resolve, reject })
try {
socket.send(frame)
onReqId?.(reqId)
} catch (error) {
this.#pending.delete(reqId)
reject(error instanceof Error ? error : new Error(String(error)))