diff options
author | Florrie <towerofnix@gmail.com> | 2018-08-12 16:46:56 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-08-12 16:46:56 -0300 |
commit | e661bd800c193a81faa1f88b5acb4197fada253c (patch) | |
tree | 4e5d49da965bc2e840ee757160cff4c084b8c5a1 /index.js | |
parent | 87b37dc9d6dfc9fe48d8226657d11e36e2a66b99 (diff) |
Target type menu
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/index.js b/index.js index 8bf7ee5..6e339d3 100644 --- a/index.js +++ b/index.js @@ -350,12 +350,16 @@ class BaseBattleMenu { class ActionMenu extends BaseBattleMenu { constructor(battle) { - super({options: Object.values(actionDatabase) - .map(chain => ({chain, levelTexts: chain.map(action => action.label)})) - }) + super({options: []}) this.battle = battle - this.uiLevel = 3 // 1-3 -- which of "fire", "fira", "firaga" is selected. + this.uiLevel = 2 // 1-3 -- which of "fire", "fira", "firaga" is selected. + } + + buildOptions(targetType) { + this.options = Object.values(actionDatabase) + .filter(chain => chain[0].target === targetType) // Assume all actions have the same target type + .map(chain => ({chain, levelTexts: chain.map(action => action.label)})) } drawOption(option, ctx) { @@ -426,8 +430,8 @@ class TargetMenu extends BaseBattleMenu { this.battle = battle } - buildOptions(action) { - this.options = this.battle.playerCharacter.getValidTargets(action) + buildOptions(targetType) { + this.options = this.battle.playerCharacter.getValidTargets(targetType) .map(char => ({label: char.name, battleCharacter: char})) } } @@ -569,6 +573,11 @@ class Battle { this.actionMenu = new ActionMenu(this) this.targetMenu = new TargetMenu(this) + this.targetTypeMenu = new BaseBattleMenu({options: [ + {label: 'Aggression', targetType: 'enemy'}, + {label: 'Reinforcement', targetType: 'ally'} + ]}) + this.backdrop = new Backdrop() this.camera = new Camera() @@ -582,7 +591,7 @@ class Battle { this.gameState = 'battle' // battle, pre-win, win - this.currentMenu = this.actionMenu + this.currentMenu = this.targetTypeMenu this.changeMenuAnim = {time: 1, direction: 1, old: null} this.preWinAnim = null } @@ -708,10 +717,16 @@ class Battle { } } + showActionMenu({direction}) { + this.changeMenuAnim = {old: this.currentMenu, direction, time: 1} + this.currentMenu = this.actionMenu + this.actionMenu.buildOptions(this.playerCharacter.targetType) + } + showTargetMenu() { this.changeMenuAnim = {old: this.currentMenu, direction: 1, time: 1} this.currentMenu = this.targetMenu - this.targetMenu.buildOptions(last(this.playerCharacter.atbBar.queuedActions).target) // TODO: Target type stored on the player + this.targetMenu.buildOptions(this.playerCharacter.targetType) } hideCurrentMenu() { @@ -852,13 +867,18 @@ function drawLoop() { } canvas.addEventListener('keypress', evt => { - const { actionMenu, targetMenu, currentMenu } = battle + const { targetTypeMenu, actionMenu, targetMenu, currentMenu } = battle const { atbBar } = battle.playerCharacter if (!battle.playerCharacter.isExecutingChain && battle.currentMenu) { if (evt.keyCode === 38) { currentMenu.upOption() } else if (evt.keyCode === 40) { currentMenu.downOption() + } else if (currentMenu === targetTypeMenu) { + if (evt.keyCode === 13 || evt.which === 32) { + battle.playerCharacter.targetType = targetTypeMenu.getCurrentOption().targetType + battle.showActionMenu({direction: 1}) + } } else if (currentMenu === actionMenu) { if (evt.keyCode === 37) { currentMenu.decreaseLevel() @@ -867,7 +887,12 @@ canvas.addEventListener('keypress', evt => { } else if (evt.which === 32) { currentMenu.queueTo(atbBar) } else if (evt.keyCode === 8) { - atbBar.dequeue() + if (atbBar.queuedActions.length) { + atbBar.dequeue() + } else { + battle.currentMenu = targetTypeMenu + battle.changeMenuAnim = {old: actionMenu, direction: -1, time: 1} + } } else if (evt.keyCode === 13 || evt.key.toLowerCase() === 'e') { if (battle.playerCharacter.atbBar.queuedActions.length) { battle.showTargetMenu() |