updated index and proper addGame() function with hidden by default

game-multiple-levels
Fabien Benetou 2 weeks ago
parent 5544b53244
commit b6e52ef5c2
  1. 28
      index.html

@ -48,18 +48,12 @@ Oh non, les lettres de ton prenom ont ete melangees. Pince chacune avec ta main
AFRAME.registerComponent('startfunctions', {
init: function(){
addGames()
// example of adding a game programmatically
let newEl = document.createElement('a-entity')
//let gamename = "checkers"
//let gamename = "carcassone"
//let gamename = "simon"
let gamename = "voxelpaint"
newEl.id = gamename
newEl.setAttribute(gamename, "")
newEl.classList.add( "game" )
AFRAME.scenes[0].appendChild(newEl)
let untestedGames = ["checkers", "carcassone"]
addGame("voxelpaint")
addGame("simon")
addGames()
}
})
@ -78,6 +72,15 @@ game manager component
*/
function addGame(gamename, visible="false"){
let newEl = document.createElement('a-entity')
newEl.id = gamename
newEl.setAttribute(gamename, "")
newEl.setAttribute("visible", visible)
newEl.classList.add( "game" )
AFRAME.scenes[0].appendChild(newEl)
}
function addGames(){
const imgPath = "../content/games/previews/"
const imgExtension = ".jpg"
@ -102,6 +105,7 @@ function addGames(){
}
function showOnlyThisGame(name){
// should also work via URL, e.g hash or query parameter
Array.from( document.querySelectorAll('.game') ).map( (g,i) => g.setAttribute("visible", "false") )
document.getElementById(name).setAttribute("visible", "true")
document.querySelector("["+name+"]").emit("reset")
@ -217,7 +221,7 @@ AFRAME.registerComponent('simon', {
el.appendChild(newEl)
if (i==1) j++
})
setTimeout( _ => { document.querySelector("["+generatorName+"]").emit('playSequence') }, 1000)
//setTimeout( _ => { document.querySelector("["+generatorName+"]").emit('playSequence') }, 1000)
},
events: {
reset: function (evt) {

Loading…
Cancel
Save