Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ <h2 data-lang="ui.gameBoard.matchHistory"></h2>
<s-tr>
<s-th data-lang="ui.gameBoard.matchHistory.match"></s-th>
<s-th data-lang="ui.gameBoard.matchHistory.score"></s-th>
<s-th data-lang="ui.gameBoard.matchHistory.setScore"></s-th>
<s-th data-lang="ui.gameBoard.matchHistory.winner"></s-th>
</s-tr>
</s-thead>
Expand Down
5 changes: 5 additions & 0 deletions src/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const languages = {
'ui.tooltip.noScoreToUndo': 'No score to undo',
'ui.gameBoard.matchHistory.match': 'Match',
'ui.gameBoard.matchHistory.score': 'Score',
'ui.gameBoard.matchHistory.setScore': 'Set Score',
'ui.gameBoard.matchHistory.winner': 'Winner',
},
'zh-CN': {
Expand Down Expand Up @@ -98,6 +99,7 @@ export const languages = {
'ui.tooltip.noScoreToUndo': '没有可撤销的分数',
'ui.gameBoard.matchHistory.match': '比赛',
'ui.gameBoard.matchHistory.score': '比分',
'ui.gameBoard.matchHistory.setScore': '局分',
'ui.gameBoard.matchHistory.winner': '获胜者',
},
'zh-TW': {
Expand Down Expand Up @@ -145,6 +147,7 @@ export const languages = {
'ui.tooltip.noScoreToUndo': '沒有可撤銷的分數',
'ui.gameBoard.matchHistory.match': '比賽',
'ui.gameBoard.matchHistory.score': '比分',
'ui.gameBoard.matchHistory.setScore': '局分',
'ui.gameBoard.matchHistory.winner': '獲勝者',
},
'ja-JP': {
Expand Down Expand Up @@ -192,6 +195,7 @@ export const languages = {
'ui.tooltip.noScoreToUndo': '取り消すスコアはありません',
'ui.gameBoard.matchHistory.match': '試合',
'ui.gameBoard.matchHistory.score': 'スコア',
'ui.gameBoard.matchHistory.setScore': 'セットスコア',
'ui.gameBoard.matchHistory.winner': '勝者',
},
'el-GR': {
Expand Down Expand Up @@ -239,6 +243,7 @@ export const languages = {
'ui.tooltip.noScoreToUndo': 'Δεν υπάρχει σκορ για αναίρεση',
'ui.gameBoard.matchHistory.match': 'Αγώνας',
'ui.gameBoard.matchHistory.score': 'Σκορ',
'ui.gameBoard.matchHistory.setScore': 'Σκορ σετ',
'ui.gameBoard.matchHistory.winner': 'Νικητής',
},
};
Expand Down
65 changes: 46 additions & 19 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,27 @@ export function incrementCurrentMatchScore(playerName) {
: currentMatchScores[playerName] >= winBalls;

if (hasWon) {
const player1 = players[currentMatch[0]];
const player2 = players[currentMatch[1]];
const player1Score = currentMatchScores[player1];
const player2Score = currentMatchScores[player2];

totalScores[playerName]++;

matchHistory.push({
player1,
player2,
player1Score,
player2Score,
player1SetScore: totalScores[player1],
player2SetScore: totalScores[player2],
winner: playerName,
});

document.getElementById('result').innerText = lang(
'ui.gameBoard.winMessage',
playerName
);
matchHistory.push(
lang(
'ui.gameBoard.matchHistory.item',
players[currentMatch[0]],
players[currentMatch[1]],
playerName
)
);
disableScoreButtons();

// Wining Animation
Expand Down Expand Up @@ -288,29 +296,48 @@ export function updateHistoryList() {
const tbody = historyTable.querySelector('s-tbody');
tbody.innerHTML = '';

matchHistory.forEach((match, index) => {
// Extract the two players from the match string
const matchParts = match.split(' vs ');
const player1 = matchParts[0].trim();
const player2 = matchParts[1].split(':')[0].trim();
matchHistory.forEach((match) => {
let matchUp;
let scoreLine;
let setScoreLine;
let winner;

if (typeof match === 'string') {
const matchParts = match.split(' vs ');
const player1 = matchParts[0]?.trim?.() ?? '';
const player2 = matchParts[1]?.split(':')[0]?.trim?.() ?? '';

const scoreLine = `${totalScores[player1]}:${totalScores[player2]}`;
// Extract winner
const afterColon = match.substring(match.lastIndexOf(':') + 1).trim();
const winnerParts = afterColon.split(' ');
const winner = winnerParts.length > 1 ? winnerParts.slice(0, -1).join(' ') : afterColon;
matchUp = `${player1} vs ${player2}`.trim();
scoreLine = `${totalScores[player1] ?? 0}:${totalScores[player2] ?? 0}`;
setScoreLine = '—';

const matchUp = `${player1} vs ${player2}`;
const afterColon = match.substring(match.lastIndexOf(':') + 1).trim();
const winnerParts = afterColon.split(' ');
winner = winnerParts.length > 1 ? winnerParts.slice(0, -1).join(' ') : afterColon;
} else {
matchUp = `${match.player1} vs ${match.player2}`;
scoreLine = `${match.player1Score}:${match.player2Score}`;
setScoreLine = `${match.player1SetScore}:${match.player2SetScore}`;
winner = match.winner;
}

const tr = document.createElement('s-tr');

const tdMatch = document.createElement('s-td');
tdMatch.textContent = matchUp;

const tdScore = document.createElement('s-td');
tdScore.textContent = scoreLine;

const tdSetScore = document.createElement('s-td');
tdSetScore.textContent = setScoreLine;

const tdWinner = document.createElement('s-td');
tdWinner.textContent = winner;

tr.appendChild(tdMatch);
tr.appendChild(tdScore);
tr.appendChild(tdSetScore);
tr.appendChild(tdWinner);
tbody.appendChild(tr);
});
Expand Down