Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the percent complete #114

Merged
merged 1 commit into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/browser/WebworkerTableEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ export default class WebworkerTableEngine implements Engineish {
clearInterval(this.inputInterval)
}

private pollInputWatcher() {
const button = this.inputWatcher.pollControls()
if (button) {
this.press(button)
}
}

public press(button: INPUT_BUTTON) {
this.worker.postMessage({ type: MESSAGE_TYPE.PRESS, button })
}
Expand All @@ -123,6 +116,13 @@ export default class WebworkerTableEngine implements Engineish {
this.inputInterval = window.setInterval(this.pollInputWatcher, 10)
}
}

private pollInputWatcher() {
const button = this.inputWatcher.pollControls()
if (button) {
this.press(button)
}
}
private async messageListener({ data }: {data: WorkerResponse}) {
switch (data.type) {
case MESSAGE_TYPE.ON_GAME_CHANGE:
Expand Down
24 changes: 19 additions & 5 deletions src/pwa-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,16 @@ window.addEventListener('load', () => {
gameSelection.removeAttribute('disabled')

saveCurrentLevelNum(currentGameId, newLevelNum)
updateGameSelectionInfo()
updateGameSelectionInfo(false)
},
onGameChange(gameData) {
saveGameInfo(currentGameId, gameData.levels, gameData.title)
}
}

updateGameSelectionInfo() // update the % complete in the dropdown
// update the % complete in the dropdown AND
// Select the first game (not IceCrates all the time)
updateGameSelectionInfo(true)

// startTableEngine
if (!table) { throw new Error(`BUG: Could not find table on the page`) }
Expand Down Expand Up @@ -269,7 +271,7 @@ window.addEventListener('load', () => {
option.setAttribute('data-original-index', `${index}`)
})

function updateGameSelectionInfo() {
function updateGameSelectionInfo(selectFirstGame: boolean) {
const storage = loadStorage()

// Update the last-updated time for all of the games and then sort them
Expand All @@ -281,7 +283,7 @@ window.addEventListener('load', () => {
}
const gameInfo = storage[gameId]
if (gameInfo) {
const completedMapLevels = gameInfo.levelMaps.slice(0, gameInfo.currentLevelNum - 1).filter((b) => b).length
const completedMapLevels = gameInfo.levelMaps.slice(0, gameInfo.currentLevelNum).filter((b) => b).length
const totalMapLevels = gameInfo.levelMaps.filter((b) => b).length
const percent = Math.floor(100 * completedMapLevels / totalMapLevels)
option.setAttribute('data-percent-complete', `${percent}`)
Expand Down Expand Up @@ -350,8 +352,20 @@ window.addEventListener('load', () => {
if (completedOptions.length > 0) {
completedOptions.unshift(createSeparator('Completed'))
}
gameSelection.append(...continuePlayingOptions, ...newGameOptions, ...uncompletedOptions, ...completedOptions)
const allOptions = [...continuePlayingOptions, ...newGameOptions, ...uncompletedOptions, ...completedOptions]
gameSelection.append(...allOptions)

gameSelection.value = selectedGameId

// Select the 1st game so we can select it if this is the initial load
if (selectFirstGame) {
const firstOption = allOptions.find((option) => option.hasAttribute('value'))
if (firstOption) {
gameSelection.selectedIndex = allOptions.indexOf(firstOption)
const gameId = firstOption.getAttribute('value')
if (gameId) gameSelection.value = gameId
}
}
}

function createSeparator(textContent: string) {
Expand Down