import * as React from "react"; import { Tooltip } from "@dndbeyond/character-common-components/es"; import { Note, FormatUtils, Constants, NoteUtils, CharacterTheme, } from "@dndbeyond/character-rules-engine/es"; import { NumberDisplay } from "~/components/NumberDisplay"; import Damage from "../Damage"; import { AoeTypeIcon, DisadvantageIcon } from "../Icons"; import { AoeTypePropType } from "../Icons/IconConstants"; interface Props { notes: Array; className: string; theme: CharacterTheme; } export default class NoteComponents extends React.PureComponent { static defaultProps = { className: "", }; renderPlainText = (note: Note): React.ReactNode => { const { theme } = this.props; let classNames: Array = [ "ddbc-note-components__component", "ddbc-note-components__component--plain", ]; if (note.data.displayIntention) { classNames.push( `ddbc-note-components__component--${note.data.displayIntention}` ); } if (theme.isDarkMode) { classNames.push("ddbc-note-components__component--dark-mode"); } return {note.data.text}; }; renderTooltip = (note: Note): React.ReactNode => { const { theme } = this.props; let classNames: Array = [ "ddbc-note-components__component", "ddbc-note-components__component--tooltip", ]; if (note.data.displayIntention) { classNames.push( `ddbc-note-components__component--${note.data.displayIntention}` ); } if (theme.isDarkMode) { classNames.push("ddbc-note-components__component--dark-mode"); } return ( {note.data.text} ); }; renderDistance = (note: Note): React.ReactNode => { const { theme } = this.props; let classNames: Array = [ "ddbc-note-components__component", "ddbc-note-components__component--distance", ]; return ( ); }; renderAoeIcon = (note: Note): React.ReactNode => { const { theme } = this.props; let classNames: Array = [ "ddbc-note-components__component", "ddbc-note-components__component--aoe-icon", ]; return ( ); //` }; renderDamage = (note: Note): React.ReactNode => { const { theme } = this.props; let classNames: Array = [ "ddbc-note-components__component", "ddbc-note-components__component--damage", ]; return ( ); }; renderDisadvantageIcon = (note: Note): React.ReactNode => { const { theme } = this.props; let classNames: Array = [ "ddbc-note-components__component", "ddbc-note-components__component--disadvantage-icon", ]; return ( ); }; renderGroup = ( notes: Array | null, separator: string = " ", key: string | number | null = null ): React.ReactNode => { if (notes === null) { return null; } return ( {notes.map((note, idx): React.ReactNode => { if (note === null) { return null; } return ( {this.renderNote(note)} {idx + 1 < notes.length ? separator : ""} ); })} ); }; renderNote = (note: Note | null): React.ReactNode => { if (note === null) { return null; } switch (NoteUtils.getType(note)) { case Constants.NoteTypeEnum.PLAIN_TEXT: return this.renderPlainText(note); case Constants.NoteTypeEnum.TOOLTIP: return this.renderTooltip(note); case Constants.NoteTypeEnum.DISTANCE: return this.renderDistance(note); case Constants.NoteTypeEnum.AOE_ICON: return this.renderAoeIcon(note); case Constants.NoteTypeEnum.DAMAGE: return this.renderDamage(note); case Constants.NoteTypeEnum.DISADVANTAGE_ICON: return this.renderDisadvantageIcon(note); case Constants.NoteTypeEnum.GROUP: return this.renderGroup( note.data.notes, note.data.separator, note.data.key ); default: // not implement } return null; }; render() { const { notes, className } = this.props; let classNames: Array = [className, "ddbc-note-components"]; return (
{this.renderGroup(notes, ", ")}
); } }