Skip to content
Snippets Groups Projects
Commit c522aefc authored by Samuli Virtapohja's avatar Samuli Virtapohja
Browse files

replay audited

parent 87b5bdde
No related branches found
No related tags found
2 merge requests!59Development to master,!58Development to testing
......@@ -24,6 +24,7 @@ import { GameDTO, FlagboxEventDTO, GameStateDTO, newGameDTO } from './game.dto';
import { ValidationPipe } from '../shared/validation.pipe';
import { Roles, GameStates } from '../shared/guard.decorator';
import { GameEntity } from './game.entity';
import { TickService } from './tick.service';
/////////////////////////////////////////////////////////////////////////
/// GameController ///
......@@ -36,7 +37,12 @@ import { GameEntity } from './game.entity';
@Controller('game')
export class GameController {
constructor(private gameservice: GameService) {}
constructor(
private gameservice: GameService,
private tickservice: TickService,
) {
this.tickservice.startTimer();
}
@Post('new')
@UseGuards(new AuthGuard())
......
......@@ -9,8 +9,6 @@ export class TickService {
WARNING: multiple calls start multiple timers,
if you need to use this service somewhere else remember to call startTimer method from somewhere else
*/
this.startTimer();
}
private logger: Logger = new Logger('TickLogger');
......
......@@ -7,6 +7,11 @@ import {
ClassSerializerInterceptor,
} from '@nestjs/common';
import { ReplayService } from './replay.service';
import { Roles } from 'src/shared/guard.decorator';
/*
POST mockdata is mainly used for development, it can be removed from the code when needed, remember to remove service & test relations.
*/
@Controller('replay')
export class ReplayController {
......@@ -21,6 +26,7 @@ export class ReplayController {
// gets mockdata for specified Game
@Post('mockdata/:id')
@Roles('admin')
async mockData(@Param('id') gameId) {
return this.replayservice.mockdata(gameId);
}
......
......@@ -46,17 +46,13 @@ 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
//
let playerdata = await this.trackingRepository.find({
where: { game: gameId },
relations: ['faction', 'gamepersonId', 'gamepersonId.person'],
......@@ -75,9 +71,9 @@ export class ReplayService {
return player['data'];
}),
);
//
// this block returns all faction data from the game
//
let factions = await this.factionRepository.find({ game: gameId });
let currentFactions = factions.map(faction => {
return {
......@@ -87,10 +83,8 @@ export class ReplayService {
active: true,
};
});
let factionIds = factions.map(faction => faction.factionId);
//
// this block returns all score data from the game
//
let currentScore = [];
await Promise.all(
factions.map(async faction => {
......@@ -109,9 +103,9 @@ export class ReplayService {
);
}),
);
//
// this block returns all map drawings from the game
//
let refs = await this.mapdrawingRepository.find({
where: { gameId: gameId },
select: ['mapDrawingId'],
......@@ -124,9 +118,9 @@ export class ReplayService {
});
}),
);
//
// this function returns all flagbox-events from the game
//
let objectivepoints = await this.returnObjectivePointInfo(gameId);
return {
......@@ -204,7 +198,7 @@ export class ReplayService {
// insert x amont of flagbox events
// insert x amount of score ticks for score mockdata
// use the game's initial geojson to draw game area
//
async mockdata(gameId) {
// initial settings for mockdata
// set the x amount of users to be created
......
......@@ -32,10 +32,7 @@ export class TaskService {
await this.taskRepository.insert(createdTask);
// notify subscribers about a new task
// if faction was set it notifies only faction members, else everyone
this.notificationGateway.server.emit(
task.faction != null ? task.faction.toString() : task.taskGame.toString(),
{ type: 'task-update' },
);
await this.triggerTasks(task);
return {
message: 'Task added',
};
......@@ -59,15 +56,24 @@ export class TaskService {
task.taskWinner = data.taskWinner;
task.taskIsActive = false;
await this.taskRepository.save(task);
await this.triggerTasks(task);
return {
message: 'Task updated and closed',
};
}
private async triggerTasks(task) {
this.notificationGateway.server.emit(
task.faction != null ? task.faction.toString() : task.taskGame.toString(),
{ type: 'task-update' },
);
}
async deleteTask(data: DeleteTaskDTO) {
const task = await this.taskRepository.findOne({ taskId: data.taskId });
if (task) {
await this.taskRepository.delete({ taskId: task.taskId });
await this.triggerTasks(task);
return {
message: 'Task deleted',
};
......
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