This commit is contained in:
2025-12-17 00:33:13 +01:00
parent 8c67081953
commit f01e01e50c
186 changed files with 9242 additions and 1342 deletions

View File

@@ -7,35 +7,42 @@
import type { IEntity } from '@core/shared/domain';
import { RacingDomainValidationError } from '../errors/RacingDomainError';
import { CarName } from './CarName';
import { Manufacturer } from './Manufacturer';
import { CarClass, CarClassType } from './CarClass';
import { CarLicense, CarLicenseType } from './CarLicense';
import { Year } from './Year';
import { Horsepower } from './Horsepower';
import { Weight } from './Weight';
import { GameId } from './GameId';
import { CarId } from './CarId';
import { ImageUrl } from './ImageUrl';
export type CarClass = 'formula' | 'gt' | 'prototype' | 'touring' | 'sports' | 'oval' | 'dirt';
export type CarLicense = 'R' | 'D' | 'C' | 'B' | 'A' | 'Pro';
export class Car implements IEntity<string> {
readonly id: string;
readonly name: string;
export class Car implements IEntity<CarId> {
readonly id: CarId;
readonly name: CarName;
readonly shortName: string;
readonly manufacturer: string;
readonly manufacturer: Manufacturer;
readonly carClass: CarClass;
readonly license: CarLicense;
readonly year: number;
readonly horsepower: number | undefined;
readonly weight: number | undefined;
readonly imageUrl: string | undefined;
readonly gameId: string;
readonly year: Year;
readonly horsepower: Horsepower | undefined;
readonly weight: Weight | undefined;
readonly imageUrl: ImageUrl | undefined;
readonly gameId: GameId;
private constructor(props: {
id: string;
name: string;
id: CarId;
name: CarName;
shortName: string;
manufacturer: string;
manufacturer: Manufacturer;
carClass: CarClass;
license: CarLicense;
year: number;
horsepower?: number;
weight?: number;
imageUrl?: string;
gameId: string;
year: Year;
horsepower?: Horsepower;
weight?: Weight;
imageUrl?: ImageUrl;
gameId: GameId;
}) {
this.id = props.id;
this.name = props.name;
@@ -58,8 +65,8 @@ export class Car implements IEntity<string> {
name: string;
shortName?: string;
manufacturer: string;
carClass?: CarClass;
license?: CarLicense;
carClass?: CarClassType;
license?: CarLicenseType;
year?: number;
horsepower?: number;
weight?: number;
@@ -69,17 +76,17 @@ export class Car implements IEntity<string> {
this.validate(props);
return new Car({
id: props.id,
name: props.name,
id: CarId.create(props.id),
name: CarName.create(props.name),
shortName: props.shortName ?? props.name.slice(0, 10),
manufacturer: props.manufacturer,
carClass: props.carClass ?? 'gt',
license: props.license ?? 'D',
year: props.year ?? new Date().getFullYear(),
...(props.horsepower !== undefined ? { horsepower: props.horsepower } : {}),
...(props.weight !== undefined ? { weight: props.weight } : {}),
...(props.imageUrl !== undefined ? { imageUrl: props.imageUrl } : {}),
gameId: props.gameId,
manufacturer: Manufacturer.create(props.manufacturer),
carClass: CarClass.create(props.carClass ?? 'gt'),
license: CarLicense.create(props.license ?? 'D'),
year: Year.create(props.year ?? new Date().getFullYear()),
...(props.horsepower !== undefined ? { horsepower: Horsepower.create(props.horsepower) } : {}),
...(props.weight !== undefined ? { weight: Weight.create(props.weight) } : {}),
...(props.imageUrl !== undefined ? { imageUrl: ImageUrl.create(props.imageUrl) } : {}),
gameId: GameId.create(props.gameId),
});
}
@@ -109,25 +116,4 @@ export class Car implements IEntity<string> {
}
}
/**
* Get formatted car display name
*/
getDisplayName(): string {
return `${this.manufacturer} ${this.name}`;
}
/**
* Get license badge color
*/
getLicenseColor(): string {
const colors: Record<CarLicense, string> = {
'R': '#FF6B6B',
'D': '#FFB347',
'C': '#FFD700',
'B': '#7FFF00',
'A': '#00BFFF',
'Pro': '#9370DB',
};
return colors[this.license];
}
}