began work to get inactive state of properties denormalised
This commit is contained in:
@@ -44,7 +44,13 @@ let CreaturePropertySchema = new SimpleSchema({
|
||||
icon: {
|
||||
type: storedIconsSchema,
|
||||
optional: true,
|
||||
}
|
||||
},
|
||||
// Denormalised flag if this property is inactive on the sheet for any reason
|
||||
// Including being disabled, or a decendent of a disabled property
|
||||
inactive: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (let key in propertySchemasIndex){
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function computeToggle(toggle, memo){
|
||||
toggle.toggleResult = !!+toggle.condition;
|
||||
} else {
|
||||
let {value, errors} = evaluateCalculation(toggle.condition, memo);
|
||||
toggle.toggleResult = value;
|
||||
toggle.toggleResult = !!value;
|
||||
if (errors.length){
|
||||
toggle.errors = errors;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import ComputationMemo from '/imports/api/creature/computation/ComputationMemo.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import computeMemo from '/imports/api/creature/computation/computeMemo.js';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
import writeAlteredProperties from '/imports/api/creature/computation/writeAlteredProperties.js';
|
||||
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.js';
|
||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js';
|
||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/denormalise/recomputeDamageMultipliers.js';
|
||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
|
||||
export const recomputeCreature = new ValidatedMethod({
|
||||
@@ -95,12 +97,18 @@ export function recomputeCreatureById(creatureId){
|
||||
*/
|
||||
export function recomputeCreatureByDoc(creature){
|
||||
const creatureId = creature._id;
|
||||
let props = getActiveProperties({
|
||||
recomputeInactiveProperties(creatureId);
|
||||
let props = CreatureProperties.find({
|
||||
'ancestors.id': creatureId,
|
||||
inactive: {$ne: true},
|
||||
type: {$in: calculationPropertyTypes},
|
||||
}).fetch();
|
||||
/*getActiveProperties({
|
||||
ancestorId: creatureId,
|
||||
filter: {type: {$in: calculationPropertyTypes}},
|
||||
includeUntoggled: true,
|
||||
// TODO filter out expensive fields, particularly icon field
|
||||
});
|
||||
});*/
|
||||
let computationMemo = new ComputationMemo(props, creature);
|
||||
computeMemo(computationMemo);
|
||||
writeAlteredProperties(computationMemo);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
export default function recomputeInactiveProperties(ancestorId){
|
||||
let disabledFilter = {
|
||||
'ancestors.id': ancestorId,
|
||||
$or: [
|
||||
{disabled: true}, // Everything can be disabled
|
||||
{type: 'buff', applied: false}, // Buffs can be applied
|
||||
{type: 'item', equipped: {$ne: true}},
|
||||
{type: 'toggle', toggleResult: false},
|
||||
{type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}},
|
||||
],
|
||||
};
|
||||
let disabledIds = CreatureProperties.find(disabledFilter, {
|
||||
fields: {_id: 1},
|
||||
}).map(prop => prop._id);
|
||||
|
||||
// Set all the properties inactive that aren't already inactive but should be
|
||||
CreatureProperties.update({
|
||||
'ancestors.id': ancestorId,
|
||||
$or: [{
|
||||
'_id': {$in: disabledIds}
|
||||
}, {
|
||||
'ancestors.id': {$in: disabledIds}
|
||||
}],
|
||||
inactive: {$ne: true},
|
||||
}, {
|
||||
$set: {inactive: true},
|
||||
}, {
|
||||
multi: true,
|
||||
selector: {type: 'any'},
|
||||
});
|
||||
// Remove inactive from all the properties that are inactive but shouldn't be
|
||||
CreatureProperties.update({
|
||||
'ancestors.id': {$eq: ancestorId, $nin: disabledIds},
|
||||
'_id': {$nin: disabledIds},
|
||||
inactive: true,
|
||||
}, {
|
||||
$unset: {inactive: 1},
|
||||
}, {
|
||||
multi: true,
|
||||
selector: {type: 'any'},
|
||||
});
|
||||
}
|
||||
@@ -25,7 +25,7 @@ const ToggleSchema = new SimpleSchema({
|
||||
const ComputedOnlyToggleSchema = new SimpleSchema({
|
||||
// The computed result of the effect
|
||||
toggleResult: {
|
||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
// The errors encountered while computing the result
|
||||
|
||||
Reference in New Issue
Block a user