1
0
Fork 0

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.
This commit is contained in:
Jason Fraley 2026-11-24 19:35:51 -05:00
parent 464ba2d5d4
commit cde1e2f5d1
3 changed files with 104 additions and 58 deletions

View file

@ -90,12 +90,9 @@ function resolveFlow(dialogue: NpcConversationProps["dialogue"]): ResolvedFlow |
const sleep = (ms: number) => new Promise<void>((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({
<Dialog open={open} onOpenChange={(next) => !next && close()}>
<DialogContent
showCloseButton={false}
className="flex w-[calc(100%-1.5rem)] max-w-2xl flex-col gap-0 overflow-hidden rounded-none border border-white/20 bg-zinc-950 p-0 text-white sm:w-full sm:rounded-none"
className={`flex w-[calc(100%-1.5rem)] max-w-2xl flex-col gap-0 overflow-hidden rounded-none border border-white/20 bg-zinc-950 p-0 text-white sm:w-full sm:rounded-none ${
// A frame of fixed height. The dialog used to size itself to its
// content, so the choice footer appearing made it taller, and being
// vertically centred made the whole box jump up and down. With a
// fixed height the window never moves: the log gives up space and
// scrolls instead, and a long choice list scrolls inside its own
// band rather than shrinking the conversation to nothing.
flow.startId === null ? "" : "h-[min(80dvh,36rem)]"
}`}
>
<div className={`relative flex items-center justify-between ${DOSSIER.strip}`}>
<DialogTitle className="min-w-0 truncate font-mono text-[10px] font-normal uppercase tracking-widest text-white/60">
@ -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) => (
<TimelineEntry
key={entry.id}
entry={entry}
speakerDefault={npc.name}
onPlayVoice={(url) => {
// 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. */}
<div className="flex min-h-full flex-col justify-end gap-3">
{log.map((entry) => (
<TimelineEntry
key={entry.id}
entry={entry}
speakerDefault={npc.name}
onPlayVoice={(url) => {
// 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 && <TypingIndicator speaker={typing} />}
{playerTyping && <TypingIndicator player />}
)
.catch(() => undefined);
}}
/>
))}
{typing !== null && <TypingIndicator speaker={typing} />}
{playerTyping && <TypingIndicator player />}
</div>
</div>
{!typing &&
@ -701,7 +721,7 @@ export function NpcConversation({
lastNode &&
lastNode.kind === "node" &&
(lastNode.node.type === "choice" || lastNode.node.type === "end") && (
<div className="flex flex-col gap-2 border-t border-white/15 bg-black/50 p-4">
<div className="flex max-h-[45%] shrink-0 flex-col gap-2 overflow-y-auto border-t border-white/15 bg-black/50 p-4">
{lastNode.node.type === "choice" && visibleChoices.length > 0 && (
<TooltipProvider delayDuration={150}>
{visibleChoices.map(({ hop, index, locked }) => {

View file

@ -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.

View file

@ -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<string, PauseProfile> = {
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,
},
};