simple logging

This commit is contained in:
Gavin McDonald
2025-04-21 17:24:16 -04:00
parent 626094cc2c
commit 6856660fa0
2 changed files with 52 additions and 0 deletions

View File

@@ -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);