« get me outta code hell

Wrap action menu options - 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-09 18:59:47 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-09 18:59:47 -0300
commitbce822d92c4b0ea7f49f7e18a858e16e85d79b2c (patch)
tree9d9654d058d3bb5ad5f6376e81eb10c9de04ca8c /index.js
parent1aa951fc2b4970674510a18c2e0f1e92378dc446 (diff)
Wrap action menu options
Diffstat (limited to 'index.js')
-rw-r--r--index.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/index.js b/index.js
index 8703cf9..ca401a5 100644
--- a/index.js
+++ b/index.js
@@ -106,14 +106,17 @@ class ActionMenu {
     const ctx = this.canvas.getContext('2d')
     ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
 
-    const startIndex = Math.max(0, this.currentOptionIndex - 1)
-    const endIndex = Math.min(this.options.length, startIndex + 3)
+    const startIndex = this.currentOptionIndex - 1
+    const endIndex = startIndex + 3
+
+    const len = this.options.length
 
     let y = 1
     for (let i = startIndex; i < endIndex; i++) {
-      const maxLevel = this.options[i].length
+      const option = this.options[i === -1 ? len - 1 : i === len ? 0 : i]
+      const maxLevel = option.length
       const effectiveLevel = Math.min(maxLevel, this.uiLevel)
-      const text = this.options[i][effectiveLevel - 1]
+      const text = option[effectiveLevel - 1]
       const rectW = this.getRectW(effectiveLevel)
       if (effectiveLevel < maxLevel) {
         const ghostRectW = this.getRectW(maxLevel)