From 3bd2806bc652e84b0d9cb7f1d8d07dc2bf57ec40 Mon Sep 17 00:00:00 2001 From: Thaum Rystra <9525416+ThaumRystra@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:49:32 +0200 Subject: [PATCH] Moved action system to new tree format --- .../actions/applyPropertyByType/applyAdjustment.js | 2 +- .../actions/applyPropertyByType/applyBranch.js | 2 +- .../actions/applyPropertyByType/applyBuff.js | 2 +- .../applyPropertyByType/applyBuffRemover.js | 2 +- .../actions/applyPropertyByType/applyDamage.js | 2 +- .../actions/applyPropertyByType/applyItemAsAmmo.js | 2 +- .../actions/applyPropertyByType/applyNote.js | 2 +- .../actions/applyPropertyByType/applyRoll.js | 2 +- .../applyPropertyByType/applySavingThrow.js | 2 +- .../actions/applyPropertyByType/applyToggle.js | 2 +- .../buildComputation/computeInactiveStatus.ts | 7 +++---- .../buildComputation/computeSlotQuantityFilled.js | 4 ++-- .../buildComputation/computeToggleDependencies.js | 14 +++++++------- .../computation/buildComputation/linkInventory.js | 4 ++-- .../character/characterSheetTabs/StatsTab.vue | 2 +- 15 files changed, 25 insertions(+), 26 deletions(-) diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyAdjustment.js b/app/imports/api/engine/actions/applyPropertyByType/applyAdjustment.js index 756b244c..1a4f5c72 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyAdjustment.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyAdjustment.js @@ -5,7 +5,7 @@ import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers'; export default function applyAdjustment(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc const damageTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets; if (!prop.amount) { diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js b/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js index b336c929..314333eb 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js @@ -8,7 +8,7 @@ export default function applyBranch(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); const scope = actionContext.scope; const targets = actionContext.targets; - const prop = node.node; + const prop = node.doc switch (prop.branchType) { case 'if': recalculateCalculation(prop.condition, actionContext); diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyBuff.js b/app/imports/api/engine/actions/applyPropertyByType/applyBuff.js index 56ffb109..c609aa9b 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyBuff.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyBuff.js @@ -17,7 +17,7 @@ import recalculateInlineCalculations from './shared/recalculateInlineCalculation export default function applyBuff(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc let buffTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets; // Mark the buff as dirty for recalculation diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyBuffRemover.js b/app/imports/api/engine/actions/applyPropertyByType/applyBuffRemover.js index d73954cc..ae3ecf4b 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyBuffRemover.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyBuffRemover.js @@ -11,7 +11,7 @@ export default function applyBuffRemover(node, actionContext) { // Apply triggers applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc // Log Name if (prop.name && !prop.silent) { diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js b/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js index d2e27a05..5e96ed42 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js @@ -15,7 +15,7 @@ import applySavingThrow from '/imports/api/engine/actions/applyPropertyByType/ap export default function applyDamage(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc const scope = actionContext.scope; // Skip if there is no parse node to work with diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyItemAsAmmo.js b/app/imports/api/engine/actions/applyPropertyByType/applyItemAsAmmo.js index d148184c..17d377e7 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyItemAsAmmo.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyItemAsAmmo.js @@ -6,7 +6,7 @@ import { adjustQuantityWork } from '/imports/api/creature/creatureProperties/met export default function applyItemAsAmmo(node, actionContext) { // The item node should come without children, since it is not part of the original action tree - const prop = node.node; + const prop = node.doc // Get all the item's descendant properties const properties = getPropertyDecendants(actionContext.creature._id, prop._id); properties.sort((a, b) => a.order - b.order); diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyNote.js b/app/imports/api/engine/actions/applyPropertyByType/applyNote.js index 27d320f0..c227e99e 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyNote.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyNote.js @@ -4,7 +4,7 @@ import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers'; export default function applyNote(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc // Log Name, summary let content = { name: prop.name }; diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyRoll.js b/app/imports/api/engine/actions/applyPropertyByType/applyRoll.js index f24d5dcc..2d9b9e19 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyRoll.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyRoll.js @@ -6,7 +6,7 @@ import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers'; export default function applyRoll(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc if (prop.roll?.calculation) { const logValue = []; diff --git a/app/imports/api/engine/actions/applyPropertyByType/applySavingThrow.js b/app/imports/api/engine/actions/applyPropertyByType/applySavingThrow.js index 1c5d4cec..1df1a1bb 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applySavingThrow.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applySavingThrow.js @@ -8,7 +8,7 @@ import { applyUnresolvedEffects } from '/imports/api/engine/actions/doCheck.js'; export default function applySavingThrow(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc const originalTargets = actionContext.targets; let saveTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets; diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyToggle.js b/app/imports/api/engine/actions/applyPropertyByType/applyToggle.js index a73831c0..a07a77ca 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyToggle.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyToggle.js @@ -4,7 +4,7 @@ import applyChildren from '/imports/api/engine/actions/applyPropertyByType/share export default function applyToggle(node, actionContext) { applyNodeTriggers(node, 'before', actionContext); - const prop = node.node; + const prop = node.doc recalculateCalculation(prop.condition, actionContext); if (prop.condition?.value) { return applyChildren(node, actionContext); diff --git a/app/imports/api/engine/computation/buildComputation/computeInactiveStatus.ts b/app/imports/api/engine/computation/buildComputation/computeInactiveStatus.ts index 6dd96867..a9c1785b 100644 --- a/app/imports/api/engine/computation/buildComputation/computeInactiveStatus.ts +++ b/app/imports/api/engine/computation/buildComputation/computeInactiveStatus.ts @@ -13,8 +13,8 @@ export default function computeInactiveStatus(node: TreeNode): if (!childrenActive(prop)) { // Mark children as inactive due to ancestor walkDown(node.children, child => { - child.node.inactive = true; - child.node.deactivatedByAncestor = true; + child.doc.inactive = true; + child.doc.deactivatedByAncestor = true; }); } } @@ -23,9 +23,8 @@ function isActive(prop: CreatureProperty): boolean { if (prop.disabled) return false; if (isSpell(prop)) { return !!prop.prepared || !!prop.alwaysPrepared; - } else { - return true; } + return true; } function childrenActive(prop): boolean { diff --git a/app/imports/api/engine/computation/buildComputation/computeSlotQuantityFilled.js b/app/imports/api/engine/computation/buildComputation/computeSlotQuantityFilled.js index e9e4a287..e7485c11 100644 --- a/app/imports/api/engine/computation/buildComputation/computeSlotQuantityFilled.js +++ b/app/imports/api/engine/computation/buildComputation/computeSlotQuantityFilled.js @@ -3,11 +3,11 @@ * before `spacesLeft` can be computed */ export default function computeSlotQuantityFilled(node, dependencyGraph) { - let slot = node.node; + let slot = node.doc; if (slot.type !== 'propertySlot') return; slot.totalFilled = 0; node.children.forEach(child => { - let childProp = child.node; + let childProp = child.doc; dependencyGraph.addLink(slot._id, childProp._id, 'slotFill'); if ( Number.isFinite(childProp.slotQuantityFilled) diff --git a/app/imports/api/engine/computation/buildComputation/computeToggleDependencies.js b/app/imports/api/engine/computation/buildComputation/computeToggleDependencies.js index 3d9bf564..d6541df8 100644 --- a/app/imports/api/engine/computation/buildComputation/computeToggleDependencies.js +++ b/app/imports/api/engine/computation/buildComputation/computeToggleDependencies.js @@ -2,7 +2,7 @@ import walkDown from '/imports/api/engine/computation/utility/walkdown.js'; import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies.js'; export default function computeToggleDependencies(node, dependencyGraph, computation, forest) { - const prop = node.node; + const prop = node.doc // Only for toggles if (prop.type !== 'toggle') return; @@ -11,12 +11,12 @@ export default function computeToggleDependencies(node, dependencyGraph, computa getEffectTagTargets(prop, computation).forEach(targetId => { const target = forest.nodeIndex[targetId]; if (!target) return; - target.node._computationDetails.toggleAncestors.push(prop); - dependencyGraph.addLink(target.node._id, prop._id, 'toggle'); + target.doc._computationDetails.toggleAncestors.push(prop); + dependencyGraph.addLink(target.doc._id, prop._id, 'toggle'); walkDown(target.children, child => { // The child nodes depend on the toggle - child.node._computationDetails.toggleAncestors.push(prop); - dependencyGraph.addLink(child.node._id, prop._id, 'toggle'); + child.doc._computationDetails.toggleAncestors.push(prop); + dependencyGraph.addLink(child.doc._id, prop._id, 'toggle'); }); }); } @@ -26,7 +26,7 @@ export default function computeToggleDependencies(node, dependencyGraph, computa walkDown(node.children, child => { // The child nodes depend on the toggle - child.node._computationDetails.toggleAncestors.push(prop); - dependencyGraph.addLink(child.node._id, prop._id, 'toggle'); + child.doc._computationDetails.toggleAncestors.push(prop); + dependencyGraph.addLink(child.doc._id, prop._id, 'toggle'); }); } diff --git a/app/imports/api/engine/computation/buildComputation/linkInventory.js b/app/imports/api/engine/computation/buildComputation/linkInventory.js index 7961e4df..faa2674c 100644 --- a/app/imports/api/engine/computation/buildComputation/linkInventory.js +++ b/app/imports/api/engine/computation/buildComputation/linkInventory.js @@ -10,7 +10,7 @@ export default function linkInventory(forest, dependencyGraph) { while (stack.length) { const top = stack[stack.length - 1]; - const prop = top.node; + const prop = top.doc; if (prop._computationDetails.inventoryChildrenVisited) { if (prop.type === 'container') containerStack.pop(); stack.pop(); @@ -18,7 +18,7 @@ export default function linkInventory(forest, dependencyGraph) { } else { // Add all containers to the stack when we first visit them if (prop.type === 'container') { - containerStack.push(top.node); + containerStack.push(top.doc); } // Push children onto the stack and mark this as children are visited stack.push(...top.children); diff --git a/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue b/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue index 8caeed03..2a746558 100644 --- a/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue +++ b/app/imports/client/ui/creature/character/characterSheetTabs/StatsTab.vue @@ -559,7 +559,7 @@ export default { const forest = nodeArrayToTree(allProps); const properties = { folder: {}, attribute: {}, skill: {} }; walkDown(forest, node => { - const prop = node.node; + const prop = node.doc const { propPath, skipChildren } = propertyHandlers[prop.type]?.(prop) || { propPath: prop.type }; if (propPath) {