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