feat(npc-dialogue): choose the conversation typing pace in the admin panel
The pace was a code constant, so changing it meant a build and a deploy. It is now a select on the NPC Dialogue Prompt global (Presentation, "Typing pace") with three presets, and a change applies to the next conversation opened. Each preset moves the character cost and the punctuation pauses together, because a slow character rate with brisk pauses reads as broken rather than deliberate: subtle 22ms a character (about 45 a second), natural 30ms (about 33), pronounced 42ms (about 24). natural stays the default. The per-unit cost moved into PauseProfile, and BASE_UNIT_MS is now derived from natural, so the existing schedule tests keep their meaning. loadDialogueSettings reads presentation.pacing through normalizePacingPreset: an unrecognised stored value (an older row, a newer admin, a typo) falls back to natural instead of leaving the conversation with no pacing at all. The contact page reads the global once for both presentation defaults and passes the preset to NpcConversation, which uses it for the reveal schedule and the beat between lines. Measured in the running app on one fixed 71 character line: subtle 2377ms, natural 2880ms, pronounced 3627ms, and the admin select renders with Natural selected. Migration 20261201_180344 applied to dev. 220 npc-dialogue tests pass.
This commit is contained in:
parent
802e2391a8
commit
4ed5b4ee79
11 changed files with 48390 additions and 25 deletions
|
|
@ -178,10 +178,12 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
|
||||||
|
|
||||||
// Typing animation: the unit default from the settings global, overridden by
|
// Typing animation: the unit default from the settings global, overridden by
|
||||||
// this player's own preference. Read here so the dialog needs no round trip.
|
// this player's own preference. Read here so the dialog needs no round trip.
|
||||||
|
// One read of the settings global for both presentation defaults.
|
||||||
|
const dialogueSettings = dialogue ? await loadDialogueSettings(payload) : null;
|
||||||
const typewriterEnabled = dialogue
|
const typewriterEnabled = dialogue
|
||||||
? resolveTypewriter(
|
? resolveTypewriter(
|
||||||
isPayloadUser(user) ? user.preferences?.dialogue?.typewriter : undefined,
|
isPayloadUser(user) ? user.preferences?.dialogue?.typewriter : undefined,
|
||||||
(await loadDialogueSettings(payload)).typewriterDefault,
|
dialogueSettings?.typewriterDefault ?? true,
|
||||||
)
|
)
|
||||||
: false;
|
: false;
|
||||||
// Sound is on unless the player turned voice clips off in their account.
|
// Sound is on unless the player turned voice clips off in their account.
|
||||||
|
|
@ -207,6 +209,7 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
|
||||||
typewriter={typewriterEnabled}
|
typewriter={typewriterEnabled}
|
||||||
typewriterSound={typewriterSoundEnabled}
|
typewriterSound={typewriterSoundEnabled}
|
||||||
voice={voiceEnabled}
|
voice={voiceEnabled}
|
||||||
|
pacing={dialogueSettings?.pacing}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
employmentSlot={
|
employmentSlot={
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,21 @@ export const NpcDialogueSettings: GlobalConfig = {
|
||||||
"The default for everyone. Players can override it in their account preferences, and a player whose device asks for reduced motion never sees the animation.",
|
"The default for everyone. Players can override it in their account preferences, and a player whose device asks for reduced motion never sees the animation.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "pacing",
|
||||||
|
label: "Typing pace",
|
||||||
|
type: "select",
|
||||||
|
defaultValue: "natural",
|
||||||
|
options: [
|
||||||
|
{ label: "Subtle (quick, about 45 characters a second)", value: "subtle" },
|
||||||
|
{ label: "Natural (about 33 a second)", value: "natural" },
|
||||||
|
{ label: "Pronounced (slow and deliberate, about 24 a second)", value: "pronounced" },
|
||||||
|
],
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"How fast conversation lines type out and how long the pauses at punctuation last. Applies to the next conversation opened, with no deploy. Authors can still hold a specific line with {1.2s} or {400ms}.",
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import {
|
||||||
scaleSchedule,
|
scaleSchedule,
|
||||||
shownAt,
|
shownAt,
|
||||||
} from "@/lib/npc-dialogue/pacing";
|
} from "@/lib/npc-dialogue/pacing";
|
||||||
|
import type { PacingPreset } from "@/lib/npc-dialogue/pacing";
|
||||||
import { playTypeTick, primeTypeSound } from "@/lib/npc-dialogue/typeSound";
|
import { playTypeTick, primeTypeSound } from "@/lib/npc-dialogue/typeSound";
|
||||||
import { DialogueAttachments } from "@/components/frontend/personnel/DialogueAttachments";
|
import { DialogueAttachments } from "@/components/frontend/personnel/DialogueAttachments";
|
||||||
import {
|
import {
|
||||||
|
|
@ -59,6 +60,9 @@ interface NpcConversationProps {
|
||||||
readonly typewriterSound?: boolean;
|
readonly typewriterSound?: boolean;
|
||||||
/** Play recorded voice clips. The header button mutes for the session. */
|
/** Play recorded voice clips. The header button mutes for the session. */
|
||||||
readonly voice?: boolean;
|
readonly voice?: boolean;
|
||||||
|
/** Typing speed and punctuation pauses, chosen in the admin panel. Resolved
|
||||||
|
* server-side so the dialog needs no round trip for it. */
|
||||||
|
readonly pacing?: PacingPreset;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ResolvedFlow {
|
interface ResolvedFlow {
|
||||||
|
|
@ -153,6 +157,7 @@ export function NpcConversation({
|
||||||
typewriter = true,
|
typewriter = true,
|
||||||
typewriterSound = true,
|
typewriterSound = true,
|
||||||
voice = true,
|
voice = true,
|
||||||
|
pacing = DEFAULT_PACING_PRESET,
|
||||||
}: NpcConversationProps) {
|
}: NpcConversationProps) {
|
||||||
const flow = useMemo(() => resolveFlow(dialogue), [dialogue]);
|
const flow = useMemo(() => resolveFlow(dialogue), [dialogue]);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
@ -374,7 +379,7 @@ export function NpcConversation({
|
||||||
// clip takes over as the target and the schedule is scaled to fit it, which
|
// 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
|
// keeps text and speech together. Only a very long line is compressed, by
|
||||||
// the cap.
|
// the cap.
|
||||||
const unscaled = buildRevealSchedule(text);
|
const unscaled = buildRevealSchedule(text, pacing);
|
||||||
const voicedMs =
|
const voicedMs =
|
||||||
voiceStarted && clipSeconds > 0.4 ? Math.min(60_000, clipSeconds * 1000) : null;
|
voiceStarted && clipSeconds > 0.4 ? Math.min(60_000, clipSeconds * 1000) : null;
|
||||||
const durationMs = lineDurationMs(unscaled, voicedMs);
|
const durationMs = lineDurationMs(unscaled, voicedMs);
|
||||||
|
|
@ -459,7 +464,7 @@ export function NpcConversation({
|
||||||
const beatThen = async (node: DialogueNode, token: number) => {
|
const beatThen = async (node: DialogueNode, token: number) => {
|
||||||
skipBeatRef.current = false;
|
skipBeatRef.current = false;
|
||||||
setTyping(node.data.speaker?.trim() || npc.name);
|
setTyping(node.data.speaker?.trim() || npc.name);
|
||||||
const wait = beatMs();
|
const wait = beatMs(pacing);
|
||||||
const startedAt = performance.now();
|
const startedAt = performance.now();
|
||||||
try {
|
try {
|
||||||
while (performance.now() - startedAt < wait) {
|
while (performance.now() - startedAt < wait) {
|
||||||
|
|
|
||||||
|
|
@ -336,8 +336,15 @@ failing the directory.
|
||||||
|
|
||||||
### Typing pace and authored pauses
|
### Typing pace and authored pauses
|
||||||
|
|
||||||
`pacing.ts` prices the reveal: `BASE_UNIT_MS` (30ms, about 33 characters a
|
`pacing.ts` prices the reveal: a per-unit cost from the active preset plus a
|
||||||
second) per visible unit plus a pause after punctuation and line breaks. A line
|
pause after punctuation and line breaks. Three presets exist (`subtle` 22ms,
|
||||||
|
`natural` 30ms, `pronounced` 42ms per character) and each moves the character cost
|
||||||
|
and the punctuation pauses together, because a slow character rate with brisk
|
||||||
|
pauses reads as broken rather than deliberate. The unit picks one in the NPC
|
||||||
|
Dialogue Prompt global (Presentation, "Typing pace"); `loadDialogueSettings`
|
||||||
|
normalises it, so an unknown stored value falls back to `natural` instead of
|
||||||
|
rendering with no pacing. Changing it applies to the next conversation opened,
|
||||||
|
no deploy. A line
|
||||||
takes `lineDurationMs` of the schedule: a recorded clip sets the target, an
|
takes `lineDurationMs` of the schedule: a recorded clip sets the target, an
|
||||||
authored pause outlasts a short clip, and a silent line is never compressed
|
authored pause outlasts a short clip, and a silent line is never compressed
|
||||||
below the base pace (ceiling `MAX_LINE_MS` 20s, floor 500ms).
|
below the base pace (ceiling `MAX_LINE_MS` 20s, floor 500ms).
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import type { Payload } from "payload";
|
import type { Payload } from "payload";
|
||||||
|
|
||||||
|
import { normalizePacingPreset } from "./pacing";
|
||||||
|
import type { PacingPreset } from "./pacing";
|
||||||
import { resolveVoice } from "./generationPrompt";
|
import { resolveVoice } from "./generationPrompt";
|
||||||
import type { ResolvedVoice } from "./generationPrompt";
|
import type { ResolvedVoice } from "./generationPrompt";
|
||||||
|
|
||||||
|
|
@ -27,6 +29,7 @@ type SettingsDoc = {
|
||||||
revision?: number | null;
|
revision?: number | null;
|
||||||
presentation?: {
|
presentation?: {
|
||||||
typewriterDefault?: boolean | null;
|
typewriterDefault?: boolean | null;
|
||||||
|
pacing?: string | null;
|
||||||
} | null;
|
} | null;
|
||||||
} | null;
|
} | null;
|
||||||
|
|
||||||
|
|
@ -39,6 +42,8 @@ export interface DialoguePromptSettings {
|
||||||
revision: number | null;
|
revision: number | null;
|
||||||
/** Unit default for typing conversation lines out character by character. */
|
/** Unit default for typing conversation lines out character by character. */
|
||||||
typewriterDefault: boolean;
|
typewriterDefault: boolean;
|
||||||
|
/** How fast conversations type out, chosen in the admin panel. */
|
||||||
|
pacing: PacingPreset;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EMPTY: DialoguePromptSettings = {
|
const EMPTY: DialoguePromptSettings = {
|
||||||
|
|
@ -46,6 +51,7 @@ const EMPTY: DialoguePromptSettings = {
|
||||||
extraRules: null,
|
extraRules: null,
|
||||||
revision: null,
|
revision: null,
|
||||||
typewriterDefault: true,
|
typewriterDefault: true,
|
||||||
|
pacing: "natural",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Read the prompt settings, falling back to the built-in defaults on any miss. */
|
/** Read the prompt settings, falling back to the built-in defaults on any miss. */
|
||||||
|
|
@ -67,6 +73,7 @@ export async function loadDialogueSettings(payload: Payload): Promise<DialoguePr
|
||||||
// Only an explicit false turns it off, so a document written before this
|
// Only an explicit false turns it off, so a document written before this
|
||||||
// field existed still types out (its default).
|
// field existed still types out (its default).
|
||||||
typewriterDefault: doc?.presentation?.typewriterDefault !== false,
|
typewriterDefault: doc?.presentation?.typewriterDefault !== false,
|
||||||
|
pacing: normalizePacingPreset(doc?.presentation?.pacing),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// A missing global (fresh database before the migration ran) must not make
|
// A missing global (fresh database before the migration ran) must not make
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ import { visibleSegments } from "./DialogueText";
|
||||||
* Pure and client-safe: no Payload, no timers. The component owns the clock.
|
* Pure and client-safe: no Payload, no timers. The component owns the clock.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** How long each of the four kinds of pause costs. */
|
/** How long each of the four kinds of pause costs, and how fast characters land. */
|
||||||
export interface PauseProfile {
|
export interface PauseProfile {
|
||||||
|
/** Cost of one visible character. The overall speed of a line. */
|
||||||
|
readonly baseMs: number;
|
||||||
/** After a comma, semicolon or colon. */
|
/** After a comma, semicolon or colon. */
|
||||||
readonly clauseMs: number;
|
readonly clauseMs: number;
|
||||||
/** After a full stop, question mark, exclamation mark or ellipsis. */
|
/** After a full stop, question mark, exclamation mark or ellipsis. */
|
||||||
|
|
@ -28,23 +30,34 @@ export interface PauseProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cost of one visible unit before any pause is added.
|
* The three strengths, chosen in the admin panel (NPC Dialogue Prompt,
|
||||||
|
* Presentation). Each one changes both speeds at once: how fast characters land
|
||||||
|
* and how long each punctuation pause holds, because a slow character rate with
|
||||||
|
* brisk pauses reads as broken, not deliberate.
|
||||||
*
|
*
|
||||||
* Thirty milliseconds is about 33 characters a second, the top of a comfortable
|
* `natural` is the default: about 33 characters a second, long enough to read as
|
||||||
* reading pace for prose read aloud to yourself. It was 24, which measured fine
|
* speech, short enough that a ten line conversation is not a chore. The first cut
|
||||||
* on paper and read as a blur in the app.
|
* was 24ms a character, which measured fine on paper and read as a blur.
|
||||||
*/
|
|
||||||
export const BASE_UNIT_MS = 30;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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> = {
|
export const PACING_PRESETS: Record<string, PauseProfile> = {
|
||||||
subtle: { clauseMs: 80, sentenceMs: 220, newlineMs: 280, paragraphMs: 460, beatMs: 460 },
|
subtle: {
|
||||||
natural: { clauseMs: 155, sentenceMs: 370, newlineMs: 450, paragraphMs: 720, beatMs: 720 },
|
baseMs: 22,
|
||||||
|
clauseMs: 80,
|
||||||
|
sentenceMs: 220,
|
||||||
|
newlineMs: 280,
|
||||||
|
paragraphMs: 460,
|
||||||
|
beatMs: 460,
|
||||||
|
},
|
||||||
|
natural: {
|
||||||
|
baseMs: 30,
|
||||||
|
clauseMs: 155,
|
||||||
|
sentenceMs: 370,
|
||||||
|
newlineMs: 450,
|
||||||
|
paragraphMs: 720,
|
||||||
|
beatMs: 720,
|
||||||
|
},
|
||||||
pronounced: {
|
pronounced: {
|
||||||
|
baseMs: 42,
|
||||||
clauseMs: 225,
|
clauseMs: 225,
|
||||||
sentenceMs: 540,
|
sentenceMs: 540,
|
||||||
newlineMs: 640,
|
newlineMs: 640,
|
||||||
|
|
@ -57,6 +70,20 @@ export type PacingPreset = keyof typeof PACING_PRESETS;
|
||||||
|
|
||||||
export const DEFAULT_PACING_PRESET: PacingPreset = "natural";
|
export const DEFAULT_PACING_PRESET: PacingPreset = "natural";
|
||||||
|
|
||||||
|
/** Cost of one visible unit at the default preset; see `PauseProfile.baseMs`. */
|
||||||
|
export const BASE_UNIT_MS = PACING_PRESETS[DEFAULT_PACING_PRESET].baseMs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coerce a stored setting to a known preset. Anything unrecognised (an older
|
||||||
|
* document, a value removed from the list) means the default, so a bad value in
|
||||||
|
* the database cannot make a conversation render with no pacing at all.
|
||||||
|
*/
|
||||||
|
export function normalizePacingPreset(value: unknown): PacingPreset {
|
||||||
|
return typeof value === "string" && value in PACING_PRESETS
|
||||||
|
? (value as PacingPreset)
|
||||||
|
: DEFAULT_PACING_PRESET;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gaps between typing ticks, in relative units. Wide enough that a fast line
|
/** Gaps between typing ticks, in relative units. Wide enough that a fast line
|
||||||
* does not turn into a buzz, narrow enough to sound like keys under a sentence. */
|
* does not turn into a buzz, narrow enough to sound like keys under a sentence. */
|
||||||
const TICK_MIN_GAP = 95;
|
const TICK_MIN_GAP = 95;
|
||||||
|
|
@ -170,12 +197,12 @@ export function buildRevealSchedule(
|
||||||
let cursor = 0;
|
let cursor = 0;
|
||||||
for (let i = 0; i < visible.length; i += 1) {
|
for (let i = 0; i < visible.length; i += 1) {
|
||||||
arrival.push(cursor);
|
arrival.push(cursor);
|
||||||
cursor += BASE_UNIT_MS + pauseAfter(visible, i, profile) + pauses[i];
|
cursor += profile.baseMs + pauseAfter(visible, i, profile) + pauses[i];
|
||||||
}
|
}
|
||||||
// The last unit's own cost is what finishes the line; its trailing punctuation
|
// The last unit's own cost is what finishes the line; its trailing punctuation
|
||||||
// pause is dropped so the reveal never sits on a complete line waiting for
|
// pause is dropped so the reveal never sits on a complete line waiting for
|
||||||
// nothing. An authored pause there is kept: that is a deliberate beat.
|
// nothing. An authored pause there is kept: that is a deliberate beat.
|
||||||
const total = arrival[arrival.length - 1] + BASE_UNIT_MS + pauses[pauses.length - 1];
|
const total = arrival[arrival.length - 1] + profile.baseMs + pauses[pauses.length - 1];
|
||||||
|
|
||||||
const random = seededRandom(hashText(visible));
|
const random = seededRandom(hashText(visible));
|
||||||
const ticks: number[] = [];
|
const ticks: number[] = [];
|
||||||
|
|
|
||||||
48252
src/migrations/20261201_180344_add_npc_dialogue_typing_pace.json
Normal file
48252
src/migrations/20261201_180344_add_npc_dialogue_typing_pace.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||||
|
|
||||||
|
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
||||||
|
await db.execute(sql`
|
||||||
|
CREATE TYPE "public"."enum_npc_dialogue_settings_presentation_pacing" AS ENUM('subtle', 'natural', 'pronounced');
|
||||||
|
CREATE TYPE "public"."enum__npc_dialogue_settings_v_version_presentation_pacing" AS ENUM('subtle', 'natural', 'pronounced');
|
||||||
|
ALTER TABLE "npc_dialogue_settings" ADD COLUMN "presentation_pacing" "enum_npc_dialogue_settings_presentation_pacing" DEFAULT 'natural';
|
||||||
|
ALTER TABLE "_npc_dialogue_settings_v" ADD COLUMN "version_presentation_pacing" "enum__npc_dialogue_settings_v_version_presentation_pacing" DEFAULT 'natural';`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
||||||
|
await db.execute(sql`
|
||||||
|
ALTER TABLE "npc_dialogue_settings" DROP COLUMN "presentation_pacing";
|
||||||
|
ALTER TABLE "_npc_dialogue_settings_v" DROP COLUMN "version_presentation_pacing";
|
||||||
|
DROP TYPE "public"."enum_npc_dialogue_settings_presentation_pacing";
|
||||||
|
DROP TYPE "public"."enum__npc_dialogue_settings_v_version_presentation_pacing";`)
|
||||||
|
}
|
||||||
|
|
@ -171,6 +171,7 @@ import * as migration_20261124_223724_add_conversation_typewriter_setting from '
|
||||||
import * as migration_20261124_225400_add_conversation_voice_preference from './20261124_225400_add_conversation_voice_preference';
|
import * as migration_20261124_225400_add_conversation_voice_preference from './20261124_225400_add_conversation_voice_preference';
|
||||||
import * as migration_20261124_232253_add_npc_dialogue_testing_flag from './20261124_232253_add_npc_dialogue_testing_flag';
|
import * as migration_20261124_232253_add_npc_dialogue_testing_flag from './20261124_232253_add_npc_dialogue_testing_flag';
|
||||||
import * as migration_20261125_000236_add_dialogue_typing_sound_preference from './20261125_000236_add_dialogue_typing_sound_preference';
|
import * as migration_20261125_000236_add_dialogue_typing_sound_preference from './20261125_000236_add_dialogue_typing_sound_preference';
|
||||||
|
import * as migration_20261201_180344_add_npc_dialogue_typing_pace from './20261201_180344_add_npc_dialogue_typing_pace';
|
||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
{
|
{
|
||||||
|
|
@ -1036,6 +1037,11 @@ export const migrations = [
|
||||||
{
|
{
|
||||||
up: migration_20261125_000236_add_dialogue_typing_sound_preference.up,
|
up: migration_20261125_000236_add_dialogue_typing_sound_preference.up,
|
||||||
down: migration_20261125_000236_add_dialogue_typing_sound_preference.down,
|
down: migration_20261125_000236_add_dialogue_typing_sound_preference.down,
|
||||||
name: '20261125_000236_add_dialogue_typing_sound_preference'
|
name: '20261125_000236_add_dialogue_typing_sound_preference',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
up: migration_20261201_180344_add_npc_dialogue_typing_pace.up,
|
||||||
|
down: migration_20261201_180344_add_npc_dialogue_typing_pace.down,
|
||||||
|
name: '20261201_180344_add_npc_dialogue_typing_pace'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -159,12 +159,17 @@ describe("reveal pacing", () => {
|
||||||
const text = "Hold, trooper.";
|
const text = "Hold, trooper.";
|
||||||
const comma = text.indexOf(",");
|
const comma = text.indexOf(",");
|
||||||
|
|
||||||
|
// Each preset moves speed and pauses together, so a character and the pause
|
||||||
|
// after a comma both cost its own base.
|
||||||
expect(gapAfter(buildRevealSchedule(text, "subtle").arrival, comma)).toBe(
|
expect(gapAfter(buildRevealSchedule(text, "subtle").arrival, comma)).toBe(
|
||||||
BASE_UNIT_MS + subtle.clauseMs,
|
subtle.baseMs + subtle.clauseMs,
|
||||||
);
|
);
|
||||||
expect(gapAfter(buildRevealSchedule(text, "pronounced").arrival, comma)).toBe(
|
expect(gapAfter(buildRevealSchedule(text, "pronounced").arrival, comma)).toBe(
|
||||||
BASE_UNIT_MS + pronounced.clauseMs,
|
pronounced.baseMs + pronounced.clauseMs,
|
||||||
);
|
);
|
||||||
|
expect(subtle.baseMs).toBeLessThan(PACING_PRESETS.natural.baseMs);
|
||||||
|
expect(PACING_PRESETS.natural.baseMs).toBeLessThan(pronounced.baseMs);
|
||||||
|
expect(BASE_UNIT_MS).toBe(PACING_PRESETS.natural.baseMs);
|
||||||
expect(beatMs("subtle")).toBeLessThan(beatMs("natural"));
|
expect(beatMs("subtle")).toBeLessThan(beatMs("natural"));
|
||||||
expect(beatMs("natural")).toBeLessThan(beatMs("pronounced"));
|
expect(beatMs("natural")).toBeLessThan(beatMs("pronounced"));
|
||||||
expect(beatMs("unknown" as never)).toBe(beatMs("natural"));
|
expect(beatMs("unknown" as never)).toBe(beatMs("natural"));
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ beforeAll(async () => {
|
||||||
const update = (data: {
|
const update = (data: {
|
||||||
voice?: string | null;
|
voice?: string | null;
|
||||||
extraRules?: string | null;
|
extraRules?: string | null;
|
||||||
presentation?: { typewriterDefault?: boolean | null };
|
presentation?: { typewriterDefault?: boolean | null; pacing?: string | null };
|
||||||
}) =>
|
}) =>
|
||||||
payload.updateGlobal({
|
payload.updateGlobal({
|
||||||
slug: "npc-dialogue-settings",
|
slug: "npc-dialogue-settings",
|
||||||
|
|
@ -109,6 +109,7 @@ describe("npc-dialogue-settings global", () => {
|
||||||
extraRules: null,
|
extraRules: null,
|
||||||
revision: null,
|
revision: null,
|
||||||
typewriterDefault: true,
|
typewriterDefault: true,
|
||||||
|
pacing: "natural",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -127,4 +128,24 @@ describe("npc-dialogue-settings global", () => {
|
||||||
expect(on.revision).toBe(revision);
|
expect(on.revision).toBe(revision);
|
||||||
expect((await loadDialogueSettings(payload)).typewriterDefault).toBe(true);
|
expect((await loadDialogueSettings(payload)).typewriterDefault).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("carries the typing pace, and falls back to natural for a value it does not know", async () => {
|
||||||
|
const voice = unique("Unchanged by pace.");
|
||||||
|
const before = await update({ voice, presentation: { pacing: "pronounced" } });
|
||||||
|
expect((await loadDialogueSettings(payload)).pacing).toBe("pronounced");
|
||||||
|
// Pace is presentation, not prompt copy: stored drafts are unaffected.
|
||||||
|
expect(before.revision).toBe((await loadDialogueSettings(payload)).revision);
|
||||||
|
|
||||||
|
// A row written with a value this build does not know (an older or newer
|
||||||
|
// admin) must still render at a real pace rather than none.
|
||||||
|
const stale = await loadDialogueSettings({
|
||||||
|
findGlobal: async () => ({ presentation: { pacing: "molasses" } }),
|
||||||
|
logger: { warn: () => undefined },
|
||||||
|
} as unknown as Payload);
|
||||||
|
expect(stale.pacing).toBe("natural");
|
||||||
|
|
||||||
|
await update({ presentation: { pacing: "subtle" } });
|
||||||
|
expect((await loadDialogueSettings(payload)).pacing).toBe("subtle");
|
||||||
|
await update({ presentation: { pacing: "natural" } });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue