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

ticking works

parent f647667e
No related branches found
No related tags found
3 merge requests!59Development to master,!54Development to testing,!51Scoretick
import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; import { Injectable, HttpException, HttpStatus, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository, Not } from 'typeorm'; import { Repository, Not } from 'typeorm';
...@@ -30,7 +30,6 @@ export class GameService { ...@@ -30,7 +30,6 @@ export class GameService {
>, >,
private notificationGateway: NotificationGateway, private notificationGateway: NotificationGateway,
) {} ) {}
// create a new game // create a new game
async createNewGame(personId: PersonEntity, gameData: GameDTO) { async createNewGame(personId: PersonEntity, gameData: GameDTO) {
// checks if a game with the same name exists already // checks if a game with the same name exists already
......
...@@ -7,7 +7,7 @@ import { AppModule } from './app.module'; ...@@ -7,7 +7,7 @@ import { AppModule } from './app.module';
*/ */
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule, { logger: console });
// Cors is needed for application/json POST // Cors is needed for application/json POST
app.enableCors(); app.enableCors();
await app.listen(5000); await app.listen(5000);
......
import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; import {
Injectable,
HttpException,
HttpStatus,
Logger,
OnModuleInit,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
...@@ -24,7 +30,10 @@ export class ScoreService { ...@@ -24,7 +30,10 @@ export class ScoreService {
@InjectRepository(FactionEntity) @InjectRepository(FactionEntity)
private factionRepository: Repository<FactionEntity>, private factionRepository: Repository<FactionEntity>,
private notificationGateway: NotificationGateway, private notificationGateway: NotificationGateway,
) {} ) {
// initialize timer when service is loaded
this.startTimer();
}
async addScore(scoreData: ScoreDTO, gameId: GameEntity) { async addScore(scoreData: ScoreDTO, gameId: GameEntity) {
// check if faction exists // check if faction exists
...@@ -110,10 +119,32 @@ export class ScoreService { ...@@ -110,10 +119,32 @@ export class ScoreService {
); );
return scores; return scores;
} }
} //
// Hae kaikki Objective pointit // tickinterval in milliseconds (10 minutes = 600 000)
// aja map funktio pelin objective pointteihin private readonly tickInterval: number = 5000;
// jokaisella objective point ID:llä hae historystä // dictionary to push gameId linked to start state
// relaatio, missä uusin timestamp private ongoingGames = {};
// katso uusimmista history entrystä omistaja
// initializing timer
async startTimer() {
setInterval(this.Tick, this.tickInterval);
}
async addToTimer(gameId: string) {
this.Tick();
this.ongoingGames[gameId] = Date.now();
}
async removeFromTimer(gameId: string) {
delete this.ongoingGames[gameId];
}
// tick score for games with STARTED-status
Tick = () => {
if (this.ongoingGames != null) {
for (var game in this.ongoingGames) {
console.log(game);
}
}
};
}
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