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) {
|
||||
appElement.innerHTML = ''
|
||||
appElement.append(headingElement, gameBoard)
|
||||
appElement.append(initializeSourceLink())
|
||||
}
|
||||
generateGrid(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
|
||||
generateGrid({ initial: true })
|
||||
}
|
||||
|
||||
function initializeFootbar() {
|
||||
|
|
@ -182,11 +171,17 @@ const Minesweeper = function(appId, version, hooks = undefined) {
|
|||
function updateSetting(key) {
|
||||
setting = levels[key]
|
||||
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
|
||||
grid.innerHTML = ''
|
||||
grid.oncontextmenu = () => false
|
||||
|
|
@ -223,7 +218,7 @@ const Minesweeper = function(appId, version, hooks = undefined) {
|
|||
* TODO: add hook afterGridGenerated
|
||||
* - for initializing the leaderboard
|
||||
*/
|
||||
if (initial)
|
||||
if (options.initial)
|
||||
hooks.levelChanged(setting)
|
||||
|
||||
timerService.initialize(timerDisplay)
|
||||
|
|
|
|||
Loading…
Reference in a new issue