1
0
Fork 0

feat(minigames): add period, entry, achievement and registry schema

Phase 0 of the minigame periods feature:

- New collections: minigames (registry), minigame-entries (append-only
  ledger), minigame-periods, achievements; new minigame-rules global
  (anchor, 14-day periods, top-10 ladder, precision minimum).
- Pure registry lib with the seven built-in games, achievement
  type/window enums and rule defaults.
- Permissions: extend the Minigames group with registry/entries/
  periods/achievements CRUD (plus minigame-periods:close) and add a
  Minigame Rules (Global) group; mirror both into ALL_PERMISSION_VALUES.
- Migration add_minigame_periods seeds the seven registry rows and the
  minigame-rules defaults idempotently so production seeds from the
  migration chain; dev seed script mirrors it for local resets.
This commit is contained in:
Jason Fraley 2026-10-11 15:56:38 -04:00
parent 0c00726759
commit d4d121b5a7
15 changed files with 42354 additions and 3 deletions

View file

@ -0,0 +1,75 @@
import { GlobalConfig } from "payload";
import { requirePermission } from "@/utils/access-control/hasPermission";
import {
MINIGAME_ANCHOR_DATE,
PERIOD_LENGTH_DAYS_DEFAULT,
PLACEMENT_LADDER_TOP_N_DEFAULT,
PRECISION_MIN_ATTEMPTS_DEFAULT,
} from "@/lib/minigames/registry";
/**
* Global tuning for minigame periods and achievements.
*
* `anchorDate` is treated as immutable: changing it re-slices and re-labels
* every period, so it should only change through an explicit, confirmed admin
* action. Periods before the anchor do not exist.
*/
export const MinigameRules: GlobalConfig = {
slug: "minigame-rules",
label: "Minigame Rules",
access: {
read: requirePermission("minigame-rules:read"),
update: requirePermission("minigame-rules:update"),
},
fields: [
{
name: "enabled",
type: "checkbox",
defaultValue: true,
admin: {
description:
"Master gate for anchored scoring periods and achievements. When off, the period tick does nothing and period boards fall back to All-Time.",
},
},
{
name: "periodLengthDays",
type: "number",
required: true,
min: 1,
defaultValue: PERIOD_LENGTH_DAYS_DEFAULT,
admin: { description: "Length of each scoring period in days." },
},
{
name: "anchorDate",
type: "date",
required: true,
defaultValue: MINIGAME_ANCHOR_DATE,
admin: {
description:
"Start of Period 1 (UTC). Immutable once set: changing it re-slices every period, so confirm before editing.",
},
},
{
name: "placementLadderTopN",
type: "number",
required: true,
min: 1,
defaultValue: PLACEMENT_LADDER_TOP_N_DEFAULT,
admin: {
description:
"How many placements earn points on each board (1st = N points down to Nth = 1). Points sum across the five Core boards.",
},
},
{
name: "precisionMinAttempts",
type: "number",
required: true,
min: 1,
defaultValue: PRECISION_MIN_ATTEMPTS_DEFAULT,
admin: {
description:
"Minimum qualifying attempts (Aim Trainer + Radio + OPORD) for the Precision achievement.",
},
},
],
};

View file

@ -0,0 +1,85 @@
import { CollectionConfig } from "payload";
import { MINIGAME_ACHIEVEMENT_TYPES, MINIGAME_ACHIEVEMENT_WINDOWS } from "@/lib/minigames/registry";
const readOnly = { admin: { readOnly: true } } as const;
const TYPE_LABELS: Record<string, string> = {
"period-champion": "Period Champion",
"player-of-month": "Player of the Month",
"player-of-year": "Player of the Year",
diligence: "Diligence (Most Attempts)",
dedication: "Dedication (Most Time)",
precision: "Precision (Accuracy)",
"most-improved": "Most Improved",
};
const WINDOW_LABELS: Record<string, string> = {
period: "Period",
month: "Month",
year: "Year",
};
/**
* Evidence store for close-time achievements. This is NOT the Awards system:
* awards are unit decorations, achievements are minigame honors.
*
* Written only by the close pipeline (`src/lib/minigames/periods/`, running
* with `overrideAccess`). Publicly readable for the honor roll. The unique
* `type:windowStart:user` key makes concurrent closes (the tick and the admin
* override) idempotent: a second close inserts nothing.
*/
export const Achievements: CollectionConfig = {
slug: "achievements",
labels: { singular: "Achievement", plural: "Achievements" },
admin: {
group: "Minigames",
useAsTitle: "detail",
defaultColumns: ["type", "window", "user", "value", "rank", "windowStart", "announcedAt"],
description:
"Minigame achievements granted at period/month/year close. Read-only here; written by the close pipeline.",
},
access: {
read: () => true,
create: () => false,
update: () => false,
delete: () => false,
},
fields: [
{
name: "window",
type: "select",
required: true,
index: true,
options: MINIGAME_ACHIEVEMENT_WINDOWS.map((value) => ({
label: WINDOW_LABELS[value] ?? value,
value,
})),
...readOnly,
},
{ name: "windowStart", type: "date", required: true, index: true, ...readOnly },
{ name: "windowEnd", type: "date", required: true, ...readOnly },
{
name: "type",
type: "select",
required: true,
index: true,
options: MINIGAME_ACHIEVEMENT_TYPES.map((value) => ({
label: TYPE_LABELS[value] ?? value,
value,
})),
...readOnly,
},
{ name: "user", type: "relationship", relationTo: "users", required: true, index: true, ...readOnly },
{ name: "value", type: "number", required: true, ...readOnly },
{
name: "detail",
type: "text",
...readOnly,
admin: { readOnly: true, description: "Short human-readable context, e.g. '42 points across 5 boards'." },
},
{ name: "rank", type: "number", ...readOnly },
{ name: "announcedAt", type: "date", index: true, ...readOnly },
{ name: "discordMessageId", type: "text", ...readOnly },
],
indexes: [{ fields: ["type", "windowStart", "user"], unique: true }],
};

View file

@ -0,0 +1,75 @@
import { CollectionConfig } from "payload";
const readOnly = { admin: { readOnly: true } } as const;
/**
* Append-only ledger of completed minigame runs for the Core 5 games.
*
* One row per completed, scored run: the same runs that emit `minigame:*`
* events. Rows are the source of truth for anchored period boards and
* achievements; the all-time profile aggregates on
* `profiles.progression.minigames.*` stay untouched and continue to update.
*
* Writes are service-only (`src/lib/minigames/periods/` runs with
* `overrideAccess`) so the collection denies create/update/delete outright and
* the admin panel is a read-only review surface. Never let a client author a
* row: the validating submit actions are the only write path.
*/
export const MinigameEntries: CollectionConfig = {
slug: "minigame-entries",
labels: { singular: "Minigame Entry", plural: "Minigame Entries" },
admin: {
group: "Minigames",
useAsTitle: "game",
defaultColumns: ["user", "game", "mode", "score", "accuracy", "durationMs", "period", "createdAt"],
description:
"Append-only ledger of completed minigame runs. Read-only here; writes flow through the minigame submit actions.",
},
access: {
read: () => true,
create: () => false,
update: () => false,
delete: () => false,
},
fields: [
{ name: "user", type: "relationship", relationTo: "users", required: true, index: true, ...readOnly },
{
name: "game",
type: "text",
required: true,
index: true,
...readOnly,
admin: { readOnly: true, description: "Registry key (minigames.key)." },
},
{
name: "mode",
type: "text",
...readOnly,
admin: { readOnly: true, description: "Mode or difficulty label when applicable (e.g. sprint, elite)." },
},
{ name: "score", type: "number", required: true, index: true, ...readOnly },
{
name: "accuracy",
type: "number",
min: 0,
max: 1,
...readOnly,
admin: { readOnly: true, description: "Fractional accuracy for games that score it." },
},
{
name: "durationMs",
type: "number",
required: true,
min: 0,
...readOnly,
admin: { readOnly: true, description: "Server-validated run duration in milliseconds." },
},
{ name: "period", type: "relationship", relationTo: "minigame-periods", index: true, ...readOnly },
{
name: "meta",
type: "json",
...readOnly,
admin: { readOnly: true, description: "Small extras (e.g. EOD win flags) that do not warrant a column." },
},
],
};

View file

@ -0,0 +1,65 @@
import { CollectionConfig } from "payload";
const readOnly = { admin: { readOnly: true } } as const;
/**
* Anchored 14-day scoring periods for the Core 5 minigames.
*
* Period 1 starts at the `minigame-rules.anchorDate` and each subsequent period
* is `periodLengthDays` long. Boards reset each period; the ledger history is
* never removed. Exactly one period is expected to be `open` at a time (the
* close pipeline is idempotent and re-checks status before writing).
*
* Writes are service-only (`src/lib/minigames/periods/` runs with
* `overrideAccess`), so the collection denies create/update/delete; the admin
* panel is a read-only review surface plus the close/reopen control.
*/
export const MinigamePeriods: CollectionConfig = {
slug: "minigame-periods",
labels: { singular: "Minigame Period", plural: "Minigame Periods" },
admin: {
group: "Minigames",
useAsTitle: "label",
defaultColumns: ["label", "startDate", "endDate", "status", "closedAt"],
description:
"Anchored scoring periods. Read-only here; the period tick and the close/reopen control manage them.",
},
access: {
read: () => true,
create: () => false,
update: () => false,
delete: () => false,
},
fields: [
{
name: "startDate",
type: "date",
required: true,
unique: true,
index: true,
...readOnly,
admin: { readOnly: true, description: "Inclusive UTC start. Unique; drives period identity." },
},
{ name: "endDate", type: "date", required: true, ...readOnly },
{ name: "label", type: "text", required: true, ...readOnly },
{
name: "status",
type: "select",
required: true,
defaultValue: "open",
index: true,
options: [
{ label: "Open", value: "open" },
{ label: "Closed", value: "closed" },
],
},
{ name: "closedAt", type: "date", ...readOnly },
{
name: "previousPeriod",
type: "relationship",
relationTo: "minigame-periods",
...readOnly,
admin: { readOnly: true, description: "Previous period in the chain, for most-improved deltas." },
},
],
};

View file

@ -0,0 +1,85 @@
import { CollectionConfig } from "payload";
import { requirePermission } from "@/utils/access-control/hasPermission";
/**
* Registry of minigames.
*
* Drives the Core / Cardtable sidebar grouping and the period-scoring scope.
* Games are never deleted: setting `status: "retired"` removes a game from the
* nav and from future period scoring while its ledger history stays intact.
* Publicly readable so the frontend can render the nav and boards; writes are
* admin-gated.
*/
export const Minigames: CollectionConfig = {
slug: "minigames",
labels: { singular: "Minigame", plural: "Minigames" },
admin: {
group: "Minigames",
useAsTitle: "label",
defaultColumns: ["key", "label", "category", "status", "order", "countsForPeriods"],
description:
"Registry of minigames. Retired games keep their history but leave the nav and future period scoring.",
},
access: {
read: () => true,
create: requirePermission("minigames:create"),
update: requirePermission("minigames:update"),
delete: requirePermission("minigames:delete"),
},
fields: [
{
name: "key",
type: "text",
required: true,
unique: true,
index: true,
admin: {
description:
"Stable machine key (e.g. flappy, eod). Ledger rows reference it; avoid changing it after launch.",
},
},
{ name: "label", type: "text", required: true },
{ name: "description", type: "textarea" },
{
name: "route",
type: "text",
required: true,
admin: { description: "Frontend path, e.g. /minigames/flappy." },
},
{
name: "icon",
type: "text",
defaultValue: "Gamepad2",
admin: { description: "lucide-react icon name, mapped in the client." },
},
{
name: "category",
type: "select",
required: true,
defaultValue: "core",
options: [
{ label: "Core", value: "core" },
{ label: "Cardtable", value: "cardtable" },
],
},
{
name: "status",
type: "select",
required: true,
defaultValue: "active",
options: [
{ label: "Active", value: "active" },
{ label: "Upcoming", value: "upcoming" },
{ label: "Retired", value: "retired" },
],
},
{ name: "order", type: "number", required: true, defaultValue: 0 },
{
name: "countsForPeriods",
type: "checkbox",
defaultValue: false,
admin: { description: "When on, ledger entries for this game feed anchored period boards." },
},
{ name: "scoreLabel", type: "text", defaultValue: "Score" },
],
};

View file

@ -0,0 +1,165 @@
/**
* Canonical registry data for the minigames feature.
*
* Pure and client-safe (no Payload import): the `minigames` collection seeds
* its rows from `BUILTIN_MINIGAMES`, the `minigame-rules` global seeds its
* defaults from `MINIGAME_RULE_DEFAULTS`, and the sidebar can read the same
* list without a Payload round trip.
*
* `icon` is a lucide-react icon name (a string), mapped to a component in the
* client. Keeping it as data means the registry can be edited in the admin
* panel without shipping new code.
*/
export type MinigameCategory = "core" | "cardtable";
export type MinigameStatus = "active" | "retired" | "upcoming";
/** The five period-scoring games. Poker and Blackjack stay out of periods. */
export const CORE_MINIGAME_KEYS = [
"flappy",
"eod",
"radio",
"qualification",
"opord",
] as const;
export const CARDTABLE_MINIGAME_KEYS = ["poker", "blackjack"] as const;
export type CoreMinigameKey = (typeof CORE_MINIGAME_KEYS)[number];
export type MinigameKey = CoreMinigameKey | (typeof CARDTABLE_MINIGAME_KEYS)[number];
export interface BuiltinMinigame {
key: string;
label: string;
description: string;
route: string;
/** lucide-react icon name, resolved in the client. */
icon: string;
category: MinigameCategory;
status: MinigameStatus;
/** Sort order within the sidebar / leaderboards. */
order: number;
/** Whether this game's ledger entries feed anchored period boards. */
countsForPeriods: boolean;
/** Label for the score column, e.g. "Passes", "Time". */
scoreLabel: string;
}
/** The seven built-in games, seeded into the `minigames` registry collection. */
export const BUILTIN_MINIGAMES: BuiltinMinigame[] = [
{
key: "flappy",
label: "Flight Simulator",
description: "Guide an aircraft through an obstacle course for as many passes as you can manage.",
route: "/minigames/flappy",
icon: "Bird",
category: "core",
status: "active",
order: 1,
countsForPeriods: true,
scoreLabel: "Passes",
},
{
key: "eod",
label: "Minefield Clearance",
description: "Clear a minefield without detonating a charge, against the clock.",
route: "/minigames/eod",
icon: "Bomb",
category: "core",
status: "active",
order: 2,
countsForPeriods: true,
scoreLabel: "Score",
},
{
key: "radio",
label: "Radio Traffic",
description: "Transcribe and repeat radio traffic accurately, sprint or watch mode.",
route: "/minigames/radio",
icon: "Radio",
category: "core",
status: "active",
order: 3,
countsForPeriods: true,
scoreLabel: "Score",
},
{
key: "qualification",
label: "Qualification Course",
description: "Range drill: engage targets quickly and accurately while sparing civilians.",
route: "/minigames/qualification",
icon: "Crosshair",
category: "core",
status: "active",
order: 4,
countsForPeriods: true,
scoreLabel: "Score",
},
{
key: "opord",
label: "OPORD Recall",
description: "Study a briefing, then recall its details under time pressure.",
route: "/minigames/opord",
icon: "FileTextIcon",
category: "core",
status: "active",
order: 5,
countsForPeriods: true,
scoreLabel: "Score",
},
{
key: "poker",
label: "Poker",
description: "Cardtable game. Play chips earned from Core minigames. Keeps its own all-time board.",
route: "/minigames/poker",
icon: "Spade",
category: "cardtable",
status: "active",
order: 6,
countsForPeriods: false,
scoreLabel: "Chips",
},
{
key: "blackjack",
label: "Blackjack",
description: "Cardtable game. Play chips earned from Core minigames. Keeps its own all-time board.",
route: "/minigames/blackjack",
icon: "Club",
category: "cardtable",
status: "active",
order: 7,
countsForPeriods: false,
scoreLabel: "Chips",
},
];
/** Anchor for Period 1: the Monday 00:00 UTC the feature goes live. */
export const MINIGAME_ANCHOR_DATE = "2026-10-12T00:00:00.000Z";
export const PERIOD_LENGTH_DAYS_DEFAULT = 14;
export const PLACEMENT_LADDER_TOP_N_DEFAULT = 10;
export const PRECISION_MIN_ATTEMPTS_DEFAULT = 5;
export const MINIGAME_ACHIEVEMENT_TYPES = [
"period-champion",
"player-of-month",
"player-of-year",
"diligence",
"dedication",
"precision",
"most-improved",
] as const;
export type MinigameAchievementType = (typeof MINIGAME_ACHIEVEMENT_TYPES)[number];
export const MINIGAME_ACHIEVEMENT_WINDOWS = ["period", "month", "year"] as const;
export type MinigameAchievementWindow = (typeof MINIGAME_ACHIEVEMENT_WINDOWS)[number];
/** Defaults for the `minigame-rules` global, seeded on first migration. */
export const MINIGAME_RULE_DEFAULTS = {
enabled: true,
periodLengthDays: PERIOD_LENGTH_DAYS_DEFAULT,
anchorDate: MINIGAME_ANCHOR_DATE,
placementLadderTopN: PLACEMENT_LADDER_TOP_N_DEFAULT,
precisionMinAttempts: PRECISION_MIN_ATTEMPTS_DEFAULT,
} as const;

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -120,6 +120,7 @@ import * as migration_20261009_160740_add_campaign_on_hold_status from './202610
import * as migration_20261009_185259_add_wiki_featured_curation from './20261009_185259_add_wiki_featured_curation';
import * as migration_20261009_201920_add_contribution_entries from './20261009_201920_add_contribution_entries';
import * as migration_20261010_050644_add_mission_threat_assessment from './20261010_050644_add_mission_threat_assessment';
import * as migration_20261011_195306_add_minigame_periods from './20261011_195306_add_minigame_periods';
export const migrations = [
{
@ -730,6 +731,11 @@ export const migrations = [
{
up: migration_20261010_050644_add_mission_threat_assessment.up,
down: migration_20261010_050644_add_mission_threat_assessment.down,
name: '20261010_050644_add_mission_threat_assessment'
name: '20261010_050644_add_mission_threat_assessment',
},
{
up: migration_20261011_195306_add_minigame_periods.up,
down: migration_20261011_195306_add_minigame_periods.down,
name: '20261011_195306_add_minigame_periods'
},
];

File diff suppressed because it is too large Load diff

View file

@ -151,6 +151,10 @@ export interface Config {
'custom-minefield-scores': CustomMinefieldScore;
'custom-radio-tests': CustomRadioTest;
'custom-radio-test-scores': CustomRadioTestScore;
minigames: Minigame;
'minigame-entries': MinigameEntry;
'minigame-periods': MinigamePeriod;
achievements: Achievement;
forms: Form;
'form-submissions': FormSubmission;
'plugin-ai-instructions': PluginAiInstruction;
@ -252,6 +256,10 @@ export interface Config {
'custom-minefield-scores': CustomMinefieldScoresSelect<false> | CustomMinefieldScoresSelect<true>;
'custom-radio-tests': CustomRadioTestsSelect<false> | CustomRadioTestsSelect<true>;
'custom-radio-test-scores': CustomRadioTestScoresSelect<false> | CustomRadioTestScoresSelect<true>;
minigames: MinigamesSelect<false> | MinigamesSelect<true>;
'minigame-entries': MinigameEntriesSelect<false> | MinigameEntriesSelect<true>;
'minigame-periods': MinigamePeriodsSelect<false> | MinigamePeriodsSelect<true>;
achievements: AchievementsSelect<false> | AchievementsSelect<true>;
forms: FormsSelect<false> | FormsSelect<true>;
'form-submissions': FormSubmissionsSelect<false> | FormSubmissionsSelect<true>;
'plugin-ai-instructions': PluginAiInstructionsSelect<false> | PluginAiInstructionsSelect<true>;
@ -268,10 +276,12 @@ export interface Config {
globals: {
'game-rules': GameRule;
shims: Shim;
'minigame-rules': MinigameRule;
};
globalsSelect: {
'game-rules': GameRulesSelect<false> | GameRulesSelect<true>;
shims: ShimsSelect<false> | ShimsSelect<true>;
'minigame-rules': MinigameRulesSelect<false> | MinigameRulesSelect<true>;
};
locale: null;
widgets: {
@ -919,6 +929,8 @@ export interface Role {
| 'game-rules:update'
| 'shims:read'
| 'shims:update'
| 'minigame-rules:read'
| 'minigame-rules:update'
| 'logistics:manage'
| 'intelligence:manage'
| 'profiles:intel_excerpt:update'
@ -932,6 +944,27 @@ export interface Role {
| 'custom-radio-tests:update'
| 'custom-radio-tests:delete'
| 'custom-radio-test-scores:delete'
| 'minigames:create'
| 'minigames:read'
| 'minigames:update'
| 'minigames:delete'
| 'admin:minigames:manage'
| 'minigame-entries:create'
| 'minigame-entries:read'
| 'minigame-entries:update'
| 'minigame-entries:delete'
| 'admin:minigame-entries:manage'
| 'minigame-periods:create'
| 'minigame-periods:read'
| 'minigame-periods:update'
| 'minigame-periods:delete'
| 'minigame-periods:close'
| 'admin:minigame-periods:manage'
| 'achievements:create'
| 'achievements:read'
| 'achievements:update'
| 'achievements:delete'
| 'admin:achievements:manage'
)[]
| null;
/**
@ -3005,6 +3038,8 @@ export interface GameEventLog {
| 'game-rules:update'
| 'shims:read'
| 'shims:update'
| 'minigame-rules:read'
| 'minigame-rules:update'
| 'logistics:manage'
| 'intelligence:manage'
| 'profiles:intel_excerpt:update'
@ -3018,6 +3053,27 @@ export interface GameEventLog {
| 'custom-radio-tests:update'
| 'custom-radio-tests:delete'
| 'custom-radio-test-scores:delete'
| 'minigames:create'
| 'minigames:read'
| 'minigames:update'
| 'minigames:delete'
| 'admin:minigames:manage'
| 'minigame-entries:create'
| 'minigame-entries:read'
| 'minigame-entries:update'
| 'minigame-entries:delete'
| 'admin:minigame-entries:manage'
| 'minigame-periods:create'
| 'minigame-periods:read'
| 'minigame-periods:update'
| 'minigame-periods:delete'
| 'minigame-periods:close'
| 'admin:minigame-periods:manage'
| 'achievements:create'
| 'achievements:read'
| 'achievements:update'
| 'achievements:delete'
| 'admin:achievements:manage'
)[]
| null;
timestamp: string;
@ -5913,6 +5969,135 @@ export interface CustomRadioTestScore {
updatedAt: string;
createdAt: string;
}
/**
* Registry of minigames. Retired games keep their history but leave the nav and future period scoring.
*
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigames".
*/
export interface Minigame {
id: number;
/**
* Stable machine key (e.g. flappy, eod). Ledger rows reference it; avoid changing it after launch.
*/
key: string;
label: string;
description?: string | null;
/**
* Frontend path, e.g. /minigames/flappy.
*/
route: string;
/**
* lucide-react icon name, mapped in the client.
*/
icon?: string | null;
category: 'core' | 'cardtable';
status: 'active' | 'upcoming' | 'retired';
order: number;
/**
* When on, ledger entries for this game feed anchored period boards.
*/
countsForPeriods?: boolean | null;
scoreLabel?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* Append-only ledger of completed minigame runs. Read-only here; writes flow through the minigame submit actions.
*
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigame-entries".
*/
export interface MinigameEntry {
id: number;
user: number | User;
/**
* Registry key (minigames.key).
*/
game: string;
/**
* Mode or difficulty label when applicable (e.g. sprint, elite).
*/
mode?: string | null;
score: number;
/**
* Fractional accuracy for games that score it.
*/
accuracy?: number | null;
/**
* Server-validated run duration in milliseconds.
*/
durationMs: number;
period?: (number | null) | MinigamePeriod;
/**
* Small extras (e.g. EOD win flags) that do not warrant a column.
*/
meta?:
| {
[k: string]: unknown;
}
| unknown[]
| string
| number
| boolean
| null;
updatedAt: string;
createdAt: string;
}
/**
* Anchored scoring periods. Read-only here; the period tick and the close/reopen control manage them.
*
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigame-periods".
*/
export interface MinigamePeriod {
id: number;
/**
* Inclusive UTC start. Unique; drives period identity.
*/
startDate: string;
endDate: string;
label: string;
status: 'open' | 'closed';
closedAt?: string | null;
/**
* Previous period in the chain, for most-improved deltas.
*/
previousPeriod?: (number | null) | MinigamePeriod;
updatedAt: string;
createdAt: string;
}
/**
* Minigame achievements granted at period/month/year close. Read-only here; written by the close pipeline.
*
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "achievements".
*/
export interface Achievement {
id: number;
window: 'period' | 'month' | 'year';
windowStart: string;
windowEnd: string;
type:
| 'period-champion'
| 'player-of-month'
| 'player-of-year'
| 'diligence'
| 'dedication'
| 'precision'
| 'most-improved';
user: number | User;
value: number;
/**
* Short human-readable context, e.g. '42 points across 5 boards'.
*/
detail?: string | null;
rank?: number | null;
announcedAt?: string | null;
discordMessageId?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "forms".
@ -7695,6 +7880,78 @@ export interface PayloadMcpApiKey {
*/
delete?: boolean | null;
};
minigames?: {
/**
* Allow clients to find minigames.
*/
find?: boolean | null;
/**
* Allow clients to create minigames.
*/
create?: boolean | null;
/**
* Allow clients to update minigames.
*/
update?: boolean | null;
/**
* Allow clients to delete minigames.
*/
delete?: boolean | null;
};
minigameEntries?: {
/**
* Allow clients to find minigame-entries.
*/
find?: boolean | null;
/**
* Allow clients to create minigame-entries.
*/
create?: boolean | null;
/**
* Allow clients to update minigame-entries.
*/
update?: boolean | null;
/**
* Allow clients to delete minigame-entries.
*/
delete?: boolean | null;
};
minigamePeriods?: {
/**
* Allow clients to find minigame-periods.
*/
find?: boolean | null;
/**
* Allow clients to create minigame-periods.
*/
create?: boolean | null;
/**
* Allow clients to update minigame-periods.
*/
update?: boolean | null;
/**
* Allow clients to delete minigame-periods.
*/
delete?: boolean | null;
};
achievements?: {
/**
* Allow clients to find achievements.
*/
find?: boolean | null;
/**
* Allow clients to create achievements.
*/
create?: boolean | null;
/**
* Allow clients to update achievements.
*/
update?: boolean | null;
/**
* Allow clients to delete achievements.
*/
delete?: boolean | null;
};
updatedAt: string;
createdAt: string;
enableAPIKey?: boolean | null;
@ -8058,6 +8315,22 @@ export interface PayloadLockedDocument {
relationTo: 'custom-radio-test-scores';
value: number | CustomRadioTestScore;
} | null)
| ({
relationTo: 'minigames';
value: number | Minigame;
} | null)
| ({
relationTo: 'minigame-entries';
value: number | MinigameEntry;
} | null)
| ({
relationTo: 'minigame-periods';
value: number | MinigamePeriod;
} | null)
| ({
relationTo: 'achievements';
value: number | Achievement;
} | null)
| ({
relationTo: 'forms';
value: number | Form;
@ -10434,6 +10707,72 @@ export interface CustomRadioTestScoresSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigames_select".
*/
export interface MinigamesSelect<T extends boolean = true> {
key?: T;
label?: T;
description?: T;
route?: T;
icon?: T;
category?: T;
status?: T;
order?: T;
countsForPeriods?: T;
scoreLabel?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigame-entries_select".
*/
export interface MinigameEntriesSelect<T extends boolean = true> {
user?: T;
game?: T;
mode?: T;
score?: T;
accuracy?: T;
durationMs?: T;
period?: T;
meta?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigame-periods_select".
*/
export interface MinigamePeriodsSelect<T extends boolean = true> {
startDate?: T;
endDate?: T;
label?: T;
status?: T;
closedAt?: T;
previousPeriod?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "achievements_select".
*/
export interface AchievementsSelect<T extends boolean = true> {
window?: T;
windowStart?: T;
windowEnd?: T;
type?: T;
user?: T;
value?: T;
detail?: T;
rank?: T;
announcedAt?: T;
discordMessageId?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "forms_select".
@ -11322,6 +11661,38 @@ export interface PayloadMcpApiKeysSelect<T extends boolean = true> {
update?: T;
delete?: T;
};
minigames?:
| T
| {
find?: T;
create?: T;
update?: T;
delete?: T;
};
minigameEntries?:
| T
| {
find?: T;
create?: T;
update?: T;
delete?: T;
};
minigamePeriods?:
| T
| {
find?: T;
create?: T;
update?: T;
delete?: T;
};
achievements?:
| T
| {
find?: T;
create?: T;
update?: T;
delete?: T;
};
updatedAt?: T;
createdAt?: T;
enableAPIKey?: T;
@ -11541,6 +11912,35 @@ export interface Shim {
updatedAt?: string | null;
createdAt?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigame-rules".
*/
export interface MinigameRule {
id: number;
/**
* Master gate for anchored scoring periods and achievements. When off, the period tick does nothing and period boards fall back to All-Time.
*/
enabled?: boolean | null;
/**
* Length of each scoring period in days.
*/
periodLengthDays: number;
/**
* Start of Period 1 (UTC). Immutable once set: changing it re-slices every period, so confirm before editing.
*/
anchorDate: string;
/**
* How many placements earn points on each board (1st = N points down to Nth = 1). Points sum across the five Core boards.
*/
placementLadderTopN: number;
/**
* Minimum qualifying attempts (Aim Trainer + Radio + OPORD) for the Precision achievement.
*/
precisionMinAttempts: number;
updatedAt?: string | null;
createdAt?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "game-rules_select".
@ -11612,6 +12012,20 @@ export interface ShimsSelect<T extends boolean = true> {
createdAt?: T;
globalType?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "minigame-rules_select".
*/
export interface MinigameRulesSelect<T extends boolean = true> {
enabled?: T;
periodLengthDays?: T;
anchorDate?: T;
placementLadderTopN?: T;
precisionMinAttempts?: T;
updatedAt?: T;
createdAt?: T;
globalType?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "collections_widget".

View file

@ -90,6 +90,11 @@ import { CustomMinefields } from "@/collections/minigames/CustomMinefields";
import { CustomMinefieldScores } from "@/collections/minigames/CustomMinefieldScores";
import { CustomRadioTests } from "@/collections/minigames/CustomRadioTests";
import { CustomRadioTestScores } from "@/collections/minigames/CustomRadioTestScores";
import { Minigames } from "@/collections/minigames/Minigames";
import { MinigameEntries } from "@/collections/minigames/MinigameEntries";
import { MinigamePeriods } from "@/collections/minigames/MinigamePeriods";
import { Achievements } from "@/collections/minigames/Achievements";
import { MinigameRules } from "@/collections/game/MinigameRules";
import { RibbonSubmissions } from "@/collections/users/RibbonSubmissions";
import { PromotionNominations } from "@/collections/users/PromotionNominations";
import { LeadershipTransfers } from "@/collections/users/LeadershipTransfers";
@ -377,6 +382,10 @@ const collections = [
CustomMinefieldScores,
CustomRadioTests,
CustomRadioTestScores,
Minigames,
MinigameEntries,
MinigamePeriods,
Achievements,
];
// Scoped admin pages: a user needs BOTH `<slug>:read` AND `admin:<slug>:manage`
@ -452,7 +461,7 @@ export default buildConfig({
},
},
},
globals: [GameRules, Shims],
globals: [GameRules, Shims, MinigameRules],
collections: scopedCollections,
editor: lexicalEditor({
features: ({ defaultFeatures }) => {

View file

@ -734,6 +734,13 @@ export const PERMISSION_GROUPS: PermissionGroup[] = [
{ value: "shims:update", label: "Update" },
],
},
{
group: "Minigame Rules (Global)",
permissions: [
{ value: "minigame-rules:read", label: "Read" },
{ value: "minigame-rules:update", label: "Update" },
],
},
// ---- Special / Feature-area ----------------------------------------------
{
@ -771,6 +778,27 @@ export const PERMISSION_GROUPS: PermissionGroup[] = [
{ value: "custom-radio-tests:update", label: "Edit Any Custom Radio Test" },
{ value: "custom-radio-tests:delete", label: "Delete Custom Radio Tests" },
{ value: "custom-radio-test-scores:delete", label: "Delete Custom Radio Test Scores" },
{ value: "minigames:create", label: ["Registry", "Create"] },
{ value: "minigames:read", label: ["Registry", "Read"] },
{ value: "minigames:update", label: ["Registry", "Update"] },
{ value: "minigames:delete", label: ["Registry", "Delete"] },
{ value: "admin:minigames:manage", label: ["Registry", "Manage Admin Page"] },
{ value: "minigame-entries:create", label: ["Entries", "Create"] },
{ value: "minigame-entries:read", label: ["Entries", "Read"] },
{ value: "minigame-entries:update", label: ["Entries", "Update"] },
{ value: "minigame-entries:delete", label: ["Entries", "Delete"] },
{ value: "admin:minigame-entries:manage", label: ["Entries", "Manage Admin Page"] },
{ value: "minigame-periods:create", label: ["Periods", "Create"] },
{ value: "minigame-periods:read", label: ["Periods", "Read"] },
{ value: "minigame-periods:update", label: ["Periods", "Update"] },
{ value: "minigame-periods:delete", label: ["Periods", "Delete"] },
{ value: "minigame-periods:close", label: ["Periods", "Close or Reopen"] },
{ value: "admin:minigame-periods:manage", label: ["Periods", "Manage Admin Page"] },
{ value: "achievements:create", label: ["Achievements", "Create"] },
{ value: "achievements:read", label: ["Achievements", "Read"] },
{ value: "achievements:update", label: ["Achievements", "Update"] },
{ value: "achievements:delete", label: ["Achievements", "Delete"] },
{ value: "admin:achievements:manage", label: ["Achievements", "Manage Admin Page"] },
],
},
];
@ -1102,6 +1130,8 @@ export const ALL_PERMISSION_VALUES = PERMISSION_GROUPS.flatMap((g) =>
"game-rules:update",
"shims:read",
"shims:update",
"minigame-rules:read",
"minigame-rules:update",
"announcements:create",
"announcements:read",
"announcements:update",
@ -1134,6 +1164,27 @@ export const ALL_PERMISSION_VALUES = PERMISSION_GROUPS.flatMap((g) =>
"custom-radio-tests:update",
"custom-radio-tests:delete",
"custom-radio-test-scores:delete",
"minigames:create",
"minigames:read",
"minigames:update",
"minigames:delete",
"admin:minigames:manage",
"minigame-entries:create",
"minigame-entries:read",
"minigame-entries:update",
"minigame-entries:delete",
"admin:minigame-entries:manage",
"minigame-periods:create",
"minigame-periods:read",
"minigame-periods:update",
"minigame-periods:delete",
"minigame-periods:close",
"admin:minigame-periods:manage",
"achievements:create",
"achievements:read",
"achievements:update",
"achievements:delete",
"admin:achievements:manage",
];
/**

View file

@ -2,6 +2,7 @@ import { seedRanks } from "@/tools/seed/seedRanks";
import { seedUsers } from "@/tools/seed/seedUsers";
import { seedFactions } from "@/tools/seed/seedFactions";
import { seedExperience } from "@/tools/seed/seedExperience";
import { seedMinigames } from "@/tools/seed/seedMinigames";
// Users
await seedUsers();
@ -10,3 +11,6 @@ await seedExperience();
// Intelligence
await seedFactions();
// Minigames
await seedMinigames();

View file

@ -0,0 +1,77 @@
import { getPayload } from "payload";
import config from "@payload-config";
import { BUILTIN_MINIGAMES, MINIGAME_RULE_DEFAULTS } from "@/lib/minigames/registry";
/**
* Idempotent seed for the minigame registry and rules global.
*
* Production gets the same defaults from the `add_minigame_periods` migration;
* this script exists for local resets and test/dev databases. Safe to re-run:
* existing registry rows are left untouched and only unset global fields are
* filled.
*/
export const seedMinigames = async (): Promise<void> => {
const payload = await getPayload({ config });
payload.logger.info("Seeding minigame registry...");
for (const game of BUILTIN_MINIGAMES) {
const existing = await payload.find({
collection: "minigames",
where: { key: { equals: game.key } },
limit: 1,
depth: 0,
overrideAccess: true,
});
if (existing.docs.length > 0) {
payload.logger.info(` Minigame "${game.key}" already exists, skipping.`);
continue;
}
const created = await payload.create({
collection: "minigames",
data: game,
overrideAccess: true,
});
payload.logger.info(` Created minigame "${game.key}" (id=${created.id}).`);
}
payload.logger.info("Seeding minigame-rules defaults...");
const existingRules = (await payload.findGlobal({
slug: "minigame-rules",
depth: 0,
overrideAccess: true,
})) as unknown as Record<string, unknown> | null;
const current = existingRules ?? {};
const data: Record<string, unknown> = {};
if (current.enabled == null) data.enabled = MINIGAME_RULE_DEFAULTS.enabled;
if (current.periodLengthDays == null) data.periodLengthDays = MINIGAME_RULE_DEFAULTS.periodLengthDays;
if (!current.anchorDate) data.anchorDate = MINIGAME_RULE_DEFAULTS.anchorDate;
if (current.placementLadderTopN == null) {
data.placementLadderTopN = MINIGAME_RULE_DEFAULTS.placementLadderTopN;
}
if (current.precisionMinAttempts == null) {
data.precisionMinAttempts = MINIGAME_RULE_DEFAULTS.precisionMinAttempts;
}
if (Object.keys(data).length > 0) {
await payload.updateGlobal({
slug: "minigame-rules",
data,
overrideAccess: true,
});
payload.logger.info(` Seeded minigame-rules defaults: ${Object.keys(data).join(", ")}.`);
} else {
payload.logger.info(" minigame-rules already seeded.");
}
};
if (import.meta.main) {
await seedMinigames();
// CLI script: the Payload pool keeps the event loop alive after completion;
// exit explicitly (same convention as the game-tick bins).
process.exit(0);
}