Modify how score displayed in log events and tables should be score gained instead of total score (#6)

This commit is contained in:
Trần Quốc Lân
2025-06-16 04:51:42 +07:00
committed by GitHub
parent ff4b07debd
commit 94220039f9
2 changed files with 25 additions and 20 deletions

View File

@@ -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({
<TableCell className='text-right font-mono'>{handNumber}</TableCell>
<TableCell className='text-right font-mono'>
{index < logOwnerScores.length
? formatNumber(logOwnerScores[index]?.score)
? formatNumber(logOwnerScores[index]?.gainedScore)
: '-'}
</TableCell>
<TableCell className='text-right font-mono'>
{index < opponentScores.length
? formatNumber(opponentScores[index]?.score)
? formatNumber(opponentScores[index]?.gainedScore)
: '-'}
</TableCell>
</TableRow>

View File

@@ -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',
})
}