Added setupAutoComplete

This commit is contained in:
thepaperpilot 2022-03-11 12:48:53 -06:00
parent 14b1420b55
commit b33de01a96

View file

@ -272,6 +272,19 @@ export function createChallenge<T extends ChallengeOptions>(
}); });
} }
export function setupAutoComplete(
challenge: GenericChallenge,
autoActive: Computable<boolean> = true,
exitOnComplete = true
): WatchStopHandle {
const isActive = typeof autoActive === "function" ? computed(autoActive) : autoActive;
return watch([challenge.canComplete, isActive], ([canComplete, isActive]) => {
if (canComplete && isActive) {
challenge.complete(!exitOnComplete);
}
});
}
declare module "game/settings" { declare module "game/settings" {
interface Settings { interface Settings {
hideChallenges: boolean; hideChallenges: boolean;