summaryrefslogtreecommitdiff
path: root/resources/js/main.js
blob: aa864239e979b0cb7e158399051695f8fcc72e63 (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
UI.createEventListener(async function () {
  await initializeDB();

  // Start Game
  const possibleStarterMonsters = ['budaye', 'dollfin', 'grintot', 'ignibus', 'memnomnom'];

  const monsterSelection = UI.openStarterMonsterSelection(
    await Promise.all(possibleStarterMonsters.map(async (monsterSlug) => await fetchMonster(monsterSlug)))
  );
  monsterSelection.addEventListener('starter:monster:selected', UI.createEventListener(async (event) => {
    if (!confirm(`Select ${event.detail.monster.name}?`)) {
      return;
    }

    Memory.state.player = new Trainer({
      monsters: [
        event.detail.monster,
      ],
      inventory: [
        new InventoryItem(await fetchItem('tuxeball'), 5),
        new InventoryItem(await fetchItem('potion')),
      ]
    });
    await Memory.state.player.initialize();

    Game.setActivePlayerMonster(Memory.state.player.monsters[0]);
    Memory.state.activeBall = Memory.state.player.inventory[0]; // tuxeball

    possibleStarterMonsters.splice(possibleStarterMonsters.indexOf(event.detail.monster), 1);
    Memory.state.rivalMonster = possibleStarterMonsters[Math.round(Math.random() * (possibleStarterMonsters.length - 1))];

    await Game.goToArea('paper-town');

    UI.drawActiveMonster();
    UI.drawActiveTechniques();

    event.detail.popup.remove();
  }));
})();