Skip to content
Snippets Groups Projects
Commit 4fc0abaa authored by L4721's avatar L4721
Browse files

Merge branch 'mapdrawing-replay' into 'Development'

Mapdrawing replay

See merge request !53
parents e60ff46c 063d7e98
No related branches found
No related tags found
3 merge requests!59Development to master,!54Development to testing,!53Mapdrawing replay
......@@ -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;
......
......@@ -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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment