« get me outta code hell

Don't make <=3-item menus render like spinners - 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:
authorFlorrie <towerofnix@gmail.com>2018-08-12 16:50:20 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-12 16:50:20 -0300
commit183a354ce48774d24a1c52cd9cdafa030685325c (patch)
tree0d09fedb22360e8a2f573ff2ab62eb2441c1a7dd /index.js
parente661bd800c193a81faa1f88b5acb4197fada253c (diff)
Don't make <=3-item menus render like spinners
Diffstat (limited to 'index.js')
-rw-r--r--index.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/index.js b/index.js
index 6e339d3..f493585 100644
--- a/index.js
+++ b/index.js
@@ -293,15 +293,20 @@ class BaseBattleMenu {
       return
     }
 
-    const startIndex = this.currentOptionIndex - 1
-    const endIndex = startIndex + 3
-
-    const len = this.options.length
-
     this.drawY = 1
-    for (let i = startIndex; i < endIndex; i++) {
-      const option = this.options[i === -1 ? len - 1 : i === len ? 0 : i]
-      this.drawOption(option, ctx)
+
+    if (this.options.length > 3) {
+      const startIndex = this.currentOptionIndex - 1
+      const endIndex = startIndex + 3
+      const len = this.options.length
+      for (let i = startIndex; i < endIndex; i++) {
+        const option = this.options[i === -1 ? len - 1 : i === len ? 0 : i]
+        this.drawOption(option, ctx)
+      }
+    } else {
+      for (const option of this.options) {
+        this.drawOption(option, ctx)
+      }
     }
   }
 
@@ -867,6 +872,10 @@ function drawLoop() {
 }
 
 canvas.addEventListener('keypress', evt => {
+  if (battle.gameState !== 'battle') {
+    return
+  }
+
   const { targetTypeMenu, actionMenu, targetMenu, currentMenu } = battle
   const { atbBar } = battle.playerCharacter
   if (!battle.playerCharacter.isExecutingChain && battle.currentMenu) {