diff --git a/src/features/challenges/challenge.tsx b/src/features/challenges/challenge.tsx index 16e97d1..56c31ea 100644 --- a/src/features/challenges/challenge.tsx +++ b/src/features/challenges/challenge.tsx @@ -272,6 +272,19 @@ export function createChallenge( }); } +export function setupAutoComplete( + challenge: GenericChallenge, + autoActive: Computable = 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" { interface Settings { hideChallenges: boolean;