Support live attribute restoration mechanics

This commit is contained in:
JB
2026-07-27 21:32:04 -04:00
parent 36dd018a4a
commit 568e46cd05
19 changed files with 979 additions and 31 deletions
@@ -179,6 +179,90 @@ describe('conditional mechanic authoring payload', () => {
]);
});
it('accepts catalog Attribute references and rejects unknown IDs recursively', () => {
const referenced = draft();
referenced.clauses[0].outcomes[0] = {
key: 'health-restoration',
label: 'Health Restoration',
phase: 'after_event',
kind: 'restoration',
resource: 'health',
scope: 'self',
basis: 'flat',
delivery: 'continuous',
durationSeconds: 3,
variants: {
I: {
value: 240,
expression: {
op: 'multiply',
left: 240,
right: {
op: 'divide',
left: {
ref: {
source: 'attribute',
attributeId: 'firepower-multiplier'
}
},
right: 100
}
}
},
II: {
value: 336,
expression: {
op: 'multiply',
left: 336,
right: {
op: 'divide',
left: {
ref: {
source: 'attribute',
attributeId: 'firepower-multiplier'
}
},
right: 100
}
}
}
}
};
const accepted = parseConditionalMechanicDraft(referenced, {
variantKeys: ['I', 'II'],
allowedAttributeIds: new Set(['firepower-multiplier'])
});
expect(accepted.ok).toBe(true);
if (accepted.ok) {
expect(accepted.value.programs.I.clauses[0].outcomes?.[0].value).toMatchObject({
right: {
left: {
ref: {
source: 'attribute',
attributeId: 'firepower-multiplier'
}
}
}
});
expect(accepted.value.programs.II.clauses[0].outcomes?.[0]).toMatchObject({
delivery: 'continuous',
durationSeconds: 3,
value: { left: 336 }
});
}
const rejected = parseConditionalMechanicDraft(referenced, {
variantKeys: ['I', 'II'],
allowedAttributeIds: new Set(['weapon-damage'])
});
expect(rejected.ok).toBe(false);
if (!rejected.ok) {
expect(rejected.errors).toContain(
'Conditional mechanic clauses item 1 outcomes item 1 variants I expression right left ref references unknown Attribute "firepower-multiplier".'
);
}
});
it('requires the exact configured variants and returns validation errors without throwing', () => {
const invalid = draft();
invalid.clauses[0].outcomes[0].variants = {