Skip to content
Snippets Groups Projects
Commit cee0c00c authored by Ronnie Friman's avatar Ronnie Friman
Browse files

update get playerlocations

parent 62ad3f5e
No related branches found
No related tags found
3 merge requests!59Development to master,!58Development to testing,!55Flagbox replay
......@@ -6,6 +6,7 @@ import { TrackingService } from './tracking.service';
import { TrackingEntity } from './tracking.entity';
import { Game_PersonEntity } from '../game/game.entity';
import { PersonEntity } from '../user/user.entity';
import { FactionEntity } from '../faction/faction.entity';
/////////////////////////////////////////////////////////////////////
/// Tracking ///
......@@ -13,7 +14,12 @@ import { PersonEntity } from '../user/user.entity';
/////////////////////////////////////////////////////////////////////
@Module({
imports: [
TypeOrmModule.forFeature([TrackingEntity, Game_PersonEntity, PersonEntity]),
TypeOrmModule.forFeature([
TrackingEntity,
Game_PersonEntity,
PersonEntity,
FactionEntity,
]),
],
controllers: [TrackingController],
providers: [TrackingService],
......
......@@ -5,6 +5,7 @@ import { Repository } from 'typeorm';
import { Game_PersonEntity } from '../game/game.entity';
import { TrackingEntity } from './tracking.entity';
import { GeoDTO } from './geo.dto';
import { FactionEntity } from 'src/faction/faction.entity';
@Injectable()
export class TrackingService {
......@@ -13,6 +14,8 @@ export class TrackingService {
private trackingrepository: Repository<TrackingEntity>,
@InjectRepository(Game_PersonEntity)
private gamepersonrepository: Repository<Game_PersonEntity>,
@InjectRepository(FactionEntity)
private factionRepository: Repository<FactionEntity>,
) {}
private icons = {
......@@ -59,34 +62,45 @@ export class TrackingService {
// get player data while game is running
async getPlayers(gameperson, gameId) {
let playerdata;
let playerdata = [];
// get playerdata
if (gameperson.faction) {
playerdata = await this.trackingrepository.find({
where: { faction: gameperson.faction },
relations: ['faction', 'gamepersonId'],
});
// create an array of the response as frontend maps the response
// to create different clusters for factions
playerdata.push(
await this.trackingrepository.find({
where: { faction: gameperson.faction },
relations: ['faction', 'gamepersonId'],
}),
);
} else {
playerdata = await this.trackingrepository.find({
where: { game: gameId },
relations: ['faction', 'gamepersonId'],
});
let factions = await this.factionRepository.find({ game: gameId });
playerdata = await Promise.all(
factions.map(async faction => {
return await this.trackingrepository.find({
where: { faction: faction.factionId },
relations: ['faction', 'gamepersonId'],
});
}),
);
}
// parse data
const currentdata = await Promise.all(
playerdata.map(async player => {
return {
gamepersonId: player['gamepersonId']['gamepersonId'],
gamepersonRole: player['gamepersonId']['role'],
factionId: player['faction']['factionId'],
factionColour: player['faction']['colour'],
icon: player['icon'],
coordinates: player['data'].pop(),
};
await playerdata.map(async faction => {
return await Promise.all(
faction.map(async player => {
return await {
gamepersonId: player['gamepersonId']['gamepersonId'],
gamepersonRole: player['gamepersonId']['role'],
factionId: player['faction']['factionId'],
factionColour: player['faction']['colour'],
icon: player['icon'],
coordinates: player['data'].pop(),
};
}),
);
}),
);
return currentdata;
}
......
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