Implemented utility to unwrap computable resources
This commit is contained in:
parent
351d4873be
commit
72dbc2da90
1 changed files with 9 additions and 1 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue