forked from profectus/Profectus
Added isAnyChallengeActive
This commit is contained in:
parent
e56f34c13c
commit
ada566b53a
1 changed files with 21 additions and 17 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { isArray } from "@vue/shared";
|
||||||
import Toggle from "components/fields/Toggle.vue";
|
import Toggle from "components/fields/Toggle.vue";
|
||||||
import ChallengeComponent from "features/challenges/Challenge.vue";
|
import ChallengeComponent from "features/challenges/Challenge.vue";
|
||||||
import {
|
import {
|
||||||
|
@ -94,12 +95,6 @@ export type GenericChallenge = Replace<
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export function createActiveChallenge(
|
|
||||||
challenges: GenericChallenge[]
|
|
||||||
): Ref<GenericChallenge | undefined> {
|
|
||||||
return computed(() => challenges.find(challenge => challenge.active.value));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createChallenge<T extends ChallengeOptions>(
|
export function createChallenge<T extends ChallengeOptions>(
|
||||||
optionsFunc: () => T & ThisType<Challenge<T>>
|
optionsFunc: () => T & ThisType<Challenge<T>>
|
||||||
): Challenge<T> {
|
): Challenge<T> {
|
||||||
|
@ -149,7 +144,11 @@ export function createChallenge<T extends ChallengeOptions>(
|
||||||
genericChallenge.active.value = false;
|
genericChallenge.active.value = false;
|
||||||
genericChallenge.onExit?.();
|
genericChallenge.onExit?.();
|
||||||
genericChallenge.reset?.reset();
|
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.reset?.reset();
|
||||||
genericChallenge.active.value = true;
|
genericChallenge.active.value = true;
|
||||||
genericChallenge.onEnter?.();
|
genericChallenge.onEnter?.();
|
||||||
|
@ -188,16 +187,6 @@ export function createChallenge<T extends ChallengeOptions>(
|
||||||
}
|
}
|
||||||
return unref(visibility);
|
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) {
|
if (challenge.canComplete == null) {
|
||||||
challenge.canComplete = computed(() => {
|
challenge.canComplete = computed(() => {
|
||||||
const genericChallenge = challenge as GenericChallenge;
|
const genericChallenge = challenge as GenericChallenge;
|
||||||
|
@ -285,6 +274,21 @@ export function setupAutoComplete(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createActiveChallenge(
|
||||||
|
challenges: GenericChallenge[]
|
||||||
|
): Ref<GenericChallenge | undefined> {
|
||||||
|
return computed(() => challenges.find(challenge => challenge.active.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAnyChallengeActive(
|
||||||
|
challenges: GenericChallenge[] | Ref<GenericChallenge | undefined>
|
||||||
|
): Ref<boolean> {
|
||||||
|
if (isArray(challenges)) {
|
||||||
|
challenges = createActiveChallenge(challenges);
|
||||||
|
}
|
||||||
|
return computed(() => (challenges as Ref<GenericChallenge | undefined>).value != null);
|
||||||
|
}
|
||||||
|
|
||||||
declare module "game/settings" {
|
declare module "game/settings" {
|
||||||
interface Settings {
|
interface Settings {
|
||||||
hideChallenges: boolean;
|
hideChallenges: boolean;
|
||||||
|
|
Loading…
Reference in a new issue