Skip to content

Commit

Permalink
- fix navigating through the games
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasMue91 committed Jun 15, 2024
1 parent 14f09b1 commit eea1c6b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions games/human_benchmark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ <h2 class="text-xl font-semibold mt-2">Button Mashing Test</h2>
window.location.hash = screenName;
$('#landing-tab').addClass('hidden');
$('#game-container').removeClass('hidden');
$('#game-container .test-screen').removeClass('hidden');
return $.getScript(jsFileName);
};

Expand All @@ -342,6 +343,7 @@ <h2 class="text-xl font-semibold mt-2">Button Mashing Test</h2>
return $.get(htmlFileName)
.then(html => {
screenCache[screenName] = { html };
history.pushState({ screenName }, '', `#${screenName}`);
return loadContent();
})
.catch(error => {
Expand All @@ -351,8 +353,8 @@ <h2 class="text-xl font-semibold mt-2">Button Mashing Test</h2>
}

$('.homeButton').click(() => {
$('.test-screen.tab-content:visible').hide();
$('#landing-tab').removeClass('hidden');
$('#game-container .test-screen').addClass('hidden');
});

$('.game-card a').click(function (e) {
Expand All @@ -361,9 +363,24 @@ <h2 class="text-xl font-semibold mt-2">Button Mashing Test</h2>
loadTestScreen(screenName);
});

function handlePopState(event) {
const screenName = event.state ? event.state.screenName : '';
if (screenName) {
loadTestScreen(screenName);
} else {
$('#landing-tab').removeClass('hidden');
$('#game-container .test-screen').addClass('hidden');
}
}

window.addEventListener('popstate', handlePopState);

const initialHash = window.location.hash.substring(1);
if (initialHash) {
loadTestScreen(initialHash);
history.replaceState({ screenName: initialHash }, '', `#${initialHash}`);
handlePopState({ state: { screenName: initialHash } });
} else {
history.replaceState({}, '', '#');
}
});

Expand All @@ -387,9 +404,8 @@ <h2 class="text-xl font-semibold mt-2">Button Mashing Test</h2>
document.getElementById('closeScoresModal').addEventListener('click', () => {
document.getElementById('scoresModal').classList.add('hidden');
});
document.getElementById('showScoresButton').addEventListener('click', showScores);
document.getElementById('resetScoresButton').addEventListener('click', resetScores);

document.getElementById('showScoresButton').addEventListener('click', showScores);

function showScores(e) {
e.preventDefault();
Expand All @@ -413,16 +429,16 @@ <h2 class="text-xl font-semibold mt-2">Button Mashing Test</h2>
<td class="py-2 px-4 border-b border-gray-300">${score}</td>
</tr>
`;
index++;
}

tableHTML += '</tbody></table>';

// Assuming you have a modal with an ID of 'scoresModal' and a content area with an ID of 'scoresContent'
document.getElementById('scoresContent').innerHTML = tableHTML;
// Add logic to open the modal here, e.g.:
document.getElementById('scoresModal').classList.remove('hidden');
}

document.getElementById('resetScoresButton').addEventListener('click', resetScores);

function resetScores() {
if (confirm('Are you sure you want to reset all scores?')) {
Expand Down

0 comments on commit eea1c6b

Please sign in to comment.