diff options
| author | Bobby <[email protected]> | 2026-04-22 09:47:33 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-04-22 09:47:33 +0530 |
| commit | 8877f532599011ca02f267863189d4ffe6755955 (patch) | |
| tree | 1d764290084dfc3c629f30d10d9814263b2159ae /loading | |
| parent | ae02de7dd6c402d8cc4923668a1e7c17e152ca36 (diff) | |
| download | hollowdark-8877f532599011ca02f267863189d4ffe6755955.tar.xz hollowdark-8877f532599011ca02f267863189d4ffe6755955.zip | |
Wire the begin-state detector through Dexie via world and people repositories
Diffstat (limited to 'loading')
| -rw-r--r-- | loading/session.ts | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/loading/session.ts b/loading/session.ts index a1a685b..788f0e6 100644 --- a/loading/session.ts +++ b/loading/session.ts @@ -1,3 +1,6 @@ +import { getPerson } from '@hollowdark/persistence/people' +import { getCurrentWorld } from '@hollowdark/persistence/worlds' + /** * The three states the Begin screen can render. * @@ -16,11 +19,23 @@ export type BeginState = | { readonly kind: 'returning-no-active' } /** - * Inspect device-local state and decide which Begin variant to show. The - * real implementation queries IndexedDB for worlds and the currently - * active player character; while persistence is still being wired up this - * returns `first-ever` unconditionally. + * Inspect device-local state and decide which Begin variant to show. Reads + * the single world record (design invariant) and, when a current player + * character is set, reads their name for the continue prompt. */ export async function detectBeginState(): Promise<BeginState> { - return { kind: 'first-ever' } + const world = await getCurrentWorld() + if (world === null) return { kind: 'first-ever' } + + const activeId = world.currentPlayerCharacterId + if (activeId === null) return { kind: 'returning-no-active' } + + const active = await getPerson(activeId) + if (active === null) return { kind: 'returning-no-active' } + + return { kind: 'returning-active', characterName: displayName(active.name) } +} + +function displayName(name: { given: string; preferredName: string | null }): string { + return name.preferredName ?? name.given } |
