fixed: Show only the last event with a var name
This commit is contained in:
@@ -23,23 +23,26 @@ const linkDependenciesByType = {
|
||||
toggle: linkToggle,
|
||||
}
|
||||
|
||||
export default function linkTypeDependencies(dependencyGraph, prop, computation){
|
||||
export default function linkTypeDependencies(dependencyGraph, prop, computation) {
|
||||
linkDependenciesByType[prop.type]?.(dependencyGraph, prop, computation);
|
||||
}
|
||||
|
||||
function dependOnCalc({dependencyGraph, prop, key}){
|
||||
function dependOnCalc({ dependencyGraph, prop, key }) {
|
||||
let calc = get(prop, key);
|
||||
if (!calc) return;
|
||||
if (calc.type !== '_calculation'){
|
||||
if (calc.type !== '_calculation') {
|
||||
throw `Expected calculation got ${calc.type}`
|
||||
}
|
||||
dependencyGraph.addLink(prop._id, `${prop._id}.${key}`, 'calculation');
|
||||
}
|
||||
|
||||
function linkAction(dependencyGraph, prop, {propsById}){
|
||||
function linkAction(dependencyGraph, prop, { propsById }) {
|
||||
if (prop.variableName) {
|
||||
dependencyGraph.addLink(prop.variableName, prop._id, 'eventDefinition');
|
||||
}
|
||||
// The action depends on its attack roll and uses calculations
|
||||
dependOnCalc({dependencyGraph, prop, key: 'attackRoll'});
|
||||
dependOnCalc({dependencyGraph, prop, key: 'uses'});
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'attackRoll' });
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'uses' });
|
||||
|
||||
// Link the resources the action uses
|
||||
if (!prop.resources) return;
|
||||
@@ -47,7 +50,7 @@ function linkAction(dependencyGraph, prop, {propsById}){
|
||||
prop.resources.itemsConsumed.forEach((itemConsumed, index) => {
|
||||
if (!itemConsumed.itemId) return;
|
||||
const item = propsById[itemConsumed.itemId];
|
||||
if (!item || item.inactive){
|
||||
if (!item || item.inactive) {
|
||||
// Unlink if the item doesn't exist or is inactive
|
||||
itemConsumed.itemId = undefined;
|
||||
return;
|
||||
@@ -79,48 +82,48 @@ function linkAction(dependencyGraph, prop, {propsById}){
|
||||
});
|
||||
}
|
||||
|
||||
function linkAdjustment(dependencyGraph, prop){
|
||||
function linkAdjustment(dependencyGraph, prop) {
|
||||
// Adjustment depends on its amount
|
||||
dependOnCalc({dependencyGraph, prop, key: 'amount'});
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'amount' });
|
||||
}
|
||||
|
||||
function linkAttribute(dependencyGraph, prop){
|
||||
function linkAttribute(dependencyGraph, prop) {
|
||||
linkVariableName(dependencyGraph, prop);
|
||||
// Depends on spellSlotLevel
|
||||
dependOnCalc({dependencyGraph, prop, key: 'spellSlotLevel'});
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'spellSlotLevel' });
|
||||
|
||||
// Depends on base value
|
||||
dependOnCalc({dependencyGraph, prop, key: 'baseValue'});
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'baseValue' });
|
||||
|
||||
// hit dice depend on constitution
|
||||
if (prop.attributeType === 'hitDice'){
|
||||
if (prop.attributeType === 'hitDice') {
|
||||
dependencyGraph.addLink(prop._id, 'constitution', 'hitDiceConMod');
|
||||
}
|
||||
}
|
||||
|
||||
function linkBranch(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'condition'});
|
||||
function linkBranch(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'condition' });
|
||||
}
|
||||
|
||||
function linkBuff(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'duration'});
|
||||
function linkBuff(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'duration' });
|
||||
}
|
||||
|
||||
function linkClassLevel(dependencyGraph, prop) {
|
||||
if (prop.inactive) return;
|
||||
// The variableName of the prop depends on the prop
|
||||
if (prop.variableName && prop.level){
|
||||
if (prop.variableName && prop.level) {
|
||||
dependencyGraph.addLink(prop.variableName, prop._id, 'classLevel');
|
||||
// The level variable depends on the class variableName variable
|
||||
let existingLevelLink = dependencyGraph.getLink('level', prop.variableName);
|
||||
if (!existingLevelLink){
|
||||
if (!existingLevelLink) {
|
||||
dependencyGraph.addLink('level', prop.variableName, 'level');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function linkDamage(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'amount'});
|
||||
function linkDamage(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'amount' });
|
||||
}
|
||||
|
||||
function linkEffects(dependencyGraph, prop, computation) {
|
||||
@@ -132,7 +135,7 @@ function linkEffects(dependencyGraph, prop, computation) {
|
||||
if (prop.inactive) {
|
||||
// Inactive effects apply to no stats
|
||||
return;
|
||||
} else if (prop.targetByTags){
|
||||
} else if (prop.targetByTags) {
|
||||
getEffectTagTargets(prop, computation).forEach(targetId => {
|
||||
const targetProp = computation.propsById[targetId];
|
||||
if (
|
||||
@@ -147,8 +150,8 @@ function linkEffects(dependencyGraph, prop, computation) {
|
||||
// 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');
|
||||
if (calcObj && calcObj.calculation) {
|
||||
dependencyGraph.addLink(`${targetProp._id}.${key}`, prop._id, 'effect');
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -161,14 +164,14 @@ function linkEffects(dependencyGraph, prop, computation) {
|
||||
}
|
||||
|
||||
// Returns an array of IDs of the properties the effect targets
|
||||
function getEffectTagTargets(effect, computation){
|
||||
function getEffectTagTargets(effect, computation) {
|
||||
let targets = getTargetListFromTags(effect.targetTags, computation);
|
||||
let notIds = [];
|
||||
if (effect.extraTags){
|
||||
if (effect.extraTags) {
|
||||
effect.extraTags.forEach(ex => {
|
||||
if (ex.operation === 'OR') {
|
||||
targets = union(targets, getTargetListFromTags(ex.tags, computation));
|
||||
} else if (ex.operation === 'NOT'){
|
||||
} else if (ex.operation === 'NOT') {
|
||||
ex.tags.forEach(tag => {
|
||||
const idList = computation.propsWithTag[tag];
|
||||
if (idList) {
|
||||
@@ -181,7 +184,7 @@ function getEffectTagTargets(effect, computation){
|
||||
return difference(targets, notIds);
|
||||
}
|
||||
|
||||
function getTargetListFromTags(tags, computation){
|
||||
function getTargetListFromTags(tags, computation) {
|
||||
const targetTagIdLists = [];
|
||||
if (!tags) return [];
|
||||
tags.forEach(tag => {
|
||||
@@ -192,8 +195,8 @@ function getTargetListFromTags(tags, computation){
|
||||
return targets;
|
||||
}
|
||||
|
||||
function getDefaultCalculationField(prop){
|
||||
switch (prop.type){
|
||||
function getDefaultCalculationField(prop) {
|
||||
switch (prop.type) {
|
||||
case 'action': return 'attackRoll';
|
||||
case 'adjustment': return 'amount';
|
||||
case 'attribute': return 'baseValue';
|
||||
@@ -223,13 +226,13 @@ function getDefaultCalculationField(prop){
|
||||
}
|
||||
}
|
||||
|
||||
function linkRoll(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'roll'});
|
||||
function linkRoll(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'roll' });
|
||||
}
|
||||
|
||||
function linkVariableName(dependencyGraph, prop){
|
||||
function linkVariableName(dependencyGraph, prop) {
|
||||
// The variableName of the prop depends on the prop if the prop is active
|
||||
if (prop.variableName && !prop.inactive){
|
||||
if (prop.variableName && !prop.inactive) {
|
||||
dependencyGraph.addLink(prop.variableName, prop._id, 'definition');
|
||||
}
|
||||
}
|
||||
@@ -243,7 +246,7 @@ function linkDamageMultiplier(dependencyGraph, prop) {
|
||||
});
|
||||
}
|
||||
|
||||
function linkPointBuy(dependencyGraph, prop){
|
||||
function linkPointBuy(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'min' });
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'max' });
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'cost' });
|
||||
@@ -265,7 +268,7 @@ function linkPointBuy(dependencyGraph, prop){
|
||||
if (prop.inactive) return;
|
||||
}
|
||||
|
||||
function linkProficiencies(dependencyGraph, prop){
|
||||
function linkProficiencies(dependencyGraph, prop) {
|
||||
// The stats depend on the proficiency
|
||||
if (prop.inactive) return;
|
||||
prop.stats.forEach(statName => {
|
||||
@@ -274,36 +277,36 @@ function linkProficiencies(dependencyGraph, prop){
|
||||
});
|
||||
}
|
||||
|
||||
function linkSavingThrow(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'dc'});
|
||||
function linkSavingThrow(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'dc' });
|
||||
}
|
||||
|
||||
function linkSkill(dependencyGraph, prop){
|
||||
function linkSkill(dependencyGraph, prop) {
|
||||
// Depends on base value
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'baseValue' });
|
||||
// Link dependents
|
||||
if (prop.inactive) return;
|
||||
linkVariableName(dependencyGraph, prop);
|
||||
// The prop depends on the variable references as the ability
|
||||
if (prop.ability){
|
||||
if (prop.ability) {
|
||||
dependencyGraph.addLink(prop._id, prop.ability, 'skillAbilityScore');
|
||||
}
|
||||
// Skills depend on the creature's proficiencyBonus
|
||||
dependencyGraph.addLink(prop._id, 'proficiencyBonus', 'skillProficiencyBonus');
|
||||
}
|
||||
|
||||
function linkSlot(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'quantityExpected'});
|
||||
dependOnCalc({dependencyGraph, prop, key: 'slotCondition'});
|
||||
function linkSlot(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'quantityExpected' });
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'slotCondition' });
|
||||
}
|
||||
|
||||
function linkSpellList(dependencyGraph, prop){
|
||||
dependOnCalc({dependencyGraph, prop, key: 'maxPrepared'});
|
||||
dependOnCalc({dependencyGraph, prop, key: 'attackRollBonus'});
|
||||
dependOnCalc({dependencyGraph, prop, key: 'dc'});
|
||||
function linkSpellList(dependencyGraph, prop) {
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'maxPrepared' });
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'attackRollBonus' });
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'dc' });
|
||||
}
|
||||
|
||||
function linkToggle(dependencyGraph, prop){
|
||||
function linkToggle(dependencyGraph, prop) {
|
||||
linkVariableName(dependencyGraph, prop);
|
||||
dependOnCalc({dependencyGraph, prop, key: 'condition'});
|
||||
dependOnCalc({ dependencyGraph, prop, key: 'condition' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user