diff --git a/README.md b/README.md index 28fb75c..c1db16f 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,12 @@ cd backend npm run seed:hollowcrown ``` -On a server, apply new migrations with `npx prisma migrate deploy`. Change -your password from the account page (click your name in the top bar). +On a server, after pulling a new version, run `npm run deploy` in `backend` +and then restart the backend. It applies new migrations **and** regenerates +the Prisma client; without the second half the server keeps running with the +old data model and pages that use anything new fail to load (for example +"Could not load this encounter"). Change your password from the account page +(click your name in the top bar). ## Tests diff --git a/backend/package.json b/backend/package.json index e33aeb4..84941c9 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "backend", - "version": "1.3.0", + "version": "1.3.1", "private": true, "type": "commonjs", "main": "src/index.js", @@ -15,6 +15,7 @@ "prisma:migrate": "prisma migrate dev", "prisma:generate": "prisma generate", "prisma:seed": "prisma db seed", + "deploy": "prisma migrate deploy && prisma generate", "seed:hollowcrown": "node prisma/seed-hollowcrown.js", "prisma:studio": "prisma studio" }, diff --git a/backend/src/routes/api.integration.test.js b/backend/src/routes/api.integration.test.js index e2937f2..1926630 100644 --- a/backend/src/routes/api.integration.test.js +++ b/backend/src/routes/api.integration.test.js @@ -1896,6 +1896,15 @@ describe('initiative', () => { expect(playerView.Goblin.initiative).toBe(12); expect(playerView.Quick.character.userId).toBeTruthy(); + // Only the die stops at 20: a natural 20 plus a bonus goes past it. + expect((await patch(goblinRow, dmAuth, { initiativeRoll: 20 })).body.participant).toMatchObject({ initiativeRoll: 20, initiative: 22 }); + + // Quests take initiative exactly as battles do. + await request(app).patch(e).set(dmAuth).send({ mode: 'QUEST' }); + expect((await patch(heroRow, playerAuth, { initiativeRoll: 19 })).body.participant.initiative).toBe(19 + heroBonus); + await request(app).patch(e).set(dmAuth).send({ mode: 'BATTLE' }); + await patch(heroRow, playerAuth, { initiativeRoll: 20 }); + // The DM can re-roll anyone, or clear a roll. expect((await patch(goblinRow, dmAuth, { initiativeRoll: 1 })).body.participant.initiative).toBe(3); expect((await patch(heroRow, dmAuth, { initiativeRoll: null })).body.participant).toMatchObject({ initiativeRoll: null, initiative: 0 }); diff --git a/docs/ENCOUNTERS.md b/docs/ENCOUNTERS.md index d982d8d..cdbe342 100644 --- a/docs/ENCOUNTERS.md +++ b/docs/ENCOUNTERS.md @@ -48,7 +48,7 @@ time from the top of the page. | For | A fight | A scene built around people and an objective | | Layout | Everyone in one list, in initiative order | Three groups: "People you meet", "The party", "Creatures" | | Rounds and turns | Yes | No | -| Initiative | The d20 roll, typed in per combatant; the bonus is added | Not shown | +| Initiative | The d20 roll, typed in per combatant; the bonus is added | The same; each group lists highest first | | Start button | Begin Battle | Begin Quest | | End button | End Battle | Complete Quest | @@ -156,11 +156,13 @@ The DM types an amount and clicks Damage or Heal on a card. ## 7. Initiative, turns and rounds -Battles only. +Initiative is entered in battles and quests alike. Turns and rounds are for +battles only. - Each combatant has an **initiative roll** field. Type what the d20 showed, 1 to 20; the field accepts nothing else. The app does not roll the die, but - it adds the bonus for you and shows the total: a character's initiative + it adds the bonus for you and shows the total, which can go past 20 (a 20 on + the die with a +3 bonus is 23): a character's initiative bonus from their sheet, a monster's Dexterity modifier, nothing for an NPC. - The DM can enter the roll for anyone, when adding them or on the card. A player can enter the roll for **their own character** on its card. diff --git a/frontend/package.json b/frontend/package.json index d6b5d02..9977f7b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "frontend", "private": true, - "version": "1.3.0", + "version": "1.3.1", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/components/InfoTip.tsx b/frontend/src/components/InfoTip.tsx index 39daad1..22a9725 100644 --- a/frontend/src/components/InfoTip.tsx +++ b/frontend/src/components/InfoTip.tsx @@ -1,4 +1,5 @@ -import { useId, useState } from 'react'; +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 @@ -38,8 +39,36 @@ export const STAT_HELP: Record = { // (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(null); + const trigger = useRef(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 ( @@ -49,6 +78,7 @@ export function InfoTip({ term, text: custom, label = 'What is this?' }: { term? className="info-tip-trigger" aria-describedby={id} aria-label={label} + ref={trigger} onMouseEnter={() => setOpen(true)} onFocus={() => setOpen(true)} onBlur={() => setOpen(false)} @@ -56,11 +86,14 @@ export function InfoTip({ term, text: custom, label = 'What is this?' }: { term? > ⓘ - {open && ( - - {text} - - )} + {open && + place && + createPortal( + + {text} + , + document.body, + )} ); } diff --git a/frontend/src/index.css b/frontend/src/index.css index 2d37a03..f4bdd14 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -631,10 +631,9 @@ input[type='radio'] { color: var(--accent-strong); outline: none; } +/* Placed by InfoTip.tsx against the viewport, so no scrolling container can clip it. */ .info-tip-bubble { - position: absolute; - bottom: calc(100% + 8px); - left: 50%; + position: fixed; transform: translateX(-50%); width: max-content; max-width: 260px; @@ -648,7 +647,7 @@ input[type='radio'] { letter-spacing: normal; color: var(--text); box-shadow: var(--shadow-deep); - z-index: 100; + z-index: 200; pointer-events: none; } diff --git a/frontend/src/pages/EncounterPage.tsx b/frontend/src/pages/EncounterPage.tsx index 539faa0..2376ea4 100644 --- a/frontend/src/pages/EncounterPage.tsx +++ b/frontend/src/pages/EncounterPage.tsx @@ -94,7 +94,6 @@ function subline(p: EncounterParticipant): string { function CombatantCard({ participant: p, isDM, - mode, isActive, onPatch, canRollInitiative, @@ -102,7 +101,6 @@ function CombatantCard({ }: { participant: EncounterParticipant; isDM: boolean; - mode: EncounterMode; isActive: boolean; onPatch: (data: Partial) => void; // The DM for anyone; a player for their own character. @@ -162,8 +160,8 @@ function CombatantCard({
{subline(p)}
- {mode === 'BATTLE' && - (canRollInitiative ? ( + {/* Battles and quests both take initiative: who speaks or acts first matters in either. */} + {canRollInitiative ? (