Added compute triggers to store trigger ids on their
targeted props. Needs testing
This commit is contained in:
@@ -94,6 +94,36 @@ const DenormalisedOnlyCreaturePropertySchema = new SimpleSchema({
|
||||
optional: true,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
// Triggers that fire when this property is applied
|
||||
'triggerIds': {
|
||||
type: Object,
|
||||
optional: true,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
'triggerIds.before': {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'triggerIds.before.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
'triggerIds.after': {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'triggerIds.after.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
'triggerIds.afterChildren': {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'triggerIds.afterChildren.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
// When this is true on any property, the creature needs to be recomputed
|
||||
dirty: {
|
||||
type: Boolean,
|
||||
|
||||
@@ -7,6 +7,7 @@ import propertySlot from './computeByType/computeSlot.js';
|
||||
import container from './computeByType/computeContainer.js';
|
||||
import spellList from './computeByType/computeSpellList.js';
|
||||
import toggle from './computeByType/computeToggle.js';
|
||||
import trigger from './computeByType/computeTrigger.js'
|
||||
import _calculation from './computeByType/computeCalculation.js';
|
||||
|
||||
export default Object.freeze({
|
||||
@@ -21,4 +22,5 @@ export default Object.freeze({
|
||||
spell: action,
|
||||
spellList,
|
||||
toggle,
|
||||
trigger,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { get, set } from 'lodash';
|
||||
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies';
|
||||
|
||||
export default function computeTrigger(computation, node) {
|
||||
const prop = node.data;
|
||||
|
||||
// Triggers that aren't active aren't linked to properties
|
||||
if (prop.inactive) return;
|
||||
|
||||
// Link triggers to all the properties that would fire them when applied
|
||||
if (prop.event === 'doActionProperty') {
|
||||
getEffectTagTargets(prop, computation).forEach(targetId => {
|
||||
const targetProp = computation.propsById[targetId];
|
||||
// Only apply if the trigger matches this property type
|
||||
if (targetProp.type !== prop.actionPropertyType) return;
|
||||
let triggerIdArray = get(targetProp, `triggerIds.${prop.timing}`);
|
||||
if (!triggerIdArray) {
|
||||
triggerIdArray = [];
|
||||
set(targetProp, `triggerIds.${prop.timing}`, triggerIdArray);
|
||||
}
|
||||
triggerIdArray.push(prop._id);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user