From 0483a7effc52794964dc632adbe91b7b7a829a23 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sun, 24 Jul 2022 22:32:40 +0200 Subject: [PATCH] Tag targeting attributes and skills with effects now works like normal effects would --- .../buildComputation/linkTypeDependencies.js | 19 +++++++++++++++---- .../computeVariable/computeVariableAsSkill.js | 2 ++ app/imports/api/properties/Attributes.js | 9 +++++++++ app/imports/api/properties/Skills.js | 9 +++++++++ .../ui/properties/viewers/AttributeViewer.vue | 16 ++++------------ .../ui/properties/viewers/SkillViewer.vue | 17 ++++------------- 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js index 3de06818..5e907acc 100644 --- a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js +++ b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js @@ -128,10 +128,21 @@ function linkEffects(dependencyGraph, prop, computation){ if (prop.targetByTags){ getEffectTagTargets(prop, computation).forEach(targetId => { const targetProp = computation.propsById[targetId]; - const key = prop.targetField || getDefaultCalculationField(targetProp); - const calcObj = get(targetProp, key); - if (calcObj && calcObj.calculation){ - dependencyGraph.addLink(`${targetProp._id}.${key}`, prop._id , 'effect'); + if ( + (targetProp.type === 'attribute' || targetProp.type === 'skill') + && targetProp.variableName + && !prop.targetField + ) { + // If the field wasn't specified and we're targeting an attribute or + // skill, just treat it like a normal effect on its variable name + dependencyGraph.addLink(targetProp.variableName, prop._id, 'effect'); + } else { + // Otherwise target a field on that property + const key = prop.targetField || getDefaultCalculationField(targetProp); + const calcObj = get(targetProp, key); + if (calcObj && calcObj.calculation){ + dependencyGraph.addLink(`${targetProp._id}.${key}`, prop._id , 'effect'); + } } }); } else { diff --git a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js index 6b9c3222..828059c0 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js @@ -71,6 +71,8 @@ export default function computeVariableAsSkill(computation, node, prop){ prop.fail = aggregator.fail; // Rollbonus prop.rollBonuses = aggregator.rollBonus; + // Store effects + prop.effects = node.data.effects; } function aggregateAbilityEffects({computation, skillNode, abilityNode}){ diff --git a/app/imports/api/properties/Attributes.js b/app/imports/api/properties/Attributes.js index 5c83a660..4b4537c0 100644 --- a/app/imports/api/properties/Attributes.js +++ b/app/imports/api/properties/Attributes.js @@ -145,6 +145,15 @@ let ComputedOnlyAttributeSchema = createPropertySchema({ optional: true, removeBeforeCompute: true, }, + // A list of effect ids targeting this attribute + effects: { + type: Array, + optional: true, + }, + 'effects.$': { + type: Object, + blackbox: true, + }, }); const ComputedAttributeSchema = new SimpleSchema() diff --git a/app/imports/api/properties/Skills.js b/app/imports/api/properties/Skills.js index 281fe985..47ba2a76 100644 --- a/app/imports/api/properties/Skills.js +++ b/app/imports/api/properties/Skills.js @@ -131,6 +131,15 @@ let ComputedOnlySkillSchema = createPropertySchema({ optional: true, removeBeforeCompute: true, }, + // A list of effect ids targeting this skill + effects: { + type: Array, + optional: true, + }, + 'effects.$': { + type: Object, + blackbox: true, + }, }) const ComputedSkillSchema = new SimpleSchema() diff --git a/app/imports/ui/properties/viewers/AttributeViewer.vue b/app/imports/ui/properties/viewers/AttributeViewer.vue index 8e9cc4a4..6a2844c8 100644 --- a/app/imports/ui/properties/viewers/AttributeViewer.vue +++ b/app/imports/ui/properties/viewers/AttributeViewer.vue @@ -232,18 +232,10 @@ return []; } }, - effects(){ - if (this.context.creatureId && this.model.variableName){ - let creatureId = this.context.creatureId; - return CreatureProperties.find({ - 'ancestors.id': creatureId, - 'stats': this.model.variableName, - removed: {$ne: true}, - inactive: {$ne: true}, - }); - } else { - return []; - } + effects() { + return CreatureProperties.find({ + _id: { $in: this.model.effects?.map(e => e._id) || [] } + }); }, }, } diff --git a/app/imports/ui/properties/viewers/SkillViewer.vue b/app/imports/ui/properties/viewers/SkillViewer.vue index 62adf4a7..5cc7479e 100644 --- a/app/imports/ui/properties/viewers/SkillViewer.vue +++ b/app/imports/ui/properties/viewers/SkillViewer.vue @@ -210,19 +210,10 @@ export default { return []; } }, - effects(){ - if (this.context.creatureId && this.model.variableName){ - let creatureId = this.context.creatureId; - return CreatureProperties.find({ - 'ancestors.id': creatureId, - stats: this.model.variableName, - type: 'effect', - removed: {$ne: true}, - inactive: {$ne: true}, - }).fetch(); - } else { - return []; - } + effects() { + return CreatureProperties.find({ + _id: { $in: this.model.effects?.map(e => e._id) || [] } + }); }, baseProficiencies(){ if (this.context.creatureId){