1
0
Fork 0
polaris-task-force/src/collections/game/PlayerFlags.ts

75 lines
2.2 KiB
TypeScript

import { CollectionConfig } from "payload";
import { requirePermission } from "@/utils/access-control/hasPermission";
/**
* Generic flags — per-player (when `user` is set) or global (when null).
* The lightweight state layer conversations branch on. Event nodes write
* player flags; condition nodes read them, falling back to global if the
* player-specific flag is absent. GMs can seed or correct both 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",
admin: {
description: "The player this flag belongs to. Leave empty for a global flag.",
},
},
{
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 }],
};