Finish the NPC dialogue flowchart work carried over from the base commit:
- Coloured NPC dialogue text via friendly names ({red}) or hex ({#ff00ff});
invalid names/hex render as literal text. Shared client-safe renderer
(DialogueText.tsx) used by both the admin canvas preview and the runtime.
- Player-flags feature: condition nodes branch on flags (evaluated
server-side), flag effects set/clear/adjust flags, PlayerFlags collection
+ migration, and event nodes can set flags.
- One-time ("once") choices: a choice flagged "Hide after picked" is hidden
for the rest of the current conversation only (per-session, resets on
begin()); GMs can persist across conversations with a condition flag.
- Admin editor: colour hint, once checkbox on choices, amber "once" badge.
Migration repair: the player_flags migration (20261005_185014) was sorting
before 20261006_000000, whose stale snapshot omitted player_flags, so any
future `migrate:create` re-emitted player_flags DDL. Restored 20261006_000000's
snapshot to the full current schema so it is the correct diff base.
Verified: `bun run payload migrate` clean, `migrate:create` reports no
schema changes, `tsc --noEmit` clean.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { DOSSIER } from "@/components/frontend/operations";
|
|
import {
|
|
formatActivityLine,
|
|
resolveCurrentActivity,
|
|
type NpcActivityOption,
|
|
} from "@/lib/npcs/activity";
|
|
|
|
interface NpcActivityLineProps {
|
|
/** How often (minutes) the activity reshuffles when nothing is forced. */
|
|
readonly intervalMinutes: number;
|
|
/** The contact's possible activities. */
|
|
readonly activityOptions: NpcActivityOption[];
|
|
}
|
|
|
|
/**
|
|
* Reads the contact's "current activity" and reshuffles it on the configured
|
|
* interval. A forced activity stays put until the flag is turned off.
|
|
*/
|
|
export function NpcActivityLine({ intervalMinutes, activityOptions }: NpcActivityLineProps) {
|
|
const [tick, setTick] = useState(0);
|
|
const reshuffle = intervalMinutes > 0 && activityOptions.length > 0;
|
|
|
|
useEffect(() => {
|
|
if (!reshuffle) return;
|
|
const interval = setInterval(() => setTick((prev) => prev + 1), intervalMinutes * 60_000);
|
|
return () => clearInterval(interval);
|
|
}, [intervalMinutes, reshuffle]);
|
|
|
|
const activity = resolveCurrentActivity(activityOptions, reshuffle ? `tick-${tick}` : undefined);
|
|
|
|
return (
|
|
// leading-none keeps the label and chip off the inherited (tall) line-height,
|
|
// so the chip matches the NpcStatusChips tags below it.
|
|
<div className="flex items-center gap-3 leading-none">
|
|
<span className={DOSSIER.readoutLabel}>Activity</span>
|
|
<span className={DOSSIER.chip}>{formatActivityLine(activity)}</span>
|
|
</div>
|
|
);
|
|
}
|