Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: False touch back function #37

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Table Tennis Counter
The Pool Score Tracker is a web application that allows you to track scores for a pool (billiards) game. It supports multiple players, keeps track of the match history, and updates scores automatically.
Table Tennis Counter is a web application that you can track scores for a ping-pong game. It supports multiple players, keeps track of the match history, and updates scores automatically.

## Introduction
### Features
Expand Down
4 changes: 4 additions & 0 deletions assets/js/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const languages = {
'ui.tooltip.serveRuleError': 'Please choose a valid serve rule',
'ui.tooltip.rotationalServesError': 'Please enter a valid number of rotational serves number',
'ui.tooltip.repoTip': 'Issues and PRs are welcome!!!',
'ui.gameBoard.undo': 'Undo',
},
'zh-CN': {
'language.LanguageName': '简体中文',
Expand Down Expand Up @@ -84,6 +85,7 @@ const languages = {
'ui.tooltip.serveRuleError': '请选择一个有效的发球规则',
'ui.tooltip.rotationalServesError': '请填入有效的轮换发球数',
'ui.tooltip.repoTip': '欢迎 Issue 和 PR!!!',
'ui.gameBoard.undo': '撤销',
},
'ja-JP': {
'language.LanguageName': '日本語',
Expand Down Expand Up @@ -125,6 +127,7 @@ const languages = {
'ui.tooltip.serveRuleError': '有効なサーブルールを選択してください',
'ui.tooltip.rotationalServesError': '有効なサーブ交代数を入力してください',
'ui.tooltip.repoTip': 'IssueやPRをお待ちしています!!!',
'ui.gameBoard.undo': '取り消し',
},
'zh-TW': {
'language.LanguageName': '繁體中文',
Expand Down Expand Up @@ -166,6 +169,7 @@ const languages = {
'ui.tooltip.serveRuleError': '請選擇一個有效的發球規則',
'ui.tooltip.rotationalServesError': '請輸入有效的輪換發球數',
'ui.tooltip.repoTip': '歡迎提交 Issue 和 PR!!!',
'ui.gameBoard.undo': '取消',
},
};
/**
Expand Down
24 changes: 24 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ let rotationalServes = 1;
let currentServe = -1;
let rotationalServesCounter = 0;
let matchHistory = [];
let lastScoringPlayer = null;
let lastRotationalServesCounter = 0;
let lastServe = -1;

function addPlayer() {
const playerName = document.getElementById('playerName').value.trim();
Expand Down Expand Up @@ -91,6 +94,10 @@ function checkMatchPoint(playerName) {
}

function incrementCurrentMatchScore(playerName) {
lastScoringPlayer = playerName;
lastRotationalServesCounter = rotationalServesCounter;
lastServe = currentServe;

currentMatchScores[playerName]++;
rotationalServesCounter++;
if (serveRule === 1 && rotationalServesCounter >= rotationalServes) {
Expand Down Expand Up @@ -220,4 +227,21 @@ function resetScores() {
document.getElementById('historyList').innerHTML = '';
}

function undoLastScore() {
if (!lastScoringPlayer) {
showSnackBar(lang('ui.tooltip.noScoreToUndo'), 'NoScoreToUndo');
return;
}

currentMatchScores[lastScoringPlayer]--;
rotationalServesCounter = lastRotationalServesCounter;
currentServe = lastServe;

// Reset the last scoring player
lastScoringPlayer = null;

// Update the display
updateCurrentMatch();
}

window.incrementCurrentMatchScore = incrementCurrentMatchScore;
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ <h2 data-lang="ui.gameBoard.currentMatch"></h2>
<div id="currentMatch"></div>
<div class="result-group">
<p id="result"></p>
<s-button type="filled-tonal" onclick="undoLastScore()">
<s-icon slot="start" type="undo"></s-icon>
<span data-lang="ui.gameBoard.undo">Undo</span>
</s-button>
</div>
</div>
<div id="playerScores">
Expand Down