import clsx from "clsx"; import React from "react"; import { BoxBackground, ThemedSenseRowBoxSvg, ThemedSenseRowSmallBoxSvg, ThemedSenseRowMinimalSvg, } from "@dndbeyond/character-components/es"; import { CharacterTheme, Constants, FormatUtils, RuleDataUtils, SenseInfo, } from "@dndbeyond/character-rules-engine/es"; import { TypeScriptUtils } from "../../../Shared/utils"; import styles from "./styles.module.css"; interface Props { passivePerception: number; passiveInvestigation: number; passiveInsight: number; senses: SenseInfo; rowStyle: "small" | "normal" | "minimal"; onClick?: () => void; theme: CharacterTheme; } export default class Senses extends React.PureComponent { static defaultProps = { rowStyle: "normal", }; handleClick = (evt: React.MouseEvent): void => { const { onClick } = this.props; if (onClick) { evt.stopPropagation(); evt.nativeEvent.stopImmediatePropagation(); onClick(); } }; getSenseSummary = (senseKey: Constants.SenseTypeEnum): string | null => { const { senses } = this.props; let senseValue = senses[senseKey]; if (!senseValue) { return null; } return `${RuleDataUtils.getSenseTypeLabel( senseKey )} ${FormatUtils.renderDistance(senseValue)}`; }; renderSummaryInfo = (): React.ReactNode => { let senseKeys: Array = [ Constants.SenseTypeEnum.BLINDSIGHT, Constants.SenseTypeEnum.DARKVISION, Constants.SenseTypeEnum.TREMORSENSE, Constants.SenseTypeEnum.TRUESIGHT, ]; let senseSummaries: Array = senseKeys .map((senseKey) => this.getSenseSummary(senseKey)) .filter(TypeScriptUtils.isNotNullOrUndefined); return (
{!senseSummaries.length ? "Additional Sense Types" : senseSummaries.join(", ")}
); }; render() { const { passiveInsight, passiveInvestigation, passivePerception, rowStyle, theme, } = this.props; let isMinimal = false; let StyleComponent: React.ComponentType = ThemedSenseRowBoxSvg; if (rowStyle === "small") { StyleComponent = ThemedSenseRowSmallBoxSvg; } else if (rowStyle === "minimal") { StyleComponent = ThemedSenseRowMinimalSvg; isMinimal = true; } return (
{isMinimal ? (
{passivePerception}
Perception
{passiveInvestigation}
Investigation
{passiveInsight}
Insight
) : (
{passivePerception}
Passive Perception
{passiveInvestigation}
Passive Investigation
{passiveInsight}
Passive Insight
)} {this.renderSummaryInfo()}
); } }