import { setupLevelSelectUi } from './levelSelect.js'; import { setupLevel, setupLevelUi } from './level.js'; window.onload = () => { const root = document.getElementById('root'); root.classList.add('center'); const title = document.createElement('h1'); title.innerText = 'GENERAL PRODUCTS'; root.appendChild(title); const logo = document.createElement('h1'); logo.classList.add('logo'); logo.innerText = '※'; root.appendChild(logo); const title2 = document.createElement('h2'); title2.innerText = 'AUTOMATED MONOPOLE HARVESTER (AMH) HYPERSPACE NAVIGATIONAL SERVICES'; root.appendChild(title2); const paragraph = document.createElement('p'); paragraph.innerText = 'Greetings, navigator! Thank you for helping us to program the hyperspace engines of our Automated Monopole Harvester (AMH) platforms. By doing so, you help ensure stable antimatter production throughout the Nine Worlds.'; root.appendChild(paragraph); const start = document.createElement('input'); start.type = 'button'; start.value = 'Connect to AMH'; start.onclick = () => { root.classList.remove('center'); root.innerText = ''; const audio = new AudioContext(); const musicGain = audio.createGain(); const addMusic = (music, id) => { const element = document.getElementById(id); const source = audio.createMediaElementSource(element); source.connect(musicGain).connect(audio.destination); return [ ...music, { element, source } ]; } musicGain.gain.value = 0.5; const musicList = [ 'music-minute', 'music-starboard', 'music-cribwhistling', 'music-swish', 'music-aeroplane', ].reduce(addMusic, []); musicList.forEach( ({ element }, i) => element.addEventListener( 'ended', () => musicList[(i+1) % musicList.length].element.play(), ) ) musicList[0].element.play(); const sfx = {}; sfx.buttonEnterAudio = document.getElementById('sfx-buttonenter'); sfx.buttonClickAudio = document.getElementById('sfx-buttonclick'); audio.createMediaElementSource(sfx.buttonEnterAudio).connect(audio.destination); audio.createMediaElementSource(sfx.buttonClickAudio).connect(audio.destination); sfx.resourceAudio = document.getElementById('sfx-resource'); sfx.resourceSource = audio.createMediaElementSource(sfx.resourceAudio); sfx.resourceSource.connect(audio.destination); sfx.doneAudio = document.getElementById('sfx-done'); sfx.doneSource = audio.createMediaElementSource(sfx.doneAudio); sfx.doneSource.connect(audio.destination); sfx.wrongAudio = document.getElementById('sfx-wrong'); sfx.wrongSource = audio.createMediaElementSource(sfx.wrongAudio); sfx.wrongSource.connect(audio.destination); // const level = setupLevel([[2, 2], [3,3]], [7, 7]); // const ui = setupLevelUi(level, root, audio); setupLevelSelectUi(root, sfx); }; root.appendChild(start); }