Fixed issue: toggled off point buys still applying
This commit is contained in:
@@ -277,7 +277,6 @@ function linkPointBuy(dependencyGraph, prop) {
|
|||||||
linkVariableName(dependencyGraph, pointBuyRow);
|
linkVariableName(dependencyGraph, pointBuyRow);
|
||||||
dependencyGraph.addLink(pointBuyRow._id, prop._id, 'pointBuyRow');
|
dependencyGraph.addLink(pointBuyRow._id, prop._id, 'pointBuyRow');
|
||||||
});
|
});
|
||||||
if (prop.inactive) return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function linkProficiencies(dependencyGraph, prop, computation) {
|
function linkProficiencies(dependencyGraph, prop, computation) {
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ export default function computePointBuy(computation, node) {
|
|||||||
const max = has(prop, 'max.value') ? prop.max.value : null;
|
const max = has(prop, 'max.value') ? prop.max.value : null;
|
||||||
prop.spent = 0;
|
prop.spent = 0;
|
||||||
prop.values?.forEach(row => {
|
prop.values?.forEach(row => {
|
||||||
// Clean up added properties
|
|
||||||
// delete row.tableId;
|
|
||||||
// delete row.tableName;
|
|
||||||
// delete row.type;
|
|
||||||
|
|
||||||
row.spent = 0;
|
row.spent = 0;
|
||||||
if (row.value === undefined) return;
|
if (row.value === undefined) return;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import computeVariableAsClass from './computeVariable/computeVariableAsClass.js'
|
|||||||
import computeVariableAsToggle from './computeVariable/computeVariableAsToggle.js';
|
import computeVariableAsToggle from './computeVariable/computeVariableAsToggle.js';
|
||||||
import computeImplicitVariable from './computeVariable/computeImplicitVariable.js';
|
import computeImplicitVariable from './computeVariable/computeImplicitVariable.js';
|
||||||
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||||
|
import { computedInlineCalculationField } from '/imports/api/properties/subSchemas/inlineCalculationField';
|
||||||
|
|
||||||
export default function computeVariable(computation, node) {
|
export default function computeVariable(computation, node) {
|
||||||
const scope = computation.scope;
|
const scope = computation.scope;
|
||||||
@@ -31,6 +32,11 @@ function aggregateLinks(computation, node) {
|
|||||||
if (!linkedNode.data) linkedNode.data = {};
|
if (!linkedNode.data) linkedNode.data = {};
|
||||||
// Ignore inactive props
|
// Ignore inactive props
|
||||||
if (linkedNode.data.inactive) return;
|
if (linkedNode.data.inactive) return;
|
||||||
|
// Ignore point buy rows if their base table is inactive
|
||||||
|
if (
|
||||||
|
linkedNode.data.tableId
|
||||||
|
&& computation.propsById[linkedNode.data.tableId]?.inactive
|
||||||
|
) return;
|
||||||
// Apply all the aggregations
|
// Apply all the aggregations
|
||||||
let arg = { node, linkedNode, link, computation };
|
let arg = { node, linkedNode, link, computation };
|
||||||
aggregate.classLevel(arg);
|
aggregate.classLevel(arg);
|
||||||
|
|||||||
@@ -1,59 +1,52 @@
|
|||||||
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||||
import clean from '../../utility/cleanProp.testFn.js';
|
import { propsFromForest } from '/imports/api/properties/tests/propTestBuilder.testFn.js';
|
||||||
|
|
||||||
export default function(){
|
export default function () {
|
||||||
const computation = buildComputationFromProps(testProperties);
|
const computation = buildComputationFromProps(testProperties);
|
||||||
computeCreatureComputation(computation);
|
computeCreatureComputation(computation);
|
||||||
const prop = id => computation.propsById[id];
|
const prop = id => computation.propsById[id];
|
||||||
assert.equal(prop('strengthId').value, 26);
|
assert.equal(prop('strengthId').value, 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
var testProperties = [
|
var testProperties = propsFromForest([
|
||||||
clean({
|
{
|
||||||
_id: 'strengthId',
|
|
||||||
variableName: 'strength',
|
variableName: 'strength',
|
||||||
type: 'attribute',
|
type: 'attribute',
|
||||||
attributeType: 'ability',
|
attributeType: 'ability',
|
||||||
baseValue: {
|
baseValue: {
|
||||||
calculation: '8'
|
calculation: '8'
|
||||||
},
|
},
|
||||||
}),
|
}, {
|
||||||
clean({
|
// This strength is later in order, so it will override the other
|
||||||
_id: 'strength2Id',
|
_id: 'strengthId',
|
||||||
variableName: 'strength',
|
variableName: 'strength',
|
||||||
type: 'attribute',
|
type: 'attribute',
|
||||||
attributeType: 'ability',
|
attributeType: 'ability',
|
||||||
baseValue: {
|
baseValue: {
|
||||||
calculation: '10'
|
calculation: '10'
|
||||||
},
|
},
|
||||||
}),
|
}, {
|
||||||
clean({
|
|
||||||
_id: 'strengthBaseId',
|
|
||||||
type: 'effect',
|
type: 'effect',
|
||||||
operation: 'base',
|
operation: 'base',
|
||||||
amount: {
|
amount: {
|
||||||
calculation: '10 + 2'
|
calculation: '10 + 2'
|
||||||
},
|
},
|
||||||
stats: ['strength'],
|
stats: ['strength'],
|
||||||
}),
|
}, {
|
||||||
clean({
|
|
||||||
_id: 'strengthAddId',
|
|
||||||
type: 'effect',
|
type: 'effect',
|
||||||
operation: 'add',
|
operation: 'add',
|
||||||
amount: {
|
amount: {
|
||||||
calculation: '1'
|
calculation: '1'
|
||||||
},
|
},
|
||||||
stats: ['strength'],
|
stats: ['strength'],
|
||||||
}),
|
}, {
|
||||||
clean({
|
|
||||||
_id: 'strengthMulId',
|
|
||||||
type: 'effect',
|
type: 'effect',
|
||||||
operation: 'mul',
|
operation: 'mul',
|
||||||
amount: {
|
amount: {
|
||||||
calculation: '2'
|
calculation: '2'
|
||||||
},
|
},
|
||||||
stats: ['strength'],
|
stats: ['strength'],
|
||||||
}),
|
},
|
||||||
];
|
]);
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||||
|
import { propsFromForest } from '/imports/api/properties/tests/propTestBuilder.testFn.js';
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
const computation = buildComputationFromProps(testProperties);
|
||||||
|
computeCreatureComputation(computation);
|
||||||
|
const prop = id => computation.propsById[id];
|
||||||
|
assert.equal(prop('strengthId').value, 11, 'Point buys should apply a base value when active');
|
||||||
|
}
|
||||||
|
|
||||||
|
var testProperties = propsFromForest([
|
||||||
|
{
|
||||||
|
_id: 'strengthId',
|
||||||
|
variableName: 'strength',
|
||||||
|
type: 'attribute',
|
||||||
|
attributeType: 'ability',
|
||||||
|
baseValue: {
|
||||||
|
calculation: '8'
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
// calculated inactive toggle with point buy under it
|
||||||
|
// It should not impact the ability score
|
||||||
|
type: 'toggle',
|
||||||
|
condition: { calculation: 'false' },
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
_id: 'inactivePointBuy',
|
||||||
|
type: 'pointBuy',
|
||||||
|
values: [{ variableName: 'strength', value: 13 }],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
type: 'pointBuy',
|
||||||
|
values: [{ variableName: 'strength', value: 11 }],
|
||||||
|
}
|
||||||
|
]);
|
||||||
@@ -7,6 +7,7 @@ import computeInventory from './computeInventory.testFn.js';
|
|||||||
import computeDamageMultipliers from './computeDamageMultipliers.testFn.js';
|
import computeDamageMultipliers from './computeDamageMultipliers.testFn.js';
|
||||||
import computeEffects from './computeEffects.testFn.js';
|
import computeEffects from './computeEffects.testFn.js';
|
||||||
import computeSkills from './computeSkills.testFn.js';
|
import computeSkills from './computeSkills.testFn.js';
|
||||||
|
import computePointBuys from './computePointBuys.testFn.js';
|
||||||
import computeProficiencies from './computeProficiencies.testFn.js';
|
import computeProficiencies from './computeProficiencies.testFn.js';
|
||||||
|
|
||||||
export default [{
|
export default [{
|
||||||
@@ -36,6 +37,9 @@ export default [{
|
|||||||
}, {
|
}, {
|
||||||
text: 'Computes skills',
|
text: 'Computes skills',
|
||||||
fn: computeSkills,
|
fn: computeSkills,
|
||||||
|
}, {
|
||||||
|
text: 'Computes point buys',
|
||||||
|
fn: computePointBuys,
|
||||||
}, {
|
}, {
|
||||||
text: 'Computes proficiencies',
|
text: 'Computes proficiencies',
|
||||||
fn: computeProficiencies,
|
fn: computeProficiencies,
|
||||||
|
|||||||
40
app/imports/api/properties/tests/propTestBuilder.testFn.js
Normal file
40
app/imports/api/properties/tests/propTestBuilder.testFn.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* Take a forest of props, which can have sub-props nested in children: [], and return a list of
|
||||||
|
* clean props with correct tree and ancestry data
|
||||||
|
* @param props
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function propsFromForest(
|
||||||
|
props,
|
||||||
|
ancestry = [{ id: 'creatureId', collection: 'creatures' }],
|
||||||
|
) {
|
||||||
|
const result = [];
|
||||||
|
props.forEach(prop => {
|
||||||
|
const children = prop.children;
|
||||||
|
// Check the property has a type
|
||||||
|
if (!prop.type) {
|
||||||
|
console.log(prop);
|
||||||
|
throw 'Type is required on every property, not found on above doc';
|
||||||
|
}
|
||||||
|
// Create the clean doc
|
||||||
|
const doc = { ...prop };
|
||||||
|
if (!doc._id) {
|
||||||
|
doc._id = Random.id();
|
||||||
|
}
|
||||||
|
delete doc.children;
|
||||||
|
doc.order = result.length;
|
||||||
|
doc.parent = { ...ancestry[ancestry.length - 1] };
|
||||||
|
doc.ancestors = [...ancestry];
|
||||||
|
|
||||||
|
// Add the doc to the result and ancestry
|
||||||
|
result.push(doc);
|
||||||
|
if (children) {
|
||||||
|
ancestry.push({ id: doc._id, collection: 'creatureProperties' });
|
||||||
|
// Add the children to the result
|
||||||
|
result.push(...propsFromForest(children, ancestry));
|
||||||
|
// Remove the doc from the ancestry after its children are done
|
||||||
|
ancestry.pop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user