Files
gridpilot.gg/adapters/racing/services/DriverStatsStore.ts
2025-12-30 00:15:35 +01:00

50 lines
1.2 KiB
TypeScript

import type { DriverStats } from '@core/racing/domain/services/IDriverStatsService';
/**
* Global store for driver stats that can be populated during seeding
* and read by the InMemoryDriverStatsService
*/
export class DriverStatsStore {
private static instance: DriverStatsStore;
private statsMap = new Map<string, DriverStats>();
private constructor() {}
static getInstance(): DriverStatsStore {
if (!DriverStatsStore.instance) {
DriverStatsStore.instance = new DriverStatsStore();
}
return DriverStatsStore.instance;
}
/**
* Populate the store with stats (called during seeding)
*/
loadStats(stats: Map<string, DriverStats>): void {
this.statsMap.clear();
stats.forEach((input, driverId) => {
this.statsMap.set(driverId, input);
});
}
/**
* Get stats for a specific driver
*/
getDriverStats(driverId: string): DriverStats | null {
return this.statsMap.get(driverId) ?? null;
}
/**
* Clear all stats (useful for reseeding)
*/
clear(): void {
this.statsMap.clear();
}
/**
* Get all stats (for debugging)
*/
getAllStats(): Map<string, DriverStats> {
return new Map(this.statsMap);
}
}