diff --git a/src/draw/coordinate.entity.ts b/src/draw/coordinate.entity.ts index 8350415c98fa0160f29047c4b24355ee78049a0e..e9a1b6ff35544fa599220367638fd3ada00fa865 100644 --- a/src/draw/coordinate.entity.ts +++ b/src/draw/coordinate.entity.ts @@ -4,6 +4,7 @@ import { PrimaryGeneratedColumn, ManyToOne, CreateDateColumn, + OneToMany, } from 'typeorm'; import { GameEntity } from '../game/game.entity'; @@ -44,7 +45,7 @@ export class MapDrawingEntity { @Entity('MapDrawingHistory') export class MapDrawingHistoryEntity { @PrimaryGeneratedColumn('uuid') mapDrawingHistoryId: string; - @CreateDateColumn() timestamp: Date; + @Column('float') timestamp: number; @Column('bool') drawingIsActive: boolean; @Column('json') data: JSON; diff --git a/src/draw/draw.service.ts b/src/draw/draw.service.ts index ef56a85225e4d1ab7999c755224383a3397ff3a6..5f7566cda9d127173cbba11a8f2f92727a38f7dc 100644 --- a/src/draw/draw.service.ts +++ b/src/draw/draw.service.ts @@ -34,6 +34,7 @@ export class DrawService { data: data.data, drawingIsActive: data.drawingIsActive, mapdrawing: mapDrawing.identifiers[0]['mapDrawingId'], + timestamp: Date.now(), }); await this.mapDrawHistoryRepository.insert(history); return mapDrawing.identifiers; @@ -49,6 +50,7 @@ export class DrawService { data: data.data, drawingIsActive: data.drawingIsActive, mapdrawing: data.mapDrawingId, + timestamp: Date.now(), }); await this.mapDrawHistoryRepository.insert(history); return await this.mapDrawingRepository.save(drawing); diff --git a/src/replay/replay.service.ts b/src/replay/replay.service.ts index 0ecd90328d77fea094b182b6069a10869afda64b..bb06399aa59082ce46cd98b49b0ca21412f912eb 100644 --- a/src/replay/replay.service.ts +++ b/src/replay/replay.service.ts @@ -61,6 +61,14 @@ export class ReplayService { } */ async replayData(gameId) { + // + // this block returns game's initial location + // + let gameObj = await this.gameRepository.findOne({ + where: { id: gameId }, + select: ['center'], + }); + let gamelocation = [gameObj.center.lat, gameObj.center.lng]; // // this block returns all player data from the game // @@ -116,11 +124,28 @@ export class ReplayService { ); }), ); + // + // this block returns all map drawings from the game + // + let refs = await this.mapdrawingRepository.find({ + where: { gameId: gameId }, + select: ['mapDrawingId'], + }); + + let drawData = await Promise.all( + refs.map(async ref => { + return await this.mapHistoryRepository.find({ + where: { mapdrawing: ref.mapDrawingId }, + }); + }), + ); return { + location: gamelocation, players: currentdata, factions: currentFactions, scores: currentScore, + drawings: drawData, }; } // generate mockdata for a 3 day game