From 72dbc2da9082d5598a8037605bed9fd624cb2b52 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Mon, 25 Jul 2022 21:35:37 -0500 Subject: [PATCH] Implemented utility to unwrap computable resources --- src/features/resources/resource.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/features/resources/resource.ts b/src/features/resources/resource.ts index 5cc9cdd..019a3d7 100644 --- a/src/features/resources/resource.ts +++ b/src/features/resources/resource.ts @@ -3,8 +3,9 @@ import type { State } from "game/persistence"; import { persistent } from "game/persistence"; import type { DecimalSource } from "util/bignum"; import Decimal, { format, formatWhole } from "util/bignum"; +import type { ProcessedComputable } from "util/computed"; import type { ComputedRef, Ref } from "vue"; -import { computed, isRef, ref, watch } from "vue"; +import { computed, isRef, ref, unref, watch } from "vue"; export interface Resource extends Ref { displayName: string; @@ -114,3 +115,10 @@ export function displayResource(resource: Resource, overrideAmount?: DecimalSour } return format(amount, resource.precision, resource.small); } + +export function unwrapResource(resource: ProcessedComputable): Resource { + if ("displayName" in resource) { + return resource; + } + return unref(resource); +}