Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
game.entity.ts 7.78 KiB
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
  Timestamp,
  PrimaryColumn,
} from 'typeorm';
import { PersonEntity, PersonRoleEntity } from 'src/user/user.entity';

// table that stores all created games
@Entity('Game')
export class GameEntity {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column('text') name: string;
  @Column('text') desc: string;
  @Column('json') center: JSON;
  @Column('json') map: JSON;
  @Column('timestamp') startdate: Timestamp;
  @Column('timestamp') enddate: Timestamp;
  
  @ManyToOne(type => MapEntity, map => map.games)
    gamemap: MapEntity;
  @OneToMany(type => FactionEntity, faction => faction.game)
  factions: FactionEntity[];
  @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
  game_persons: Game_PersonEntity[];
  @OneToMany(type => ObjectivePointEntity, objective_points => objective_points.game)
  objective_points: ObjectivePointEntity[];

  gameObject() {
    const { id, name } = this;
    return { id, name };
  }
}

// table that stores players associated with particular game
@Entity('Game_Person')
export class Game_PersonEntity {
    @PrimaryGeneratedColumn('uuid') gameId: string;
    @ManyToOne(type => FactionEntity, faction => faction.game_persons)
    faction: FactionEntity;
    @ManyToOne(type => GameEntity, game => game.game_persons)
    game: GameEntity;
    @ManyToOne(type => PersonEntity, person => person.game_persons)
    person: PersonEntity;
    @ManyToOne(type => PersonRoleEntity, person_role => person_role.game_persons)
    person_role: PersonRoleEntity;
    @ManyToOne(type => CoordinateEntity, game_person_coordinates => game_person_coordinates.game_persons)
    game_person_coordinates: CoordinateEntity;
}

@Entity('ObjectivePoint')
export class ObjectivePointEntity {
    @PrimaryGeneratedColumn('uuid') objectivePointId: string;
    @Column({type: 'text'}) objectivePointDescription: string;
    @Column({type: 'float'}) objectivePointMultiplier: number;

    @ManyToOne(type => CoordinateEntity, coordinate => coordinate.objective_points)
    coordinate: CoordinateEntity;
    @ManyToOne(type => GameEntity, game => game.objective_points)
    game: GameEntity;
    @OneToMany(type => ObjectivePoint_HistoryEntity, op_history => op_history.objective_point)
    op_history: Game_PersonEntity[];
}

@Entity('ObjectivePoint_History')
export class ObjectivePoint_HistoryEntity {
    @PrimaryGeneratedColumn('uuid') oP_HistoryId: string;
    @Column({type: 'timestamp'}) oP_HistoryTimestamp: Timestamp;
    @Column({}) oP_HistoryStatus: number;

    @ManyToOne(type => ObjectivePointEntity, objective_point => objective_point.op_history)
    objective_point: ObjectivePointEntity;
}

// table that stores all factions created for games
/*@Entity('Faction')
export class FactionEntity {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column('text') name: string;
  @ManyToOne(type => GameEntity, game => game.factions)
  game: GameEntity;
  @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction)
  game_persons: Game_PersonEntity[];

}*/

@Entity('Faction')
export class FactionEntity {
    @PrimaryGeneratedColumn('uuid') factionId: string;
    @Column({type: 'text', unique: true}) factionName: string;
    @Column({type: 'text'}) factionPassword: string;
    @Column({type: 'float'}) multiplier: number;

    @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction)
    mapDrawings: MapDrawingEntity[];
    @OneToMany(type => ScoreEntity, scores => scores.faction)
    scores: ScoreEntity[];
    @OneToMany(type => PowerUpEntity, powerUps => powerUps.factions)
    powerUps: Faction_PowerUpEntity[];
    @OneToMany(type => TaskEntity, tasks => tasks.faction)
    tasks: TaskEntity[];
    @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction)
    game_persons: Game_PersonEntity[];
    @ManyToOne(type => GameEntity, game => game.factions)
    game: GameEntity;
}

@Entity('PowerUp')
export class PowerUpEntity {
    @PrimaryGeneratedColumn('uuid') powerUpId: string;
    @Column({type: 'text'}) powerUpName: string;
    @Column({type: 'text'}) powerUpDescription: string;
    @Column({type: 'int'}) amount: number;
    @Column({type: 'time'}) cooldown: string;

    @OneToMany(type => FactionEntity, factions => factions.powerUps)
    factions: Faction_PowerUpEntity[];

}

@Entity('Faction_PowerUp')
export class Faction_PowerUpEntity{
    @PrimaryGeneratedColumn('uuid') faction_powerUpId: string;

    @ManyToOne(type => FactionEntity, faction => faction.powerUps)
    faction: FactionEntity;
    @ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions)
    powerUp: PowerUpEntity;
    @OneToMany(type => FP_HistoryEntity, histories => histories.faction_PowerUp)
    histories: FP_HistoryEntity[];
}

@Entity('FP_History')
export class FP_HistoryEntity{
    @PrimaryGeneratedColumn('uuid') historyId: string;
    @Column({type: 'timestamp'}) historyTimeStamp: Timestamp;
    @ManyToOne(type => Faction_PowerUpEntity, faction_PowerUp => faction_PowerUp.histories)
    faction_PowerUp: Faction_PowerUpEntity;
}

@Entity('Score')
export class ScoreEntity {
    @PrimaryGeneratedColumn('uuid') scoreId: string;
    @Column({type: 'float'}) score: number;
    @Column({type: 'timestamp'}) scoreTimeStamp: Timestamp;

    @ManyToOne(type => FactionEntity, factionName => factionName.scores)
    faction: FactionEntity;
}

@Entity('Task')
export class TaskEntity {
    @PrimaryGeneratedColumn('uuid') taskId: string;
    @Column({type: 'text'}) taskName: string;
    @Column({type: 'text'}) taskDescription: string;
    @Column({type: 'text'}) taskWinner: string;
    @Column({type: 'bool'}) taskIsActive: boolean;
    
    @ManyToOne(type => FactionEntity, faction => faction.tasks)
    faction: FactionEntity;
    @ManyToOne(type => PersonEntity, person => person.tasks)
    person: PersonEntity;
}

@Entity('Coordinate')
export class CoordinateEntity {
    @PrimaryColumn({type: 'json', nullable: true}) features: JSON;

    @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawings_coordinates)
    mapDrawings: MapDrawingEntity[];
    @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game_person_coordinates)
    game_persons: Game_PersonEntity[];
    @OneToMany(type => ObjectivePointEntity, objective_points => objective_points.coordinate)
    objective_points: ObjectivePointEntity[];
    @OneToMany(type => MapEntity, maps => maps.coordinate)
    maps: ObjectivePointEntity[];
}


@Entity('Map')
export class MapEntity {
    @PrimaryGeneratedColumn('uuid') mapId: string;
    
    @ManyToOne(type => CoordinateEntity, coordinate => coordinate.maps)
    coordinate: CoordinateEntity;
    @OneToMany(type => GameEntity, games => games.gamemap)
    games: GameEntity[];
    @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.map)
    mapDrawings: MapDrawingEntity[];
}

@Entity('MapDrawing')
export class MapDrawingEntity {
    @PrimaryGeneratedColumn('uuid') mapDrawingId: string;
    @Column({type: 'bool'}) drawingIsActive: boolean;
    @Column({type: 'time'}) drawingValidTill: string;

    @ManyToOne(type => CoordinateEntity, mapDrawings_coordinates => mapDrawings_coordinates.mapDrawings)
    mapDrawings_coordinates: CoordinateEntity;
    @ManyToOne(type => MapEntity, map => map.mapDrawings)
    map: MapEntity;
    @ManyToOne(type => MapDrawingTypeEntity, mapDrawingType => mapDrawingType.mapDrawings)
    mapDrawingType: MapEntity;
    @ManyToOne(type => FactionEntity, faction => faction.mapDrawings)
    faction: FactionEntity;
}

@Entity('MapDrawingType')
export class MapDrawingTypeEntity {
    @PrimaryGeneratedColumn('uuid') mapDrawingTypeId: string;
    @Column({type: 'text'}) drawingTypeName: string;
    @Column({type: 'text'}) drawingTypeDescription: string;

    @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawingType)
    mapDrawings: MapDrawingEntity[];
}