import{ setupLevel, setupLevelUi } from './level.js'; function buildLevel(x, y, t) { const ts = t.slice(0, -1); const tf = t[t.length-1]; return setupLevel(ts.map(T => [ x(T), y(T) ]), [ x(tf), y(tf) ]); } const levels = { 'initial jump': [ [], setupLevel([], [8, 0]) ], 'monopole harvesting': [ ['initial jump'], setupLevel([[3, 3]], [8,8]) ], 'parabolic 0': [ ['initial jump', 'monopole harvesting'], setupLevel([[-2, 4], [0,0], [2, 4]], [3,9]) ], 'sinusoidal': [ ['initial jump', 'monopole harvesting'], buildLevel(t => t-4, t => 4 * Math.sin(t), [...Array(8).keys()].map(x => Math.PI * x / 4)), ], 'parabolic 1': [ ['parabolic 0'], buildLevel(t => -0.5*(t-3)**2 + 4, t => t-3, [...Array(8).keys()].map(x => x - 2)), ], 'orbital': [ ['parabolic 0', 'sinusoidal'], buildLevel(t => 8*Math.cos(t), t => 8*Math.sin(t), [...Array(8).keys()].map(x => Math.PI * x / 4)), ], 'lissajous 0': [ ['orbital'], buildLevel(t => 8*Math.cos(3*t), t => 8*Math.sin(2*t), [...Array(8).keys()].map(x => Math.PI * x / 4)), ], 'lissajous 1': [ ['orbital'], buildLevel(t => 8*Math.sin(4*t), t => 8*Math.cos(3*t), [...Array(16).keys()].map(x => Math.PI * x / 8)), ], }; export function setupLevelSelectUi(root, sfx) { const levelList = document.createElement('ol'); const levelPicker = name => { const [ dependencies, level ] = levels[name]; const allDependenciesSatisfied = dependencies.map(x => levels[x][1].completed).reduce((acc, x) => acc && x, true); if (allDependenciesSatisfied) { sfx.listAppearAudio.currentTime = 0; sfx.listAppearAudio.play(); // if (true) { const button = document.createElement('input'); button.type = 'button'; button.value = name; button.onmouseenter = () => { sfx.buttonEnterAudio.currentTime = 0; sfx.buttonEnterAudio.play(); } button.onclick = () => { sfx.buttonClickAudio.currentTime = 0; sfx.buttonClickAudio.play(); root.innerText = ''; setupLevelUi(level, root, sfx); } const li = document.createElement('li'); li.appendChild(button); if (level.completed) { li.appendChild(document.createTextNode('[complete]')); } levelList.appendChild(li); } } let time = 0; [...Object.keys(levels)].forEach(name => { setTimeout(() => { levelPicker(name); }, 100 * time + 100) time += 1; }); const header = document.createElement('h1'); header.classList.add('center'); header.innerText = 'AVAILABLE CONTRACTS'; root.appendChild(header); const p = document.createElement('p'); p.innerText = 'Please select a General Products AMH hyperspace navigation contract from the list below.'; root.appendChild(p); root.appendChild(levelList); }