Implemented utility to unwrap computable resources

This commit is contained in:
thepaperpilot 2022-07-25 21:35:37 -05:00
parent 351d4873be
commit 72dbc2da90

View file

@ -3,8 +3,9 @@ import type { State } from "game/persistence";
import { persistent } from "game/persistence"; import { persistent } from "game/persistence";
import type { DecimalSource } from "util/bignum"; import type { DecimalSource } from "util/bignum";
import Decimal, { format, formatWhole } from "util/bignum"; import Decimal, { format, formatWhole } from "util/bignum";
import type { ProcessedComputable } from "util/computed";
import type { ComputedRef, Ref } from "vue"; import type { ComputedRef, Ref } from "vue";
import { computed, isRef, ref, watch } from "vue"; import { computed, isRef, ref, unref, watch } from "vue";
export interface Resource<T = DecimalSource> extends Ref<T> { export interface Resource<T = DecimalSource> extends Ref<T> {
displayName: string; displayName: string;
@ -114,3 +115,10 @@ export function displayResource(resource: Resource, overrideAmount?: DecimalSour
} }
return format(amount, resource.precision, resource.small); return format(amount, resource.precision, resource.small);
} }
export function unwrapResource(resource: ProcessedComputable<Resource>): Resource {
if ("displayName" in resource) {
return resource;
}
return unref(resource);
}