« 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
diff options
context:
space:
mode:
-rw-r--r--index.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/index.js b/index.js
index c7327d6..00b35b8 100644
--- a/index.js
+++ b/index.js
@@ -336,6 +336,8 @@ class BaseBattleMenu {
       return
     }
 
+    this.keepCurrentIndexInBounds()
+
     this.drawY = 1
 
     if (this.options.length > 3) {
@@ -375,7 +377,12 @@ class BaseBattleMenu {
     return this.canvas.width - 2
   }
 
+  keepCurrentIndexInBounds() {
+    this.currentOptionIndex = Math.min(this.options.length - 1, this.currentOptionIndex)
+  }
+
   getCurrentOption() {
+    this.keepCurrentIndexInBounds()
     return this.options[this.currentOptionIndex]
   }