From 8bf68831b7ea7eff97f431dfbc01bb8ea6e81429 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Wed, 15 Feb 2023 15:24:36 -0600 Subject: [PATCH] Add utility function for ETAs --- src/data/common.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/data/common.tsx b/src/data/common.tsx index 638bc7d..801ae63 100644 --- a/src/data/common.tsx +++ b/src/data/common.tsx @@ -13,7 +13,7 @@ import type { Persistent } from "game/persistence"; import { DefaultValue, persistent } from "game/persistence"; import player from "game/player"; import type { DecimalSource } from "util/bignum"; -import Decimal, { format } from "util/bignum"; +import Decimal, { format, formatSmall, formatTime } from "util/bignum"; import type { WithRequired } from "util/common"; import type { Computable, @@ -416,3 +416,28 @@ export function createCollapsibleMilestones(milestones: Record, + target: Computable +) { + const processedRate = convertComputable(rate); + const processedTarget = convertComputable(target); + return computed(() => { + const currRate = unref(processedRate); + const currTarget = unref(processedTarget); + if (Decimal.gte(resource.value, currTarget)) { + return "Now"; + } else if (Decimal.lt(currRate, 0)) { + return "Never"; + } + return formatTime(Decimal.sub(currTarget, resource.value).div(currRate)); + }); +}