« get me outta code hell

csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/index.js b/index.js
index d02dcf6..ce4cf58 100644
--- a/index.js
+++ b/index.js
@@ -116,6 +116,12 @@ class ATBBar {
     // ATB gauge visual update
     this.visualProgress += 8 * dt * (this.progress - this.visualProgress)
 
+    // Start action chain once user has confirmed (willExecuteChain = true) and IP gauge is full enough to execute all actions
+    if (this.battleCharacter.willExecuteChain && this.progress >= 1 - this.getRemainingSpace() / this.segmentCount) {
+      this.battleCharacter.willExecuteChain = false
+      this.battleCharacter.isExecutingChain = true // Will be acknowledged by next if statement
+    }
+
     // Action chaining
     if (this.battleCharacter.isExecutingChain && !this.battleCharacter.isExecutingAction) {
       if (this.queuedActions.length) {
@@ -148,12 +154,16 @@ class ATBBar {
       }
       this.queuedActions.splice(cutoff)
 
-      this.battle.changeMenuAnim = {old: this.battle.currentMenu, direction: 1, time: 1}
-      this.battle.currentMenu = null
+      this.battle.hideCurrentMenu()
       this.battleCharacter.isExecutingChain = true
     }
   }
 
+  activateOnceGaugeFull() {
+    this.battle.hideCurrentMenu()
+    this.battleCharacter.willExecuteChain = true
+  }
+
   getCutoff() {
     // Cutoff point in the action queue where ATB does not fill the action
     let cutoff = 0, segment = 0
@@ -608,6 +618,11 @@ class Battle {
     this.targetMenu.buildOptions()
   }
 
+  hideCurrentMenu() {
+    this.changeMenuAnim = {old: this.currentMenu, direction: 1, time: 1}
+    this.currentMenu = null
+  }
+
   getAllBattleCharacters() {
     return this.teams.reduce((acc, team) => acc.concat(team.characters), [])
   }
@@ -724,7 +739,11 @@ canvas.addEventListener('keypress', evt => {
     } else if (currentMenu === targetMenu) {
       if (evt.keyCode === 13 || evt.key.toLowerCase() === 'e' || evt.which === 32) {
         battle.playerCharacter.targetCharacter = currentMenu.getCurrentOption().battleCharacter
-        atbBar.activate()
+        if (evt.key.toLowerCase() === 'e') {
+          atbBar.activate()
+        } else {
+          atbBar.activateOnceGaugeFull()
+        }
       } else if (evt.keyCode === 8) {
         battle.currentMenu = actionMenu
         battle.changeMenuAnim = {old: targetMenu, direction: -1, time: 1}