simple logging
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import Deck from '@/lib/TarokkaDeck';
|
||||
import generateID from '@/tools/simpleID';
|
||||
import parseMilliseconds from '@/tools/parseMilliseconds';
|
||||
import { GameState, GameUpdate, Settings } from '@/types';
|
||||
|
||||
const deck = new Deck();
|
||||
|
||||
export default class GameStore {
|
||||
private startTime: number;
|
||||
private dms: Map<string, GameState>;
|
||||
private spectators: Map<string, GameState>;
|
||||
private players: Map<string, string>;
|
||||
|
||||
constructor() {
|
||||
this.startTime = Date.now();
|
||||
|
||||
this.dms = new Map();
|
||||
this.spectators = new Map();
|
||||
this.players = new Map();
|
||||
|
||||
setInterval(() => this.log(), 15 * 60 * 1000);
|
||||
}
|
||||
|
||||
createGameIDs() {
|
||||
@@ -120,6 +126,25 @@ export default class GameStore {
|
||||
return this.leaveGame(gameID, playerID);
|
||||
}
|
||||
|
||||
log() {
|
||||
const now = Date.now();
|
||||
const uptime = now - this.startTime;
|
||||
|
||||
const { days, hours, minutes, seconds } = parseMilliseconds(uptime);
|
||||
|
||||
const dayLog = days ? ` ${days} ${days > 1 ? 'days' : 'day'}` : '';
|
||||
const hourLog = hours ? ` ${hours} ${hours > 1 ? 'hours' : 'hour'}` : '';
|
||||
const minuteLog = minutes ? ` ${minutes} ${minutes > 1 ? 'minutes' : 'minute'}` : '';
|
||||
|
||||
const uptimeLog = `Up${dayLog}${hourLog}${minuteLog} ${seconds} seconds`;
|
||||
|
||||
console.log('-'.repeat(uptimeLog.length));
|
||||
console.log(uptimeLog);
|
||||
console.log(`Games: ${this.dms.size}`);
|
||||
console.log(`Players: ${this.players.size}`);
|
||||
console.log('-'.repeat(uptimeLog.length));
|
||||
}
|
||||
|
||||
deleteGame(gameID: string): void {
|
||||
this.dms.delete(gameID);
|
||||
this.spectators.delete(gameID);
|
||||
|
||||
27
tools/parseMilliseconds.ts
Normal file
27
tools/parseMilliseconds.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export interface ParsedMilliseconds {
|
||||
days: number;
|
||||
hours: number;
|
||||
minutes: number;
|
||||
seconds: number;
|
||||
}
|
||||
|
||||
export default function parseMilliseconds(timestamp: number): ParsedMilliseconds {
|
||||
const SECOND = 1000;
|
||||
const MINUTE = 60 * SECOND;
|
||||
const HOUR = 60 * MINUTE;
|
||||
const DAY = 24 * HOUR;
|
||||
|
||||
const days = Math.floor(timestamp / DAY);
|
||||
timestamp %= DAY;
|
||||
|
||||
const hours = Math.floor(timestamp / HOUR);
|
||||
timestamp %= HOUR;
|
||||
|
||||
const minutes = Math.floor(timestamp / MINUTE);
|
||||
timestamp %= MINUTE;
|
||||
|
||||
const seconds = Math.floor(timestamp / SECOND);
|
||||
timestamp %= SECOND;
|
||||
|
||||
return { days, hours, minutes, seconds };
|
||||
}
|
||||
Reference in New Issue
Block a user