diff --git a/src/data/common.tsx b/src/data/common.tsx index 3cf53fa..044bb8b 100644 --- a/src/data/common.tsx +++ b/src/data/common.tsx @@ -33,9 +33,10 @@ import type { } from "util/computed"; import { convertComputable, processComputable } from "util/computed"; import { getFirstFeature, render, renderColJSX, renderJSX, VueFeature } from "util/vue"; -import { computed, Ref, unref, watchEffect } from "vue"; +import { computed, ComputedRef, Ref, unref, watchEffect } from "vue"; import "./common.css"; import { main } from "./projEntry"; +import Formula, { GenericFormula } from "game/formulas"; /** An object that configures a {@link ResetButton} */ export interface ResetButtonOptions extends ClickableOptions { @@ -457,6 +458,41 @@ export function estimateTime( }); } +export function createFormulaPreview( + formula: GenericFormula, + showPreview: Computable, + previewAmount: Computable = 1 +): ComputedRef { + const processedShowPreview = convertComputable(showPreview); + const processedPreviewAmount = convertComputable(previewAmount); + if (!formula.hasVariable()) { + throw "Cannot create formula preview if the formula does not have a variable"; + } + return computed(() => { + if (unref(processedShowPreview)) { + const curr = formatSmall(formula.evaluate()); + const preview = formatSmall( + formula.evaluate( + Decimal.add( + unref(formula.innermostVariable ?? 0), + unref(processedPreviewAmount) + ) + ) + ); + return jsx(() => ( + <> + + + {curr}→{preview} + + + + )); + } + return formatSmall(formula.evaluate()); + }); +} + export function setUpDailyProgressTracker(options: { resource: Resource; goal: DecimalSource;