wip
This commit is contained in:
176
packages/racing/domain/value-objects/GameConstraints.ts
Normal file
176
packages/racing/domain/value-objects/GameConstraints.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* Domain Value Object: GameConstraints
|
||||
*
|
||||
* Represents game-specific constraints for leagues.
|
||||
* Different sim racing games have different maximum grid sizes.
|
||||
*/
|
||||
|
||||
export interface GameConstraintsData {
|
||||
readonly maxDrivers: number;
|
||||
readonly maxTeams: number;
|
||||
readonly defaultMaxDrivers: number;
|
||||
readonly minDrivers: number;
|
||||
readonly supportsTeams: boolean;
|
||||
readonly supportsMultiClass: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Game-specific constraints for popular sim racing games
|
||||
*/
|
||||
const GAME_CONSTRAINTS: Record<string, GameConstraintsData> = {
|
||||
iracing: {
|
||||
maxDrivers: 64,
|
||||
maxTeams: 32,
|
||||
defaultMaxDrivers: 24,
|
||||
minDrivers: 2,
|
||||
supportsTeams: true,
|
||||
supportsMultiClass: true,
|
||||
},
|
||||
acc: {
|
||||
maxDrivers: 30,
|
||||
maxTeams: 15,
|
||||
defaultMaxDrivers: 24,
|
||||
minDrivers: 2,
|
||||
supportsTeams: true,
|
||||
supportsMultiClass: false,
|
||||
},
|
||||
rf2: {
|
||||
maxDrivers: 64,
|
||||
maxTeams: 32,
|
||||
defaultMaxDrivers: 24,
|
||||
minDrivers: 2,
|
||||
supportsTeams: true,
|
||||
supportsMultiClass: true,
|
||||
},
|
||||
ams2: {
|
||||
maxDrivers: 32,
|
||||
maxTeams: 16,
|
||||
defaultMaxDrivers: 20,
|
||||
minDrivers: 2,
|
||||
supportsTeams: true,
|
||||
supportsMultiClass: true,
|
||||
},
|
||||
lmu: {
|
||||
maxDrivers: 32,
|
||||
maxTeams: 16,
|
||||
defaultMaxDrivers: 24,
|
||||
minDrivers: 2,
|
||||
supportsTeams: true,
|
||||
supportsMultiClass: true,
|
||||
},
|
||||
// Default for unknown games
|
||||
default: {
|
||||
maxDrivers: 32,
|
||||
maxTeams: 16,
|
||||
defaultMaxDrivers: 20,
|
||||
minDrivers: 2,
|
||||
supportsTeams: true,
|
||||
supportsMultiClass: false,
|
||||
},
|
||||
};
|
||||
|
||||
export class GameConstraints {
|
||||
readonly gameId: string;
|
||||
readonly constraints: GameConstraintsData;
|
||||
|
||||
private constructor(gameId: string, constraints: GameConstraintsData) {
|
||||
this.gameId = gameId;
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get constraints for a specific game
|
||||
*/
|
||||
static forGame(gameId: string): GameConstraints {
|
||||
const lowerId = gameId.toLowerCase();
|
||||
const constraints = GAME_CONSTRAINTS[lowerId] ?? GAME_CONSTRAINTS.default;
|
||||
return new GameConstraints(lowerId, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all supported game IDs
|
||||
*/
|
||||
static getSupportedGames(): string[] {
|
||||
return Object.keys(GAME_CONSTRAINTS).filter(id => id !== 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum drivers allowed for this game
|
||||
*/
|
||||
get maxDrivers(): number {
|
||||
return this.constraints.maxDrivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum teams allowed for this game
|
||||
*/
|
||||
get maxTeams(): number {
|
||||
return this.constraints.maxTeams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default driver count for new leagues
|
||||
*/
|
||||
get defaultMaxDrivers(): number {
|
||||
return this.constraints.defaultMaxDrivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum drivers required
|
||||
*/
|
||||
get minDrivers(): number {
|
||||
return this.constraints.minDrivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this game supports team-based leagues
|
||||
*/
|
||||
get supportsTeams(): boolean {
|
||||
return this.constraints.supportsTeams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this game supports multi-class racing
|
||||
*/
|
||||
get supportsMultiClass(): boolean {
|
||||
return this.constraints.supportsMultiClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a driver count against game constraints
|
||||
*/
|
||||
validateDriverCount(count: number): { valid: boolean; error?: string } {
|
||||
if (count < this.minDrivers) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Minimum ${this.minDrivers} drivers required`,
|
||||
};
|
||||
}
|
||||
if (count > this.maxDrivers) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Maximum ${this.maxDrivers} drivers allowed for ${this.gameId.toUpperCase()}`,
|
||||
};
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a team count against game constraints
|
||||
*/
|
||||
validateTeamCount(count: number): { valid: boolean; error?: string } {
|
||||
if (!this.supportsTeams) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `${this.gameId.toUpperCase()} does not support team-based leagues`,
|
||||
};
|
||||
}
|
||||
if (count > this.maxTeams) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Maximum ${this.maxTeams} teams allowed for ${this.gameId.toUpperCase()}`,
|
||||
};
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user