- All of a Dexterity modifier counts toward AC in light armor, at most +2 in medium armor, none in heavy armor, going by the equipped item's kind - The gear card says when the armor is holding something back - Library and seed armor notes and docs brought in line Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
7.5 KiB
TypeScript
103 lines
7.5 KiB
TypeScript
import { useEffect, useId, useRef, useState, type CSSProperties } from 'react';
|
||
import { createPortal } from 'react-dom';
|
||
|
||
// Short explanations for the stat labels sprinkled across the sheet, quick
|
||
// stats, party table, and builder — "what is this, and how is it worked
|
||
// out" for someone who doesn't already know D&D 5e by heart.
|
||
const STAT_HELP: Record<string, string> = {
|
||
AC: 'Armor Class — how hard you are to hit. 10 + your Dexterity modifier + any armor bonus.',
|
||
HP: 'Hit Points — damage you can take before falling unconscious. Max HP is set by your class hit die, Constitution modifier, and level.',
|
||
TEMP_HP: 'Temporary Hit Points — an extra buffer that absorbs damage first and disappears when it runs out (it does not stack with more temp HP).',
|
||
DEATH_SAVES: 'Death saves — at 0 HP you roll a d20 at the start of each of your turns. 10 or more is a success, less is a failure; a 1 counts as two failures and a 20 puts you back up with 1 HP. Three successes and you are stable; three failures and you die. Being hit while down is a failure (two if it was a critical hit). Any healing ends it.',
|
||
INITIATIVE: 'Initiative — added to a d20 roll at the start of a fight to decide turn order. Equal to your Dexterity modifier.',
|
||
PROFICIENCY_BONUS: 'Proficiency Bonus — added to attacks, saves, and skills you are trained in. Grows with level (+2 at level 1, up to +6 at level 20).',
|
||
PASSIVE_PERCEPTION: 'Passive Perception — your always-on alertness score, used instead of rolling when you are not actively searching. 10 + your Perception skill bonus.',
|
||
SAVING_THROW: 'Saving Throw — a roll to resist an effect (like a spell or trap). Your ability modifier, plus your proficiency bonus if your class is trained in that save.',
|
||
SKILL_BONUS: 'Skill Bonus — added when you roll to use a skill. The governing ability modifier, plus your proficiency bonus if you are proficient (doubled if you have expertise).',
|
||
EXPERTISE: 'Expertise — doubles your proficiency bonus for this skill, on top of being proficient.',
|
||
ABILITY_MODIFIER: 'Ability Modifier — the number added to rolls that use this ability. floor((score − 10) / 2).',
|
||
ARMOR_BONUS: 'Extra AC — a number the DM sets, added to AC on top of 10 + Dex modifier and whatever equipped gear gives. Armor itself is an equipped item, and medium or heavy armor holds back how much Dexterity counts. Unarmored Defense (barbarian, monk) and a draconic sorcerer’s scales are worked out for you: do not add them here.',
|
||
SPEED: 'Speed — how far you can move on your turn, in feet. Set by your species, unless overridden.',
|
||
SPELL_SAVE_DC: 'Spell Save DC — the difficulty a target must beat to resist your spell. 8 + proficiency bonus + your spellcasting ability modifier.',
|
||
SPELL_ATTACK_BONUS: 'Spell Attack Bonus — added when you make a spell attack roll. Proficiency bonus + your spellcasting ability modifier.',
|
||
ATTACK_BONUS: 'Attack Bonus — added to the d20 when you attack with this weapon. Ability modifier (Str, Dex, or the better of the two for finesse weapons), plus proficiency bonus.',
|
||
DAMAGE_BONUS: 'Damage Bonus — added to the weapon’s damage dice on a hit. Same ability modifier as the attack bonus.',
|
||
CHALLENGE_RATING: 'Challenge Rating — a rough measure of how dangerous a monster is on its own, used to gauge encounter difficulty.',
|
||
HIT_DICE: 'Hit Dice — the die your class rolls (or uses the fixed average of) when your HP increases at each level.',
|
||
HIT_DICE_LEFT: 'Hit Dice — you have one per level. On a short rest you can spend any you have left: roll each one, add your Constitution modifier, and heal that much. A long rest gives back half your level in spent dice (at least one).',
|
||
SPELL_SLOTS: 'Spell slots — each one is one casting of a spell of that level or lower. Cantrips never use a slot. How many you have comes from your class and level. Spent slots come back on a long rest (a warlock’s on a short rest too).',
|
||
// Character builder
|
||
DICE_MODE: 'Digital dice are rolled by the app. Physical dice are rolled by you at the table, and you type in what came up. Either way a roll is final once it is made.',
|
||
WILDCARD: 'Wildcard — the luckiest result. Instead of choosing between two options you may pick any of them.',
|
||
SPECIES_BONUS: 'Species bonus — points your species adds on top of the ability scores you roll. They are added automatically.',
|
||
SAVE_PROFICIENCY: 'Each class is trained in two saving throws. On those you add your proficiency bonus when resisting spells, traps and other effects.',
|
||
KEY_ABILITY: 'Key abilities — the scores this class leans on most. Put your best rolls here.',
|
||
SPELLCASTING: 'Spellcasting ability — the score that powers this class’s spells. A higher score makes your spells harder to resist and more accurate.',
|
||
ROLL_4D6: 'Roll four six-sided dice and add up the best three (the lowest is dropped). Do that six times to get six scores, usually between 8 and 16.',
|
||
STARTING_EQUIPMENT: 'Your DM chooses which weapons, items and spells are available to brand-new characters, and how many you may take.',
|
||
DAMAGE_DICE: 'Damage dice — what you roll when this weapon hits. “1d8” means one eight-sided die. Your Strength or Dexterity modifier is added on top.',
|
||
};
|
||
|
||
// `term` looks up a standard explanation above; `text` supplies a one-off
|
||
// (a species, a skill, an ability) without adding it to the shared list.
|
||
export function InfoTip({ term, text: custom, label = 'What is this?' }: { term?: keyof typeof STAT_HELP; text?: string; label?: string }) {
|
||
const [open, setOpen] = useState(false);
|
||
const [place, setPlace] = useState<CSSProperties | null>(null);
|
||
const trigger = useRef<HTMLButtonElement>(null);
|
||
const id = useId();
|
||
const text = custom ?? (term ? STAT_HELP[term] : undefined);
|
||
|
||
// The bubble is drawn on the page itself, fixed to where the ⓘ is on
|
||
// screen, rather than inside whatever holds the ⓘ: a scrolling table or a
|
||
// drawer would otherwise cut it off. It sits above the ⓘ when there is room
|
||
// and below when there isn't, and never runs off the sides.
|
||
useEffect(() => {
|
||
if (!open || !trigger.current) return;
|
||
const rect = trigger.current.getBoundingClientRect();
|
||
const halfWidth = Math.min(130, window.innerWidth / 2 - 8);
|
||
const centre = Math.min(Math.max(rect.left + rect.width / 2, halfWidth + 8), window.innerWidth - halfWidth - 8);
|
||
const above = rect.top > 160;
|
||
setPlace({
|
||
left: centre,
|
||
...(above ? { bottom: window.innerHeight - rect.top + 8 } : { top: rect.bottom + 8 }),
|
||
});
|
||
// Its position is only right until the page moves.
|
||
const close = () => setOpen(false);
|
||
window.addEventListener('scroll', close, true);
|
||
window.addEventListener('resize', close);
|
||
return () => {
|
||
window.removeEventListener('scroll', close, true);
|
||
window.removeEventListener('resize', close);
|
||
setPlace(null); // so the next opening is measured afresh, not shown where the last one was
|
||
};
|
||
}, [open]);
|
||
|
||
if (!text) return null;
|
||
|
||
return (
|
||
<span className="info-tip" onMouseLeave={() => setOpen(false)}>
|
||
<button
|
||
type="button"
|
||
className="info-tip-trigger"
|
||
aria-describedby={id}
|
||
aria-label={label}
|
||
ref={trigger}
|
||
onMouseEnter={() => setOpen(true)}
|
||
onFocus={() => setOpen(true)}
|
||
onBlur={() => setOpen(false)}
|
||
onClick={() => setOpen((o) => !o)}
|
||
>
|
||
ⓘ
|
||
</button>
|
||
{open &&
|
||
place &&
|
||
createPortal(
|
||
<span role="tooltip" id={id} className="info-tip-bubble" style={place}>
|
||
{text}
|
||
</span>,
|
||
document.body,
|
||
)}
|
||
</span>
|
||
);
|
||
}
|