diff options
-rw-r--r-- | index.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/index.js b/index.js index 72535a0..0e52b67 100644 --- a/index.js +++ b/index.js @@ -72,6 +72,10 @@ class ATBBar { update(dt) { this.progress = Math.min(1, this.progress + dt / 6) } + + getRemainingSpace() { + return this.segmentCount - this.queuedActions.reduce((acc, { size }) => acc + size, 0) + } } class ActionMenu { @@ -176,10 +180,26 @@ class ActionMenu { this.uiLevel = 1 } } + + queueTo(atbBar) { + const option = this.options[this.currentOptionIndex] + const maxLevel = option.length + const effectiveLevel = Math.min(maxLevel, this.uiLevel) + const remainingSpace = atbBar.getRemainingSpace() + + if (effectiveLevel <= remainingSpace) { + atbBar.queuedActions.push({ + label: option[effectiveLevel - 1], + size: effectiveLevel + }) + } else { + // TODO: Feedback + } + } } const atbBar = new ATBBar() -atbBar.queuedActions = [{label: 'Fire', size: 1}, {label: 'Fira', size: 2}, {label: 'Firaga', size: 3}] +// atbBar.queuedActions = [{label: 'Fire', size: 1}, {label: 'Fira', size: 2}, {label: 'Firaga', size: 3}] const actionMenu = new ActionMenu() @@ -213,6 +233,8 @@ canvas.addEventListener('keypress', evt => { actionMenu.decreaseLevel() } else if (evt.keyCode === 39) { actionMenu.increaseLevel() + } else if (evt.which === 32 || evt.keyCode === 13) { + actionMenu.queueTo(atbBar) } }) |