From 94220039f97b190b4bd503216f1891e6f5381a98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tr=E1=BA=A7n=20Qu=E1=BB=91c=20L=C3=A2n?=
<62930566+minotour4869@users.noreply.github.com>
Date: Mon, 16 Jun 2025 04:51:42 +0700
Subject: [PATCH] Modify how score displayed in log events and tables should be
score gained instead of total score (#6)
---
.../log-parser/_components/pvp-blinds.tsx | 13 ++++----
src/app/(home)/log-parser/page.tsx | 32 +++++++++++--------
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/src/app/(home)/log-parser/_components/pvp-blinds.tsx b/src/app/(home)/log-parser/_components/pvp-blinds.tsx
index e68999a..d7fe975 100644
--- a/src/app/(home)/log-parser/_components/pvp-blinds.tsx
+++ b/src/app/(home)/log-parser/_components/pvp-blinds.tsx
@@ -13,7 +13,8 @@ import {
// Define the structure for hand scores within a PVP blind
export type HandScore = {
timestamp: Date
- score: number
+ gainedScore: number
+ totalScore: number
handsLeft: number
isLogOwner: boolean
}
@@ -172,7 +173,7 @@ function PvpHandScoresTable({
// Group hand scores by player and filter out zero scores
const logOwnerScores = sortedHandScores.filter((score) => score.isLogOwner)
const opponentScores = sortedHandScores.filter(
- (score) => !score.isLogOwner && score.score > 0
+ (score) => !score.isLogOwner && score.gainedScore > 0
)
// Determine the maximum number of hands
@@ -183,11 +184,11 @@ function PvpHandScoresTable({
// Calculate total scores
const totalLogOwnerScore = logOwnerScores.reduce(
- (sum, score) => sum + score.score,
+ (sum, score) => sum + score.gainedScore,
0
)
const totalOpponentScore = opponentScores.reduce(
- (sum, score) => sum + score.score,
+ (sum, score) => sum + score.gainedScore,
0
)
@@ -211,12 +212,12 @@ function PvpHandScoresTable({
{handNumber}
{index < logOwnerScores.length
- ? formatNumber(logOwnerScores[index]?.score)
+ ? formatNumber(logOwnerScores[index]?.gainedScore)
: '-'}
{index < opponentScores.length
- ? formatNumber(opponentScores[index]?.score)
+ ? formatNumber(opponentScores[index]?.gainedScore)
: '-'}
diff --git a/src/app/(home)/log-parser/page.tsx b/src/app/(home)/log-parser/page.tsx
index 340fb55..4f771b7 100644
--- a/src/app/(home)/log-parser/page.tsx
+++ b/src/app/(home)/log-parser/page.tsx
@@ -355,12 +355,12 @@ export default function LogParser() {
const handsLeftMatch = line.match(/handsLeft: *(\d+)/)
if (scoreMatch?.[1]) {
- const score = Number.parseInt(scoreMatch[1], 10)
+ const totalScore = Number.parseInt(scoreMatch[1], 10)
const handsLeft = handsLeftMatch?.[1]
? Number.parseInt(handsLeftMatch[1], 10)
: 0
- if (!Number.isNaN(score)) {
+ if (!Number.isNaN(totalScore)) {
const currentBlindIndex = currentGame.currentPvpBlind - 1
if (
currentBlindIndex >= 0 &&
@@ -371,21 +371,23 @@ export default function LogParser() {
continue
}
// Update opponent score in current blind
- currentBlind.opponentScore += score
+ const gainedScore = totalScore - currentBlind.opponentScore
+ currentBlind.opponentScore = totalScore
// Add hand score
currentBlind.handScores.push({
timestamp,
- score,
+ gainedScore,
+ totalScore,
handsLeft,
isLogOwner: false,
})
- // Add event for opponent score only if score > 0
- if (score > 0) {
+ // Add event for opponent score only if gainedScore > 0
+ if (gainedScore > 0) {
currentGame.events.push({
timestamp,
- text: `Opponent score: ${score} (Hands left: ${handsLeft})`,
+ text: `Opponent scored: ${gainedScore} (Total: ${totalScore}, hands left: ${handsLeft})`,
type: 'event',
})
}
@@ -600,12 +602,12 @@ export default function LogParser() {
const handsLeftMatch = line.match(/handsLeft:(\d+)/)
if (scoreMatch?.[1]) {
- const score = Number.parseInt(scoreMatch[1], 10)
+ const totalScore = Number.parseInt(scoreMatch[1], 10)
const handsLeft = handsLeftMatch?.[1]
? Number.parseInt(handsLeftMatch[1], 10)
: 0
- if (!Number.isNaN(score)) {
+ if (!Number.isNaN(totalScore)) {
const currentBlindIndex = currentGame.currentPvpBlind - 1
if (
currentBlindIndex >= 0 &&
@@ -617,21 +619,23 @@ export default function LogParser() {
continue
}
// Update log owner score in current blind
- currentBlind.logOwnerScore += score
+ const gainedScore = totalScore - currentBlind.logOwnerScore
+ currentBlind.logOwnerScore = totalScore
// Add hand score
currentBlind.handScores.push({
timestamp,
- score,
+ gainedScore,
+ totalScore,
handsLeft,
isLogOwner: true,
})
- // Add event for log owner score only if score > 0
- if (score > 0) {
+ // Add event for log owner score only if gainedScore > 0
+ if (gainedScore > 0) {
currentGame.events.push({
timestamp,
- text: `Your score: ${score} (Hands left: ${handsLeft})`,
+ text: `You scored: ${gainedScore} (Total: ${totalScore}, hands left: ${handsLeft})`,
type: 'event',
})
}