From b33de01a96616622d7e3f246b25297ccbe7b0c32 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Fri, 11 Mar 2022 12:48:53 -0600 Subject: [PATCH] Added setupAutoComplete --- src/features/challenges/challenge.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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;