106 lines
2.5 KiB
TypeScript
106 lines
2.5 KiB
TypeScript
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
|
|
import { Consequence, CardType } from '../Deck/DeckAggregate';
|
|
|
|
export enum GameState {
|
|
WAITING = 0,
|
|
ACTIVE = 1,
|
|
FINISHED = 2,
|
|
CANCELLED = 3
|
|
}
|
|
|
|
export enum LoginType {
|
|
PUBLIC = 0,
|
|
PRIVATE = 1,
|
|
ORGANIZATION = 2
|
|
}
|
|
|
|
export enum DeckType {
|
|
JOCKER = 0,
|
|
LUCK = 1,
|
|
QUEST = 2
|
|
}
|
|
|
|
export interface GameCard {
|
|
cardid: string;
|
|
question?: string;
|
|
answer?: any; // Support complex answer structures (string, object, array)
|
|
type?: CardType; // Card type for validation logic
|
|
consequence?: Consequence | null;
|
|
played?: boolean;
|
|
playerid?: string;
|
|
}
|
|
|
|
export interface GameDeck {
|
|
deckid: string;
|
|
decktype: DeckType;
|
|
cards: GameCard[];
|
|
}
|
|
|
|
@Entity('Games')
|
|
export class GameAggregate {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'varchar', length: 10, unique: true })
|
|
gamecode!: string;
|
|
|
|
@Column({ type: 'int' })
|
|
maxplayers!: number;
|
|
|
|
@Column({ type: 'int', default: LoginType.PUBLIC })
|
|
logintype!: LoginType;
|
|
|
|
@Column({ type: 'int', default: 50 })
|
|
boardsize!: number;
|
|
|
|
@Column({ type: 'uuid', nullable: false, name: 'createdBy' })
|
|
createdby!: string;
|
|
|
|
@Column({ type: 'uuid', nullable: true, name: 'organizationid' })
|
|
orgid!: string | null;
|
|
|
|
@Column({ type: 'jsonb', default: () => "'[]'", name: 'decks' })
|
|
gamedecks!: GameDeck[];
|
|
|
|
@Column({ type: 'uuid', array: true, default: () => "'{}'", name: 'playerids' })
|
|
players!: string[];
|
|
|
|
@Column({ type: 'boolean', default: false })
|
|
started!: boolean;
|
|
|
|
@Column({ type: 'boolean', default: false })
|
|
finished!: boolean;
|
|
|
|
@Column({ type: 'uuid', nullable: true, name: 'winnerid' })
|
|
winner!: string | null;
|
|
|
|
@Column({ type: 'int', default: GameState.WAITING })
|
|
state!: GameState;
|
|
|
|
@CreateDateColumn({ name: 'createDate' })
|
|
createdate!: Date;
|
|
|
|
@Column({ type: 'timestamp', nullable: true, name: 'start_date' })
|
|
startdate!: Date | null;
|
|
|
|
@Column({ type: 'timestamp', nullable: true, name: 'finishDate' })
|
|
enddate!: Date | null;
|
|
|
|
@UpdateDateColumn()
|
|
updateDate!: Date;
|
|
}
|
|
|
|
// Board Generation Types
|
|
export interface GameField {
|
|
position: number;
|
|
type: 'regular' | 'positive' | 'negative' | 'luck';
|
|
stepValue?: number;
|
|
}
|
|
|
|
export interface BoardData {
|
|
gameId?: string;
|
|
fields: GameField[];
|
|
generationComplete?: boolean;
|
|
generatedAt?: Date;
|
|
error?: string;
|
|
} |