repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Robin-hood Game
stars
latest
clone command
git clone gitlawb://did:key:z6MkwMR9...adEc/robin-hood-gamegit clone gitlawb://did:key:z6MkwMR9.../robin-hood-gamec8777c8csync from playground7h ago| #1 | import type { LeaderboardEntry, GameSettings } from './types'; |
| #2 | |
| #3 | const LEADERBOARD_KEY = 'robinhood_leaderboard'; |
| #4 | const SETTINGS_KEY = 'robinhood_settings'; |
| #5 | const MAX_ENTRIES = 20; |
| #6 | |
| #7 | export function loadLeaderboard(): LeaderboardEntry[] { |
| #8 | try { |
| #9 | const raw = localStorage.getItem(LEADERBOARD_KEY); |
| #10 | if (!raw) return []; |
| #11 | return JSON.parse(raw) as LeaderboardEntry[]; |
| #12 | } catch { |
| #13 | return []; |
| #14 | } |
| #15 | } |
| #16 | |
| #17 | export function saveScore(name: string, score: number, coins: number): LeaderboardEntry[] { |
| #18 | const entries = loadLeaderboard(); |
| #19 | entries.push({ |
| #20 | name: name.trim() || 'Anonymous', |
| #21 | score, |
| #22 | coins, |
| #23 | date: new Date().toISOString().slice(0, 10), |
| #24 | }); |
| #25 | entries.sort((a, b) => b.score - a.score); |
| #26 | const trimmed = entries.slice(0, MAX_ENTRIES); |
| #27 | localStorage.setItem(LEADERBOARD_KEY, JSON.stringify(trimmed)); |
| #28 | return trimmed; |
| #29 | } |
| #30 | |
| #31 | export function loadSettings(): GameSettings { |
| #32 | try { |
| #33 | const raw = localStorage.getItem(SETTINGS_KEY); |
| #34 | if (!raw) return { soundEnabled: true, difficulty: 'normal' }; |
| #35 | return { ...{ soundEnabled: true, difficulty: 'normal' as const }, ...JSON.parse(raw) }; |
| #36 | } catch { |
| #37 | return { soundEnabled: true, difficulty: 'normal' }; |
| #38 | } |
| #39 | } |
| #40 | |
| #41 | export function saveSettings(settings: GameSettings): void { |
| #42 | localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings)); |
| #43 | } |
| #44 |