Added option to exponential modifiers to support low numbers
This commit is contained in:
parent
1729fa8561
commit
21eb5409b4
1 changed files with 26 additions and 3 deletions
|
@ -148,6 +148,8 @@ export interface ExponentialModifierOptions {
|
||||||
description?: Computable<CoercableComponent> | undefined;
|
description?: Computable<CoercableComponent> | undefined;
|
||||||
/** A computable that will be processed and passed directly into the returned modifier. */
|
/** A computable that will be processed and passed directly into the returned modifier. */
|
||||||
enabled?: Computable<boolean> | undefined;
|
enabled?: Computable<boolean> | undefined;
|
||||||
|
/** Add 1 before calculating, then remove it afterwards. This prevents low numbers from becoming lower. */
|
||||||
|
supportLowNumbers?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,14 +160,34 @@ export function createExponentialModifier<T extends ExponentialModifierOptions>(
|
||||||
optionsFunc: () => T
|
optionsFunc: () => T
|
||||||
): ModifierFromOptionalParams<T["description"], T["enabled"]> {
|
): ModifierFromOptionalParams<T["description"], T["enabled"]> {
|
||||||
return createLazyProxy(() => {
|
return createLazyProxy(() => {
|
||||||
const { exponent, description, enabled } = optionsFunc();
|
const { exponent, description, enabled, supportLowNumbers } = optionsFunc();
|
||||||
|
|
||||||
const processedExponent = convertComputable(exponent);
|
const processedExponent = convertComputable(exponent);
|
||||||
const processedDescription = convertComputable(description);
|
const processedDescription = convertComputable(description);
|
||||||
const processedEnabled = enabled == null ? undefined : convertComputable(enabled);
|
const processedEnabled = enabled == null ? undefined : convertComputable(enabled);
|
||||||
return {
|
return {
|
||||||
apply: (gain: DecimalSource) => Decimal.pow(gain, unref(processedExponent)),
|
apply: (gain: DecimalSource) => {
|
||||||
revert: (gain: DecimalSource) => Decimal.root(gain, unref(processedExponent)),
|
let result = gain;
|
||||||
|
if (supportLowNumbers) {
|
||||||
|
result = Decimal.add(result, 1);
|
||||||
|
}
|
||||||
|
result = Decimal.pow(result, unref(processedExponent));
|
||||||
|
if (supportLowNumbers) {
|
||||||
|
result = Decimal.sub(result, 1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
revert: (gain: DecimalSource) => {
|
||||||
|
let result = gain;
|
||||||
|
if (supportLowNumbers) {
|
||||||
|
result = Decimal.add(result, 1);
|
||||||
|
}
|
||||||
|
result = Decimal.root(result, unref(processedExponent));
|
||||||
|
if (supportLowNumbers) {
|
||||||
|
result = Decimal.sub(result, 1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
enabled: processedEnabled,
|
enabled: processedEnabled,
|
||||||
description:
|
description:
|
||||||
description == null
|
description == null
|
||||||
|
@ -179,6 +201,7 @@ export function createExponentialModifier<T extends ExponentialModifierOptions>(
|
||||||
<span class="modifier-description">
|
<span class="modifier-description">
|
||||||
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */}
|
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */}
|
||||||
{renderJSX(unref(processedDescription)!)}
|
{renderJSX(unref(processedDescription)!)}
|
||||||
|
{supportLowNumbers ? " (+1 effective)" : null}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue