Change bonus mixin

This commit is contained in:
thepaperpilot 2024-12-15 19:39:11 -06:00
parent 5718abc013
commit 5bdb5ceed1
3 changed files with 16 additions and 30 deletions

View file

@ -108,7 +108,7 @@ export function createClickable<T extends ClickableOptions>(optionsFunc?: () =>
onHold.call(clickable);
}
}
} satisfies Clickable & { onClick: T["onClick"] };
} satisfies Clickable;
return clickable;
});

15
src/mixins/bonusAmount.ts Normal file
View file

@ -0,0 +1,15 @@
import Decimal, { DecimalSource } from "util/bignum";
import { processGetter } from "util/computed";
import { MaybeRefOrGetter, Ref, computed, unref } from "vue";
/** Allows the addition of "bonus levels" to a feature, with an accompanying "total amount". */
export function bonusAmountMixin(
baseAmount: Ref<DecimalSource>,
bonusAmount: MaybeRefOrGetter<DecimalSource>
) {
const processedBonusAmount = processGetter(bonusAmount);
return {
bonusAmount: processedBonusAmount,
totalAmount: computed(() => Decimal.add(unref(baseAmount), unref(processedBonusAmount)))
};
}

View file

@ -1,29 +0,0 @@
import Decimal, { DecimalSource } from "util/bignum";
import { processGetter } from "util/computed";
import { MaybeRefOrGetter, Ref, computed, unref } from "vue";
/** Allows the addition of "bonus levels" to a feature, with an accompanying "total amount". */
export function bonusAmountMixin(
feature: { amount: Ref<DecimalSource> },
bonusAmount: MaybeRefOrGetter<DecimalSource>
) {
const processedBonusAmount = processGetter(bonusAmount);
return {
bonusAmount,
totalAmount: computed(() => Decimal.add(unref(feature.amount), unref(processedBonusAmount)))
};
}
/** Allows the addition of "bonus completions" to a feature, with an accompanying "total completions". */
export function bonusCompletionsMixin(
feature: { completions: Ref<DecimalSource> },
bonusCompletions: MaybeRefOrGetter<DecimalSource>
) {
const processedBonusCompletions = processGetter(bonusCompletions);
return {
bonusCompletions,
totalCompletions: computed(() =>
Decimal.add(unref(feature.completions), unref(processedBonusCompletions))
)
};
}