fix: initialize the leaderboard only on initial generateGrid or updating the level
This commit is contained in:
parent
82b74dcbe2
commit
964268c311
2 changed files with 13 additions and 19 deletions
|
|
@ -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 VERSION = import.meta.env.MODE === 'development' ? 'dev' : `v${pkg.version}`
|
||||||
const MOBILE_BUSY_DELAY = 250
|
const MOBILE_BUSY_DELAY = 250
|
||||||
const PC_BUSY_DELAY = 500
|
const PC_BUSY_DELAY = 500
|
||||||
const CASUAL_MODE = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Minesweeper game board
|
* Create Minesweeper game board
|
||||||
|
|
@ -88,7 +87,7 @@ export const Minesweeper = function(appId) {
|
||||||
appElement.append(headingElement, gameBoard)
|
appElement.append(headingElement, gameBoard)
|
||||||
appElement.append(initializeSourceLink())
|
appElement.append(initializeSourceLink())
|
||||||
}
|
}
|
||||||
generateGrid()
|
generateGrid(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeSourceLink() {
|
function initializeSourceLink() {
|
||||||
|
|
@ -122,7 +121,7 @@ export const Minesweeper = function(appId) {
|
||||||
|
|
||||||
const resetButton = document.createElement('button')
|
const resetButton = document.createElement('button')
|
||||||
resetButton.innerText = 'Reset'
|
resetButton.innerText = 'Reset'
|
||||||
resetButton.onmousedown = () => location.reload()
|
resetButton.onmousedown = () => generateGrid()
|
||||||
footBar.append(resetButton)
|
footBar.append(resetButton)
|
||||||
|
|
||||||
let levelsDropdown = document.createElement('select')
|
let levelsDropdown = document.createElement('select')
|
||||||
|
|
@ -189,11 +188,11 @@ export const Minesweeper = function(appId) {
|
||||||
function updateSetting(key) {
|
function updateSetting(key) {
|
||||||
setting = levels[key]
|
setting = levels[key]
|
||||||
storageService.saveToLocal('setting', setting)
|
storageService.saveToLocal('setting', setting)
|
||||||
generateGrid()
|
generateGrid(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function generateGrid() {
|
function generateGrid(initial = false) {
|
||||||
firstClick = true
|
firstClick = true
|
||||||
grid.innerHTML = ''
|
grid.innerHTML = ''
|
||||||
grid.oncontextmenu = () => false
|
grid.oncontextmenu = () => false
|
||||||
|
|
@ -226,9 +225,8 @@ export const Minesweeper = function(appId) {
|
||||||
appElement.style.margin = '0 auto'
|
appElement.style.margin = '0 auto'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CASUAL_MODE) {
|
if (initial)
|
||||||
initializeLeaderBoard()
|
initializeLeaderBoard()
|
||||||
}
|
|
||||||
|
|
||||||
timerService.initialize(timerDisplay)
|
timerService.initialize(timerDisplay)
|
||||||
updateFlagsCountDisplay()
|
updateFlagsCountDisplay()
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ export class LeaderBoardService {
|
||||||
timerService = new TimerService()
|
timerService = new TimerService()
|
||||||
loggerService = new LoggerService()
|
loggerService = new LoggerService()
|
||||||
user = new UserService()
|
user = new UserService()
|
||||||
previousLevel
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -55,18 +54,15 @@ export class LeaderBoardService {
|
||||||
async update(level, title) {
|
async update(level, title) {
|
||||||
const displayElement = document.createElement('div')
|
const displayElement = document.createElement('div')
|
||||||
|
|
||||||
if (level !== this.previousLevel) {
|
this.lastPlace = Number.MAX_SAFE_INTEGER
|
||||||
this.previousLevel = level
|
|
||||||
this.lastPlace = Number.MAX_SAFE_INTEGER
|
|
||||||
|
|
||||||
const q = query(
|
const q = query(
|
||||||
collection(this.store, 'mw-leaders', level, 'games'),
|
collection(this.store, 'mw-leaders', level, 'games'),
|
||||||
orderBy('time'),
|
orderBy('time'),
|
||||||
limit(10)
|
limit(10)
|
||||||
)
|
)
|
||||||
this.topListSnapshot = await getDocs(q)
|
this.topListSnapshot = await getDocs(q)
|
||||||
this.renderList(displayElement, title, this.topListSnapshot.docs)
|
this.renderList(displayElement, title, this.topListSnapshot.docs)
|
||||||
}
|
|
||||||
|
|
||||||
return displayElement
|
return displayElement
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue