From 964268c31173e9ac178e50f4edb0a03e72c565dc Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 2 Apr 2026 21:43:15 +0200 Subject: [PATCH] fix: initialize the leaderboard only on initial generateGrid or updating the level --- src/mnswpr.js | 12 +++++------- src/modules/leader-board/leader-board.js | 20 ++++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/mnswpr.js b/src/mnswpr.js index ef7d13e..7e8a48a 100644 --- a/src/mnswpr.js +++ b/src/mnswpr.js @@ -15,7 +15,6 @@ const TEST_MODE = false // set to true if you want to test the game with visual const VERSION = import.meta.env.MODE === 'development' ? 'dev' : `v${pkg.version}` const MOBILE_BUSY_DELAY = 250 const PC_BUSY_DELAY = 500 -const CASUAL_MODE = false /** * Create Minesweeper game board @@ -88,7 +87,7 @@ export const Minesweeper = function(appId) { appElement.append(headingElement, gameBoard) appElement.append(initializeSourceLink()) } - generateGrid() + generateGrid(true) } function initializeSourceLink() { @@ -122,7 +121,7 @@ export const Minesweeper = function(appId) { const resetButton = document.createElement('button') resetButton.innerText = 'Reset' - resetButton.onmousedown = () => location.reload() + resetButton.onmousedown = () => generateGrid() footBar.append(resetButton) let levelsDropdown = document.createElement('select') @@ -189,11 +188,11 @@ export const Minesweeper = function(appId) { function updateSetting(key) { setting = levels[key] storageService.saveToLocal('setting', setting) - generateGrid() + generateGrid(true) } - function generateGrid() { + function generateGrid(initial = false) { firstClick = true grid.innerHTML = '' grid.oncontextmenu = () => false @@ -226,9 +225,8 @@ export const Minesweeper = function(appId) { appElement.style.margin = '0 auto' } - if (!CASUAL_MODE) { + if (initial) initializeLeaderBoard() - } timerService.initialize(timerDisplay) updateFlagsCountDisplay() diff --git a/src/modules/leader-board/leader-board.js b/src/modules/leader-board/leader-board.js index edf9873..cac592e 100644 --- a/src/modules/leader-board/leader-board.js +++ b/src/modules/leader-board/leader-board.js @@ -13,7 +13,6 @@ export class LeaderBoardService { timerService = new TimerService() loggerService = new LoggerService() user = new UserService() - previousLevel /** * @@ -55,18 +54,15 @@ export class LeaderBoardService { async update(level, title) { const displayElement = document.createElement('div') - if (level !== this.previousLevel) { - this.previousLevel = level - this.lastPlace = Number.MAX_SAFE_INTEGER + this.lastPlace = Number.MAX_SAFE_INTEGER - const q = query( - collection(this.store, 'mw-leaders', level, 'games'), - orderBy('time'), - limit(10) - ) - this.topListSnapshot = await getDocs(q) - this.renderList(displayElement, title, this.topListSnapshot.docs) - } + const q = query( + collection(this.store, 'mw-leaders', level, 'games'), + orderBy('time'), + limit(10) + ) + this.topListSnapshot = await getDocs(q) + this.renderList(displayElement, title, this.topListSnapshot.docs) return displayElement }