diff options
Diffstat (limited to 'resources/js/main.js')
-rw-r--r-- | resources/js/main.js | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/resources/js/main.js b/resources/js/main.js index 24eafec..6ea94e2 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -4,24 +4,36 @@ // Start Game const possibleStarterMonsters = ['budaye', 'dollfin', 'grintot', 'ignibus', 'memnomnom']; - Memory.state.player = new Trainer({ - monsters: [ - await fetchMonster(possibleStarterMonsters[Math.round(Math.random() * (possibleStarterMonsters.length - 1))]), - ], - inventory: [ - new InventoryItem(await fetchItem('tuxeball'), 5), - new InventoryItem(await fetchItem('potion')), - ] - }); - await Memory.state.player.initialize(); + const monsterSelection = UI.openStarterMonsterSelection( + await Promise.all(possibleStarterMonsters.map(async (monsterSlug) => await fetchMonster(monsterSlug))) + ); + monsterSelection.addEventListener('starter:monster:selected', 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 + Game.setActivePlayerMonster(Memory.state.player.monsters[0]); + Memory.state.activeBall = Memory.state.player.inventory[0]; // tuxeball - Memory.state.rivalMonster = possibleStarterMonsters[Math.round(Math.random() * (possibleStarterMonsters.length - 1))]; + possibleStarterMonsters.splice(possibleStarterMonsters.indexOf(event.detail.monster), 1); + Memory.state.rivalMonster = possibleStarterMonsters[Math.round(Math.random() * (possibleStarterMonsters.length - 1))]; - await Game.goToArea('paper-town'); + await Game.goToArea('paper-town'); - UI.drawActiveMonster(); - UI.drawActiveTechniques(); + UI.drawActiveMonster(); + UI.drawActiveTechniques(); + + event.detail.popup.remove(); + }); })(); |