From cde1e2f5d159791d0ef2feb9ad68e1393671c6d6 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 24 Nov 2026 19:35:51 -0500 Subject: [PATCH] feat(npc-dialogue): longer pauses and a frame that holds still Pauses are longer and now literal: the schedule's own total is the target, so a preset's milliseconds are what a player waits (155 after a comma, 370 at a sentence end, 450 at a line break, 720 at a paragraph, 720 for the beat). The cap moved to 3000ms and compresses the whole schedule rather than stealing time from characters. The dialog was sizing itself to its content and Radix centres it, so the choice footer appearing made the whole window jump. It is now a fixed-height frame: the log gives up height and scrolls, the footer scrolls inside its own band, and the window's top edge and height are identical before and after the menu appears (measured: 162px / 576px in both states). The log is bottom-anchored so a short conversation sits above its choices instead of floating in empty space, and the auto-scroll follows the footer appearing. --- .../frontend/personnel/NpcConversation.tsx | 112 +++++++++++------- src/lib/npc-dialogue/AGENTS.md | 35 +++++- src/lib/npc-dialogue/pacing.ts | 15 +-- 3 files changed, 104 insertions(+), 58 deletions(-) diff --git a/src/components/frontend/personnel/NpcConversation.tsx b/src/components/frontend/personnel/NpcConversation.tsx index a8e39a05..1064f48a 100644 --- a/src/components/frontend/personnel/NpcConversation.tsx +++ b/src/components/frontend/personnel/NpcConversation.tsx @@ -90,12 +90,9 @@ function resolveFlow(dialogue: NpcConversationProps["dialogue"]): ResolvedFlow | const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); -/** How long a line takes to type out: brisk for short lines, capped so a long - * paragraph does not hold the player up. `visibleLength` units, not raw - * characters, so markup does not slow the reveal down. */ -function revealDurationMs(units: number): number { - return Math.min(2600, 450 + units * 24); -} +/** Longest a line may take, pauses included. Past this the schedule is + * compressed: a wall of text still has to arrive while the player is looking. */ +const REVEAL_CAP_MS = 3000; /** True when the device asks for reduced motion; the animation is skipped * entirely rather than merely shortened. */ @@ -203,12 +200,6 @@ export function NpcConversation({ [], ); - // Keep the newest line in view. - useEffect(() => { - const el = scrollRef.current; - if (el) el.scrollTop = el.scrollHeight; - }, [log, typing, playerTyping, open]); - // The choice node the log currently rests on (if any). const activeChoiceNodeId = useMemo(() => { const last = [...log].reverse().find((entry) => entry.kind === "node"); @@ -305,12 +296,16 @@ export function NpcConversation({ // player is not being spoken to by. const animate = typewriter && node.type === "dialogue" && total > 0 && !prefersReducedMotion(); - // A clip paces the reveal: the text finishes with the read, so the two do - // not drift apart on a long line. + // The schedule is already a duration in milliseconds (one base cost per + // unit plus its pauses), so a preset's pause values mean what they say. A + // clip takes over as the target and the schedule is scaled to fit it, which + // keeps text and speech together. Only a very long line is compressed, by + // the cap. + const unscaled = buildRevealSchedule(text); const durationMs = voiceStarted && clipSeconds > 0.4 ? Math.min(60_000, clipSeconds * 1000) - : revealDurationMs(total); + : Math.min(REVEAL_CAP_MS, unscaled.total); setLog((prev) => [ ...prev, @@ -343,7 +338,7 @@ export function NpcConversation({ // relative units and scaled here, so a recorded line keeps the rhythm and // only stretches. Ticks are precomputed from the same schedule (seeded, so // a re-render cannot re-roll the rhythm) and fire as the reveal crosses them. - const schedule = scaleSchedule(buildRevealSchedule(text), durationMs); + const schedule = scaleSchedule(unscaled, durationMs); const unitCount = Math.min(total, schedule.arrivalMs.length); const ticking = typewriterSound && soundOnRef.current && !voiceStarted; let tickIndex = 0; @@ -554,6 +549,16 @@ export function NpcConversation({ : []; const anySelectableChoice = visibleChoices.some((choice) => !choice.locked); + // Keep the newest line in view. `streamingId` and the choice count are in the + // dependencies because the footer appearing (or a menu growing) changes how + // much room the log has, and the log would otherwise leave the newest line + // scrolled out of sight. + useEffect(() => { + const el = scrollRef.current; + if (el) el.scrollTop = el.scrollHeight; + }, [log, typing, playerTyping, open, streamingId, visibleChoices.length]); + + /** Button text for a choice: the server-resolved label when the choice * node's strings contained flag tokens, the raw label otherwise. */ const choiceLabel = (hop: DialogueNext, index: number): string => @@ -603,7 +608,15 @@ export function NpcConversation({ !next && close()}>
@@ -663,36 +676,43 @@ export function NpcConversation({ if (streamingId) skipRevealRef.current = streamingId; else skipBeatRef.current = true; }} - className="max-h-[55vh] min-h-32 space-y-3 overflow-y-auto p-5" + className="min-h-0 flex-1 overflow-y-auto p-5" > - {log.map((entry) => ( - { - // Explicit click: always allowed, and clears the notice. - const audio = audioRef.current; - if (!audio) return; - audio.src = url; - audio.currentTime = 0; - void audio - .play() - .then(() => - setLog((prev) => - prev.map((e) => - e.kind === "node" && e.id === entry.id - ? { ...e, voiceBlocked: false } - : e, + {/* Bottom-anchored like a messenger: a short conversation sits + just above its choices instead of floating in a tall empty + box. `min-h-full` keeps the block able to grow past the + viewport, so a long conversation still scrolls from the top + and nothing becomes unreachable above the scroll origin. */} +
+ {log.map((entry) => ( + { + // Explicit click: always allowed, and clears the notice. + const audio = audioRef.current; + if (!audio) return; + audio.src = url; + audio.currentTime = 0; + void audio + .play() + .then(() => + setLog((prev) => + prev.map((e) => + e.kind === "node" && e.id === entry.id + ? { ...e, voiceBlocked: false } + : e, + ), ), - ), - ) - .catch(() => undefined); - }} - /> - ))} - {typing !== null && } - {playerTyping && } + ) + .catch(() => undefined); + }} + /> + ))} + {typing !== null && } + {playerTyping && } +
{!typing && @@ -701,7 +721,7 @@ export function NpcConversation({ lastNode && lastNode.kind === "node" && (lastNode.node.type === "choice" || lastNode.node.type === "end") && ( -
+
{lastNode.node.type === "choice" && visibleChoices.length > 0 && ( {visibleChoices.map(({ hop, index, locked }) => { diff --git a/src/lib/npc-dialogue/AGENTS.md b/src/lib/npc-dialogue/AGENTS.md index dea6ea91..27d92f54 100644 --- a/src/lib/npc-dialogue/AGENTS.md +++ b/src/lib/npc-dialogue/AGENTS.md @@ -182,11 +182,17 @@ Rules that keep pauses from stacking or misfiring: cluster, not between the mark and its quote. - A comma between two digits (`1,000 rounds`) is a number, not a clause. -The schedule is built in relative units and scaled to the target duration by -`scaleSchedule`, which is also how a recorded line is paced: the rhythm is -preserved and only stretched, so a clip does not flatten the pauses. The last -unit's trailing pause is excluded from `total`, so a finished line never sits -waiting for nothing. +The schedule is already a duration: `BASE_UNIT_MS` per unit plus its pauses, so a +preset's numbers are the milliseconds a player actually waits. The default target +is `schedule.total`, with a `REVEAL_CAP_MS` ceiling (3000) that compresses the +whole schedule for a wall of text. `scaleSchedule` exists for the one case that +needs a different target: a recorded line scales the schedule to the clip length, +so the rhythm is preserved and only stretched. The last unit's trailing pause is +excluded from `total`, so a finished line never sits waiting for nothing. + +`natural` (155 / 370 / 450 / 720, beat 720) was tuned up once from the first cut, +which read as too rushed at commas. Do not lower it back without asking: the +original values were the author's first reaction, not a preference. **The beat between lines.** After a spoken line, if the next node is another spoken line, `cascadeFrom` shows the speaker's typing dots for `beatMs` before @@ -220,6 +226,25 @@ fall back to their Play button. - The component stores the line's resolved text on the log entry and renders that, so the reveal length and the rendered string cannot drift apart. +### The conversation frame + +The dialog is a **fixed-height frame** (`h-[min(80dvh,36rem)]`), not a box that +sizes itself to its content. It used to grow when the choice footer appeared, and +because Radix centres it vertically the whole window jumped up and down at the +moment the player was about to read a menu. Now the window never moves: the log is +`flex-1 min-h-0` and gives up height to the footer, and the footer is +`max-h-[45%] shrink-0 overflow-y-auto`, so a long menu scrolls inside its own band +instead of squeezing the conversation to nothing. + +The log's content is bottom-anchored (`flex min-h-full flex-col justify-end`) so a +short conversation sits just above its choices rather than floating in a tall empty +box. `min-h-full` is what keeps a long conversation scrollable from the top: without +it, `justify-end` puts overflow above the scroll origin where it cannot be reached. + +The auto-scroll effect depends on `streamingId` and `visibleChoices.length` as well +as the log: the footer appearing (or a menu gaining items) changes how much room the +log has, and without those the newest line can end up scrolled out of sight. + ## AI drafting behaviour worth knowing - Two attempts maximum: the second prompt carries the validator's complaints. diff --git a/src/lib/npc-dialogue/pacing.ts b/src/lib/npc-dialogue/pacing.ts index ba0a0d49..9c2feb3b 100644 --- a/src/lib/npc-dialogue/pacing.ts +++ b/src/lib/npc-dialogue/pacing.ts @@ -33,16 +33,17 @@ export const BASE_UNIT_MS = 24; /** * The three approved strengths. `natural` is the unit default: long enough to * read as speech, short enough that a ten line conversation is not a chore. + * Tuned up once from the first cut, which read as too rushed at commas. */ export const PACING_PRESETS: Record = { - subtle: { clauseMs: 60, sentenceMs: 160, newlineMs: 200, paragraphMs: 320, beatMs: 380 }, - natural: { clauseMs: 110, sentenceMs: 260, newlineMs: 320, paragraphMs: 520, beatMs: 620 }, + subtle: { clauseMs: 80, sentenceMs: 220, newlineMs: 280, paragraphMs: 460, beatMs: 460 }, + natural: { clauseMs: 155, sentenceMs: 370, newlineMs: 450, paragraphMs: 720, beatMs: 720 }, pronounced: { - clauseMs: 170, - sentenceMs: 400, - newlineMs: 480, - paragraphMs: 800, - beatMs: 900, + clauseMs: 225, + sentenceMs: 540, + newlineMs: 640, + paragraphMs: 1000, + beatMs: 1020, }, };