aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWladimir Leuschner <[email protected]>2023-12-08 13:14:25 +0100
committerWladimir Leuschner <[email protected]>2024-03-12 15:01:39 +0000
commitfddba23321bd90b39ab1028fbd7d1b52066bc1b6 (patch)
treed2179727394b74f95dc5135b77110b64a72424c6
parent4786eb0b0f2c90c0e5f456fd51cca51ddf44531c (diff)
Fix duplicate HighScore when replaying SameGame Example
The onClosed slot invokes SameGame.saveHighscore function in samegame.js. Also the startNewGame function in samegame.js is triggering the SameGame.saveHighscore function by calling Dialog.hide, which in turn calls the onClosed slot. This leads to duplicate highscore entries. Moving the closing of the dialog after the clearing of the board/score and additionally adding a condition that if the score is 0, no highscores are saved, the duplication is avoided. Fixes: QTBUG-119812 Pick-to: 6.7 6.6 Change-Id: I6aa433789f197a0d1e70abc82baf893934e53be5 Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Oliver Wolff <[email protected]>
-rw-r--r--examples/quick/tutorials/samegame/samegame4/samegame.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/quick/tutorials/samegame/samegame4/samegame.js b/examples/quick/tutorials/samegame/samegame4/samegame.js
index 80b175d450..99d34c64a0 100644
--- a/examples/quick/tutorials/samegame/samegame4/samegame.js
+++ b/examples/quick/tutorials/samegame/samegame4/samegame.js
@@ -27,10 +27,6 @@ function startNewGame() {
maxRow = Math.floor(gameCanvas.height / gameCanvas.blockSize);
maxIndex = maxRow * maxColumn;
- //Close dialogs
- nameInputDialog.hide();
- dialog.hide();
-
//Initialize Board
board = new Array(maxIndex);
gameCanvas.score = 0;
@@ -41,6 +37,10 @@ function startNewGame() {
}
}
+ //Close dialogs
+ nameInputDialog.hide();
+ dialog.hide();
+
gameDuration = new Date();
}
@@ -191,6 +191,9 @@ function floodMoveCheck(column, row, type) {
//![2]
function saveHighScore(name) {
+ if (gameCanvas.score == 0)
+ return;
+
if (scoresURL != "")
sendHighScore(name);