feat: implement scoped stat system with player/global support

Introduces a scoping mechanism for statistics, allowing properties
to be defined as either "player" (prefixed with player name) or
"global".

- Adds `scope` property to StatDef
- Implements key resolution to handle bare keys vs full keys
- Updates `canModifyStat` to enforce player-specific permissions
- Enhances `makeStatLookup` to resolve scoped references in formulas
- Adds documentation for the new stat system
This commit is contained in:
2026-07-09 09:41:16 +08:00
parent 44e4e15f3f
commit 138c089514
5 changed files with 400 additions and 77 deletions
+3
View File
@@ -43,6 +43,7 @@ export interface StatDef {
key: string;
label: string;
type: "number" | "string" | "enum" | "modifier" | "derived";
scope: "player" | "global";
default?: string;
target?: string;
options?: string[];
@@ -204,10 +205,12 @@ function parseStatYaml(yaml: string, source: string): StatDef[] {
function flushCurrent() {
if (!current || !current.key) return;
const type = (current.type || "number") as StatDef["type"];
const scope = (current.scope || "global") as StatDef["scope"];
defs.push({
key: current.key,
label: current.label || current.key,
type,
scope,
default: current.default,
target: current.target,
options: