leaderboard v2, filtro por round, game, datos historicos, salas activas

This commit is contained in:
2025-08-27 21:45:10 -06:00
parent f5082219a3
commit 0877fe1448
5 changed files with 633 additions and 145 deletions

View File

@@ -816,18 +816,28 @@ async function sendPlayersActionsUpdate(client?: Response) {
const players = uuids.map((uuid: string) => {
const history = nameManager.getSystemHistory(uuid) || [];
const counts: any = Object.fromEntries(ACTION_EVENTS.map(k => [k, 0]));
const detailedHistory: any[] = [];
for (const entry of history) {
const kind = (entry as any)?.kind || '';
if (!ACTION_EVENTS.includes(kind)) continue;
if (!isActionMade(kind, (entry as any)?.role)) continue;
counts[kind] = (counts[kind] || 0) + 1;
// Include detailed event info
detailedHistory.push({
kind,
round: (entry as any)?.round,
gameVariant: (entry as any)?.gameVariant || (entry as any)?.variant
});
}
const total = ACTION_EVENTS.reduce((acc, k) => acc + (counts[k] || 0), 0);
return {
uuid,
name: nameManager.getPlayerName(uuid) || null,
counts,
total
total,
detailedHistory
};
}).filter((p: any) => p.total > 0 || p.name);

View File

@@ -6,7 +6,7 @@ import { broadcastDashboardUpdate } from "../adminApi";
export class GameRoom extends Room<GameState> {
maxClients = 2;
private systemMessages: { text: string; kind: string; timestamp: number }[] = [];
private systemMessages: { text: string; kind: string; timestamp: number; round?: number; gameVariant?: string }[] = [];
getFilterOptions() {
// If waiting for shuffled players, report as available regardless of current client count
@@ -46,8 +46,14 @@ export class GameRoom extends Room<GameState> {
if (kind !== 'round_advance') {
this.recentSystemMessage = { text, kind, timestamp };
}
// Persist in per-room history (keep last 200)
this.systemMessages.push({ text, kind, timestamp });
// Persist in per-room history (keep last 200) with round and game variant info
this.systemMessages.push({
text,
kind,
timestamp,
round: this.state.currentRound,
gameVariant: this.state.currentVariant
});
if (this.systemMessages.length > 200) {
this.systemMessages.splice(0, this.systemMessages.length - 200);
}
@@ -78,7 +84,7 @@ export class GameRoom extends Room<GameState> {
kind,
text,
roomId: this.roomId,
variant: this.state.currentVariant,
gameVariant: this.state.currentVariant,
round: this.state.currentRound,
role: (player as any)?.role || '',
pavoTokens: (player as any)?.pavoTokens || 0,

View File

@@ -9,6 +9,7 @@ export class NameManager {
text: string;
roomId?: string;
variant?: string;
gameVariant?: string;
round?: number;
role?: 'P1' | 'P2' | '';
pavoTokens?: number;
@@ -174,7 +175,7 @@ export class NameManager {
// Per-UUID system message history (as seen while connected)
appendSystemMessage(uuid: string, entry: {
timestamp: number; kind: string; text: string;
roomId?: string; variant?: string; round?: number;
roomId?: string; variant?: string; gameVariant?: string; round?: number;
role?: 'P1'|'P2'|''; pavoTokens?: number; eloteTokens?: number; shameTokens?: number;
}): void {
if (!uuid) return;
@@ -184,7 +185,8 @@ export class NameManager {
kind: (entry.kind || '').toString(),
text: (entry.text || '').toString(),
roomId: entry.roomId,
variant: entry.variant,
variant: entry.variant || entry.gameVariant,
gameVariant: entry.gameVariant || entry.variant,
round: entry.round,
role: entry.role || '',
pavoTokens: Number(entry.pavoTokens ?? 0),
@@ -197,7 +199,7 @@ export class NameManager {
getSystemHistory(uuid: string): {
timestamp: number; kind: string; text: string;
roomId?: string; variant?: string; round?: number;
roomId?: string; variant?: string; gameVariant?: string; round?: number;
role?: 'P1'|'P2'|''; pavoTokens?: number; eloteTokens?: number; shameTokens?: number;
}[] {
return [...(this.uuidToSystemHistory.get(uuid) || [])];