Conversation lines appeared whole after a length-based pause with bouncing
dots. They now type themselves out, and the player can finish a line by
clicking it.
Control is two-tier: npc-dialogue-settings.presentation.typewriterDefault sets
the unit default, users.preferences.dialogue.typewriter (default/on/off) lets a
player override it either way. prefers-reduced-motion turns the animation off
regardless. Changing the unit setting does not bump the prompt revision, since
it is not prompt text.
The reveal truncates the rendered strings rather than the source, so a
half-typed line can never flash {amber} or an unclosed **. visibleLength()
gives pacing the same count, and the choice footer waits for the reveal to
land so nobody answers a line they have not seen.
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { normalizeTypewriterPreference, resolveTypewriter } from "@/lib/npc-dialogue/presentation";
|
|
|
|
describe("typewriter preference resolution", () => {
|
|
it("follows the unit default unless the player chose otherwise", () => {
|
|
for (const preference of [undefined, null, "default", "nonsense"]) {
|
|
expect(resolveTypewriter(preference, true)).toBe(true);
|
|
expect(resolveTypewriter(preference, false)).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("lets the player override the unit default in both directions", () => {
|
|
// Someone who dislikes the animation can turn it off even when it is on by
|
|
// default, and someone who wants it keeps it when the unit turns it off.
|
|
expect(resolveTypewriter("off", true)).toBe(false);
|
|
expect(resolveTypewriter("on", false)).toBe(true);
|
|
expect(resolveTypewriter("on", true)).toBe(true);
|
|
expect(resolveTypewriter("off", false)).toBe(false);
|
|
});
|
|
|
|
it("coerces stored values to a known preference", () => {
|
|
expect(normalizeTypewriterPreference("on")).toBe("on");
|
|
expect(normalizeTypewriterPreference("off")).toBe("off");
|
|
expect(normalizeTypewriterPreference("default")).toBe("default");
|
|
expect(normalizeTypewriterPreference(undefined)).toBe("default");
|
|
expect(normalizeTypewriterPreference("yes")).toBe("default");
|
|
});
|
|
});
|