Made toggles function properly when nested under inactive properties and each other

This commit is contained in:
Stefan Zermatten
2021-03-01 11:55:43 +02:00
parent 2e3704d096
commit 7daab97297
3 changed files with 11 additions and 14 deletions

View File

@@ -2,6 +2,11 @@ import computeToggle from '/imports/api/creature/computation/engine/computeToggl
import { union } from 'lodash';
export default function applyToggles(prop, memo){
// If it used to be inactive delete those fields
if (prop.inactive) prop.inactive = undefined;
if (prop.deactivatedByAncestor) prop.deactivatedByAncestor = undefined;
if (prop.deactivatedByToggle) prop.deactivatedByToggle = undefined;
// Iterate through the toggle ancestors from oldest to nearest
prop.computationDetails.toggleAncestors.forEach(toggleId => {
let toggle = memo.togglesById[toggleId];
computeToggle(toggle, memo);
@@ -10,6 +15,7 @@ export default function applyToggles(prop, memo){
[toggle._id],
toggle.dependencies,
);
// Deactivate if the toggle is false
if (!toggle.toggleResult){
prop.inactive = true;
prop.deactivatedByAncestor = true;