From b6e52ef5c222f511ae6f0c39036ef9f8cd2aa4c1 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Tue, 7 May 2024 11:36:21 +0200 Subject: [PATCH] updated index and proper addGame() function with hidden by default --- index.html | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 81bf9d0..6b4205d 100644 --- a/index.html +++ b/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) {