Skip to content
Snippets Groups Projects
Commit 41cd65ab authored by L4168's avatar L4168
Browse files

working on replay

parent bce14d94
No related branches found
No related tags found
3 merge requests!59Development to master,!54Development to testing,!49Replay update
...@@ -13,6 +13,7 @@ import { GameEntity } from '../game/game.entity'; ...@@ -13,6 +13,7 @@ import { GameEntity } from '../game/game.entity';
import { Game_PersonEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity';
import { MapDrawingEntity } from '../draw/coordinate.entity'; import { MapDrawingEntity } from '../draw/coordinate.entity';
import { Exclude } from 'class-transformer'; import { Exclude } from 'class-transformer';
import { ScoreEntity } from 'src/score/score.entity';
//Faction, PowerUp, Faction_powerUp, FP_History, Score //Faction, PowerUp, Faction_powerUp, FP_History, Score
...@@ -35,6 +36,10 @@ export class FactionEntity { ...@@ -35,6 +36,10 @@ export class FactionEntity {
game: GameEntity; game: GameEntity;
@OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction) @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction)
mapDrawings: MapDrawingEntity[]; mapDrawings: MapDrawingEntity[];
@OneToMany(type => ScoreEntity, score => score.scoreId, {
onDelete: 'NO ACTION',
})
scores: ScoreEntity[];
factionObject() { factionObject() {
const { factionId, factionName, game } = this; const { factionId, factionName, game } = this;
......
import { Controller, Get, Param, Post } from '@nestjs/common'; import {
Controller,
Get,
Param,
Post,
UseInterceptors,
ClassSerializerInterceptor,
} from '@nestjs/common';
import { ReplayService } from './replay.service'; import { ReplayService } from './replay.service';
import { Roles } from 'src/shared/guard.decorator';
@Controller('replay') @Controller('replay')
export class ReplayController { export class ReplayController {
constructor(private replayservice: ReplayService) {} constructor(private replayservice: ReplayService) {}
@Get(':id') @Get(':id')
@UseInterceptors(ClassSerializerInterceptor)
async replayInfo(@Param('id') gameId) { async replayInfo(@Param('id') gameId) {
return this.replayservice.replayData(gameId); return this.replayservice.replayData(gameId);
} }
......
...@@ -8,8 +8,12 @@ import { FactionEntity, GameGroupEntity } from '../faction/faction.entity'; ...@@ -8,8 +8,12 @@ import { FactionEntity, GameGroupEntity } from '../faction/faction.entity';
import { UserService } from '../user/user.service'; import { UserService } from '../user/user.service';
import { FactionService } from '../faction/faction.service'; import { FactionService } from '../faction/faction.service';
import { TrackingService } from '../tracking/tracking.service'; import { TrackingService } from '../tracking/tracking.service';
import { TrackingEntity } from 'src/tracking/tracking.entity'; import { TrackingEntity } from '../tracking/tracking.entity';
import { PersonEntity } from 'src/user/user.entity'; import { PersonEntity } from '../user/user.entity';
import {
MapDrawingEntity,
MapDrawingHistoryEntity,
} from '../draw/coordinate.entity';
@Module({ @Module({
imports: [ imports: [
...@@ -20,6 +24,8 @@ import { PersonEntity } from 'src/user/user.entity'; ...@@ -20,6 +24,8 @@ import { PersonEntity } from 'src/user/user.entity';
TrackingEntity, TrackingEntity,
GameGroupEntity, GameGroupEntity,
Game_PersonEntity, Game_PersonEntity,
MapDrawingEntity,
MapDrawingHistoryEntity,
]), ]),
], ],
controllers: [ReplayController], controllers: [ReplayController],
......
...@@ -4,11 +4,15 @@ import { Repository } from 'typeorm'; ...@@ -4,11 +4,15 @@ import { Repository } from 'typeorm';
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
import { GameEntity } from 'src/game/game.entity'; import { GameEntity } from '../game/game.entity';
import { TrackingService } from 'src/tracking/tracking.service'; import { TrackingService } from '../tracking/tracking.service';
import { UserService } from 'src/user/user.service'; import { UserService } from '../user/user.service';
import { FactionService } from 'src/faction/faction.service'; import { FactionService } from '../faction/faction.service';
import { TrackingEntity } from 'src/tracking/tracking.entity'; import { TrackingEntity } from '../tracking/tracking.entity';
import {
MapDrawingEntity,
MapDrawingHistoryEntity,
} from '../draw/coordinate.entity';
@Injectable() @Injectable()
export class ReplayService { export class ReplayService {
...@@ -19,17 +23,31 @@ export class ReplayService { ...@@ -19,17 +23,31 @@ export class ReplayService {
private gameRepository: Repository<GameEntity>, private gameRepository: Repository<GameEntity>,
@InjectRepository(TrackingEntity) @InjectRepository(TrackingEntity)
private trackingRepository: Repository<TrackingEntity>, private trackingRepository: Repository<TrackingEntity>,
@InjectRepository(MapDrawingEntity)
private mapdrawingRepository: Repository<MapDrawingEntity>,
@InjectRepository(MapDrawingHistoryEntity)
private mapHistoryRepository: Repository<MapDrawingHistoryEntity>,
private trackingService: TrackingService, private trackingService: TrackingService,
private userService: UserService, private userService: UserService,
private factionService: FactionService, private factionService: FactionService,
) {} ) {}
async replayData(gameId) { async replayData(gameId) {
const replay = await this.factionRepository.find({ let mapDrawingIds = await this.mapdrawingRepository.find({
where: { game: gameId }, where: { gameId: gameId },
relations: ['mapDrawings', 'scores', 'trackdata'], select: ['mapDrawingId'],
}); });
return replay; let drawings = [];
await Promise.all(
mapDrawingIds.map(async mapId => {
drawings.push(
await this.mapHistoryRepository.find({
mapdrawing: mapId.mapDrawingId,
}),
);
}),
);
return drawings;
} }
// get replay data for players // get replay data for players
......
...@@ -69,7 +69,8 @@ export class ScoreService { ...@@ -69,7 +69,8 @@ export class ScoreService {
i => i.faction === current.owner.factionId, i => i.faction === current.owner.factionId,
); );
index !== -1 index !== -1
? await (scoreData[index]['score'] += box.objectivePointMultiplier * current.owner.multiplier) ? await (scoreData[index]['score'] +=
box.objectivePointMultiplier * current.owner.multiplier)
: await scoreData.push({ : await scoreData.push({
score: box.objectivePointMultiplier, score: box.objectivePointMultiplier,
faction: current.owner.factionId, faction: current.owner.factionId,
......
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