From e4bf4f63afe0a7cfba84c60c7f0ad1ee9b1a5b96 Mon Sep 17 00:00:00 2001 From: Braeden Date: Sun, 27 Oct 2024 18:22:34 -0400 Subject: [PATCH] feat: chal.canEnter(), chal.canExit() --- js/game.js | 17 +++++++++++------ js/utils/easyAccess.js | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/js/game.js b/js/game.js index dc90a68..ffca117 100644 --- a/js/game.js +++ b/js/game.js @@ -246,14 +246,19 @@ function resetRow(row) { function startChallenge(layer, x) { let enter = false - if (!player[layer].unlocked || !tmp[layer].challenges[x].unlocked) return + if (!player[layer].unlocked || !tmp[layer].challenges[x].unlocked || !canEnterChallenge(layer, x)) return + if (player[layer].activeChallenge == x) { - completeChallenge(layer, x) - Vue.set(player[layer], "activeChallenge", null) - } else { + // This needs to be embedded due to how 'enter' works + if(canExitChallenge(layer, x)){ + completeChallenge(layer, x) + Vue.set(player[layer], "activeChallenge", null) + } + } + else { enter = true - } - doReset(layer, true) + } + if(enter || canExitChallenge(layer, x)) doReset(layer, true) if(enter) { Vue.set(player[layer], "activeChallenge", x) run(layers[layer].challenges[x].onEnter, layers[layer].challenges[x]) diff --git a/js/utils/easyAccess.js b/js/utils/easyAccess.js index b6c4afc..712d7d8 100644 --- a/js/utils/easyAccess.js +++ b/js/utils/easyAccess.js @@ -22,6 +22,14 @@ function challengeCompletions(layer, id) { return (player[layer].challenges[id]) } +function canEnterChallenge(layer, id){ + return tmp[layer].challenges[id].canEnter ?? true +} + +function canExitChallenge(layer, id){ + return tmp[layer].challenges[id].canExit ?? true +} + function getBuyableAmount(layer, id) { return (player[layer].buyables[id]) }