Skip to content

feat: extensible leaderboard with local provider and async provider interface - #2

Draft
zerebos with Copilot wants to merge 1 commit into
mainfrom
copilot/create-leaderboard-implementation-plan
Draft

feat: extensible leaderboard with local provider and async provider interface#2
zerebos with Copilot wants to merge 1 commit into
mainfrom
copilot/create-leaderboard-implementation-plan

Conversation

Copilot AI commented Mar 27, 2026

Copy link
Copy Markdown

Implements a local personal leaderboard designed to support a future global backend (e.g. Supabase) without refactoring call sites.

Architecture

  • LeaderboardProvider interfacegetEntries() / addEntry() / isHighScore(), all async. New backends implement this and nothing else changes.
  • LocalLeaderboardProvider — localStorage, Promise-wrapped, keeps top 10 entries sorted by score.
  • LeaderboardManager — accepts providers: LeaderboardProvider[], fans writes to all providers, merges and deduplicates reads by entry.id.

Adding Supabase later is a one-line change in game.ts:

new LeaderboardManager([new LocalLeaderboardProvider(), new SupabaseLeaderboardProvider()])

LeaderboardEntry shape

interface LeaderboardEntry {
    id: string;            // crypto.randomUUID() — deduplicates across providers
    name: string;
    score: number;
    timeRemaining: number;
    timestamp: number;
    source: "local" | "global";  // lets UI distinguish provider origin
}

Game flow

  • endGame() triggers a leaderboard overlay (name-entry form, pre-filled with last used name).
  • On submit: saves entry → fetches merged entries → shows ranked table with the new row highlighted.
  • SPACE is gated in startGame(): no-op during name-entry; dismisses the table and starts a new game when the table is visible.

UI

New overlay panel with two phases (name-entry / score table), synthwave-styled to match the existing design system. Loading state is built in from the start so the async path works transparently when a remote provider is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants