From 2fc1b2285adf74a98269b085da3c8ab419134cb8 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 12 Aug 2018 17:23:06 -0300 Subject: Save enemy/ally menu cursor positions separately --- index.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index a5068ec..55ece5e 100644 --- a/index.js +++ b/index.js @@ -153,8 +153,7 @@ class ATBBar { } else { this.battleCharacter.isExecutingChain = false if (this.battle.playerCharacter === this.battleCharacter) { - this.battle.changeMenuAnim = {old: null, direction: 1, time: 1} - this.battle.currentMenu = this.battle.actionMenu + this.battle.showActionMenu({direction: 1}) } } } @@ -354,19 +353,17 @@ class BaseBattleMenu { } class ActionMenu extends BaseBattleMenu { - constructor(battle) { - super({options: []}) + constructor(battle, targetType) { + super({ + 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)})) + }) this.battle = battle 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) { const maxLevel = this.getMaxLevel(option) const effectiveLevel = this.getEffectiveLevel(option) @@ -576,8 +573,9 @@ class Battle { this.playerCharacter = this.teams[0].characters[0] - // TODO: Two different ActionMenus - this.actionMenu = new ActionMenu(this) + // TODO: These should probably be stored per-character, so selection is saved when you switch to control a different character + this.targetAllyActionMenu = new ActionMenu(this, 'ally') + this.targetEnemyActionMenu = new ActionMenu(this, 'enemy') this.targetMenu = new TargetMenu(this) this.targetTypeMenu = new BaseBattleMenu({options: [ @@ -726,8 +724,11 @@ class Battle { showActionMenu({direction}) { this.changeMenuAnim = {old: this.currentMenu, direction, time: 1} - this.currentMenu = this.actionMenu - this.actionMenu.buildOptions(this.playerCharacter.targetType) + if (this.playerCharacter.targetType === 'enemy') { + this.currentMenu = this.targetEnemyActionMenu + } else { + this.currentMenu = this.targetAllyActionMenu + } } showTargetMenu() { @@ -744,6 +745,10 @@ class Battle { getAllBattleCharacters() { return this.teams.reduce((acc, team) => acc.concat(team.characters), []) } + + get actionMenu() { + return this.playerCharacter.targetType === 'enemy' ? this.targetEnemyActionMenu : this.targetAllyActionMenu + } } class Team { -- cgit 1.3.0-6-gf8a5