refactor: use options object as param for generateGrid
This commit is contained in:
parent
5a682640c6
commit
1075422a1d
1 changed files with 10 additions and 15 deletions
|
|
@ -95,19 +95,8 @@ const Minesweeper = function(appId, version, hooks = undefined) {
|
||||||
if(appElement) {
|
if(appElement) {
|
||||||
appElement.innerHTML = ''
|
appElement.innerHTML = ''
|
||||||
appElement.append(headingElement, gameBoard)
|
appElement.append(headingElement, gameBoard)
|
||||||
appElement.append(initializeSourceLink())
|
|
||||||
}
|
}
|
||||||
generateGrid(true)
|
generateGrid({ initial: true })
|
||||||
}
|
|
||||||
|
|
||||||
function initializeSourceLink() {
|
|
||||||
const sourceLink = document.createElement('a')
|
|
||||||
sourceLink.href = 'https://github.com/ayoayco/mnswpr'
|
|
||||||
sourceLink.innerText = 'Source code'
|
|
||||||
sourceLink.target = '_blank'
|
|
||||||
sourceLink.style.color = 'white'
|
|
||||||
|
|
||||||
return sourceLink
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeFootbar() {
|
function initializeFootbar() {
|
||||||
|
|
@ -182,11 +171,17 @@ const Minesweeper = function(appId, version, hooks = undefined) {
|
||||||
function updateSetting(key) {
|
function updateSetting(key) {
|
||||||
setting = levels[key]
|
setting = levels[key]
|
||||||
storageService.saveToLocal('setting', setting)
|
storageService.saveToLocal('setting', setting)
|
||||||
generateGrid(true)
|
generateGrid({ initial: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function generateGrid(initial = false) {
|
/**
|
||||||
|
* Generate the Game Board
|
||||||
|
* @param {{
|
||||||
|
* initial: boolean
|
||||||
|
* }} options - Game Board Options
|
||||||
|
*/
|
||||||
|
function generateGrid(options = { initial: false }) {
|
||||||
firstClick = true
|
firstClick = true
|
||||||
grid.innerHTML = ''
|
grid.innerHTML = ''
|
||||||
grid.oncontextmenu = () => false
|
grid.oncontextmenu = () => false
|
||||||
|
|
@ -223,7 +218,7 @@ const Minesweeper = function(appId, version, hooks = undefined) {
|
||||||
* TODO: add hook afterGridGenerated
|
* TODO: add hook afterGridGenerated
|
||||||
* - for initializing the leaderboard
|
* - for initializing the leaderboard
|
||||||
*/
|
*/
|
||||||
if (initial)
|
if (options.initial)
|
||||||
hooks.levelChanged(setting)
|
hooks.levelChanged(setting)
|
||||||
|
|
||||||
timerService.initialize(timerDisplay)
|
timerService.initialize(timerDisplay)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue