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

Merge branch 'replay' into HEAD

parents 8d5b323c 1090b2a8
No related branches found
No related tags found
3 merge requests!59Development to master,!44Development to testing,!43initial replay
...@@ -19,6 +19,7 @@ import { DrawModule } from './draw/draw.module'; ...@@ -19,6 +19,7 @@ import { DrawModule } from './draw/draw.module';
import { FactionModule } from './faction/faction.module'; import { FactionModule } from './faction/faction.module';
import { GameModule } from './game/game.module'; import { GameModule } from './game/game.module';
import { ScoreModule } from './score/score.module'; import { ScoreModule } from './score/score.module';
import { ReplayModule } from './replay/replay.module';
@Module({ @Module({
imports: [ imports: [
...@@ -31,6 +32,7 @@ import { ScoreModule } from './score/score.module'; ...@@ -31,6 +32,7 @@ import { ScoreModule } from './score/score.module';
FactionModule, FactionModule,
TrackingModule, TrackingModule,
ScoreModule, ScoreModule,
ReplayModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [ providers: [
......
import { Controller, Get, Param, Post } from '@nestjs/common';
import { ReplayService } from './replay.service';
import { Roles } from 'src/shared/guard.decorator';
@Controller('replay')
export class ReplayController {
constructor(private replayservice: ReplayService) {}
@Get(':id')
async replayInfo(@Param('id') gameId) {
return this.replayservice.replayData(gameId);
}
@Post('mockdata/:id')
async mockData(@Param('id') gameId) {
return this.replayservice.mockdata(gameId);
}
@Get('players/:id')
async getPlayers(@Param('id') gameId) {
return this.replayservice.getPlayers(gameId);
}
}
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ReplayController } from './replay.controller';
import { ReplayService } from './replay.service';
import { GameEntity, Game_PersonEntity } from '../game/game.entity';
import { FactionEntity, GameGroupEntity } from '../faction/faction.entity';
import { UserService } from '../user/user.service';
import { FactionService } from '../faction/faction.service';
import { TrackingService } from '../tracking/tracking.service';
import { TrackingEntity } from 'src/tracking/tracking.entity';
import { PersonEntity } from 'src/user/user.entity';
@Module({
imports: [
TypeOrmModule.forFeature([
PersonEntity,
GameEntity,
FactionEntity,
TrackingEntity,
GameGroupEntity,
Game_PersonEntity,
]),
],
controllers: [ReplayController],
providers: [ReplayService, UserService, FactionService, TrackingService],
})
export class ReplayModule {}
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import * as jwt from 'jsonwebtoken';
import { FactionEntity } from '../faction/faction.entity';
import { GameEntity } from 'src/game/game.entity';
import { TrackingService } from 'src/tracking/tracking.service';
import { UserService } from 'src/user/user.service';
import { FactionService } from 'src/faction/faction.service';
import { TrackingEntity } from 'src/tracking/tracking.entity';
@Injectable()
export class ReplayService {
constructor(
@InjectRepository(FactionEntity)
private factionRepository: Repository<FactionEntity>,
@InjectRepository(GameEntity)
private gameRepository: Repository<GameEntity>,
@InjectRepository(TrackingEntity)
private trackingRepository: Repository<TrackingEntity>,
private trackingService: TrackingService,
private userService: UserService,
private factionService: FactionService,
) {}
async replayData(gameId) {
const replay = await this.factionRepository.find({
where: { game: gameId },
relations: ['mapDrawings', 'scores', 'trackdata'],
});
return replay;
}
// get replay data for players
async getPlayers(gameId) {
let playerdata = await this.trackingRepository.find({
where: { game: gameId },
relations: ['faction', 'gamepersonId'],
});
// parse data
const currentdata = await Promise.all(
playerdata.map(async player => {
return player['data'];
/* return {
gamepersonId: player['gamepersonId']['gamepersonId'],
gamepersonRole: player['gamepersonId']['role'],
factionId: player['faction']['factionId'],
coordinates: player['data'],
}; */
}),
);
return currentdata;
}
// generate mockdata for a 3 day game
async mockdata(gameId) {
const users = [];
const gamepersons = [];
const game = await this.gameRepository.findOne({
where: { id: gameId },
relations: ['factions'],
});
for (let i = 0; i < 20; i++) {
let res = await this.userService.register({
name: 'qqqqq' + i,
password: 'asd',
});
let user = await jwt.verify(res.token, process.env.SECRET);
users.push(user);
let gameperson = await this.factionService.joinFaction(user['id'], {
factionId:
i < 10 ? game.factions[0].factionId : game.factions[1].factionId,
factionPassword:
i < 10
? game.factions[0].factionPassword
: game.factions[1].factionPassword,
game: gameId,
});
gamepersons.push(gameperson);
}
let date: number = Date.now();
let y1 = 25.7;
let x1 = 62.3;
let y2 = 25.75;
let x2 = 62.35;
for (let i = 1; i < 16 * 6 * 3; i++) {
let x = 0;
date += 10000;
await Promise.all(
gamepersons.map(async gameperson => {
x++;
let dataObject = {
lat:
x < 10
? x1 + ((i + Math.random()) * 5) / 2000
: x2 - ((i + Math.random()) * 5) / 2000,
lng:
x < 10
? y1 + ((i + Math.random()) * 5) / 2000
: y2 - ((i + Math.random()) * 5) / 2000,
time: date,
};
await this.trackingService.trackLocation(
gameperson,
gameId,
dataObject,
);
}),
);
}
return {
message: 'all done',
};
}
}
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