feat(npc): complete dialogue feature and fix migration snapshot base
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.
This commit is contained in:
parent
2a3ad57bce
commit
ac6415d034
21 changed files with 38994 additions and 169 deletions
|
|
@ -57,6 +57,7 @@ Known pre-existing errors (not yours, don't widen scope to fix them): `src/colle
|
||||||
- Stale dev processes: killing the process is not always enough; remove `.next/dev/devserver.lock` before restarting.
|
- Stale dev processes: killing the process is not always enough; remove `.next/dev/devserver.lock` before restarting.
|
||||||
- For browser/UI verification, make a reasonable attempt with Playwright. If the browser tooling is unavailable or repeatedly unreliable, stop rather than spending excessive effort on it and defer the manual UI check to the user.
|
- For browser/UI verification, make a reasonable attempt with Playwright. If the browser tooling is unavailable or repeatedly unreliable, stop rather than spending excessive effort on it and defer the manual UI check to the user.
|
||||||
- **Browser tool tab hygiene (OpenChamber)**: when driving the in-app browser, reuse a SINGLE tab. Call `browser.open` once to obtain a `tabId`, then pass that same `tabId` to every subsequent `browser.open` / `browser.snapshot` / `browser.click` / `browser.type` / `browser.capture` / `browser.inspect` call. Calling `browser.open` without a `tabId` opens a NEW tab every time and litters the panel; the tool has no close-tab action, so minimize new tabs by reusing one (re-read the tab list from a snapshot when a `tabId` goes stale, and reuse the matching existing tab rather than opening another).
|
- **Browser tool tab hygiene (OpenChamber)**: when driving the in-app browser, reuse a SINGLE tab. Call `browser.open` once to obtain a `tabId`, then pass that same `tabId` to every subsequent `browser.open` / `browser.snapshot` / `browser.click` / `browser.type` / `browser.capture` / `browser.inspect` call. Calling `browser.open` without a `tabId` opens a NEW tab every time and litters the panel; the tool has no close-tab action, so minimize new tabs by reusing one (re-read the tab list from a snapshot when a `tabId` goes stale, and reuse the matching existing tab rather than opening another).
|
||||||
|
- **Capture verification (OpenChamber)**: `browser.capture` returning `ok` only means a file was written, NOT that the page looks right. `read` the captured image and confirm it shows your change before reporting success. Next dev error overlays persist after the code is fixed (the devtools badge reads "stale"): reload the page, re-capture, and inspect again before concluding anything. After swapping a symbol (e.g. a lucide icon import), grep the file for the old name to catch missed usages like JSX elements.
|
||||||
|
|
||||||
## Agent debugging SOP (read before fixing any bug)
|
## Agent debugging SOP (read before fixing any bug)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,12 @@ import type { User } from "@/payload-types";
|
||||||
import { emitGameEvent } from "@/utils/event-log/emit";
|
import { emitGameEvent } from "@/utils/event-log/emit";
|
||||||
import { EventTypes } from "@/utils/event-log/eventTypes";
|
import { EventTypes } from "@/utils/event-log/eventTypes";
|
||||||
import { notifyUser } from "@/lib/notifications";
|
import { notifyUser } from "@/lib/notifications";
|
||||||
import type { FlowData, NpcDialogueEffect } from "@/lib/npc-dialogue/dialogue";
|
import type {
|
||||||
|
DialogueCondition,
|
||||||
|
DialogueFlagOp,
|
||||||
|
FlowData,
|
||||||
|
NpcDialogueEffect,
|
||||||
|
} from "@/lib/npc-dialogue/dialogue";
|
||||||
|
|
||||||
interface ActionResult<T = undefined> {
|
interface ActionResult<T = undefined> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
|
|
@ -114,5 +119,193 @@ async function runEffect(
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "flag": {
|
||||||
|
const key = effect.flagKey?.trim();
|
||||||
|
if (!key) break;
|
||||||
|
const op: DialogueFlagOp = effect.flagOp ?? "set_true";
|
||||||
|
const amount = effect.flagAmount ?? 0;
|
||||||
|
await applyFlagEffect(payload, userId, key, op, amount);
|
||||||
|
await emitGameEvent(payload, {
|
||||||
|
type: EventTypes.NpcDialogue,
|
||||||
|
message: `Conversation set flag "${key}" (${op}).`,
|
||||||
|
actor: userId,
|
||||||
|
targetCollection: "game-npcs",
|
||||||
|
targetId: npcId,
|
||||||
|
data: { effect: "flag", key, op, amount },
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Effective value of a player flag: missing flags read false / 0. */
|
||||||
|
async function readFlag(
|
||||||
|
payload: Awaited<ReturnType<typeof getPayload>>,
|
||||||
|
userId: number,
|
||||||
|
key: string,
|
||||||
|
): Promise<{ bool: boolean; num: number }> {
|
||||||
|
const res = await payload.find({
|
||||||
|
collection: "player-flags",
|
||||||
|
where: {
|
||||||
|
user: { equals: userId },
|
||||||
|
key: { equals: key },
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
const doc = res.docs[0];
|
||||||
|
if (!doc) return { bool: false, num: 0 };
|
||||||
|
if (doc.flagType === "number") {
|
||||||
|
const num = doc.numberValue ?? 0;
|
||||||
|
return { bool: num !== 0, num };
|
||||||
|
}
|
||||||
|
const bool = doc.boolValue === true;
|
||||||
|
return { bool, num: bool ? 1 : 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create-or-update a player flag according to the effect's write mode. */
|
||||||
|
async function applyFlagEffect(
|
||||||
|
payload: Awaited<ReturnType<typeof getPayload>>,
|
||||||
|
userId: number,
|
||||||
|
key: string,
|
||||||
|
op: DialogueFlagOp,
|
||||||
|
amount: number,
|
||||||
|
): Promise<void> {
|
||||||
|
const existing = await payload.find({
|
||||||
|
collection: "player-flags",
|
||||||
|
where: {
|
||||||
|
user: { equals: userId },
|
||||||
|
key: { equals: key },
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
const doc = existing.docs[0];
|
||||||
|
|
||||||
|
if (op === "set_true" || op === "set_false") {
|
||||||
|
const boolValue = op === "set_true";
|
||||||
|
if (doc) {
|
||||||
|
await payload.update({
|
||||||
|
collection: "player-flags",
|
||||||
|
id: doc.id,
|
||||||
|
data: { flagType: "boolean", boolValue },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await payload.create({
|
||||||
|
collection: "player-flags",
|
||||||
|
data: { user: userId, key, flagType: "boolean", boolValue },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (op === "set_number") {
|
||||||
|
if (doc) {
|
||||||
|
await payload.update({
|
||||||
|
collection: "player-flags",
|
||||||
|
id: doc.id,
|
||||||
|
data: { flagType: "number", numberValue: amount },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await payload.create({
|
||||||
|
collection: "player-flags",
|
||||||
|
data: { user: userId, key, flagType: "number", numberValue: amount },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add: numeric flags accumulate; boolean flags convert (true = 1).
|
||||||
|
const current = doc
|
||||||
|
? doc.flagType === "number"
|
||||||
|
? doc.numberValue ?? 0
|
||||||
|
: doc.boolValue
|
||||||
|
? 1
|
||||||
|
: 0
|
||||||
|
: 0;
|
||||||
|
const numberValue = current + amount;
|
||||||
|
if (doc) {
|
||||||
|
await payload.update({
|
||||||
|
collection: "player-flags",
|
||||||
|
id: doc.id,
|
||||||
|
data: { flagType: "number", numberValue },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await payload.create({
|
||||||
|
collection: "player-flags",
|
||||||
|
data: { user: userId, key, flagType: "number", numberValue },
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate a dialogue `condition` node against the reading user's live
|
||||||
|
* web-app state (player flags). The node is looked up server-side from the
|
||||||
|
* stored flowchart, so the client can only evaluate conditions an admin
|
||||||
|
* authored for this conversation.
|
||||||
|
*/
|
||||||
|
export async function evaluateNpcDialogueCondition(
|
||||||
|
npcId: number,
|
||||||
|
nodeId: string,
|
||||||
|
): Promise<ActionResult<boolean>> {
|
||||||
|
try {
|
||||||
|
const { payload, user } = await authenticate();
|
||||||
|
|
||||||
|
const res = await payload.find({
|
||||||
|
collection: "npc-dialogues",
|
||||||
|
where: { npc: { equals: npcId } },
|
||||||
|
limit: 1,
|
||||||
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
const flowData = res.docs[0]?.flowData as unknown as FlowData | undefined;
|
||||||
|
const node = flowData?.nodes?.find((n) => n.id === nodeId);
|
||||||
|
if (!node || node.type !== "condition" || !node.data.condition) {
|
||||||
|
// Not a condition node: nothing to branch on.
|
||||||
|
return { success: true, data: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = await evaluateCondition(payload, user.id as number, node.data.condition);
|
||||||
|
return { success: true, data: value };
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
if (message === "Unauthorized") {
|
||||||
|
return { success: false, error: "You must be logged in." };
|
||||||
|
}
|
||||||
|
return { success: false, error: message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function evaluateCondition(
|
||||||
|
payload: Awaited<ReturnType<typeof getPayload>>,
|
||||||
|
userId: number,
|
||||||
|
condition: DialogueCondition,
|
||||||
|
): Promise<boolean> {
|
||||||
|
const flag = await readFlag(payload, userId, condition.key);
|
||||||
|
const amount = condition.amount ?? 0;
|
||||||
|
switch (condition.op) {
|
||||||
|
case "is_true":
|
||||||
|
return flag.bool;
|
||||||
|
case "is_false":
|
||||||
|
return !flag.bool;
|
||||||
|
case "gte":
|
||||||
|
return flag.num >= amount;
|
||||||
|
case "lte":
|
||||||
|
return flag.num <= amount;
|
||||||
|
case "gt":
|
||||||
|
return flag.num > amount;
|
||||||
|
case "lt":
|
||||||
|
return flag.num < amount;
|
||||||
|
case "eq":
|
||||||
|
return flag.num === amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,7 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
|
||||||
<NpcProfile
|
<NpcProfile
|
||||||
npc={npc}
|
npc={npc}
|
||||||
listings={listings}
|
listings={listings}
|
||||||
|
conversationSlot={<NpcConversation npc={npc} dialogue={dialogue} />}
|
||||||
employmentSlot={
|
employmentSlot={
|
||||||
<EmploymentCard
|
<EmploymentCard
|
||||||
employment={employment}
|
employment={employment}
|
||||||
|
|
@ -175,8 +176,6 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<NpcConversation npc={npc} dialogue={dialogue} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,24 @@
|
||||||
a { color: rgba(255, 255, 255, 0.35); }
|
a { color: rgba(255, 255, 255, 0.35); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NPC dialogue canvas: the default 1px grey drag line vanishes on the dark
|
||||||
|
canvas, so make the in-progress connection a bright cyan laser. */
|
||||||
|
.npc-dialogue-flow {
|
||||||
|
.react-flow__connection-path {
|
||||||
|
stroke: #22d3ee;
|
||||||
|
stroke-width: 2.5;
|
||||||
|
stroke-dasharray: 6 4;
|
||||||
|
filter: drop-shadow(0 0 4px rgba(34, 211, 238, 0.7));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make drop-target handles obvious on hover. */
|
||||||
|
.react-flow__handle.connectionindicator:hover {
|
||||||
|
background: #22d3ee;
|
||||||
|
border-color: #22d3ee;
|
||||||
|
box-shadow: 0 0 6px rgba(34, 211, 238, 0.9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Tech Tree: dark thin scrollbars for the panel and its dropdowns. */
|
/* Tech Tree: dark thin scrollbars for the panel and its dropdowns. */
|
||||||
.tech-tree-scroll {
|
.tech-tree-scroll {
|
||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
|
|
|
||||||
74
src/collections/game/PlayerFlags.ts
Normal file
74
src/collections/game/PlayerFlags.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
import { CollectionConfig } from "payload";
|
||||||
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic per-player flags: the lightweight state layer conversations branch
|
||||||
|
* on. Event nodes write them (set / add), condition nodes read them. GMs can
|
||||||
|
* also seed or correct them here in the admin panel.
|
||||||
|
*/
|
||||||
|
export const PlayerFlags: CollectionConfig = {
|
||||||
|
slug: "player-flags",
|
||||||
|
admin: {
|
||||||
|
group: "Game",
|
||||||
|
useAsTitle: "key",
|
||||||
|
listSearchableFields: ["key"],
|
||||||
|
defaultColumns: ["user", "key", "flagType"],
|
||||||
|
pagination: { defaultLimit: 50 },
|
||||||
|
},
|
||||||
|
access: {
|
||||||
|
read: requirePermission("player-flags:read"),
|
||||||
|
create: requirePermission("player-flags:create"),
|
||||||
|
update: requirePermission("player-flags:update"),
|
||||||
|
delete: requirePermission("player-flags:delete"),
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "user",
|
||||||
|
type: "relationship",
|
||||||
|
relationTo: "users",
|
||||||
|
required: true,
|
||||||
|
admin: {
|
||||||
|
description: "The player this flag belongs to.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "key",
|
||||||
|
type: "text",
|
||||||
|
required: true,
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"Stable key referenced by conversation nodes (e.g. 'met_informant', 'rep_merchants'). Lowercase with underscores.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "flagType",
|
||||||
|
type: "select",
|
||||||
|
required: true,
|
||||||
|
defaultValue: "boolean",
|
||||||
|
options: ["boolean", "number"],
|
||||||
|
admin: {
|
||||||
|
description: "Boolean flags read as true/false; numeric flags track statistics.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "boolValue",
|
||||||
|
type: "checkbox",
|
||||||
|
defaultValue: true,
|
||||||
|
admin: {
|
||||||
|
condition: (_data, blockData) => blockData?.flagType === "boolean",
|
||||||
|
description: "A missing boolean flag counts as false.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "numberValue",
|
||||||
|
type: "number",
|
||||||
|
defaultValue: 0,
|
||||||
|
admin: {
|
||||||
|
condition: (_data, blockData) => blockData?.flagType === "number",
|
||||||
|
description: "A missing numeric flag counts as 0.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
timestamps: true,
|
||||||
|
indexes: [{ fields: ["user", "key"], unique: true }],
|
||||||
|
};
|
||||||
|
|
@ -17,6 +17,8 @@ import { Label } from "@/components/ui/label";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
DialogueCondition,
|
||||||
|
DialogueFlagOp,
|
||||||
DialogueNext,
|
DialogueNext,
|
||||||
DialogueNode,
|
DialogueNode,
|
||||||
DialogueNodeData,
|
DialogueNodeData,
|
||||||
|
|
@ -38,17 +40,65 @@ const EFFECT_LABELS: Record<NpcDialogueEffect["type"], string> = {
|
||||||
notify: "Notify user (in-app)",
|
notify: "Notify user (in-app)",
|
||||||
emit: "Log game event",
|
emit: "Log game event",
|
||||||
reward: "Reward (unconfigured)",
|
reward: "Reward (unconfigured)",
|
||||||
|
flag: "Set player flag",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Short readable label for a node in the target pickers. */
|
const FLAG_OP_LABELS: Record<DialogueFlagOp, string> = {
|
||||||
|
set_true: "Set to true",
|
||||||
|
set_false: "Set to false",
|
||||||
|
set_number: "Set number to",
|
||||||
|
add: "Add to number",
|
||||||
|
};
|
||||||
|
|
||||||
|
const CONDITION_OP_LABELS: Record<DialogueCondition["op"], string> = {
|
||||||
|
is_true: "is true",
|
||||||
|
is_false: "is false",
|
||||||
|
gte: "is at least",
|
||||||
|
lte: "is at most",
|
||||||
|
gt: "is greater than",
|
||||||
|
lt: "is less than",
|
||||||
|
eq: "equals",
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Ops that compare against a number (everything except is_true/is_false). */
|
||||||
|
const NUMERIC_OPS: DialogueCondition["op"][] = ["gte", "lte", "gt", "lt", "eq"];
|
||||||
|
|
||||||
|
/** Short readable label for a node in the target pickers, with a text snippet. */
|
||||||
function nodeLabel(node: DialogueNode): string {
|
function nodeLabel(node: DialogueNode): string {
|
||||||
const preview =
|
const d = node.data;
|
||||||
node.data.speaker ||
|
let preview: string;
|
||||||
node.data.body ||
|
switch (node.type) {
|
||||||
node.data.leadIn ||
|
case "dialogue": {
|
||||||
node.data.closing ||
|
const speaker = d.speaker?.trim();
|
||||||
node.id.slice(0, 8);
|
const body = d.body?.trim();
|
||||||
const trimmed = preview.length > 28 ? `${preview.slice(0, 28)}…` : preview;
|
preview = speaker && body ? `${speaker}: ${body}` : speaker || body || "Empty line";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "choice": {
|
||||||
|
const lead = d.leadIn?.trim();
|
||||||
|
const count = d.choices?.length ?? 0;
|
||||||
|
const tail = `${count} choice${count === 1 ? "" : "s"}`;
|
||||||
|
preview = lead ? `${lead} (${tail})` : tail;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "event":
|
||||||
|
preview =
|
||||||
|
d.body?.trim() ||
|
||||||
|
d.effect?.message?.trim() ||
|
||||||
|
(d.effect ? EFFECT_LABELS[d.effect.type] : "Narration");
|
||||||
|
break;
|
||||||
|
case "delay":
|
||||||
|
preview = d.delaySeconds ? `${d.delaySeconds}s pause` : "Pause";
|
||||||
|
break;
|
||||||
|
case "condition": {
|
||||||
|
const c = d.condition;
|
||||||
|
preview = c ? `flag "${c.key || "?"}" ${CONDITION_OP_LABELS[c.op]}` : "Condition";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
preview = d.closing?.trim() || "Conversation ends";
|
||||||
|
}
|
||||||
|
const trimmed = preview.length > 48 ? `${preview.slice(0, 48)}…` : preview;
|
||||||
return `${node.type} · ${trimmed}`;
|
return `${node.type} · ${trimmed}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,6 +118,11 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
const patchEffect = (partial: Partial<NpcDialogueEffect>) =>
|
const patchEffect = (partial: Partial<NpcDialogueEffect>) =>
|
||||||
patch({ effect: { type: "notify", ...draft.effect, ...partial } });
|
patch({ effect: { type: "notify", ...draft.effect, ...partial } });
|
||||||
|
|
||||||
|
const patchCondition = (partial: Partial<DialogueCondition>) =>
|
||||||
|
patch({
|
||||||
|
condition: { kind: "flag", key: "", op: "is_true", ...draft.condition, ...partial },
|
||||||
|
});
|
||||||
|
|
||||||
const setChoice = (index: number, next: DialogueNext) =>
|
const setChoice = (index: number, next: DialogueNext) =>
|
||||||
patch({ choices: (draft.choices ?? []).map((choice, i) => (i === index ? next : choice)) });
|
patch({ choices: (draft.choices ?? []).map((choice, i) => (i === index ? next : choice)) });
|
||||||
|
|
||||||
|
|
@ -100,13 +155,13 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="flex flex-col gap-4 pt-2">
|
<div className="flex flex-col gap-4 pt-2">
|
||||||
{(node.type === "dialogue" || node.type === "event") && (
|
{node.type === "dialogue" && (
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label className="text-[10px] uppercase tracking-wider text-white/50">Speaker</Label>
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Speaker</Label>
|
||||||
<Input
|
<Input
|
||||||
value={draft.speaker ?? ""}
|
value={draft.speaker ?? ""}
|
||||||
onChange={(e) => patch({ speaker: e.target.value || undefined })}
|
onChange={(e) => patch({ speaker: e.target.value || undefined })}
|
||||||
placeholder="NPC"
|
placeholder="Defaults to the NPC's name"
|
||||||
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -122,6 +177,11 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
rows={4}
|
rows={4}
|
||||||
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
/>
|
/>
|
||||||
|
<p className="text-[10px] text-white/40">
|
||||||
|
Line breaks are kept. **bold**, *italic*, {`{red}color{/}`} and {'`code`'} render
|
||||||
|
in the conversation. Colors take a friendly name (red, amber, cyan, emerald,
|
||||||
|
violet, pink, slate, ...) or a hex code like {`{#ff00ff}`}.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -179,6 +239,19 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<label className="flex items-center gap-2 text-xs text-white/60">
|
||||||
|
<Checkbox
|
||||||
|
checked={choice.once === true}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
setChoice(index, {
|
||||||
|
...choice,
|
||||||
|
once: checked === true ? true : undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="border-white/30 data-[state=checked]:border-cyan-500 data-[state=checked]:bg-cyan-500"
|
||||||
|
/>
|
||||||
|
Hide after picked (one-time choice)
|
||||||
|
</label>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
@ -199,13 +272,31 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
|
|
||||||
{node.type === "event" && (
|
{node.type === "event" && (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Narration
|
||||||
|
</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.body ?? ""}
|
||||||
|
onChange={(e) => patch({ body: e.target.value || undefined })}
|
||||||
|
placeholder="Describe what happens. Shown as a speaker-less narrative line."
|
||||||
|
rows={3}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label className="text-[10px] uppercase tracking-wider text-white/50">Effect</Label>
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Effect</Label>
|
||||||
<select
|
<select
|
||||||
value={draft.effect?.type ?? "notify"}
|
value={draft.effect?.type ?? "none"}
|
||||||
onChange={(e) => patchEffect({ type: e.target.value as NpcDialogueEffect["type"] })}
|
onChange={(e) => {
|
||||||
|
const type = e.target.value;
|
||||||
|
if (type === "none") patch({ effect: undefined });
|
||||||
|
else patchEffect({ type: type as NpcDialogueEffect["type"] });
|
||||||
|
}}
|
||||||
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
>
|
>
|
||||||
|
<option value="none">None (narration only)</option>
|
||||||
{EFFECT_TYPES.map((type) => (
|
{EFFECT_TYPES.map((type) => (
|
||||||
<option key={type} value={type}>
|
<option key={type} value={type}>
|
||||||
{EFFECT_LABELS[type]}
|
{EFFECT_LABELS[type]}
|
||||||
|
|
@ -223,15 +314,173 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{draft.effect?.type === "flag" && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Flag key
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
value={draft.effect.flagKey ?? ""}
|
||||||
|
onChange={(e) => patchEffect({ flagKey: e.target.value || undefined })}
|
||||||
|
placeholder="met_informant"
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Write
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
value={draft.effect.flagOp ?? "set_true"}
|
||||||
|
onChange={(e) =>
|
||||||
|
patchEffect({ flagOp: e.target.value as DialogueFlagOp })
|
||||||
|
}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
{(Object.keys(FLAG_OP_LABELS) as DialogueFlagOp[]).map((op) => (
|
||||||
|
<option key={op} value={op}>
|
||||||
|
{FLAG_OP_LABELS[op]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{(draft.effect.flagOp === "set_number" ||
|
||||||
|
draft.effect.flagOp === "add") && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Amount
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={draft.effect.flagAmount ?? 0}
|
||||||
|
onChange={(e) =>
|
||||||
|
patchEffect({ flagAmount: Number(e.target.value) || 0 })
|
||||||
|
}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<p className="text-[10px] text-white/40">
|
||||||
|
Creates the flag when the player does not have it yet. "Add" keeps numeric
|
||||||
|
flags running totals.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{draft.effect && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Message</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.effect.message ?? ""}
|
||||||
|
onChange={(e) => patchEffect({ message: e.target.value || undefined })}
|
||||||
|
placeholder="What happens when the player reaches this node?"
|
||||||
|
rows={3}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{node.type === "delay" && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Pause (seconds)
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={0.5}
|
||||||
|
value={draft.delaySeconds ?? 2}
|
||||||
|
onChange={(e) =>
|
||||||
|
patch({ delaySeconds: Math.max(0, Number(e.target.value) || 0) })
|
||||||
|
}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white"
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-white/40">
|
||||||
|
The conversation shows typing dots for this long, then continues.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{node.type === "condition" && (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label className="text-[10px] uppercase tracking-wider text-white/50">Message</Label>
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
<Textarea
|
Flag key
|
||||||
value={draft.effect?.message ?? ""}
|
</Label>
|
||||||
onChange={(e) => patchEffect({ message: e.target.value || undefined })}
|
<Input
|
||||||
placeholder="What happens when the player reaches this node?"
|
value={draft.condition?.key ?? ""}
|
||||||
rows={3}
|
onChange={(e) => patchCondition({ key: e.target.value })}
|
||||||
|
placeholder="met_informant"
|
||||||
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
/>
|
/>
|
||||||
|
<p className="text-[10px] text-white/40">
|
||||||
|
Checked against the player's flags. A missing flag counts as false / 0.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
When the flag
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
value={draft.condition?.op ?? "is_true"}
|
||||||
|
onChange={(e) => patchCondition({ op: e.target.value as DialogueCondition["op"] })}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
{(Object.keys(CONDITION_OP_LABELS) as DialogueCondition["op"][]).map((op) => (
|
||||||
|
<option key={op} value={op}>
|
||||||
|
{CONDITION_OP_LABELS[op]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{NUMERIC_OPS.includes(draft.condition?.op ?? "is_true") && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Amount
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={draft.condition?.amount ?? 0}
|
||||||
|
onChange={(e) => patchCondition({ amount: Number(e.target.value) || 0 })}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
True branch goes to
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
value={draft.trueTarget ?? ""}
|
||||||
|
onChange={(e) => patch({ trueTarget: e.target.value || undefined })}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
<option value="">Nothing (ends here)</option>
|
||||||
|
{targetOptions.map((target) => (
|
||||||
|
<option key={target.id} value={target.id}>
|
||||||
|
{nodeLabel(target)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
False branch goes to
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
value={draft.falseTarget ?? ""}
|
||||||
|
onChange={(e) => patch({ falseTarget: e.target.value || undefined })}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
<option value="">Nothing (ends here)</option>
|
||||||
|
{targetOptions.map((target) => (
|
||||||
|
<option key={target.id} value={target.id}>
|
||||||
|
{nodeLabel(target)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -249,7 +498,7 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(node.type === "dialogue" || node.type === "event") && (
|
{(node.type === "dialogue" || node.type === "event" || node.type === "delay") && (
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
Continues to
|
Continues to
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ const nodeTypes = {
|
||||||
dialogue: NpcDialogueNode,
|
dialogue: NpcDialogueNode,
|
||||||
choice: NpcDialogueNode,
|
choice: NpcDialogueNode,
|
||||||
event: NpcDialogueNode,
|
event: NpcDialogueNode,
|
||||||
|
delay: NpcDialogueNode,
|
||||||
|
condition: NpcDialogueNode,
|
||||||
end: NpcDialogueNode,
|
end: NpcDialogueNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -39,6 +41,8 @@ const NODE_LABELS: Record<NpcDialogueNodeType, string> = {
|
||||||
dialogue: "Dialogue",
|
dialogue: "Dialogue",
|
||||||
choice: "Choice",
|
choice: "Choice",
|
||||||
event: "Event",
|
event: "Event",
|
||||||
|
delay: "Delay",
|
||||||
|
condition: "Condition",
|
||||||
end: "End",
|
end: "End",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -46,6 +50,8 @@ const DEFAULT_DATA: Record<string, DialogueNodeData> = {
|
||||||
dialogue: { speaker: "NPC", body: "" },
|
dialogue: { speaker: "NPC", body: "" },
|
||||||
choice: { choices: [] },
|
choice: { choices: [] },
|
||||||
event: { effect: { type: "notify", message: "" } },
|
event: { effect: { type: "notify", message: "" } },
|
||||||
|
delay: { delaySeconds: 2 },
|
||||||
|
condition: { condition: { kind: "flag", key: "", op: "is_true" } },
|
||||||
end: {},
|
end: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -62,6 +68,7 @@ export function NpcDialogueEditor() {
|
||||||
const [contextMenu, setContextMenu] = useState<ContextMenu>(null);
|
const [contextMenu, setContextMenu] = useState<ContextMenu>(null);
|
||||||
|
|
||||||
const lastSerialized = useRef<string>("");
|
const lastSerialized = useRef<string>("");
|
||||||
|
const menuRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
// Edges are a derived projection of the node data, never edited directly.
|
// Edges are a derived projection of the node data, never edited directly.
|
||||||
const syncedEdges = useMemo<Edge[]>(
|
const syncedEdges = useMemo<Edge[]>(
|
||||||
|
|
@ -121,6 +128,8 @@ export function NpcDialogueEditor() {
|
||||||
...n.data,
|
...n.data,
|
||||||
next: n.data.next && n.data.next.target !== nodeId ? n.data.next : undefined,
|
next: n.data.next && n.data.next.target !== nodeId ? n.data.next : undefined,
|
||||||
choices: (n.data.choices ?? []).filter((c) => c.target !== nodeId),
|
choices: (n.data.choices ?? []).filter((c) => c.target !== nodeId),
|
||||||
|
trueTarget: n.data.trueTarget !== nodeId ? n.data.trueTarget : undefined,
|
||||||
|
falseTarget: n.data.falseTarget !== nodeId ? n.data.falseTarget : undefined,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
setNodes(next);
|
setNodes(next);
|
||||||
|
|
@ -139,6 +148,56 @@ export function NpcDialogueEditor() {
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Drag-to-connect writes into the node data (the graph's source of truth);
|
||||||
|
// edges stay a derived projection.
|
||||||
|
const applyConnection = useCallback(
|
||||||
|
(sourceId: string, targetId: string) => {
|
||||||
|
if (sourceId === targetId) return;
|
||||||
|
const all = nodes as DialogueNode[];
|
||||||
|
const source = all.find((n) => n.id === sourceId);
|
||||||
|
const target = all.find((n) => n.id === targetId);
|
||||||
|
if (!source || !target) return;
|
||||||
|
if (source.type === "end" || target.data.isStart) return;
|
||||||
|
const next = all.map((n) => {
|
||||||
|
if (n.id !== sourceId) return n;
|
||||||
|
if (n.type === "choice") {
|
||||||
|
return {
|
||||||
|
...n,
|
||||||
|
data: { ...n.data, choices: [...(n.data.choices ?? []), { label: "", target: targetId }] },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (n.type === "condition") {
|
||||||
|
// First connection wires the true branch, the second the false one.
|
||||||
|
if (n.data.trueTarget && n.data.falseTarget) return n;
|
||||||
|
return {
|
||||||
|
...n,
|
||||||
|
data: {
|
||||||
|
...n.data,
|
||||||
|
trueTarget: n.data.trueTarget ?? targetId,
|
||||||
|
falseTarget: n.data.trueTarget ? n.data.falseTarget : targetId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ...n, data: { ...n.data, next: { target: targetId } } };
|
||||||
|
});
|
||||||
|
setNodes(next);
|
||||||
|
serialize(next);
|
||||||
|
// A fresh choice has no button text yet: pop the editor so it can be
|
||||||
|
// typed immediately (validateGraph flags empty labels).
|
||||||
|
if (source.type === "choice") setEditingNodeId(sourceId);
|
||||||
|
},
|
||||||
|
[nodes, setNodes, serialize],
|
||||||
|
);
|
||||||
|
|
||||||
|
const isValidConnection = useCallback(
|
||||||
|
(c: Connection | Edge) => {
|
||||||
|
if (!c.source || !c.target || c.source === c.target) return false;
|
||||||
|
const target = (nodes as DialogueNode[]).find((n) => n.id === c.target);
|
||||||
|
return !!target && !target.data.isStart;
|
||||||
|
},
|
||||||
|
[nodes],
|
||||||
|
);
|
||||||
|
|
||||||
const onPaneClick = useCallback(() => setContextMenu(null), []);
|
const onPaneClick = useCallback(() => setContextMenu(null), []);
|
||||||
|
|
||||||
const validation = useMemo(() => validateGraph(nodes as DialogueNode[]), [nodes]);
|
const validation = useMemo(() => validateGraph(nodes as DialogueNode[]), [nodes]);
|
||||||
|
|
@ -150,7 +209,13 @@ export function NpcDialogueEditor() {
|
||||||
const onKey = (e: KeyboardEvent) => {
|
const onKey = (e: KeyboardEvent) => {
|
||||||
if (e.key === "Escape") closeMenu();
|
if (e.key === "Escape") closeMenu();
|
||||||
};
|
};
|
||||||
const onPtr = () => closeMenu();
|
// Ignore pointerdowns inside the menu itself: pointerdown fires before
|
||||||
|
// click, so closing here would unmount the menu before its buttons can
|
||||||
|
// ever receive the click.
|
||||||
|
const onPtr = (e: PointerEvent) => {
|
||||||
|
if (menuRef.current?.contains(e.target as globalThis.Node)) return;
|
||||||
|
closeMenu();
|
||||||
|
};
|
||||||
window.addEventListener("keydown", onKey);
|
window.addEventListener("keydown", onKey);
|
||||||
document.addEventListener("pointerdown", onPtr);
|
document.addEventListener("pointerdown", onPtr);
|
||||||
return () => {
|
return () => {
|
||||||
|
|
@ -186,6 +251,18 @@ export function NpcDialogueEditor() {
|
||||||
>
|
>
|
||||||
{NODE_LABELS.event}
|
{NODE_LABELS.event}
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${buttonClass} bg-violet-950 border-violet-700 text-violet-200 hover:bg-violet-900`}
|
||||||
|
onClick={() => addNode("delay")}
|
||||||
|
>
|
||||||
|
{NODE_LABELS.delay}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${buttonClass} bg-sky-950 border-sky-700 text-sky-200 hover:bg-sky-900`}
|
||||||
|
onClick={() => addNode("condition")}
|
||||||
|
>
|
||||||
|
{NODE_LABELS.condition}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`${buttonClass} bg-slate-950 border-slate-700 text-slate-200 hover:bg-slate-900`}
|
className={`${buttonClass} bg-slate-950 border-slate-700 text-slate-200 hover:bg-slate-900`}
|
||||||
onClick={() => addNode("end")}
|
onClick={() => addNode("end")}
|
||||||
|
|
@ -204,19 +281,36 @@ export function NpcDialogueEditor() {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="h-96 border border-zinc-700 rounded-b-md overflow-hidden bg-zinc-950">
|
<div className="npc-dialogue-flow h-96 border border-zinc-700 rounded-b-md overflow-hidden bg-zinc-950">
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
edges={syncedEdges}
|
edges={syncedEdges}
|
||||||
onNodesChange={onNodesChange}
|
onNodesChange={onNodesChange}
|
||||||
onConnect={(c: Connection) => void c}
|
onConnect={(c: Connection) => {
|
||||||
|
if (c.source && c.target) applyConnection(c.source, c.target);
|
||||||
|
}}
|
||||||
|
onConnectEnd={(event, connectionState) => {
|
||||||
|
// React Flow only resolves drops onto a handle. If the pointer
|
||||||
|
// was released over a node card instead, resolve that card
|
||||||
|
// ourselves so "drag onto the node" works as people expect.
|
||||||
|
if (!("fromNode" in connectionState)) return;
|
||||||
|
if (connectionState.toHandle) return; // dropped on a handle: onConnect leads
|
||||||
|
const sourceId = connectionState.fromNode?.id;
|
||||||
|
if (!sourceId) return;
|
||||||
|
const point = event as MouseEvent;
|
||||||
|
const element = document.elementFromPoint(point.clientX ?? 0, point.clientY ?? 0);
|
||||||
|
const nodeElement = element?.closest?.(".react-flow__node") as HTMLElement | null;
|
||||||
|
const targetId = nodeElement?.getAttribute("data-id");
|
||||||
|
if (!targetId || targetId === sourceId) return;
|
||||||
|
applyConnection(sourceId, targetId);
|
||||||
|
}}
|
||||||
|
isValidConnection={isValidConnection}
|
||||||
onNodeClick={(_e, node) => setEditingNodeId(node.id)}
|
onNodeClick={(_e, node) => setEditingNodeId(node.id)}
|
||||||
onNodeContextMenu={onNodeContextMenu}
|
onNodeContextMenu={onNodeContextMenu}
|
||||||
onPaneClick={onPaneClick}
|
onPaneClick={onPaneClick}
|
||||||
nodeTypes={nodeTypes}
|
nodeTypes={nodeTypes}
|
||||||
fitView
|
fitView
|
||||||
colorMode="dark"
|
colorMode="dark"
|
||||||
nodesConnectable={false}
|
|
||||||
defaultEdgeOptions={{ animated: true }}
|
defaultEdgeOptions={{ animated: true }}
|
||||||
proOptions={{ hideAttribution: true }}
|
proOptions={{ hideAttribution: true }}
|
||||||
>
|
>
|
||||||
|
|
@ -230,12 +324,14 @@ export function NpcDialogueEditor() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-[10px] text-zinc-500">
|
<p className="text-[10px] text-zinc-500">
|
||||||
Click a node to edit. Right-click to delete. Connect nodes by pointing a choice / continuation
|
Click a node to edit. Right-click to delete. Drag from a node's right handle onto
|
||||||
at the target node in the editor.
|
another node to connect them (a choice node gains a new choice; dialogue and event nodes
|
||||||
|
re-point their continuation).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{contextMenu && (
|
{contextMenu && (
|
||||||
<div
|
<div
|
||||||
|
ref={menuRef}
|
||||||
className="fixed z-50 min-w-[7rem] overflow-hidden rounded-md border border-zinc-700 bg-zinc-900 p-1 shadow-lg"
|
className="fixed z-50 min-w-[7rem] overflow-hidden rounded-md border border-zinc-700 bg-zinc-900 p-1 shadow-lg"
|
||||||
style={{ left: contextMenu.x, top: contextMenu.y }}
|
style={{ left: contextMenu.x, top: contextMenu.y }}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,17 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Handle, NodeProps, Position } from "@xyflow/react";
|
import { Handle, NodeProps, Position } from "@xyflow/react";
|
||||||
import { FileTextIcon, GitBranchIcon, SparklesIcon, CircleStopIcon } from "lucide-react";
|
import {
|
||||||
|
FileTextIcon,
|
||||||
|
GitBranchIcon,
|
||||||
|
GitCompareIcon,
|
||||||
|
SparklesIcon,
|
||||||
|
CircleStopIcon,
|
||||||
|
TimerIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
import type { DialogueNodeData, NpcDialogueNodeType } from "@/lib/npc-dialogue/dialogue";
|
import type { DialogueNodeData, NpcDialogueNodeType } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { DialogueText } from "@/lib/npc-dialogue/DialogueText";
|
||||||
import { DIALOGUE_NODES } from "./types";
|
import { DIALOGUE_NODES } from "./types";
|
||||||
|
|
||||||
const position: Position = Position.Right;
|
const position: Position = Position.Right;
|
||||||
|
|
@ -14,11 +22,14 @@ export function NpcDialogueNode({ data, type }: NodeProps) {
|
||||||
const d = data as DialogueNodeData;
|
const d = data as DialogueNodeData;
|
||||||
const nodeType = type as NpcDialogueNodeType;
|
const nodeType = type as NpcDialogueNodeType;
|
||||||
const meta = DIALOGUE_NODES[nodeType];
|
const meta = DIALOGUE_NODES[nodeType];
|
||||||
const terminal = nodeType === "end" || (nodeType === "choice" && !(d.choices?.length ?? 0));
|
// Only end nodes are truly terminal. A choice node keeps its source handle
|
||||||
|
// even with zero choices, otherwise there would be no way to drag the
|
||||||
|
// first choice out of it.
|
||||||
|
const terminal = nodeType === "end";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`min-w-[15rem] rounded border bg-zinc-900 shadow-lg ${meta.border}`}
|
className={`w-[20rem] max-w-[20rem] rounded border bg-zinc-900 shadow-lg ${meta.border}`}
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-2 border-b border-white/10 px-3 py-1.5">
|
<div className="flex items-center gap-2 border-b border-white/10 px-3 py-1.5">
|
||||||
<NodeIcon type={nodeType} />
|
<NodeIcon type={nodeType} />
|
||||||
|
|
@ -39,7 +50,11 @@ export function NpcDialogueNode({ data, type }: NodeProps) {
|
||||||
<p className="text-[10px] uppercase tracking-wider text-white/40">{d.speaker}</p>
|
<p className="text-[10px] uppercase tracking-wider text-white/40">{d.speaker}</p>
|
||||||
)}
|
)}
|
||||||
<p className="line-clamp-3 text-sm text-white/90">
|
<p className="line-clamp-3 text-sm text-white/90">
|
||||||
{d.body || <span className="italic text-white/30">Empty line</span>}
|
{d.body ? (
|
||||||
|
<DialogueText text={d.body} />
|
||||||
|
) : (
|
||||||
|
<span className="italic text-white/30">Empty line</span>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -47,13 +62,20 @@ export function NpcDialogueNode({ data, type }: NodeProps) {
|
||||||
{nodeType === "choice" && (
|
{nodeType === "choice" && (
|
||||||
<div>
|
<div>
|
||||||
{d.leadIn && (
|
{d.leadIn && (
|
||||||
<p className="mb-1.5 line-clamp-2 text-sm text-white/70">{d.leadIn}</p>
|
<p className="mb-1.5 line-clamp-2 text-sm text-white/70">
|
||||||
|
<DialogueText text={d.leadIn} />
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
<ul className="flex flex-col gap-1">
|
<ul className="flex flex-col gap-1">
|
||||||
{(d.choices ?? []).map((choice, index) => (
|
{(d.choices ?? []).map((choice, index) => (
|
||||||
<li key={index} className="flex items-center gap-1.5 text-xs text-white/70">
|
<li key={index} className="flex items-center gap-1.5 text-xs text-white/70">
|
||||||
<span className="size-3 shrink-0 rounded border border-amber-500/50" />
|
<span className="size-3 shrink-0 rounded border border-amber-500/50" />
|
||||||
<span className="truncate">{choice.label || "Unlabeled choice"}</span>
|
<span className="truncate">{choice.label || "Unlabeled choice"}</span>
|
||||||
|
{choice.once && (
|
||||||
|
<span className="shrink-0 rounded-sm border border-amber-500/40 bg-amber-500/10 px-1 font-mono text-[8px] uppercase tracking-wider text-amber-300">
|
||||||
|
once
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{(d.choices?.length ?? 0) === 0 && (
|
{(d.choices?.length ?? 0) === 0 && (
|
||||||
|
|
@ -65,17 +87,57 @@ export function NpcDialogueNode({ data, type }: NodeProps) {
|
||||||
|
|
||||||
{nodeType === "event" && (
|
{nodeType === "event" && (
|
||||||
<div className="text-sm">
|
<div className="text-sm">
|
||||||
|
{d.body && (
|
||||||
|
<p className="line-clamp-3 italic text-amber-100/80">
|
||||||
|
<DialogueText text={d.body} />
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
{d.effect ? (
|
{d.effect ? (
|
||||||
<span className="text-white/80">
|
<span className={d.body ? "text-xs text-white/50" : "text-white/80"}>
|
||||||
{d.effect.type === "notify"
|
{d.effect.type === "notify"
|
||||||
? "Notify user"
|
? "Notify user"
|
||||||
: d.effect.type === "emit"
|
: d.effect.type === "emit"
|
||||||
? "Log game event"
|
? "Log game event"
|
||||||
: "Reward (unconfigured)"}
|
: d.effect.type === "flag"
|
||||||
|
? `Set flag "${d.effect.flagKey || "?"}"`
|
||||||
|
: "Reward (unconfigured)"}
|
||||||
{d.effect.message ? `: "${d.effect.message}"` : ""}
|
{d.effect.message ? `: "${d.effect.message}"` : ""}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="italic text-white/30">No effect configured</span>
|
!d.body && (
|
||||||
|
<span className="italic text-white/30">
|
||||||
|
No narration or effect. Leave the effect on “None” for pure narration.
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nodeType === "delay" && (
|
||||||
|
<div className="text-sm text-white/70">
|
||||||
|
{d.delaySeconds ? (
|
||||||
|
<span>
|
||||||
|
Pause <span className="font-mono text-violet-300">{d.delaySeconds}s</span> before
|
||||||
|
continuing.
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="italic text-white/30">Set a pause length.</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nodeType === "condition" && (
|
||||||
|
<div className="text-sm text-white/70">
|
||||||
|
{d.condition?.key ? (
|
||||||
|
<span>
|
||||||
|
Flag <span className="font-mono text-sky-300">{d.condition.key}</span>{" "}
|
||||||
|
<span className="text-white/50">{d.condition.op}</span>
|
||||||
|
{typeof d.condition.amount === "number" && (
|
||||||
|
<span className="font-mono text-sky-300"> {d.condition.amount}</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="italic text-white/30">Set a flag key to branch on.</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -83,7 +145,9 @@ export function NpcDialogueNode({ data, type }: NodeProps) {
|
||||||
{nodeType === "end" && (
|
{nodeType === "end" && (
|
||||||
<div className="text-sm text-white/70">
|
<div className="text-sm text-white/70">
|
||||||
{d.closing ? (
|
{d.closing ? (
|
||||||
<span className="line-clamp-3">{d.closing}</span>
|
<span className="line-clamp-3">
|
||||||
|
<DialogueText text={d.closing} />
|
||||||
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="italic text-white/30">No closing line</span>
|
<span className="italic text-white/30">No closing line</span>
|
||||||
)}
|
)}
|
||||||
|
|
@ -108,6 +172,10 @@ function NodeIcon({ type }: { type: NpcDialogueNodeType }) {
|
||||||
return <GitBranchIcon className={className} />;
|
return <GitBranchIcon className={className} />;
|
||||||
case "event":
|
case "event":
|
||||||
return <SparklesIcon className={className} />;
|
return <SparklesIcon className={className} />;
|
||||||
|
case "delay":
|
||||||
|
return <TimerIcon className={className} />;
|
||||||
|
case "condition":
|
||||||
|
return <GitCompareIcon className={className} />;
|
||||||
case "end":
|
case "end":
|
||||||
return <CircleStopIcon className={className} />;
|
return <CircleStopIcon className={className} />;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,20 @@ export const DIALOGUE_NODES: Record<NpcDialogueNodeType, NodeMeta> = {
|
||||||
node: "#10b981",
|
node: "#10b981",
|
||||||
description: "Trigger a notification or game event.",
|
description: "Trigger a notification or game event.",
|
||||||
},
|
},
|
||||||
|
delay: {
|
||||||
|
type: "delay",
|
||||||
|
label: "Delay",
|
||||||
|
border: "border-violet-500/60",
|
||||||
|
node: "#8b5cf6",
|
||||||
|
description: "Pause the conversation for a beat.",
|
||||||
|
},
|
||||||
|
condition: {
|
||||||
|
type: "condition",
|
||||||
|
label: "Condition",
|
||||||
|
border: "border-sky-500/60",
|
||||||
|
node: "#0ea5e9",
|
||||||
|
description: "Branch on live web-app state (player flags).",
|
||||||
|
},
|
||||||
end: {
|
end: {
|
||||||
type: "end",
|
type: "end",
|
||||||
label: "End",
|
label: "End",
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,9 @@ export function NpcActivityLine({ intervalMinutes, activityOptions }: NpcActivit
|
||||||
const activity = resolveCurrentActivity(activityOptions, reshuffle ? `tick-${tick}` : undefined);
|
const activity = resolveCurrentActivity(activityOptions, reshuffle ? `tick-${tick}` : undefined);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-3">
|
// 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.readoutLabel}>Activity</span>
|
||||||
<span className={DOSSIER.chip}>{formatActivityLine(activity)}</span>
|
<span className={DOSSIER.chip}>{formatActivityLine(activity)}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,23 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { CircleIcon, XIcon } from "lucide-react";
|
import { MessageCircleIcon, XIcon } from "lucide-react";
|
||||||
|
|
||||||
import type { GameNpc } from "@/payload-types";
|
import type { GameNpc } from "@/payload-types";
|
||||||
import type { DialogueNode, FlowData } from "@/lib/npc-dialogue/dialogue";
|
import type { DialogueNext, DialogueNode, FlowData } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { DialogueText } from "@/lib/npc-dialogue/DialogueText";
|
||||||
import { findStartNode } from "@/lib/npc-dialogue/dialogue";
|
import { findStartNode } from "@/lib/npc-dialogue/dialogue";
|
||||||
import { DOSSIER } from "@/components/frontend/operations";
|
import { DOSSIER } from "@/components/frontend/operations";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { triggerNpcDialogueEvent } from "@/app/(frontend)/personnel/contacts/[id]/actions";
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import {
|
||||||
|
evaluateNpcDialogueCondition,
|
||||||
|
triggerNpcDialogueEvent,
|
||||||
|
} from "@/app/(frontend)/personnel/contacts/[id]/actions";
|
||||||
|
|
||||||
interface NpcConversationProps {
|
interface NpcConversationProps {
|
||||||
readonly npc: GameNpc;
|
readonly npc: GameNpc;
|
||||||
|
|
@ -20,10 +29,9 @@ interface ResolvedFlow {
|
||||||
startId: string | null;
|
startId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LogEntry {
|
type LogEntry =
|
||||||
node: DialogueNode;
|
| { kind: "node"; id: string; node: DialogueNode; triggered: boolean }
|
||||||
triggered: boolean;
|
| { kind: "player"; id: string; text: string };
|
||||||
}
|
|
||||||
|
|
||||||
/** Resolves the authored flowchart into a shape the runtime can walk. */
|
/** Resolves the authored flowchart into a shape the runtime can walk. */
|
||||||
function resolveFlow(dialogue: NpcConversationProps["dialogue"]): ResolvedFlow | null {
|
function resolveFlow(dialogue: NpcConversationProps["dialogue"]): ResolvedFlow | null {
|
||||||
|
|
@ -32,69 +40,199 @@ function resolveFlow(dialogue: NpcConversationProps["dialogue"]): ResolvedFlow |
|
||||||
return { nodes, startId: findStartNode(nodes)?.id ?? null };
|
return { nodes, startId: findStartNode(nodes)?.id ?? null };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
/** Text length drives how long the NPC "types"; jitter keeps it human. */
|
||||||
|
function typingDelayMs(text: string): number {
|
||||||
|
return Math.min(2600, 450 + text.length * 24) * (0.85 + Math.random() * 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function nodeText(node: DialogueNode): string {
|
||||||
|
return node.data.body || node.data.effect?.message || node.data.closing || node.data.leadIn || "";
|
||||||
|
}
|
||||||
|
|
||||||
export function NpcConversation({ npc, dialogue }: NpcConversationProps) {
|
export function NpcConversation({ npc, dialogue }: NpcConversationProps) {
|
||||||
const flow = useMemo(() => resolveFlow(dialogue), [dialogue]);
|
const flow = useMemo(() => resolveFlow(dialogue), [dialogue]);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [log, setLog] = useState<LogEntry[]>([]);
|
const [log, setLog] = useState<LogEntry[]>([]);
|
||||||
|
/** Speaker label while the NPC types; "" for speaker-less narration. */
|
||||||
|
const [typing, setTyping] = useState<string | null>(null);
|
||||||
|
/** True while the player's chosen line is "typing" into the log. */
|
||||||
|
const [playerTyping, setPlayerTyping] = useState(false);
|
||||||
|
/** `${nodeId}:${index}` keys of one-time choices picked in THIS conversation.
|
||||||
|
* Purely local: it resets on every `begin()`, so a choice hidden here
|
||||||
|
* reappears the next time the conversation is opened. Persist across
|
||||||
|
* conversations with a condition + player flag instead. */
|
||||||
|
const [takenChoices, setTakenChoices] = useState<Set<string>>(new Set());
|
||||||
|
const seq = useRef(0);
|
||||||
|
const sessionRef = useRef(0);
|
||||||
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const nextId = () => `entry-${seq.current++}`;
|
||||||
|
|
||||||
|
// Invalidate pending typing timers when the component unmounts.
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
sessionRef.current += 1;
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Trigger every arrived event node's effect exactly once, in order (the
|
||||||
|
// opening cascade can land on several events at once).
|
||||||
|
useEffect(() => {
|
||||||
|
const pending = log.find(
|
||||||
|
(entry) =>
|
||||||
|
entry.kind === "node" &&
|
||||||
|
entry.node.type === "event" &&
|
||||||
|
!!entry.node.data.effect &&
|
||||||
|
!entry.triggered,
|
||||||
|
);
|
||||||
|
if (!pending || pending.kind !== "node") return;
|
||||||
|
void triggerNpcDialogueEvent(Number(npc.id), pending.node.id).catch(() => undefined);
|
||||||
|
setLog((prev) =>
|
||||||
|
prev.map((entry) => (entry.id === pending.id ? { ...entry, triggered: true } : entry)),
|
||||||
|
);
|
||||||
|
}, [log, npc.id]);
|
||||||
|
|
||||||
|
// Keep the newest line in view.
|
||||||
|
useEffect(() => {
|
||||||
|
const el = scrollRef.current;
|
||||||
|
if (el) el.scrollTop = el.scrollHeight;
|
||||||
|
}, [log, typing, playerTyping, open]);
|
||||||
|
|
||||||
if (npc.canMessage !== true || !flow || flow.nodes.length === 0) return null;
|
if (npc.canMessage !== true || !flow || flow.nodes.length === 0) return null;
|
||||||
|
|
||||||
const enterNode = (node: DialogueNode) => {
|
/** Appends a node to the log after a length-based "typing" delay. */
|
||||||
setLog((prev) => [...prev, { node, triggered: false }]);
|
const typeIn = async (node: DialogueNode, token: number) => {
|
||||||
|
setTyping(node.type === "event" ? "" : node.data.speaker?.trim() || npc.name);
|
||||||
|
await sleep(typingDelayMs(nodeText(node)));
|
||||||
|
if (sessionRef.current !== token) return;
|
||||||
|
setTyping(null);
|
||||||
|
setLog((prev) => [...prev, { kind: "node", id: nextId(), node, triggered: false }]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Opening the conversation walks the start node and auto-advances through
|
||||||
|
// linear dialogue/event nodes, so the player lands on the first interactive
|
||||||
|
// node (a choice, an end, or a dead end) without clicking Continue. Each
|
||||||
|
// line arrives after its own typing delay.
|
||||||
const begin = () => {
|
const begin = () => {
|
||||||
|
const token = ++sessionRef.current;
|
||||||
setLog([]);
|
setLog([]);
|
||||||
if (flow.startId) {
|
setTyping(null);
|
||||||
const start = flow.nodes.find((n) => n.id === flow.startId);
|
setPlayerTyping(false);
|
||||||
if (start) {
|
setTakenChoices(new Set());
|
||||||
enterNode(start);
|
setOpen(true);
|
||||||
|
if (!flow.startId) return;
|
||||||
|
void (async () => {
|
||||||
|
const start = flow.nodes.find((n) => n.id === flow.startId) ?? null;
|
||||||
|
if (start) await cascadeFrom(start, token);
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Types `start`, then auto-advances through linear dialogue/event/delay/
|
||||||
|
* condition nodes so the player always lands on the next interactive node
|
||||||
|
* (a choice or an end). Delay nodes pause the conversation; condition nodes
|
||||||
|
* branch on the player's flags, evaluated server-side. Neither is logged. */
|
||||||
|
const cascadeFrom = async (start: DialogueNode, token: number) => {
|
||||||
|
let current: DialogueNode | null = start;
|
||||||
|
const seen = new Set<string>();
|
||||||
|
while (current && !seen.has(current.id) && sessionRef.current === token) {
|
||||||
|
seen.add(current.id);
|
||||||
|
|
||||||
|
if (current.type === "delay") {
|
||||||
|
const seconds = Math.min(30, Math.max(0.5, current.data.delaySeconds ?? 2));
|
||||||
|
setTyping("");
|
||||||
|
await sleep(seconds * 1000);
|
||||||
|
if (sessionRef.current !== token) return;
|
||||||
|
setTyping(null);
|
||||||
|
const target: string | undefined = current.data.next?.target;
|
||||||
|
current = target ? (flow.nodes.find((n) => n.id === target) ?? null) : null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.type === "condition") {
|
||||||
|
const result = await evaluateNpcDialogueCondition(Number(npc.id), current.id);
|
||||||
|
if (sessionRef.current !== token) return;
|
||||||
|
const branch =
|
||||||
|
result.success && result.data ? current.data.trueTarget : current.data.falseTarget;
|
||||||
|
current = branch ? (flow.nodes.find((n) => n.id === branch) ?? null) : null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await typeIn(current, token);
|
||||||
|
if (sessionRef.current !== token) return;
|
||||||
|
if (current.type === "dialogue" || current.type === "event") {
|
||||||
|
const target: string | undefined = current.data.next?.target;
|
||||||
|
current = target ? (flow.nodes.find((n) => n.id === target) ?? null) : null;
|
||||||
|
} else {
|
||||||
|
current = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setOpen(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const close = () => setOpen(false);
|
const close = () => {
|
||||||
|
sessionRef.current += 1;
|
||||||
const last = log[log.length - 1];
|
setTyping(null);
|
||||||
|
setPlayerTyping(false);
|
||||||
// Trigger an event node's effect exactly once when it first arrives.
|
setOpen(false);
|
||||||
useEffect(() => {
|
|
||||||
if (!last || last.node.type !== "event" || !last.node.data.effect || last.triggered) return;
|
|
||||||
void triggerNpcDialogueEvent(Number(npc.id), last.node.id).catch(() => undefined);
|
|
||||||
setLog((prev) =>
|
|
||||||
prev.map((entry) =>
|
|
||||||
entry.node.id === last.node.id ? { ...entry, triggered: true } : entry,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}, [last?.node.id, last?.triggered, last, npc.id]);
|
|
||||||
|
|
||||||
const nextNode = (): DialogueNode | null => {
|
|
||||||
if (!last) return null;
|
|
||||||
const target = last.node.data.next?.target;
|
|
||||||
if (!target) return null;
|
|
||||||
return flow.nodes.find((n) => n.id === target) ?? null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const choiceHops = last?.node.type === "choice" ? last.node.data.choices ?? [] : [];
|
const lastNode = [...log].reverse().find((entry) => entry.kind === "node");
|
||||||
|
|
||||||
|
// The player's line types out (shorter than NPC pacing), lands, and then
|
||||||
|
// the NPC starts typing its reply.
|
||||||
|
const pick = (hop: DialogueNext, choiceIndex: number) => {
|
||||||
|
const token = sessionRef.current;
|
||||||
|
const text = hop.label || "…";
|
||||||
|
if (hop.once && lastNode && lastNode.kind === "node") {
|
||||||
|
const key = `${lastNode.node.id}:${choiceIndex}`;
|
||||||
|
setTakenChoices((prev) => (prev.has(key) ? prev : new Set(prev).add(key)));
|
||||||
|
}
|
||||||
|
void (async () => {
|
||||||
|
setPlayerTyping(true);
|
||||||
|
await sleep(Math.min(1100, 300 + text.length * 16) * (0.85 + Math.random() * 0.3));
|
||||||
|
if (sessionRef.current !== token) return;
|
||||||
|
setPlayerTyping(false);
|
||||||
|
setLog((prev) => [...prev, { kind: "player", id: nextId(), text }]);
|
||||||
|
const target = flow.nodes.find((n) => n.id === hop.target);
|
||||||
|
if (target) await cascadeFrom(target, token);
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
|
||||||
|
// The choices offered by the node the log currently rests on. One-time
|
||||||
|
// choices the player already took are hidden; if that empties the list the
|
||||||
|
// footer falls back to the End conversation button so nobody gets stuck.
|
||||||
|
const choiceNode =
|
||||||
|
lastNode && lastNode.kind === "node" && lastNode.node.type === "choice"
|
||||||
|
? lastNode.node
|
||||||
|
: null;
|
||||||
|
const visibleChoices = choiceNode
|
||||||
|
? (choiceNode.data.choices ?? [])
|
||||||
|
.map((hop, index) => ({ hop, index }))
|
||||||
|
.filter(({ hop, index }) => !(hop.once && takenChoices.has(`${choiceNode.id}:${index}`)))
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="flex flex-col gap-4">
|
<>
|
||||||
{!open ? (
|
<Button
|
||||||
<Button
|
onClick={begin}
|
||||||
onClick={begin}
|
className="group/converse relative overflow-hidden rounded-none border border-white/20 bg-black/40 text-white hover:border-cyan-400/60 hover:bg-zinc-800 hover:text-cyan-400"
|
||||||
className="group relative overflow-hidden rounded-none border border-white/20 bg-black/40 hover:border-white/40"
|
>
|
||||||
|
<span className="absolute -left-8 h-full w-8 bg-gradient-to-r from-cyan-500/40 via-cyan-500/15 to-transparent transition-transform group-hover/converse:translate-x-8" />
|
||||||
|
<MessageCircleIcon className="relative z-10 size-3.5 text-cyan-400" />
|
||||||
|
<span className="relative z-10 ml-2 text-xs uppercase tracking-widest">Converse</span>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Dialog open={open} onOpenChange={(next) => !next && close()}>
|
||||||
|
<DialogContent
|
||||||
|
showCloseButton={false}
|
||||||
|
className="flex max-w-2xl flex-col gap-0 overflow-hidden rounded-none border border-white/20 bg-zinc-950 p-0 text-white sm:rounded-none"
|
||||||
>
|
>
|
||||||
<span className="absolute -left-8 h-full w-8 bg-cyan-500/20 transition-transform group-hover:translate-x-8" />
|
<div className={`relative flex items-center justify-between ${DOSSIER.strip}`}>
|
||||||
<CircleIcon className="relative z-10 size-3.5 text-cyan-400" />
|
<DialogTitle className="font-mono text-[10px] font-normal uppercase tracking-widest text-white/60">
|
||||||
<span className="relative z-10 ml-2 text-xs uppercase tracking-widest">Converse</span>
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<div className="relative flex max-h-[70vh] flex-col overflow-hidden rounded-none border border-white/20 bg-black/40">
|
|
||||||
<div className="flex items-center justify-between border-b border-white/15 bg-black/50 px-4 py-2">
|
|
||||||
<span className="font-mono text-[10px] uppercase tracking-widest text-white/50">
|
|
||||||
Conversation // {npc.name}
|
Conversation // {npc.name}
|
||||||
</span>
|
</DialogTitle>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={close}
|
onClick={close}
|
||||||
|
|
@ -103,94 +241,148 @@ export function NpcConversation({ npc, dialogue }: NpcConversationProps) {
|
||||||
>
|
>
|
||||||
<XIcon className="size-4" />
|
<XIcon className="size-4" />
|
||||||
</button>
|
</button>
|
||||||
|
<span
|
||||||
|
aria-hidden
|
||||||
|
className="pointer-events-none absolute inset-0 opacity-[0.04]"
|
||||||
|
style={DOSSIER.gridTexture}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{flow.startId === null ? (
|
{flow.startId === null ? (
|
||||||
<div className="p-4 text-sm text-white/50">
|
<div className="p-5 text-sm text-white/50">
|
||||||
This conversation has no start node. Ask staff to configure it.
|
This conversation has no start node. Ask staff to configure it.
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="flex-1 space-y-3 overflow-y-auto p-4">
|
<div ref={scrollRef} className="max-h-[55vh] min-h-32 space-y-3 overflow-y-auto p-5">
|
||||||
{log.map((entry) => (
|
{log.map((entry) => (
|
||||||
<Bubble key={entry.node.id} entry={entry} />
|
<TimelineEntry key={entry.id} entry={entry} speakerDefault={npc.name} />
|
||||||
))}
|
))}
|
||||||
{log.length === 0 && <div className="text-sm text-white/40">Loading…</div>}
|
{typing !== null && <TypingIndicator speaker={typing} />}
|
||||||
|
{playerTyping && <TypingIndicator player />}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{last && (
|
{!typing &&
|
||||||
<div className="border-t border-white/15 bg-black/50 p-3 flex flex-col gap-2">
|
!playerTyping &&
|
||||||
{last.node.type === "choice" ? (
|
lastNode &&
|
||||||
choiceHops.length > 0 ? (
|
lastNode.kind === "node" &&
|
||||||
choiceHops.map((hop, index) => (
|
(lastNode.node.type === "choice" || lastNode.node.type === "end") && (
|
||||||
<button
|
<div className="flex flex-col gap-2 border-t border-white/15 bg-black/50 p-4">
|
||||||
key={index}
|
{lastNode.node.type === "choice" && visibleChoices.length > 0 ? (
|
||||||
type="button"
|
visibleChoices.map(({ hop, index }) => (
|
||||||
onClick={() => {
|
<button
|
||||||
const target = flow.nodes.find((n) => n.id === hop.target);
|
key={index}
|
||||||
if (target) enterNode(target);
|
type="button"
|
||||||
}}
|
onClick={() => pick(hop, index)}
|
||||||
className="w-full text-left rounded-none border border-white/20 bg-black/40 px-3 py-2 text-sm text-white/80 transition-colors hover:border-cyan-500/60 hover:text-white"
|
className="w-full rounded-none border border-white/20 bg-black/40 px-3 py-2 text-left text-sm text-white/80 transition-colors hover:border-cyan-500/60 hover:text-white"
|
||||||
>
|
>
|
||||||
{hop.label || "…"}
|
{hop.label || "…"}
|
||||||
</button>
|
</button>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<span className="text-xs text-white/40">No choices configured.</span>
|
<Button
|
||||||
)
|
onClick={close}
|
||||||
) : last.node.type === "end" ? (
|
className="w-full rounded-none border border-white/20 bg-black/40 text-xs uppercase tracking-widest text-white/80 hover:border-cyan-500/60 hover:bg-black/40 hover:text-white"
|
||||||
<Button onClick={close} className="bg-cyan-600 hover:bg-cyan-500 text-white">
|
>
|
||||||
End conversation
|
End conversation
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
|
||||||
nextNode() ? (
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
const target = nextNode();
|
|
||||||
if (target) enterNode(target);
|
|
||||||
}}
|
|
||||||
className="bg-cyan-600 hover:bg-cyan-500 text-white"
|
|
||||||
>
|
|
||||||
Continue
|
|
||||||
</Button>
|
|
||||||
) : null
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</DialogContent>
|
||||||
)}
|
</Dialog>
|
||||||
</section>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Bubble({ entry }: { entry: LogEntry }) {
|
function TimelineEntry({
|
||||||
const { node } = entry;
|
entry,
|
||||||
const speaker = node.data.speaker ?? "Contact";
|
speakerDefault,
|
||||||
|
}: {
|
||||||
|
entry: LogEntry;
|
||||||
|
speakerDefault: string;
|
||||||
|
}) {
|
||||||
|
if (entry.kind === "player") {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-end gap-1">
|
||||||
|
<span className={`${DOSSIER.readoutLabel} text-cyan-400/70`}>You</span>
|
||||||
|
<p className="max-w-[85%] rounded-none border border-cyan-500/30 bg-cyan-500/10 px-3 py-1.5 text-sm text-cyan-50">
|
||||||
|
{entry.text}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { node } = entry;
|
||||||
|
|
||||||
|
if (node.type === "event") {
|
||||||
|
// Narration: no speaker, styled like a mission briefing line.
|
||||||
|
const text = node.data.body || node.data.effect?.message || "An event unfolds…";
|
||||||
|
return (
|
||||||
|
<p className="border-l-2 border-amber-500/50 pl-3 text-sm italic text-amber-100/80">
|
||||||
|
<DialogueText text={text} />
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.type === "end") {
|
||||||
|
return (
|
||||||
|
<p className="text-sm italic text-white/50">
|
||||||
|
<DialogueText text={node.data.closing || "The conversation ends."} />
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.type === "choice") {
|
||||||
|
// The choice buttons live in the footer; only the lead-in joins the log.
|
||||||
|
if (!node.data.leadIn) return null;
|
||||||
|
return (
|
||||||
|
<p className="text-sm italic text-white/60">
|
||||||
|
<DialogueText text={node.data.leadIn} />
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const speaker = node.data.speaker?.trim() || speakerDefault;
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<span className={DOSSIER.readoutLabel}>{speaker}</span>
|
<span className={DOSSIER.readoutLabel}>{speaker}</span>
|
||||||
{node.type === "dialogue" && (
|
<p className="text-sm text-white/90">
|
||||||
<p className="text-sm text-white/90">
|
{node.data.body ? (
|
||||||
{node.data.body || <span className="italic text-white/30">…</span>}
|
<DialogueText text={node.data.body} />
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{node.type === "event" && (
|
|
||||||
<p className="text-sm text-emerald-300">
|
|
||||||
{node.data.effect?.message || "An event unfolds…"}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{node.type === "end" && (
|
|
||||||
<p className="text-sm text-white/80">{node.data.closing || "The conversation ends."}</p>
|
|
||||||
)}
|
|
||||||
{node.type === "choice" &&
|
|
||||||
(node.data.leadIn ? (
|
|
||||||
<p className="text-sm italic text-white/60">{node.data.leadIn}</p>
|
|
||||||
) : (
|
) : (
|
||||||
<p className="text-xs text-white/40">Choose a response.</p>
|
<span className="italic text-white/30">…</span>
|
||||||
))}
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Three bouncing dots while a line is "typing". `player` renders the
|
||||||
|
* right-aligned cyan variant for the player's incoming response. */
|
||||||
|
function TypingIndicator({ speaker, player }: { speaker?: string; player?: boolean }) {
|
||||||
|
return (
|
||||||
|
<div className={`flex flex-col gap-1 ${player ? "items-end" : ""}`}>
|
||||||
|
{player ? (
|
||||||
|
<span className={`${DOSSIER.readoutLabel} text-cyan-400/70`}>You</span>
|
||||||
|
) : speaker ? (
|
||||||
|
<span className={DOSSIER.readoutLabel}>{speaker}</span>
|
||||||
|
) : null}
|
||||||
|
<span
|
||||||
|
className={`flex items-center gap-1 py-1 ${player ? "justify-end" : ""}`}
|
||||||
|
role="status"
|
||||||
|
aria-label={player ? "You are typing" : "typing"}
|
||||||
|
>
|
||||||
|
{[0, 150, 300].map((delay) => (
|
||||||
|
<span
|
||||||
|
key={delay}
|
||||||
|
className={`size-1.5 animate-bounce rounded-full ${player ? "bg-cyan-300/80" : "bg-cyan-400/70"}`}
|
||||||
|
style={{ animationDelay: `${delay}ms` }}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ interface NpcProfileProps {
|
||||||
readonly listings: MarketListing[];
|
readonly listings: MarketListing[];
|
||||||
/** Interactive employment controls, rendered in the dossier's right column. */
|
/** Interactive employment controls, rendered in the dossier's right column. */
|
||||||
readonly employmentSlot?: ReactNode;
|
readonly employmentSlot?: ReactNode;
|
||||||
|
/** Conversation trigger, anchored to the right side of the hero card. */
|
||||||
|
readonly conversationSlot?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function assetName(asset: number | Asset): string {
|
function assetName(asset: number | Asset): string {
|
||||||
|
|
@ -77,7 +79,7 @@ function LevelDescription({ data }: { data: GameNpc["levelDescription"] }) {
|
||||||
return <div className="lexical-content"><RichText data={data as LexicalData} /></div>;
|
return <div className="lexical-content"><RichText data={data as LexicalData} /></div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
export function NpcProfile({ npc, listings, employmentSlot, conversationSlot }: NpcProfileProps) {
|
||||||
const faction = typeof npc.faction === "object" && npc.faction !== null ? npc.faction : null;
|
const faction = typeof npc.faction === "object" && npc.faction !== null ? npc.faction : null;
|
||||||
const location =
|
const location =
|
||||||
typeof npc.location === "object" && npc.location !== null ? npc.location : null;
|
typeof npc.location === "object" && npc.location !== null ? npc.location : null;
|
||||||
|
|
@ -152,6 +154,12 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
<ClassificationStrip left="Personnel File // Theater Contacts" right={`REF ${refCode}`} />
|
<ClassificationStrip left="Personnel File // Theater Contacts" right={`REF ${refCode}`} />
|
||||||
<CornerBrackets />
|
<CornerBrackets />
|
||||||
|
|
||||||
|
{conversationSlot ? (
|
||||||
|
<div className="absolute right-6 top-1/2 z-20 -translate-y-1/2 md:right-12">
|
||||||
|
{conversationSlot}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className="relative z-10 flex flex-col gap-3 px-6 py-10 md:py-14">
|
<div className="relative z-10 flex flex-col gap-3 px-6 py-10 md:py-14">
|
||||||
<h1
|
<h1
|
||||||
data-text={npc.name}
|
data-text={npc.name}
|
||||||
|
|
@ -171,6 +179,10 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
<p className="glitch-soft max-w-prose text-pretty text-sm uppercase tracking-wider text-white/60 drop-shadow">
|
<p className="glitch-soft max-w-prose text-pretty text-sm uppercase tracking-wider text-white/60 drop-shadow">
|
||||||
{npc.occupation ?? "Occupation not recorded"}
|
{npc.occupation ?? "Occupation not recorded"}
|
||||||
</p>
|
</p>
|
||||||
|
<NpcActivityLine
|
||||||
|
intervalMinutes={activityInterval}
|
||||||
|
activityOptions={activityOptions}
|
||||||
|
/>
|
||||||
<NpcStatusChips npc={npc} className="mt-1" />
|
<NpcStatusChips npc={npc} className="mt-1" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -200,11 +212,6 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
</div>
|
</div>
|
||||||
</StrategicSummary>
|
</StrategicSummary>
|
||||||
|
|
||||||
<NpcActivityLine
|
|
||||||
intervalMinutes={activityInterval}
|
|
||||||
activityOptions={activityOptions}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{hasLevel && (
|
{hasLevel && (
|
||||||
<StrategicSummary
|
<StrategicSummary
|
||||||
classificationLeft="Capabilities"
|
classificationLeft="Capabilities"
|
||||||
|
|
|
||||||
91
src/lib/npc-dialogue/DialogueText.tsx
Normal file
91
src/lib/npc-dialogue/DialogueText.tsx
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a dialogue string for display: newlines are preserved and a tiny
|
||||||
|
* inline markup subset is honoured (**bold**, *italic*, `code`, and
|
||||||
|
* {color}text{/}). Colors take a friendly name ({red}, {cyan}, ...) or a hex
|
||||||
|
* code ({#ff00ff}). Shared by the admin flow editor previews and the frontend
|
||||||
|
* conversation dialog, so it must stay client-safe (no Payload imports).
|
||||||
|
*/
|
||||||
|
export function DialogueText({ text, className }: { text: string; className?: string }) {
|
||||||
|
return <span className={`whitespace-pre-wrap ${className ?? ""}`}>{renderInline(text)}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Friendly color names mapped to Tailwind text classes (400 shades read well
|
||||||
|
* on the dark conversation surface). Keys are lowercase. */
|
||||||
|
const FRIENDLY_COLORS: Record<string, string> = {
|
||||||
|
red: "text-red-400",
|
||||||
|
rose: "text-rose-400",
|
||||||
|
orange: "text-orange-400",
|
||||||
|
amber: "text-amber-400",
|
||||||
|
yellow: "text-yellow-400",
|
||||||
|
green: "text-green-400",
|
||||||
|
emerald: "text-emerald-400",
|
||||||
|
cyan: "text-cyan-400",
|
||||||
|
sky: "text-sky-400",
|
||||||
|
blue: "text-blue-400",
|
||||||
|
violet: "text-violet-400",
|
||||||
|
purple: "text-purple-400",
|
||||||
|
pink: "text-pink-400",
|
||||||
|
slate: "text-slate-300",
|
||||||
|
};
|
||||||
|
|
||||||
|
const HEX_COLOR = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
||||||
|
|
||||||
|
const INLINE_PATTERN =
|
||||||
|
/(\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|\{(?:#[0-9a-fA-F]{3,6}|[a-zA-Z]+)\}[^{}]*\{\/\})/g;
|
||||||
|
|
||||||
|
/** Matches one colour token produced by INLINE_PATTERN. */
|
||||||
|
const COLOR_TOKEN = /^\{(#?[a-zA-Z0-9#]+)\}([^{}]*)\{\/\}$/;
|
||||||
|
|
||||||
|
function renderInline(text: string): ReactNode {
|
||||||
|
const parts = text.split(INLINE_PATTERN);
|
||||||
|
return parts.map((part, index) => {
|
||||||
|
if (part.length > 4 && part.startsWith("**") && part.endsWith("**")) {
|
||||||
|
return (
|
||||||
|
<strong key={index} className="font-semibold">
|
||||||
|
{part.slice(2, -2)}
|
||||||
|
</strong>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (part.length > 2 && part.startsWith("*") && part.endsWith("*")) {
|
||||||
|
return <em key={index}>{part.slice(1, -1)}</em>;
|
||||||
|
}
|
||||||
|
if (part.length > 2 && part.startsWith("`") && part.endsWith("`")) {
|
||||||
|
return (
|
||||||
|
<code
|
||||||
|
key={index}
|
||||||
|
className="rounded-sm bg-white/10 px-1 py-0.5 font-mono text-[0.85em] text-cyan-300"
|
||||||
|
>
|
||||||
|
{part.slice(1, -1)}
|
||||||
|
</code>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const colorMatch = part.match(COLOR_TOKEN);
|
||||||
|
if (colorMatch) {
|
||||||
|
const token = colorMatch[1];
|
||||||
|
const inner = colorMatch[2];
|
||||||
|
if (token.startsWith("#")) {
|
||||||
|
// Only well-formed hex codes reach the style attribute; anything else
|
||||||
|
// (e.g. {#12345}) renders as literal text.
|
||||||
|
if (HEX_COLOR.test(token)) {
|
||||||
|
return (
|
||||||
|
<span key={index} style={{ color: token }}>
|
||||||
|
{inner}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <span key={index}>{part}</span>;
|
||||||
|
}
|
||||||
|
const cls = FRIENDLY_COLORS[token.toLowerCase()];
|
||||||
|
if (cls) {
|
||||||
|
return (
|
||||||
|
<span key={index} className={cls}>
|
||||||
|
{inner}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return <span key={index}>{part}</span>;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,13 @@
|
||||||
* canvas and the runtime walker always agree.
|
* canvas and the runtime walker always agree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type NpcDialogueNodeType = "dialogue" | "choice" | "event" | "end";
|
export type NpcDialogueNodeType =
|
||||||
|
| "dialogue"
|
||||||
|
| "choice"
|
||||||
|
| "event"
|
||||||
|
| "end"
|
||||||
|
| "delay"
|
||||||
|
| "condition";
|
||||||
|
|
||||||
/** A directed hop to another node. `label` is the choice button text. */
|
/** A directed hop to another node. `label` is the choice button text. */
|
||||||
export interface DialogueNext {
|
export interface DialogueNext {
|
||||||
|
|
@ -15,21 +21,53 @@ export interface DialogueNext {
|
||||||
label?: string;
|
label?: string;
|
||||||
/** Target node id. */
|
/** Target node id. */
|
||||||
target: string;
|
target: string;
|
||||||
|
/**
|
||||||
|
* Choice hops only: once the player picks this choice it is hidden from
|
||||||
|
* them in every later conversation turn (tracked per player as a reserved
|
||||||
|
* `dlg-once:` player flag).
|
||||||
|
*/
|
||||||
|
once?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Branch condition evaluated server-side against live web-app state when the
|
||||||
|
* conversation arrives at a `condition` node. Boolean flags compare against
|
||||||
|
* true/false; numeric flags compare against `amount` (a missing flag counts
|
||||||
|
* as false / zero).
|
||||||
|
*/
|
||||||
|
export interface DialogueCondition {
|
||||||
|
/** Currently only generic player flags; more kinds can join later. */
|
||||||
|
kind: "flag";
|
||||||
|
/** `player-flags` key checked for the reading user. */
|
||||||
|
key: string;
|
||||||
|
/** Comparison applied to the flag's effective value. */
|
||||||
|
op: "is_true" | "is_false" | "gte" | "lte" | "gt" | "lt" | "eq";
|
||||||
|
/** Right-hand side for the numeric comparisons. */
|
||||||
|
amount?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How a flag effect writes the flag. */
|
||||||
|
export type DialogueFlagOp = "set_true" | "set_false" | "set_number" | "add";
|
||||||
|
|
||||||
/** Configured effect for an `event` node. */
|
/** Configured effect for an `event` node. */
|
||||||
export interface NpcDialogueEffect {
|
export interface NpcDialogueEffect {
|
||||||
type: "notify" | "emit" | "reward";
|
type: "notify" | "emit" | "reward" | "flag";
|
||||||
/** In-app notification title (notify). */
|
/** In-app notification title (notify). */
|
||||||
title?: string;
|
title?: string;
|
||||||
/** Notification / event-log body (notify, emit). */
|
/** Notification / event-log body (notify, emit). */
|
||||||
message?: string;
|
message?: string;
|
||||||
|
/** Flag key to write (flag). */
|
||||||
|
flagKey?: string;
|
||||||
|
/** Write mode (flag). */
|
||||||
|
flagOp?: DialogueFlagOp;
|
||||||
|
/** Value for set_number / addend for add (flag). */
|
||||||
|
flagAmount?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DialogueNodeData = {
|
export type DialogueNodeData = {
|
||||||
/** Speaker label shown above the line. */
|
/** Speaker label shown above the line. Defaults to the NPC's name at runtime. */
|
||||||
speaker?: string;
|
speaker?: string;
|
||||||
/** The spoken line. */
|
/** The spoken line (dialogue) or narrative description (event nodes). */
|
||||||
body?: string;
|
body?: string;
|
||||||
/** Branching options (choice nodes). */
|
/** Branching options (choice nodes). */
|
||||||
choices?: DialogueNext[];
|
choices?: DialogueNext[];
|
||||||
|
|
@ -43,6 +81,14 @@ export type DialogueNodeData = {
|
||||||
isStart?: boolean;
|
isStart?: boolean;
|
||||||
/** Single continuation (dialogue / event / end nodes). */
|
/** Single continuation (dialogue / event / end nodes). */
|
||||||
next?: DialogueNext;
|
next?: DialogueNext;
|
||||||
|
/** Pause in seconds before the conversation continues (delay nodes). */
|
||||||
|
delaySeconds?: number;
|
||||||
|
/** Branch condition evaluated when the conversation arrives (condition nodes). */
|
||||||
|
condition?: DialogueCondition;
|
||||||
|
/** Continuation when the condition passes (condition nodes). */
|
||||||
|
trueTarget?: string;
|
||||||
|
/** Continuation when the condition fails (condition nodes). */
|
||||||
|
falseTarget?: string;
|
||||||
} & Record<string, unknown>;
|
} & Record<string, unknown>;
|
||||||
|
|
||||||
export interface DialogueNode {
|
export interface DialogueNode {
|
||||||
|
|
@ -65,12 +111,32 @@ export interface FlowData {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** All effect types the runtime can actually trigger. */
|
/** All effect types the runtime can actually trigger. */
|
||||||
export const EFFECT_TYPES: NpcDialogueEffect["type"][] = ["notify", "emit", "reward"];
|
export const EFFECT_TYPES: NpcDialogueEffect["type"][] = [
|
||||||
|
"notify",
|
||||||
|
"emit",
|
||||||
|
"reward",
|
||||||
|
"flag",
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every outgoing hop of a node, in canvas order: choice buttons, the single
|
||||||
|
* continuation, or the condition's true/false branches. The edge projection,
|
||||||
|
* validation, and the runtime walker all share this so they never disagree.
|
||||||
|
*/
|
||||||
|
export function outgoingHops(node: DialogueNode): DialogueNext[] {
|
||||||
|
if (node.type === "choice") return node.data.choices ?? [];
|
||||||
|
if (node.type === "condition") {
|
||||||
|
const hops: DialogueNext[] = [];
|
||||||
|
if (node.data.trueTarget) hops.push({ label: "true", target: node.data.trueTarget });
|
||||||
|
if (node.data.falseTarget) hops.push({ label: "false", target: node.data.falseTarget });
|
||||||
|
return hops;
|
||||||
|
}
|
||||||
|
return node.data.next ? [node.data.next] : [];
|
||||||
|
}
|
||||||
|
|
||||||
/** True when a node has no outgoing hops (conversation ends here). */
|
/** True when a node has no outgoing hops (conversation ends here). */
|
||||||
export function isTerminalNode(node: DialogueNode): boolean {
|
export function isTerminalNode(node: DialogueNode): boolean {
|
||||||
if (node.type === "choice") return (node.data.choices?.length ?? 0) === 0;
|
return outgoingHops(node).length === 0;
|
||||||
return !node.data.next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves the node the conversation should start at. */
|
/** Resolves the node the conversation should start at. */
|
||||||
|
|
@ -79,7 +145,7 @@ export function findStartNode(nodes: DialogueNode[]): DialogueNode | null {
|
||||||
const marked = nodes.find((node) => node.data.isStart === true);
|
const marked = nodes.find((node) => node.data.isStart === true);
|
||||||
if (marked) return marked;
|
if (marked) return marked;
|
||||||
// Fall back to the first node with no incoming edges.
|
// Fall back to the first node with no incoming edges.
|
||||||
const targets = new Set(nodes.flatMap((n) => (n.data.choices ?? []).map((c) => c.target).concat(n.data.next ? [n.data.next.target] : [])));
|
const targets = new Set(nodes.flatMap((n) => outgoingHops(n).map((h) => h.target)));
|
||||||
const roots = nodes.filter((n) => !targets.has(n.id));
|
const roots = nodes.filter((n) => !targets.has(n.id));
|
||||||
return (roots.length ? roots[0] : nodes[0]) ?? null;
|
return (roots.length ? roots[0] : nodes[0]) ?? null;
|
||||||
}
|
}
|
||||||
|
|
@ -88,9 +154,7 @@ export function findStartNode(nodes: DialogueNode[]): DialogueNode | null {
|
||||||
export function deriveEdges(nodes: DialogueNode[]): DialogueEdge[] {
|
export function deriveEdges(nodes: DialogueNode[]): DialogueEdge[] {
|
||||||
const edges: DialogueEdge[] = [];
|
const edges: DialogueEdge[] = [];
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
const hops =
|
outgoingHops(node).forEach((hop, index) => {
|
||||||
node.type === "choice" ? node.data.choices ?? [] : node.data.next ? [node.data.next] : [];
|
|
||||||
hops.forEach((hop, index) => {
|
|
||||||
if (!hop || !hop.target) return;
|
if (!hop || !hop.target) return;
|
||||||
edges.push({
|
edges.push({
|
||||||
id: `${node.id}->${index}`,
|
id: `${node.id}->${index}`,
|
||||||
|
|
@ -125,7 +189,7 @@ export function validateGraph(nodes: DialogueNode[]): GraphValidation {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
const hops = node.type === "choice" ? node.data.choices ?? [] : node.data.next ? [node.data.next] : [];
|
const hops = outgoingHops(node);
|
||||||
for (const hop of hops) {
|
for (const hop of hops) {
|
||||||
if (!hop) continue;
|
if (!hop) continue;
|
||||||
if (hop.target && !ids.has(hop.target)) {
|
if (hop.target && !ids.has(hop.target)) {
|
||||||
|
|
|
||||||
37379
src/migrations/20261005_185014_add_player_flags.json
Normal file
37379
src/migrations/20261005_185014_add_player_flags.json
Normal file
File diff suppressed because it is too large
Load diff
53
src/migrations/20261005_185014_add_player_flags.ts
Normal file
53
src/migrations/20261005_185014_add_player_flags.ts
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -3558,6 +3558,154 @@
|
||||||
"checkConstraints": {},
|
"checkConstraints": {},
|
||||||
"isRLSEnabled": false
|
"isRLSEnabled": false
|
||||||
},
|
},
|
||||||
|
"public.player_flags": {
|
||||||
|
"name": "player_flags",
|
||||||
|
"schema": "",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "serial",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"name": "user_id",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"key": {
|
||||||
|
"name": "key",
|
||||||
|
"type": "varchar",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"flag_type": {
|
||||||
|
"name": "flag_type",
|
||||||
|
"type": "enum_player_flags_flag_type",
|
||||||
|
"typeSchema": "public",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "'boolean'"
|
||||||
|
},
|
||||||
|
"bool_value": {
|
||||||
|
"name": "bool_value",
|
||||||
|
"type": "boolean",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"number_value": {
|
||||||
|
"name": "number_value",
|
||||||
|
"type": "numeric",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"name": "updated_at",
|
||||||
|
"type": "timestamp(3) with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "now()"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "timestamp(3) with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "now()"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"player_flags_user_idx": {
|
||||||
|
"name": "player_flags_user_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "user_id",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
},
|
||||||
|
"player_flags_updated_at_idx": {
|
||||||
|
"name": "player_flags_updated_at_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "updated_at",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
},
|
||||||
|
"player_flags_created_at_idx": {
|
||||||
|
"name": "player_flags_created_at_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "created_at",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
},
|
||||||
|
"user_key_idx": {
|
||||||
|
"name": "user_key_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "user_id",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"expression": "key",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": true,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foreignKeys": {
|
||||||
|
"player_flags_user_id_users_id_fk": {
|
||||||
|
"name": "player_flags_user_id_users_id_fk",
|
||||||
|
"tableFrom": "player_flags",
|
||||||
|
"tableTo": "users",
|
||||||
|
"columnsFrom": [
|
||||||
|
"user_id"
|
||||||
|
],
|
||||||
|
"columnsTo": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"onDelete": "set null",
|
||||||
|
"onUpdate": "no action"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"policies": {},
|
||||||
|
"checkConstraints": {},
|
||||||
|
"isRLSEnabled": false
|
||||||
|
},
|
||||||
"public.labor_classifications": {
|
"public.labor_classifications": {
|
||||||
"name": "labor_classifications",
|
"name": "labor_classifications",
|
||||||
"schema": "",
|
"schema": "",
|
||||||
|
|
@ -29108,6 +29256,34 @@
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
"player_flags_find": {
|
||||||
|
"name": "player_flags_find",
|
||||||
|
"type": "boolean",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"player_flags_create": {
|
||||||
|
"name": "player_flags_create",
|
||||||
|
"type": "boolean",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"player_flags_update": {
|
||||||
|
"name": "player_flags_update",
|
||||||
|
"type": "boolean",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"player_flags_delete": {
|
||||||
|
"name": "player_flags_delete",
|
||||||
|
"type": "boolean",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
"labor_classifications_find": {
|
"labor_classifications_find": {
|
||||||
"name": "labor_classifications_find",
|
"name": "labor_classifications_find",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
@ -31433,6 +31609,12 @@
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": false
|
||||||
},
|
},
|
||||||
|
"player_flags_id": {
|
||||||
|
"name": "player_flags_id",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
"labor_classifications_id": {
|
"labor_classifications_id": {
|
||||||
"name": "labor_classifications_id",
|
"name": "labor_classifications_id",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
@ -32056,6 +32238,21 @@
|
||||||
"method": "btree",
|
"method": "btree",
|
||||||
"with": {}
|
"with": {}
|
||||||
},
|
},
|
||||||
|
"payload_locked_documents_rels_player_flags_id_idx": {
|
||||||
|
"name": "payload_locked_documents_rels_player_flags_id_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "player_flags_id",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
},
|
||||||
"payload_locked_documents_rels_labor_classifications_id_idx": {
|
"payload_locked_documents_rels_labor_classifications_id_idx": {
|
||||||
"name": "payload_locked_documents_rels_labor_classifications_id_idx",
|
"name": "payload_locked_documents_rels_labor_classifications_id_idx",
|
||||||
"columns": [
|
"columns": [
|
||||||
|
|
@ -33315,6 +33512,19 @@
|
||||||
"onDelete": "cascade",
|
"onDelete": "cascade",
|
||||||
"onUpdate": "no action"
|
"onUpdate": "no action"
|
||||||
},
|
},
|
||||||
|
"payload_locked_documents_rels_player_flags_fk": {
|
||||||
|
"name": "payload_locked_documents_rels_player_flags_fk",
|
||||||
|
"tableFrom": "payload_locked_documents_rels",
|
||||||
|
"tableTo": "player_flags",
|
||||||
|
"columnsFrom": [
|
||||||
|
"player_flags_id"
|
||||||
|
],
|
||||||
|
"columnsTo": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"onDelete": "cascade",
|
||||||
|
"onUpdate": "no action"
|
||||||
|
},
|
||||||
"payload_locked_documents_rels_labor_classifications_fk": {
|
"payload_locked_documents_rels_labor_classifications_fk": {
|
||||||
"name": "payload_locked_documents_rels_labor_classifications_fk",
|
"name": "payload_locked_documents_rels_labor_classifications_fk",
|
||||||
"tableFrom": "payload_locked_documents_rels",
|
"tableFrom": "payload_locked_documents_rels",
|
||||||
|
|
@ -35619,6 +35829,14 @@
|
||||||
"terminated"
|
"terminated"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"public.enum_player_flags_flag_type": {
|
||||||
|
"name": "enum_player_flags_flag_type",
|
||||||
|
"schema": "public",
|
||||||
|
"values": [
|
||||||
|
"boolean",
|
||||||
|
"number"
|
||||||
|
]
|
||||||
|
},
|
||||||
"public.enum_game_event_logs_target_collection": {
|
"public.enum_game_event_logs_target_collection": {
|
||||||
"name": "enum_game_event_logs_target_collection",
|
"name": "enum_game_event_logs_target_collection",
|
||||||
"schema": "public",
|
"schema": "public",
|
||||||
|
|
@ -35997,6 +36215,11 @@
|
||||||
"npc-dialogues:update",
|
"npc-dialogues:update",
|
||||||
"npc-dialogues:delete",
|
"npc-dialogues:delete",
|
||||||
"admin:npc-dialogues:manage",
|
"admin:npc-dialogues:manage",
|
||||||
|
"player-flags:create",
|
||||||
|
"player-flags:read",
|
||||||
|
"player-flags:update",
|
||||||
|
"player-flags:delete",
|
||||||
|
"admin:player-flags:manage",
|
||||||
"mission-files:create",
|
"mission-files:create",
|
||||||
"mission-files:read",
|
"mission-files:read",
|
||||||
"mission-files:update",
|
"mission-files:update",
|
||||||
|
|
@ -37151,6 +37374,6 @@
|
||||||
"tables": {},
|
"tables": {},
|
||||||
"columns": {}
|
"columns": {}
|
||||||
},
|
},
|
||||||
"id": "2f2e1cc1-3e43-4c2f-897f-7f4db16f2089",
|
"id": "2e320cab-a302-4de3-825c-276c5a331af4",
|
||||||
"prevId": "00000000-0000-0000-0000-000000000000"
|
"prevId": "00000000-0000-0000-0000-000000000000"
|
||||||
}
|
}
|
||||||
|
|
@ -106,6 +106,7 @@ import * as migration_20261005_001212_add_map_grid_config from './20261005_00121
|
||||||
import * as migration_20261005_051452_add_game_structure_item_storage from './20261005_051452_add_game_structure_item_storage';
|
import * as migration_20261005_051452_add_game_structure_item_storage from './20261005_051452_add_game_structure_item_storage';
|
||||||
import * as migration_20261005_054132_add_game_npc_bio_richtext from './20261005_054132_add_game_npc_bio_richtext';
|
import * as migration_20261005_054132_add_game_npc_bio_richtext from './20261005_054132_add_game_npc_bio_richtext';
|
||||||
import * as migration_20261005_063613_add_game_npc_image from './20261005_063613_add_game_npc_image';
|
import * as migration_20261005_063613_add_game_npc_image from './20261005_063613_add_game_npc_image';
|
||||||
|
import * as migration_20261005_185014_add_player_flags from './20261005_185014_add_player_flags';
|
||||||
import * as migration_20261006_000000_add_npc_dialogue_and_activity_fields from './20261006_000000_add_npc_dialogue_and_activity_fields';
|
import * as migration_20261006_000000_add_npc_dialogue_and_activity_fields from './20261006_000000_add_npc_dialogue_and_activity_fields';
|
||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
|
|
@ -649,6 +650,11 @@ export const migrations = [
|
||||||
down: migration_20261005_063613_add_game_npc_image.down,
|
down: migration_20261005_063613_add_game_npc_image.down,
|
||||||
name: '20261005_063613_add_game_npc_image',
|
name: '20261005_063613_add_game_npc_image',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
up: migration_20261005_185014_add_player_flags.up,
|
||||||
|
down: migration_20261005_185014_add_player_flags.down,
|
||||||
|
name: '20261005_185014_add_player_flags',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
up: migration_20261006_000000_add_npc_dialogue_and_activity_fields.up,
|
up: migration_20261006_000000_add_npc_dialogue_and_activity_fields.up,
|
||||||
down: migration_20261006_000000_add_npc_dialogue_and_activity_fields.down,
|
down: migration_20261006_000000_add_npc_dialogue_and_activity_fields.down,
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ export interface Config {
|
||||||
'game-npcs': GameNpc;
|
'game-npcs': GameNpc;
|
||||||
'npc-staffing': NpcStaffing;
|
'npc-staffing': NpcStaffing;
|
||||||
'npc-dialogues': NpcDialogue;
|
'npc-dialogues': NpcDialogue;
|
||||||
|
'player-flags': PlayerFlag;
|
||||||
'labor-classifications': LaborClassification;
|
'labor-classifications': LaborClassification;
|
||||||
'game-event-logs': GameEventLog;
|
'game-event-logs': GameEventLog;
|
||||||
users: User;
|
users: User;
|
||||||
|
|
@ -174,6 +175,7 @@ export interface Config {
|
||||||
'game-npcs': GameNpcsSelect<false> | GameNpcsSelect<true>;
|
'game-npcs': GameNpcsSelect<false> | GameNpcsSelect<true>;
|
||||||
'npc-staffing': NpcStaffingSelect<false> | NpcStaffingSelect<true>;
|
'npc-staffing': NpcStaffingSelect<false> | NpcStaffingSelect<true>;
|
||||||
'npc-dialogues': NpcDialoguesSelect<false> | NpcDialoguesSelect<true>;
|
'npc-dialogues': NpcDialoguesSelect<false> | NpcDialoguesSelect<true>;
|
||||||
|
'player-flags': PlayerFlagsSelect<false> | PlayerFlagsSelect<true>;
|
||||||
'labor-classifications': LaborClassificationsSelect<false> | LaborClassificationsSelect<true>;
|
'labor-classifications': LaborClassificationsSelect<false> | LaborClassificationsSelect<true>;
|
||||||
'game-event-logs': GameEventLogsSelect<false> | GameEventLogsSelect<true>;
|
'game-event-logs': GameEventLogsSelect<false> | GameEventLogsSelect<true>;
|
||||||
users: UsersSelect<false> | UsersSelect<true>;
|
users: UsersSelect<false> | UsersSelect<true>;
|
||||||
|
|
@ -821,6 +823,11 @@ export interface Role {
|
||||||
| 'npc-dialogues:update'
|
| 'npc-dialogues:update'
|
||||||
| 'npc-dialogues:delete'
|
| 'npc-dialogues:delete'
|
||||||
| 'admin:npc-dialogues:manage'
|
| 'admin:npc-dialogues:manage'
|
||||||
|
| 'player-flags:create'
|
||||||
|
| 'player-flags:read'
|
||||||
|
| 'player-flags:update'
|
||||||
|
| 'player-flags:delete'
|
||||||
|
| 'admin:player-flags:manage'
|
||||||
| 'mission-files:create'
|
| 'mission-files:create'
|
||||||
| 'mission-files:read'
|
| 'mission-files:read'
|
||||||
| 'mission-files:update'
|
| 'mission-files:update'
|
||||||
|
|
@ -2531,6 +2538,35 @@ export interface NpcDialogue {
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "player-flags".
|
||||||
|
*/
|
||||||
|
export interface PlayerFlag {
|
||||||
|
id: number;
|
||||||
|
/**
|
||||||
|
* The player this flag belongs to.
|
||||||
|
*/
|
||||||
|
user: number | User;
|
||||||
|
/**
|
||||||
|
* Stable key referenced by conversation nodes (e.g. 'met_informant', 'rep_merchants'). Lowercase with underscores.
|
||||||
|
*/
|
||||||
|
key: string;
|
||||||
|
/**
|
||||||
|
* Boolean flags read as true/false; numeric flags track statistics.
|
||||||
|
*/
|
||||||
|
flagType: 'boolean' | 'number';
|
||||||
|
/**
|
||||||
|
* A missing boolean flag counts as false.
|
||||||
|
*/
|
||||||
|
boolValue?: boolean | null;
|
||||||
|
/**
|
||||||
|
* A missing numeric flag counts as 0.
|
||||||
|
*/
|
||||||
|
numberValue?: number | null;
|
||||||
|
updatedAt: string;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "game-event-logs".
|
* via the `definition` "game-event-logs".
|
||||||
|
|
@ -5780,6 +5816,24 @@ export interface PayloadMcpApiKey {
|
||||||
*/
|
*/
|
||||||
delete?: boolean | null;
|
delete?: boolean | null;
|
||||||
};
|
};
|
||||||
|
playerFlags?: {
|
||||||
|
/**
|
||||||
|
* Allow clients to find player-flags.
|
||||||
|
*/
|
||||||
|
find?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Allow clients to create player-flags.
|
||||||
|
*/
|
||||||
|
create?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Allow clients to update player-flags.
|
||||||
|
*/
|
||||||
|
update?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Allow clients to delete player-flags.
|
||||||
|
*/
|
||||||
|
delete?: boolean | null;
|
||||||
|
};
|
||||||
laborClassifications?: {
|
laborClassifications?: {
|
||||||
/**
|
/**
|
||||||
* Allow clients to find labor-classifications.
|
* Allow clients to find labor-classifications.
|
||||||
|
|
@ -7139,6 +7193,10 @@ export interface PayloadLockedDocument {
|
||||||
relationTo: 'npc-dialogues';
|
relationTo: 'npc-dialogues';
|
||||||
value: number | NpcDialogue;
|
value: number | NpcDialogue;
|
||||||
} | null)
|
} | null)
|
||||||
|
| ({
|
||||||
|
relationTo: 'player-flags';
|
||||||
|
value: number | PlayerFlag;
|
||||||
|
} | null)
|
||||||
| ({
|
| ({
|
||||||
relationTo: 'labor-classifications';
|
relationTo: 'labor-classifications';
|
||||||
value: number | LaborClassification;
|
value: number | LaborClassification;
|
||||||
|
|
@ -7778,6 +7836,19 @@ export interface NpcDialoguesSelect<T extends boolean = true> {
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "player-flags_select".
|
||||||
|
*/
|
||||||
|
export interface PlayerFlagsSelect<T extends boolean = true> {
|
||||||
|
user?: T;
|
||||||
|
key?: T;
|
||||||
|
flagType?: T;
|
||||||
|
boolValue?: T;
|
||||||
|
numberValue?: T;
|
||||||
|
updatedAt?: T;
|
||||||
|
createdAt?: T;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "labor-classifications_select".
|
* via the `definition` "labor-classifications_select".
|
||||||
|
|
@ -10004,6 +10075,14 @@ export interface PayloadMcpApiKeysSelect<T extends boolean = true> {
|
||||||
update?: T;
|
update?: T;
|
||||||
delete?: T;
|
delete?: T;
|
||||||
};
|
};
|
||||||
|
playerFlags?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
find?: T;
|
||||||
|
create?: T;
|
||||||
|
update?: T;
|
||||||
|
delete?: T;
|
||||||
|
};
|
||||||
laborClassifications?:
|
laborClassifications?:
|
||||||
| T
|
| T
|
||||||
| {
|
| {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ import { GameVehicles } from "@/collections/game/GameVehicles";
|
||||||
import { GameNpcs } from "@/collections/game/GameNpcs";
|
import { GameNpcs } from "@/collections/game/GameNpcs";
|
||||||
import { NpcStaffing } from "@/collections/game/NpcStaffing";
|
import { NpcStaffing } from "@/collections/game/NpcStaffing";
|
||||||
import { NpcDialogues } from "@/collections/game/NpcDialogues";
|
import { NpcDialogues } from "@/collections/game/NpcDialogues";
|
||||||
|
import { PlayerFlags } from "@/collections/game/PlayerFlags";
|
||||||
import { LaborClassifications } from "@/collections/game/LaborClassifications";
|
import { LaborClassifications } from "@/collections/game/LaborClassifications";
|
||||||
import { Experience } from "@/collections/users/Experience";
|
import { Experience } from "@/collections/users/Experience";
|
||||||
import { BankAccounts } from "@/collections/banking/BankAccounts";
|
import { BankAccounts } from "@/collections/banking/BankAccounts";
|
||||||
|
|
@ -270,6 +271,7 @@ const collections = [
|
||||||
GameNpcs,
|
GameNpcs,
|
||||||
NpcStaffing,
|
NpcStaffing,
|
||||||
NpcDialogues,
|
NpcDialogues,
|
||||||
|
PlayerFlags,
|
||||||
LaborClassifications,
|
LaborClassifications,
|
||||||
GameEventLogs,
|
GameEventLogs,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -548,6 +548,16 @@ export const PERMISSION_GROUPS: PermissionGroup[] = [
|
||||||
{ value: "admin:npc-dialogues:manage", label: "Manage Admin Page" },
|
{ value: "admin:npc-dialogues:manage", label: "Manage Admin Page" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
group: "Player Flags",
|
||||||
|
permissions: [
|
||||||
|
{ value: "player-flags:create", label: "Create" },
|
||||||
|
{ value: "player-flags:read", label: "Read" },
|
||||||
|
{ value: "player-flags:update", label: "Update" },
|
||||||
|
{ value: "player-flags:delete", label: "Delete" },
|
||||||
|
{ value: "admin:player-flags:manage", label: "Manage Admin Page" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
// ---- Server --------------------------------------------------------------
|
// ---- Server --------------------------------------------------------------
|
||||||
{
|
{
|
||||||
|
|
@ -999,6 +1009,11 @@ export const ALL_PERMISSION_VALUES = PERMISSION_GROUPS.flatMap((g) =>
|
||||||
"npc-dialogues:update",
|
"npc-dialogues:update",
|
||||||
"npc-dialogues:delete",
|
"npc-dialogues:delete",
|
||||||
"admin:npc-dialogues:manage",
|
"admin:npc-dialogues:manage",
|
||||||
|
"player-flags:create",
|
||||||
|
"player-flags:read",
|
||||||
|
"player-flags:update",
|
||||||
|
"player-flags:delete",
|
||||||
|
"admin:player-flags:manage",
|
||||||
"mission-files:create",
|
"mission-files:create",
|
||||||
"mission-files:read",
|
"mission-files:read",
|
||||||
"mission-files:update",
|
"mission-files:update",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue