Phase 8: player view (local/projector) + sync seam
- Player View (/play): read-only projector screen — party HP bars + conditions, active-encounter initiative with current turn; enemy HP hidden behind a Healthy/Bloodied/Down status band; Fullscreen button - SyncAdapter seam (src/lib/sync): local-first default via Dexie liveQuery; documents where a future networked (WebSocket/CRDT) backend plugs in - Dashboard + routes get a Player View entry - Robustness: encountersRepo.mutate() does transactional read-modify-write so rapid combat mutations can't overwrite each other (old C19 race); tracker uses it New player-view e2e. Networked multiplayer backend intentionally deferred. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -164,6 +164,19 @@ export const encountersRepo = {
|
||||
await db.encounters.put(validated);
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a transition by reading the freshest committed state inside a
|
||||
* transaction, so two rapid mutations can't overwrite each other (the
|
||||
* read-modify-write race the old app shipped — bug class C19).
|
||||
*/
|
||||
async mutate(id: string, fn: (e: Encounter) => Encounter): Promise<void> {
|
||||
await db.transaction('rw', db.encounters, async () => {
|
||||
const current = await db.encounters.get(id);
|
||||
if (!current) return;
|
||||
await db.encounters.put(encounterSchema.parse({ ...fn(current), updatedAt: now() }));
|
||||
});
|
||||
},
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
await db.encounters.delete(id);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Sync seam.
|
||||
*
|
||||
* Today the app is local-first: all data lives in Dexie and the "player view" is
|
||||
* driven on the same device by liveQuery, so there is nothing to sync. This
|
||||
* interface is the seam a future networked adapter (e.g. a WebSocket/CRDT
|
||||
* service) implements to mirror repository writes to other devices — without the
|
||||
* feature code needing to change.
|
||||
*/
|
||||
export type SyncStatus = 'local' | 'connecting' | 'connected' | 'error';
|
||||
|
||||
export interface SyncAdapter {
|
||||
readonly status: SyncStatus;
|
||||
/** begin syncing this campaign (no-op locally) */
|
||||
start(campaignId: string): Promise<void>;
|
||||
stop(): void;
|
||||
}
|
||||
|
||||
/** Default adapter: single-device, backed entirely by Dexie liveQuery. */
|
||||
export const localSync: SyncAdapter = {
|
||||
status: 'local',
|
||||
async start() {
|
||||
/* nothing to do — same-device sharing is automatic via liveQuery */
|
||||
},
|
||||
stop() {},
|
||||
};
|
||||
Reference in New Issue
Block a user