diff --git a/app/imports/api/engine/computation/buildComputation/tests/computeInactiveStatus.testFn.js b/app/imports/api/engine/computation/buildComputation/tests/computeInactiveStatus.testFn.js index c7565156..463a072f 100644 --- a/app/imports/api/engine/computation/buildComputation/tests/computeInactiveStatus.testFn.js +++ b/app/imports/api/engine/computation/buildComputation/tests/computeInactiveStatus.testFn.js @@ -2,8 +2,9 @@ import { buildComputationFromProps } from '/imports/api/engine/computation/build import { assert } from 'chai'; import clean from '../../utility/cleanProp.testFn.js'; -export default function(){ +export default function () { let computation = buildComputationFromProps(testProperties); + const bySelf = (propId, note) => assertDeactivatedBySelf(computation, propId, note); const byAncestor = (propId, note) => assertDeactivatedByAncestor(computation, propId, note); const active = (propId, note) => assertActive(computation, propId, note); @@ -24,22 +25,22 @@ export default function(){ // Notes active('NoteId', 'Notes should be active'); - byAncestor('NoteChildId', 'children of notes should always be inactive'); + active('NoteChildId', 'children of notes should be active'); } -function assertDeactivatedBySelf(computation, propId, note){ +function assertDeactivatedBySelf(computation, propId, note) { const prop = computation.propsById[propId]; assert.isTrue(prop.deactivatedBySelf, note); assert.isTrue(prop.inactive, note + '. The property should be inactive'); } -function assertDeactivatedByAncestor(computation, propId, note){ +function assertDeactivatedByAncestor(computation, propId, note) { const prop = computation.propsById[propId]; assert.isTrue(prop.deactivatedByAncestor, note); assert.isTrue(prop.inactive, 'The property should be inactive'); } -function assertActive(computation, propId, note){ +function assertActive(computation, propId, note) { const prop = computation.propsById[propId]; assert.isNotTrue(prop.inactive, note); assert.isNotTrue(prop.deactivatedBySelf, note); @@ -51,66 +52,90 @@ var testProperties = [ clean({ _id: 'itemUnequippedId', type: 'item', - ancestors: [{id: 'charId'}], + parentId: 'charId', + left: 1, + right: 4, }), clean({ _id: 'itemUnequippedChildId', type: 'folder', - ancestors: [{id: 'charId'}, {id: 'itemUnequippedId'}], + parentId: 'itemUnequippedId', + left: 2, + right: 3, }), clean({ _id: 'itemEquippedId', type: 'item', equipped: true, - ancestors: [{id: 'charId'}], + parentId: 'charId', + left: 5, + right: 8, }), clean({ _id: 'itemEquippedChildId', type: 'folder', - ancestors: [{id: 'charId'}, {id: 'itemEquippedId'}], + parentId: 'itemEquippedId', + left: 6, + right: 7, }), // Spells clean({ _id: 'spellPreparedId', type: 'spell', - ancestors: [{id: 'charId'}], + parentId: 'charId', prepared: true, + left: 9, + right: 12, }), clean({ _id: 'spellPreparedChildId', type: 'folder', - ancestors: [{id: 'charId'}, {id: 'spellPreparedId'}], + parentId: 'spellPreparedId', + left: 10, + right: 11, }), clean({ _id: 'spellAlwaysPreparedId', type: 'spell', - ancestors: [{id: 'charId'}], + parentId: 'charId', alwaysPrepared: true, + left: 13, + right: 16, }), clean({ _id: 'spellAlwaysPreparedChildId', type: 'folder', - ancestors: [{id: 'charId'}, {id: 'spellAlwaysPreparedId'}], + parentId: 'spellAlwaysPreparedId', + left: 14, + right: 15, }), clean({ _id: 'spellUnpreparedId', type: 'spell', - ancestors: [{id: 'charId'}], + parentId: 'charId', + left: 17, + right: 20, }), clean({ _id: 'spellUnpreparedChildId', type: 'folder', - ancestors: [{id: 'charId'}, {id: 'spellUnpreparedId'}], + parentId: 'spellUnpreparedId', + left: 18, + right: 19, }), // Notes clean({ _id: 'NoteId', type: 'note', - ancestors: [{id: 'charId'}], + parentId: 'charId', + left: 21, + right: 24, }), clean({ _id: 'NoteChildId', type: 'folder', - ancestors: [{id: 'charId'}, {id: 'NoteId'}], + parentId: 'NoteId', + left: 22, + right: 23, }), ]; diff --git a/app/imports/api/engine/computation/buildCreatureComputation.js b/app/imports/api/engine/computation/buildCreatureComputation.js index 776d0db5..44d0edf4 100644 --- a/app/imports/api/engine/computation/buildCreatureComputation.js +++ b/app/imports/api/engine/computation/buildCreatureComputation.js @@ -1,4 +1,4 @@ -import { docsToForest as nodeArrayToTree } from '/imports/api/parenting/parentingFunctions'; +import { docsToForest } from '/imports/api/parenting/parentingFunctions'; import { DenormalisedOnlyCreaturePropertySchema as denormSchema } from '/imports/api/creature/creatureProperties/CreatureProperties'; import { getProperties, getCreature, getVariables } from '/imports/api/engine/loadCreatures.js'; @@ -12,7 +12,7 @@ import computeToggleDependencies from './buildComputation/computeToggleDependenc import linkCalculationDependencies from './buildComputation/linkCalculationDependencies.js'; import linkTypeDependencies from './buildComputation/linkTypeDependencies.js'; import computeSlotQuantityFilled from './buildComputation/computeSlotQuantityFilled.js'; -import CreatureComputation from './CreatureComputation.ts'; +import CreatureComputation from './CreatureComputation'; import removeSchemaFields from './buildComputation/removeSchemaFields.js'; /** @@ -86,7 +86,7 @@ export function buildComputationFromProps(properties, creature, variables) { }); // Get all the properties as trees based on their ancestors - let forest = nodeArrayToTree(properties); + let forest = docsToForest(properties); // Walk the property trees computing things that need to be inherited walkDown(forest, node => { computeInactiveStatus(node);