mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-22 00:21:34 +00:00
Add utility function for showing previews of how formulas will change
This commit is contained in:
parent
adb35191ea
commit
be5c3435c6
1 changed files with 37 additions and 1 deletions
|
@ -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<boolean>,
|
||||
previewAmount: Computable<DecimalSource> = 1
|
||||
): ComputedRef<CoercableComponent> {
|
||||
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(() => (
|
||||
<>
|
||||
<b>
|
||||
<i>
|
||||
{curr}→{preview}
|
||||
</i>
|
||||
</b>
|
||||
</>
|
||||
));
|
||||
}
|
||||
return formatSmall(formula.evaluate());
|
||||
});
|
||||
}
|
||||
|
||||
export function setUpDailyProgressTracker(options: {
|
||||
resource: Resource;
|
||||
goal: DecimalSource;
|
||||
|
|
Loading…
Reference in a new issue