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