Skip to content

Commit

Permalink
fix match chart for multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
k2xl committed Dec 26, 2024
1 parent 391ebdf commit 55802f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion components/multiplayer/matchChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export default function MatchChart({ match }: MatchChartProps) {
const lastActionTime = {} as { [id: string]: number };
const playerScore = {} as { [id: string]: number };

// Initialize lastActionTime with match start time for all players
for (const player of match.players) {
lastActionTime[player._id.toString()] = 0; // Initialize with 0 (match start time)
}

for (let i = 0; i < match.matchLog.length; i++) {
const log = match.matchLog[i];

Expand Down Expand Up @@ -107,7 +112,7 @@ export default function MatchChart({ match }: MatchChartProps) {
}

// Calculate time spent on level
if (lastActionTime[completedBy] !== undefined) {
if (completedBy) { // Removed the lastActionTime check since we initialize it for all players
const timeSpent = timestamp - lastActionTime[completedBy];

if (!timePerLevelMap.has(levelName)) {
Expand Down
1 change: 0 additions & 1 deletion pages/api/match/[matchId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ export default withAuth(
// cleanUser for players, winners
populatedMatch.players.map(player => cleanUser(player as User));
populatedMatch.winners.map(winner => cleanUser(winner as User));
console.log('DNE');
enrichMultiplayerMatch(populatedMatch, req.userId);

await Promise.all([
Expand Down

0 comments on commit 55802f8

Please sign in to comment.