1
0
Fork 0

Compare commits

..

No commits in common. "78dc4945f76550c7b79baec7669fed5595d6d05e" and "4c2fc86ecb6c8e6b13a15456e215d004282cf3dd" have entirely different histories.

8 changed files with 18 additions and 37440 deletions

View file

@ -1,6 +1,6 @@
{
"name": "polaris-task-force",
"version": "0.5.1",
"version": "0.5.0",
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
"license": "MIT",
"type": "module",

View file

@ -138,17 +138,13 @@ async function runEffect(
}
}
/**
* Effective value of a flag: player-specific entry takes priority; if absent,
* fall back to the global entry (user is null). Missing flags read false / 0.
*/
/** 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 }> {
// Player-specific flag (priority).
const playerRes = await payload.find({
const res = await payload.find({
collection: "player-flags",
where: {
user: { equals: userId },
@ -158,34 +154,13 @@ async function readFlag(
depth: 0,
overrideAccess: true,
});
const playerDoc = playerRes.docs[0];
if (playerDoc) {
if (playerDoc.flagType === "number") {
const num = playerDoc.numberValue ?? 0;
return { bool: num !== 0, num };
}
const bool = playerDoc.boolValue === true;
return { bool, num: bool ? 1 : 0 };
}
// Global fallback (user is null).
const globalRes = await payload.find({
collection: "player-flags",
where: {
user: { equals: null },
key: { equals: key },
},
limit: 1,
depth: 0,
overrideAccess: true,
});
const globalDoc = globalRes.docs[0];
if (!globalDoc) return { bool: false, num: 0 };
if (globalDoc.flagType === "number") {
const num = globalDoc.numberValue ?? 0;
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 = globalDoc.boolValue === true;
const bool = doc.boolValue === true;
return { bool, num: bool ? 1 : 0 };
}

View file

@ -2,11 +2,9 @@ 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.
* 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",
@ -28,8 +26,9 @@ export const PlayerFlags: CollectionConfig = {
name: "user",
type: "relationship",
relationTo: "users",
required: true,
admin: {
description: "The player this flag belongs to. Leave empty for a global flag.",
description: "The player this flag belongs to.",
},
},
{

View file

@ -411,8 +411,8 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N
placeholder="met_informant"
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
/>
<p className="text-[10px] text-zinc-400">
Player-specific flag takes priority; falls back to global (no user). Missing = false / 0.
<p className="text-[10px] text-white/40">
Checked against the player&apos;s flags. A missing flag counts as false / 0.
</p>
</div>

File diff suppressed because it is too large Load diff

View file

@ -1,11 +0,0 @@
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "player_flags" ALTER COLUMN "user_id" DROP NOT NULL;`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "player_flags" ALTER COLUMN "user_id" SET NOT NULL;`)
}

View file

@ -108,7 +108,6 @@ import * as migration_20261005_054132_add_game_npc_bio_richtext from './20261005
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_155244_add_global_flag_support from './20261006_155244_add_global_flag_support';
export const migrations = [
{
@ -659,11 +658,6 @@ export const migrations = [
{
up: migration_20261006_000000_add_npc_dialogue_and_activity_fields.up,
down: migration_20261006_000000_add_npc_dialogue_and_activity_fields.down,
name: '20261006_000000_add_npc_dialogue_and_activity_fields',
},
{
up: migration_20261006_155244_add_global_flag_support.up,
down: migration_20261006_155244_add_global_flag_support.down,
name: '20261006_155244_add_global_flag_support'
name: '20261006_000000_add_npc_dialogue_and_activity_fields'
},
];

View file

@ -2545,9 +2545,9 @@ export interface NpcDialogue {
export interface PlayerFlag {
id: number;
/**
* The player this flag belongs to. Leave empty for a global flag.
* The player this flag belongs to.
*/
user?: (number | null) | User;
user: number | User;
/**
* Stable key referenced by conversation nodes (e.g. 'met_informant', 'rep_merchants'). Lowercase with underscores.
*/