Fix smallerIsBetter handling in createCollapsibleModifierSections

This commit is contained in:
thepaperpilot 2023-04-16 12:43:04 -05:00
parent 1928be236d
commit 8ebfb85360

View file

@ -253,17 +253,17 @@ export interface Section {
baseText?: Computable<CoercableComponent>; baseText?: Computable<CoercableComponent>;
/** Whether or not this section should be currently visible to the player. **/ /** Whether or not this section should be currently visible to the player. **/
visible?: Computable<boolean>; visible?: Computable<boolean>;
/** Determines if numbers larger or smaller than the base should be displayed as red. */
smallerIsBetter?: boolean;
} }
/** /**
* Takes an array of modifier "sections", and creates a JSXFunction that can render all those sections, and allow each section to be collapsed. * Takes an array of modifier "sections", and creates a JSXFunction that can render all those sections, and allow each section to be collapsed.
* Also returns a list of persistent refs that are used to control which sections are currently collapsed. * Also returns a list of persistent refs that are used to control which sections are currently collapsed.
* @param sectionsFunc A function that returns the sections to display. * @param sectionsFunc A function that returns the sections to display.
* @param smallerIsBetter Determines whether numbers larger or smaller than the base should be displayed as red.
*/ */
export function createCollapsibleModifierSections( export function createCollapsibleModifierSections(
sectionsFunc: () => Section[], sectionsFunc: () => Section[]
smallerIsBetter = false
): [JSXFunction, Persistent<Record<number, boolean>>] { ): [JSXFunction, Persistent<Record<number, boolean>>] {
const sections: Section[] = []; const sections: Section[] = [];
const processed: const processed:
@ -324,7 +324,9 @@ export function createCollapsibleModifierSections(
{s.unit} {s.unit}
</span> </span>
</div> </div>
{renderJSX(unref(s.modifier.description))} {s.modifier.description == null
? null
: renderJSX(unref(s.modifier.description))}
</> </>
); );
@ -353,7 +355,7 @@ export function createCollapsibleModifierSections(
class="modifier-amount" class="modifier-amount"
style={ style={
( (
smallerIsBetter === true s.smallerIsBetter === true
? Decimal.gt(total, base ?? 1) ? Decimal.gt(total, base ?? 1)
: Decimal.lt(total, base ?? 1) : Decimal.lt(total, base ?? 1)
) )