Add "goodness" from upstream

This commit is contained in:
kvan7
2025-03-20 20:12:42 -05:00
parent f3142ee4fe
commit 36f7119cfb
2 changed files with 30 additions and 0 deletions
@@ -225,6 +225,7 @@ export function createExactStatFilters(
) {
enableAllFilters(ctx.filters);
}
if (opts.defaultAllSelected) {
enableAllFilters(ctx.filters);
}
@@ -453,6 +454,18 @@ export function calculatedStatToFilter(
}
}
let goodness: number | undefined;
if (calc.stat.better !== StatBetter.NotComparable) {
if (roll.min === roll.max) {
goodness = 1;
} else {
goodness = (roll.value - roll.min) / (roll.max - roll.min);
if (calc.stat.better === StatBetter.NegativeRoll) {
goodness = 1 - goodness;
}
}
}
const dp =
calc.stat.dp ||
calc.sources.some(
@@ -506,6 +519,7 @@ export function calculatedStatToFilter(
dp,
isNegated: false,
tradeInvert: calc.stat.trade.inverted,
goodness,
};
filterFillMinMax(filter.roll, calc.stat.better);
@@ -765,3 +779,18 @@ function enableAllFilters(filters: StatFilter[]) {
}
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function enableGoodRolledFilters(filters: StatFilter[], abovePct: number) {
for (const filter of filters) {
if (filter.hidden) continue;
if (!filter.roll || filter.roll.goodness == null) {
filter.disabled = false;
continue;
}
if (filter.roll.goodness >= abovePct) {
filter.disabled = false;
}
}
}
@@ -108,6 +108,7 @@ export interface StatFilterRoll {
tradeInvert?: boolean;
dp: boolean;
isNegated: boolean;
goodness?: number;
}
export interface StatFilter {