Moved action system to new tree format

This commit is contained in:
Thaum Rystra
2023-09-28 14:49:32 +02:00
parent e6963ec865
commit 3bd2806bc6
15 changed files with 25 additions and 26 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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

View File

@@ -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) {

View File

@@ -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

View File

@@ -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);

View File

@@ -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 };

View File

@@ -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 = [];

View File

@@ -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;

View File

@@ -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);

View File

@@ -13,8 +13,8 @@ export default function computeInactiveStatus(node: TreeNode<CreatureProperty>):
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 {

View File

@@ -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)

View File

@@ -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');
});
}

View File

@@ -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);

View File

@@ -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) {