import { CollectionConfig } from "payload"; import { requirePermission } from "@/utils/access-control/hasPermission"; import { CONDITION_OPS } from "@/lib/npc-dialogue/dialogue"; export const NpcDialogues: CollectionConfig = { slug: "npc-dialogues", admin: { group: "Game", useAsTitle: "name", listSearchableFields: ["name"], defaultColumns: ["name", "npc", "priority"], pagination: { defaultLimit: 50 }, }, access: { read: requirePermission("npc-dialogues:read"), create: requirePermission("npc-dialogues:create"), update: requirePermission("npc-dialogues:update"), delete: requirePermission("npc-dialogues:delete"), }, fields: [ { name: "name", type: "text", required: true, admin: { description: "A short label for this conversation (e.g. 'Merchant greeting').", }, }, { name: "npc", type: "relationship", relationTo: "game-npcs", required: true, hasMany: false, admin: { description: "The contact this conversation belongs to.", }, filterOptions: { canMessage: { equals: true }, }, }, { name: "priority", type: "number", defaultValue: 0, admin: { description: "When a contact has several conversations, the highest-priority one whose entry gate passes is the one offered. Ties break by oldest first.", }, }, { name: "entryGate", type: "group", admin: { description: "Only offer this conversation to players whose flags pass this condition. Leave the key empty to always offer it (ungated conversations are the fallback).", }, fields: [ { name: "key", type: "text", admin: { description: "player-flags key checked for the reading player. Player-specific flag takes priority; falls back to global. Missing = false / 0.", }, }, { name: "op", type: "select", defaultValue: "is_true", options: CONDITION_OPS, admin: { description: "Comparison applied to the flag's effective value.", }, }, { name: "amount", type: "number", admin: { condition: (_data, blockData) => ["gte", "lte", "gt", "lt", "eq"].includes(String(blockData?.op)), description: "Right-hand side for the numeric comparisons.", }, }, ], }, { type: "tabs", tabs: [ { label: "Flow Editor", description: "Build the conversation: dialogue lines, branching choices, and trigger events. Mark one node as the start.", fields: [ { name: "flowData", type: "json", required: true, defaultValue: () => ({ nodes: [], edges: [], }), admin: { components: { Field: "@/components/admin/npc-dialogue/NpcDialogueEditor", }, }, }, ], }, ], }, ], };