forked from gabboraron/JS13K2024_Witch-hunter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
minicharacterselection.js
1 lines (1 loc) · 1.08 KB
/
minicharacterselection.js
1
AFRAME.registerComponent("main-character-chooser",{init:function(){this.chooseCharacter=this.chooseCharacter.bind(this),this.el.addEventListener("click",this.chooseCharacter)},chooseCharacter:function(e){const t=this.el.getAttribute("data-character");localStorage.setItem("chosenCharacter",t);const a=dq("#mainCharacters");a.parentNode.removeChild(a);dq("#cat").setAttribute("visible","true"),this.showCharacterInfo(t)},showCharacterInfo:function(e){const t=dq("#infoPanel");t.setAttribute("visible","true"),t.setAttribute("scale","1 1 1"),dq("#characterName").setAttribute("text","value",e),document.querySelectorAll('[id$="CharacterImage"]').forEach((e=>e.setAttribute("visible","false")));const a=dq(`#${e.replace(" ","")}CharacterImage`);a&&a.setAttribute("visible","true")}}),window.addEventListener("load",(()=>{const e=localStorage.getItem("chosenCharacter");if(e){const t=document.querySelectorAll("[main-character-chooser]");t.length>0&&dq("a-scene").addEventListener("loaded",(function(){const a=t[0].components["main-character-chooser"];a&&a.chooseCharacter({detail:{characterName:e}})}))}}));