Fixed properties not being made inactive by toggles
This commit is contained in:
@@ -7,6 +7,7 @@ export default class ComputationMemo {
|
||||
constructor(props, creature){
|
||||
this.statsByVariableName = {};
|
||||
this.constantsByVariableName = {};
|
||||
this.constantsById = {};
|
||||
this.extraStatsByVariableName = {};
|
||||
this.statsById = {};
|
||||
this.originalPropsById = {};
|
||||
@@ -77,11 +78,7 @@ export default class ComputationMemo {
|
||||
}
|
||||
addConstant(prop){
|
||||
prop = this.registerProperty(prop);
|
||||
if (
|
||||
!this.constantsByVariableName[prop.variableName]
|
||||
){
|
||||
this.constantsByVariableName[prop.variableName] = prop
|
||||
}
|
||||
this.constantsById[prop._id] = prop;
|
||||
}
|
||||
registerProperty(prop){
|
||||
this.originalPropsById[prop._id] = cloneDeep(prop);
|
||||
|
||||
@@ -3,4 +3,10 @@ import applyToggles from '/imports/api/creature/computation/engine/applyToggles.
|
||||
export default function computeConstant(constant, memo){
|
||||
// Apply any toggles
|
||||
applyToggles(constant, memo);
|
||||
if (constant.deactivatedByToggle) return;
|
||||
if (
|
||||
!memo.constantsByVariableName[constant.variableName]
|
||||
){
|
||||
memo.constantsByVariableName[constant.variableName] = constant
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
||||
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||
import { union } from 'lodash';
|
||||
|
||||
export default function computeEndStepProperty(prop, memo){
|
||||
applyToggles(prop, memo);
|
||||
|
||||
switch (prop.type){
|
||||
case 'action':
|
||||
case 'spell':
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { forOwn, has, union } from 'lodash';
|
||||
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||
|
||||
export default function computeLevels(memo){
|
||||
computeClassLevels(memo);
|
||||
@@ -7,11 +8,13 @@ export default function computeLevels(memo){
|
||||
|
||||
function computeClassLevels(memo){
|
||||
forOwn(memo.classLevelsById, classLevel => {
|
||||
applyToggles(classLevel, memo);
|
||||
// class levels are mutually dependent
|
||||
classLevel.dependencies = union(
|
||||
classLevel.dependencies,
|
||||
Object.keys(memo.classLevelsById)
|
||||
);
|
||||
if (classLevel.deactivatedByToggle) return;
|
||||
let name = classLevel.variableName;
|
||||
let stat = memo.statsByVariableName[name];
|
||||
if (!stat){
|
||||
@@ -29,7 +32,7 @@ function computeClassLevels(memo){
|
||||
|
||||
function computeTotalLevel(memo){
|
||||
let currentLevel = memo.statsByVariableName['level'];
|
||||
if (!currentLevel){
|
||||
if (!currentLevel || currentLevel.deactivatedByToggle){
|
||||
currentLevel = {
|
||||
value: 0,
|
||||
dependencies: [],
|
||||
|
||||
@@ -9,7 +9,7 @@ import computeConstant from '/imports/api/creature/computation/engine/computeCon
|
||||
|
||||
export default function computeMemo(memo){
|
||||
// Compute all constants that could be used
|
||||
forOwn(memo.constantsByVariableName, constant => {
|
||||
forOwn(memo.constantsById, constant => {
|
||||
computeConstant (constant, memo);
|
||||
});
|
||||
// Compute level
|
||||
|
||||
@@ -22,28 +22,25 @@ export default function computeStat(stat, memo){
|
||||
// Apply any toggles
|
||||
applyToggles(stat, memo);
|
||||
|
||||
if (!stat.deactivatedByToggle){
|
||||
// Compute and aggregate all the effects
|
||||
let aggregator = new EffectAggregator(stat, memo)
|
||||
each(stat.computationDetails.effects, (effect) => {
|
||||
computeEffect(effect, memo);
|
||||
if (effect._id){
|
||||
stat.dependencies = union(
|
||||
stat.dependencies,
|
||||
[effect._id]
|
||||
);
|
||||
}
|
||||
// Compute and aggregate all the effects
|
||||
let aggregator = new EffectAggregator(stat, memo)
|
||||
each(stat.computationDetails.effects, (effect) => {
|
||||
computeEffect(effect, memo);
|
||||
if (effect.deactivatedByToggle) return;
|
||||
if (effect._id){
|
||||
stat.dependencies = union(
|
||||
stat.dependencies,
|
||||
effect.dependencies
|
||||
)
|
||||
if (!effect.deactivatedByToggle){
|
||||
aggregator.addEffect(effect);
|
||||
}
|
||||
});
|
||||
// Conglomerate all the effects to compute the final stat values
|
||||
combineStat(stat, aggregator, memo);
|
||||
}
|
||||
[effect._id]
|
||||
);
|
||||
}
|
||||
stat.dependencies = union(
|
||||
stat.dependencies,
|
||||
effect.dependencies
|
||||
)
|
||||
aggregator.addEffect(effect);
|
||||
});
|
||||
// Conglomerate all the effects to compute the final stat values
|
||||
combineStat(stat, aggregator, memo);
|
||||
// Mark the attribute as computed
|
||||
stat.computationDetails.computed = true;
|
||||
stat.computationDetails.busyComputing = false;
|
||||
|
||||
@@ -8,7 +8,10 @@ export default function writeAlteredProperties(memo){
|
||||
// Loop through all properties on the memo
|
||||
forOwn(memo.propsById, changed => {
|
||||
let schema = propertySchemasIndex[changed.type];
|
||||
if (!schema) return;
|
||||
if (!schema){
|
||||
console.warn('No schema for ' + changed.type);
|
||||
return;
|
||||
}
|
||||
let extraIds = changed.computationDetails.idsOfSameName;
|
||||
let ids;
|
||||
if (extraIds && extraIds.length){
|
||||
|
||||
@@ -4,21 +4,22 @@ import { ComputedOnlyAdjustmentSchema } from '/imports/api/properties/Adjustment
|
||||
import { ComputedOnlyAttackSchema } from '/imports/api/properties/Attacks.js';
|
||||
import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes.js';
|
||||
import { ComputedOnlyBuffSchema } from '/imports/api/properties/Buffs.js';
|
||||
// import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
|
||||
import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
|
||||
import { ConstantSchema } from '/imports/api/properties/Constants.js';
|
||||
import { ComputedOnlyContainerSchema } from '/imports/api/properties/Containers.js';
|
||||
import { ComputedOnlyDamageSchema } from '/imports/api/properties/Damages.js';
|
||||
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
||||
import { ComputedOnlyEffectSchema } from '/imports/api/properties/Effects.js';
|
||||
import { ComputedOnlyFeatureSchema } from '/imports/api/properties/Features.js';
|
||||
// import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||
import { ComputedOnlyItemSchema } from '/imports/api/properties/Items.js';
|
||||
import { ComputedOnlyNoteSchema } from '/imports/api/properties/Notes.js';
|
||||
// import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
||||
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
||||
import { ComputedOnlyRollSchema } from '/imports/api/properties/Rolls.js';
|
||||
import { ComputedOnlySavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
|
||||
import { ComputedOnlySkillSchema } from '/imports/api/properties/Skills.js';
|
||||
import { ComputedOnlySlotSchema } from '/imports/api/properties/Slots.js';
|
||||
// import { SlotFillerSchema } from '/imports/api/properties/SlotFillers.js';
|
||||
import { SlotFillerSchema } from '/imports/api/properties/SlotFillers.js';
|
||||
import { ComputedOnlySpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { ComputedOnlySpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||
import { ComputedOnlyToggleSchema } from '/imports/api/properties/Toggles.js';
|
||||
@@ -29,23 +30,25 @@ const propertySchemasIndex = {
|
||||
attack: ComputedOnlyAttackSchema,
|
||||
attribute: ComputedOnlyAttributeSchema,
|
||||
buff: ComputedOnlyBuffSchema,
|
||||
// classLevel: ClassLevelSchema,
|
||||
classLevel: ClassLevelSchema,
|
||||
constant: ConstantSchema,
|
||||
container: ComputedOnlyContainerSchema,
|
||||
damage: ComputedOnlyDamageSchema,
|
||||
damageMultiplier: DamageMultiplierSchema,
|
||||
effect: ComputedOnlyEffectSchema,
|
||||
feature: ComputedOnlyFeatureSchema,
|
||||
// folder: FolderSchema,
|
||||
folder: FolderSchema,
|
||||
item: ComputedOnlyItemSchema,
|
||||
note: ComputedOnlyNoteSchema,
|
||||
// proficiency: ProficiencySchema,
|
||||
proficiency: ProficiencySchema,
|
||||
propertySlot: ComputedOnlySlotSchema,
|
||||
roll: ComputedOnlyRollSchema,
|
||||
savingThrow: ComputedOnlySavingThrowSchema,
|
||||
skill: ComputedOnlySkillSchema,
|
||||
slotFiller: SlotFillerSchema,
|
||||
spellList: ComputedOnlySpellListSchema,
|
||||
spell: ComputedOnlySpellSchema,
|
||||
toggle: ComputedOnlyToggleSchema,
|
||||
container: ComputedOnlyContainerSchema,
|
||||
item: ComputedOnlyItemSchema,
|
||||
any: new SimpleSchema({}),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user