From a262d6fd0333bb74a126570ed7f05da856025465 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Tue, 18 Apr 2023 20:55:40 -0500 Subject: [PATCH] Make formulas unwrap persistent refs automatically --- src/game/formulas/formulas.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/game/formulas/formulas.ts b/src/game/formulas/formulas.ts index 3b897dd..9f6ad5a 100644 --- a/src/game/formulas/formulas.ts +++ b/src/game/formulas/formulas.ts @@ -1,7 +1,8 @@ import { Resource } from "features/resources/resource"; +import { NonPersistent } from "game/persistence"; import Decimal, { DecimalSource, format } from "util/bignum"; -import { Computable, convertComputable, ProcessedComputable } from "util/computed"; -import { computed, ComputedRef, ref, unref } from "vue"; +import { Computable, ProcessedComputable, convertComputable } from "util/computed"; +import { ComputedRef, Ref, computed, ref, unref } from "vue"; import * as ops from "./operations"; import type { EvaluateFunction, @@ -58,7 +59,15 @@ export default class Formula { constructor(options: FormulaOptions) { let readonlyProperties; + if ("inputs" in options) { + options.inputs = options.inputs.map(input => + typeof input === "object" && NonPersistent in input ? input[NonPersistent] : input + ) as T | [FormulaSource]; + } if ("variable" in options) { + if (typeof options.variable === "object" && NonPersistent in options.variable) { + options.variable = options.variable[NonPersistent] as Ref; + } readonlyProperties = this.setupVariable(options); } else if (!("evaluate" in options)) { readonlyProperties = this.setupConstant(options);