Skip to content
Snippets Groups Projects
game.dto.ts 2.21 KiB
Newer Older
import {
  IsNotEmpty,
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  IsString,
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  IsDateString,
L4168's avatar
L4168 committed
  IsNumber,
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  Validate,
  ValidateNested,
  Allow,
L4168's avatar
L4168 committed
  IsUUID,
  IsIn,
L4168's avatar
L4168 committed
  IsOptional,
} from 'class-validator';
L4168's avatar
L4168 committed

Samuli Virtapohja's avatar
Samuli Virtapohja committed
import { ObjectivePointEntity } from './game.entity';
import { CenterJSON } from '../shared/custom-validation';
import { FactionDTO } from '../faction/faction.dto';
import { CenterDTO, NodeSettingsDTO } from './game.json.dto';
import { Type } from 'class-transformer';

export class GameDTO {
L4168's avatar
L4168 committed
  @IsOptional()
  id: string;
  @IsString()
  @IsNotEmpty()
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  @Length(3, 30)
  name: string;
  @IsNotEmpty()
  @Length(1, 255)
  desc: string;
  @ValidateNested()
  @Type(() => CenterDTO)
  center: CenterDTO;
  @Allow()
  @ValidateNested()
  @Type(() => NodeSettingsDTO)
  nodesettings?: NodeSettingsDTO;
  @Allow()
  map?: JSON;
  @IsDateString()
  @IsNotEmpty()
  startdate: string;
  @IsDateString()
  @IsNotEmpty()
  enddate: string;
  @ValidateNested()
  @Type(() => FactionDTO)
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  factions?: FactionDTO[];
  @ValidateNested()
  @Type(() => FlagboxDTO)
L4168's avatar
L4168 committed
  objective_points?: FlagboxDTO[];
L4168's avatar
L4168 committed
export class newGameDTO {
  @IsString()
  @IsNotEmpty()
  @Length(3, 30)
  name: string;
  @IsString()
  @IsNotEmpty()
  @Length(1, 255)
  desc: string;
  @IsNotEmpty()
L4168's avatar
L4168 committed
  @Validate(CenterJSON)
L4168's avatar
L4168 committed
  center: JSON;
  @IsDateString()
  @IsNotEmpty()
  startdate: string;
  @IsDateString()
  @IsNotEmpty()
  enddate: string;
}

L4168's avatar
L4168 committed
export class GameStateDTO {
  @IsUUID('4')
  id: string;
  @IsIn(['CREATED', 'STARTED', 'PAUSED', 'ENDED'])
  state: string;
}

L4168's avatar
L4168 committed
export class FlagboxDTO {
  @IsOptional()
  @IsUUID('4')
  objectivePointId: string;
L4168's avatar
L4168 committed
  @IsString()
  @IsNotEmpty()
  @Length(7)
  objectivePointDescription: string;
  @IsNumber()
  objectivePointMultiplier: number;
}

export class FlagboxEventDTO {
  @IsString()
  @IsNotEmpty()
  @Length(7)
L4168's avatar
L4168 committed
  node_id: string;
  @IsNumber()
  @Min(0)
  @Max(3)
  owner: number; // owner = 0, => first entry in faction db, owner = 1, => second entry etc
  @IsNumber()
  @Min(0)
  @Max(3)
  action: number; // 0=no capture ongoing, 1=captured, 2=capture ongoing
  @IsNumber()
  @Min(0)
  @Max(3)
  capture: number; // which faction is capturing, same logic as in owner with numbers
L4168's avatar
L4168 committed
  oP_HistoryTimestamp?: string;
  objective_point?: ObjectivePointEntity;
L4168's avatar
L4168 committed
}