1
0
Fork 0
Browse Source

refactor: prepare for scene transitions

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 10 months ago
parent
commit
859f1a261a
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. 19
      src/js/app.js

19
src/js/app.js

@ -75,7 +75,8 @@ function tick () {
window.requestAnimationFrame(tick)
} catch (_) {
console.log('Catched')
location.hash = '#scene-gameover'
// FIXME: clean up using https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
navigateTo('gameover')
}
}
@ -207,3 +208,19 @@ function rotateShape (shape, angle) {
computeNormals(shape)
})
}
/**
* Navigate to another scene.
*
* @param {string} target
*/
function navigateTo (target) {
const state = {}
const title = ''
const url = new URL(window.location.href)
url.hash = `#scene-${target}`
history.pushState(state, title, url.href)
// Required to update CSS
window.location.hash = `#scene-${target}`
}

Loading…
Cancel
Save