summaryrefslogtreecommitdiff
path: root/levelSelect.js
blob: 2fe3d52efad3ebe0c22fad51e9a9335d9e2f4c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import{ setupLevel, setupLevelUi } from './level.js';

const levels = {
  'initial jump': [ [], setupLevel([], [8, 0]) ],
  'monopole harvesting': [ ['initial jump'], setupLevel([[3, 3]], [8,8]) ],
  'parabolic': [ ['initial jump', 'monopole harvesting'], setupLevel([[-2, 4], [0,0], [2, 4]], [3,9]) ],
  'sinusoidal': [ 
    ['initial jump', 'monopole harvesting'], 
    setupLevel([ 
      [-4, 4*Math.sin(0)], 
      [0.5*Math.PI - 4, 4*Math.sin(0.5*Math.PI)], 
      [1.0*Math.PI - 4, 4*Math.sin(1.0*Math.PI)], 
      [1.5*Math.PI - 4, 4*Math.sin(1.5*Math.PI)], 
    ], [2.0*Math.PI - 4, 4*Math.sin(2.0*Math.PI)]),
  ],
};

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) {
    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(() => {
      sfx.listAppearAudio.currentTime = 0;
      sfx.listAppearAudio.play();
      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);
}