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 // Define the structure for hand scores within a PVP blind
export type HandScore = { export type HandScore = {
timestamp: Date timestamp: Date
score: number gainedScore: number
totalScore: number
handsLeft: number handsLeft: number
isLogOwner: boolean isLogOwner: boolean
} }
@@ -172,7 +173,7 @@ function PvpHandScoresTable({
// Group hand scores by player and filter out zero scores // Group hand scores by player and filter out zero scores
const logOwnerScores = sortedHandScores.filter((score) => score.isLogOwner) const logOwnerScores = sortedHandScores.filter((score) => score.isLogOwner)
const opponentScores = sortedHandScores.filter( const opponentScores = sortedHandScores.filter(
(score) => !score.isLogOwner && score.score > 0 (score) => !score.isLogOwner && score.gainedScore > 0
) )
// Determine the maximum number of hands // Determine the maximum number of hands
@@ -183,11 +184,11 @@ function PvpHandScoresTable({
// Calculate total scores // Calculate total scores
const totalLogOwnerScore = logOwnerScores.reduce( const totalLogOwnerScore = logOwnerScores.reduce(
(sum, score) => sum + score.score, (sum, score) => sum + score.gainedScore,
0 0
) )
const totalOpponentScore = opponentScores.reduce( const totalOpponentScore = opponentScores.reduce(
(sum, score) => sum + score.score, (sum, score) => sum + score.gainedScore,
0 0
) )
@@ -211,12 +212,12 @@ function PvpHandScoresTable({
<TableCell className='text-right font-mono'>{handNumber}</TableCell> <TableCell className='text-right font-mono'>{handNumber}</TableCell>
<TableCell className='text-right font-mono'> <TableCell className='text-right font-mono'>
{index < logOwnerScores.length {index < logOwnerScores.length
? formatNumber(logOwnerScores[index]?.score) ? formatNumber(logOwnerScores[index]?.gainedScore)
: '-'} : '-'}
</TableCell> </TableCell>
<TableCell className='text-right font-mono'> <TableCell className='text-right font-mono'>
{index < opponentScores.length {index < opponentScores.length
? formatNumber(opponentScores[index]?.score) ? formatNumber(opponentScores[index]?.gainedScore)
: '-'} : '-'}
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@@ -355,12 +355,12 @@ export default function LogParser() {
const handsLeftMatch = line.match(/handsLeft: *(\d+)/) const handsLeftMatch = line.match(/handsLeft: *(\d+)/)
if (scoreMatch?.[1]) { if (scoreMatch?.[1]) {
const score = Number.parseInt(scoreMatch[1], 10) const totalScore = Number.parseInt(scoreMatch[1], 10)
const handsLeft = handsLeftMatch?.[1] const handsLeft = handsLeftMatch?.[1]
? Number.parseInt(handsLeftMatch[1], 10) ? Number.parseInt(handsLeftMatch[1], 10)
: 0 : 0
if (!Number.isNaN(score)) { if (!Number.isNaN(totalScore)) {
const currentBlindIndex = currentGame.currentPvpBlind - 1 const currentBlindIndex = currentGame.currentPvpBlind - 1
if ( if (
currentBlindIndex >= 0 && currentBlindIndex >= 0 &&
@@ -371,21 +371,23 @@ export default function LogParser() {
continue continue
} }
// Update opponent score in current blind // Update opponent score in current blind
currentBlind.opponentScore += score const gainedScore = totalScore - currentBlind.opponentScore
currentBlind.opponentScore = totalScore
// Add hand score // Add hand score
currentBlind.handScores.push({ currentBlind.handScores.push({
timestamp, timestamp,
score, gainedScore,
totalScore,
handsLeft, handsLeft,
isLogOwner: false, isLogOwner: false,
}) })
// Add event for opponent score only if score > 0 // Add event for opponent score only if gainedScore > 0
if (score > 0) { if (gainedScore > 0) {
currentGame.events.push({ currentGame.events.push({
timestamp, timestamp,
text: `Opponent score: ${score} (Hands left: ${handsLeft})`, text: `Opponent scored: ${gainedScore} (Total: ${totalScore}, hands left: ${handsLeft})`,
type: 'event', type: 'event',
}) })
} }
@@ -600,12 +602,12 @@ export default function LogParser() {
const handsLeftMatch = line.match(/handsLeft:(\d+)/) const handsLeftMatch = line.match(/handsLeft:(\d+)/)
if (scoreMatch?.[1]) { if (scoreMatch?.[1]) {
const score = Number.parseInt(scoreMatch[1], 10) const totalScore = Number.parseInt(scoreMatch[1], 10)
const handsLeft = handsLeftMatch?.[1] const handsLeft = handsLeftMatch?.[1]
? Number.parseInt(handsLeftMatch[1], 10) ? Number.parseInt(handsLeftMatch[1], 10)
: 0 : 0
if (!Number.isNaN(score)) { if (!Number.isNaN(totalScore)) {
const currentBlindIndex = currentGame.currentPvpBlind - 1 const currentBlindIndex = currentGame.currentPvpBlind - 1
if ( if (
currentBlindIndex >= 0 && currentBlindIndex >= 0 &&
@@ -617,21 +619,23 @@ export default function LogParser() {
continue continue
} }
// Update log owner score in current blind // Update log owner score in current blind
currentBlind.logOwnerScore += score const gainedScore = totalScore - currentBlind.logOwnerScore
currentBlind.logOwnerScore = totalScore
// Add hand score // Add hand score
currentBlind.handScores.push({ currentBlind.handScores.push({
timestamp, timestamp,
score, gainedScore,
totalScore,
handsLeft, handsLeft,
isLogOwner: true, isLogOwner: true,
}) })
// Add event for log owner score only if score > 0 // Add event for log owner score only if gainedScore > 0
if (score > 0) { if (gainedScore > 0) {
currentGame.events.push({ currentGame.events.push({
timestamp, timestamp,
text: `Your score: ${score} (Hands left: ${handsLeft})`, text: `You scored: ${gainedScore} (Total: ${totalScore}, hands left: ${handsLeft})`,
type: 'event', type: 'event',
}) })
} }