feat: support custom labels for stat modifiers
Allows passing an optional label to `parseStatModifiers` to override the default ID-based label. This enables more descriptive names in the UI and improves how modifier labels are derived in the journal view.
This commit is contained in:
@@ -114,7 +114,7 @@ export function processBlocks(
|
||||
|
||||
if (attrs.role === "stat-modifiers") {
|
||||
const id = attrs.id || `_mod_${contentHash(body)}`;
|
||||
const result = parseStatModifiers(body, fileRelativePath, id);
|
||||
const result = parseStatModifiers(body, fileRelativePath, id, "player", attrs.extra["label"]);
|
||||
blocks.stats.push(result.statDef);
|
||||
blocks.stats.push(...result.modifierDefs);
|
||||
blocks.statTemplates.push(result.template);
|
||||
|
||||
@@ -270,7 +270,9 @@ export function parseStatModifiers(
|
||||
source: string,
|
||||
id: string,
|
||||
scope: "player" | "global" = "player",
|
||||
label?: string,
|
||||
): StatModifiersResult {
|
||||
const statLabel = label || id;
|
||||
const lines = csv.trim().split(/\r?\n/);
|
||||
const emptyTemplate: StatTemplate = {
|
||||
name: id,
|
||||
@@ -281,7 +283,7 @@ export function parseStatModifiers(
|
||||
|
||||
if (lines.length === 0) {
|
||||
return {
|
||||
statDef: { key: id, label: id, type: "template", scope, template: id, source },
|
||||
statDef: { key: id, label: statLabel, type: "template", scope, template: id, source },
|
||||
modifierDefs: [],
|
||||
template: emptyTemplate,
|
||||
};
|
||||
@@ -290,7 +292,7 @@ export function parseStatModifiers(
|
||||
const headers = lines[0].split(",").map((h) => h.trim().toLowerCase());
|
||||
if (headers.length < 2) {
|
||||
return {
|
||||
statDef: { key: id, label: id, type: "template", scope, template: id, source },
|
||||
statDef: { key: id, label: statLabel, type: "template", scope, template: id, source },
|
||||
modifierDefs: [],
|
||||
template: emptyTemplate,
|
||||
};
|
||||
@@ -344,7 +346,7 @@ export function parseStatModifiers(
|
||||
|
||||
const statDef: StatDef = {
|
||||
key: id,
|
||||
label: id,
|
||||
label: statLabel,
|
||||
type: "template",
|
||||
scope,
|
||||
template: id,
|
||||
|
||||
Reference in New Issue
Block a user