diff --git a/index.html b/index.html index 455e423..6c1ea6c 100644 --- a/index.html +++ b/index.html @@ -785,6 +785,10 @@ function appendToHUD(txt){ setHUD( textHUD + " " + txt ) } +function getHUD(){ + return document.querySelector("#typinghud").getAttribute("value") +} + function setHUD(txt){ document.querySelector("#typinghud").setAttribute("value",txt) } @@ -1468,6 +1472,42 @@ function toggleVisibilityAllButClass(classname){ toggleVisibilityEntitiesFromClass("hidableassets") } +AFRAME.registerComponent('text-game', { + init: function(){ + // could also add the keyboard component if not already present + this.words = [ + {glb:"../content/textGameAssets/bag.glb",text_en:"bag",text_fr:"sac"}, + {glb:"../content/textGameAssets/cat.glb",text_en:"cat",text_fr:"chat",scale:.01} + ] + let generatorName = this.attrName + this.status_won=false + this.words.map( w => { + addNewNote(w.text_fr) + let el = document.createElement("a-gltf-model"); + el.setAttribute("src", w.glb) + el.setAttribute("position", "" + Math.random()*10/2-2 + " 1 -1"); + el.setAttribute("visible", "false"); + el.id = generatorName+"_"+w.text_en + if (w.scale) + el.setAttribute("scale", " " + w.scale + " " + w.scale + " " + w.scale ); + AFRAME.scenes[0].appendChild(el) + // could add back the element to change visibility later + }) + }, + tick: function () { + let generatorName = this.attrName + // check if typed properly + const text = getHUD() // unecessary, should have add then listen to a new letter typed event instead + this.words.map( w => { + if (w.text_fr == text) { + this.status_won = true + setFeedbackHUD( "you won" ) + document.getElementById( generatorName+"_"+w.text_en ).setAttribute("visible", "true"); + } + }) + } +}) + AFRAME.registerComponent('adjust-height-in-vr', { init: function(){ AFRAME.scenes[0].addEventListener("enter-vr", _ => { @@ -1635,8 +1675,8 @@ function cloneAndDistribute(){
- @@ -1704,13 +1744,7 @@ function cloneAndDistribute(){ --> - - - - - - +