From ada566b53aa1265c59a2f45556c0e10405c90fcb Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Fri, 11 Mar 2022 15:41:13 -0600 Subject: [PATCH] Added isAnyChallengeActive --- src/features/challenges/challenge.tsx | 38 +++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/features/challenges/challenge.tsx b/src/features/challenges/challenge.tsx index 56c31ea..0f47abf 100644 --- a/src/features/challenges/challenge.tsx +++ b/src/features/challenges/challenge.tsx @@ -1,3 +1,4 @@ +import { isArray } from "@vue/shared"; import Toggle from "components/fields/Toggle.vue"; import ChallengeComponent from "features/challenges/Challenge.vue"; import { @@ -94,12 +95,6 @@ export type GenericChallenge = Replace< } >; -export function createActiveChallenge( - challenges: GenericChallenge[] -): Ref { - return computed(() => challenges.find(challenge => challenge.active.value)); -} - export function createChallenge( optionsFunc: () => T & ThisType> ): Challenge { @@ -149,7 +144,11 @@ export function createChallenge( genericChallenge.active.value = false; genericChallenge.onExit?.(); genericChallenge.reset?.reset(); - } else if (unref(genericChallenge.canStart)) { + } else if ( + unref(genericChallenge.canStart) && + unref(genericChallenge.visibility) === Visibility.Visible && + !genericChallenge.maxed.value + ) { genericChallenge.reset?.reset(); genericChallenge.active.value = true; genericChallenge.onEnter?.(); @@ -188,16 +187,6 @@ export function createChallenge( } return unref(visibility); }); - if (challenge.canStart == null) { - challenge.canStart = computed( - () => - unref((challenge as GenericChallenge).visibility) === Visibility.Visible && - Decimal.lt( - (challenge as GenericChallenge).completions.value, - unref((challenge as GenericChallenge).completionLimit) - ) - ); - } if (challenge.canComplete == null) { challenge.canComplete = computed(() => { const genericChallenge = challenge as GenericChallenge; @@ -285,6 +274,21 @@ export function setupAutoComplete( }); } +export function createActiveChallenge( + challenges: GenericChallenge[] +): Ref { + return computed(() => challenges.find(challenge => challenge.active.value)); +} + +export function isAnyChallengeActive( + challenges: GenericChallenge[] | Ref +): Ref { + if (isArray(challenges)) { + challenges = createActiveChallenge(challenges); + } + return computed(() => (challenges as Ref).value != null); +} + declare module "game/settings" { interface Settings { hideChallenges: boolean;