space-game/src/stores/gameResults.ts
Michael Mainguy 3f164df9e8
All checks were successful
Build / build (push) Successful in 1m30s
Add game results leaderboard system
- Create GameResultsService for storing game results in localStorage
- Create gameResultsStore Svelte store for reactive data access
- Add Leaderboard component showing top 20 scores
- Add leaderboard route and navigation link
- Record game results on victory/death/stranded (not manual exits)
- Fix header visibility when exiting game
- Fix camera error by stopping render loop after cleanup
- Clear canvas after cleanup to prevent last frame showing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 12:39:23 -06:00

48 lines
1.1 KiB
TypeScript

import { writable } from 'svelte/store';
import { GameResultsService, GameResult } from '../services/gameResultsService';
/**
* Svelte store for game results
* Provides reactive access to leaderboard data
*/
function createGameResultsStore() {
const service = GameResultsService.getInstance();
const { subscribe, set } = writable<GameResult[]>(service.getTopResults(20));
return {
subscribe,
/**
* Refresh the store with latest top results
*/
refresh: () => {
set(service.getTopResults(20));
},
/**
* Add a new result and refresh the store
*/
addResult: (result: GameResult) => {
service.saveResult(result);
set(service.getTopResults(20));
},
/**
* Get all results (not just top 20)
*/
getAll: () => {
return service.getAllResults();
},
/**
* Clear all results (for testing/reset)
*/
clear: () => {
service.clearAll();
set([]);
}
};
}
export const gameResultsStore = createGameResultsStore();