« get me outta code hell

Save enemy/ally menu cursor positions separately - csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-12 17:23:06 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-12 17:23:06 -0300
commit2fc1b2285adf74a98269b085da3c8ab419134cb8 (patch)
tree253c94b17de26f41c595dc8b031028a0b72b3db5
parent186be8c409b1272ff5c4f5ef55cebe1427ed971e (diff)
Save enemy/ally menu cursor positions separately
-rw-r--r--index.js33
1 files 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 {