Files
gridpilot.gg/apps/website/lib/view-models/ScoringConfigurationViewModel.ts
2026-01-26 17:47:37 +01:00

39 lines
1.3 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import type { CustomPointsConfig, ScoringConfigurationViewData } from "../view-data/ScoringConfigurationViewData";
export type { CustomPointsConfig };
import { LeagueScoringPresetViewModel } from './LeagueScoringPresetViewModel';
export class ScoringConfigurationViewModel extends ViewModel {
readonly patternId?: string;
readonly customScoringEnabled: boolean;
readonly customPoints?: CustomPointsConfig;
readonly currentPreset?: LeagueScoringPresetViewModel;
constructor(data: ScoringConfigurationViewData) {
super();
this.patternId = data.config.patternId;
this.customScoringEnabled = data.config.customScoringEnabled || false;
this.customPoints = data.customPoints;
this.currentPreset = data.config.patternId
? new LeagueScoringPresetViewModel(data.presets.find(p => p.id === data.config.patternId)!)
: undefined;
}
/**
* Get the active points configuration
*/
getActivePointsConfig(): CustomPointsConfig {
if (this.customScoringEnabled && this.customPoints) {
return this.customPoints;
}
// Return default points if no custom config
return {
racePoints: [25, 18, 15, 12, 10, 8, 6, 4, 2, 1],
poleBonusPoints: 1,
fastestLapPoints: 1,
leaderLapPoints: 0,
};
}
}