Moved action system to new tree format
This commit is contained in:
@@ -5,7 +5,7 @@ import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers';
|
|||||||
|
|
||||||
export default function applyAdjustment(node, actionContext) {
|
export default function applyAdjustment(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
const damageTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
const damageTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
||||||
|
|
||||||
if (!prop.amount) {
|
if (!prop.amount) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default function applyBranch(node, actionContext) {
|
|||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const scope = actionContext.scope;
|
const scope = actionContext.scope;
|
||||||
const targets = actionContext.targets;
|
const targets = actionContext.targets;
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
switch (prop.branchType) {
|
switch (prop.branchType) {
|
||||||
case 'if':
|
case 'if':
|
||||||
recalculateCalculation(prop.condition, actionContext);
|
recalculateCalculation(prop.condition, actionContext);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import recalculateInlineCalculations from './shared/recalculateInlineCalculation
|
|||||||
|
|
||||||
export default function applyBuff(node, actionContext) {
|
export default function applyBuff(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
let buffTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
let buffTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
||||||
|
|
||||||
// Mark the buff as dirty for recalculation
|
// Mark the buff as dirty for recalculation
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default function applyBuffRemover(node, actionContext) {
|
|||||||
// Apply triggers
|
// Apply triggers
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
|
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
|
|
||||||
// Log Name
|
// Log Name
|
||||||
if (prop.name && !prop.silent) {
|
if (prop.name && !prop.silent) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import applySavingThrow from '/imports/api/engine/actions/applyPropertyByType/ap
|
|||||||
export default function applyDamage(node, actionContext) {
|
export default function applyDamage(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
|
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
const scope = actionContext.scope;
|
const scope = actionContext.scope;
|
||||||
|
|
||||||
// Skip if there is no parse node to work with
|
// Skip if there is no parse node to work with
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { adjustQuantityWork } from '/imports/api/creature/creatureProperties/met
|
|||||||
|
|
||||||
export default function applyItemAsAmmo(node, actionContext) {
|
export default function applyItemAsAmmo(node, actionContext) {
|
||||||
// The item node should come without children, since it is not part of the original action tree
|
// 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
|
// Get all the item's descendant properties
|
||||||
const properties = getPropertyDecendants(actionContext.creature._id, prop._id);
|
const properties = getPropertyDecendants(actionContext.creature._id, prop._id);
|
||||||
properties.sort((a, b) => a.order - b.order);
|
properties.sort((a, b) => a.order - b.order);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers';
|
|||||||
|
|
||||||
export default function applyNote(node, actionContext) {
|
export default function applyNote(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
|
|
||||||
// Log Name, summary
|
// Log Name, summary
|
||||||
let content = { name: prop.name };
|
let content = { name: prop.name };
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers';
|
|||||||
|
|
||||||
export default function applyRoll(node, actionContext) {
|
export default function applyRoll(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
|
|
||||||
if (prop.roll?.calculation) {
|
if (prop.roll?.calculation) {
|
||||||
const logValue = [];
|
const logValue = [];
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { applyUnresolvedEffects } from '/imports/api/engine/actions/doCheck.js';
|
|||||||
|
|
||||||
export default function applySavingThrow(node, actionContext) {
|
export default function applySavingThrow(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
const originalTargets = actionContext.targets;
|
const originalTargets = actionContext.targets;
|
||||||
|
|
||||||
let saveTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
let saveTargets = prop.target === 'self' ? [actionContext.creature] : actionContext.targets;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import applyChildren from '/imports/api/engine/actions/applyPropertyByType/share
|
|||||||
|
|
||||||
export default function applyToggle(node, actionContext) {
|
export default function applyToggle(node, actionContext) {
|
||||||
applyNodeTriggers(node, 'before', actionContext);
|
applyNodeTriggers(node, 'before', actionContext);
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
recalculateCalculation(prop.condition, actionContext);
|
recalculateCalculation(prop.condition, actionContext);
|
||||||
if (prop.condition?.value) {
|
if (prop.condition?.value) {
|
||||||
return applyChildren(node, actionContext);
|
return applyChildren(node, actionContext);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ export default function computeInactiveStatus(node: TreeNode<CreatureProperty>):
|
|||||||
if (!childrenActive(prop)) {
|
if (!childrenActive(prop)) {
|
||||||
// Mark children as inactive due to ancestor
|
// Mark children as inactive due to ancestor
|
||||||
walkDown(node.children, child => {
|
walkDown(node.children, child => {
|
||||||
child.node.inactive = true;
|
child.doc.inactive = true;
|
||||||
child.node.deactivatedByAncestor = true;
|
child.doc.deactivatedByAncestor = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,9 +23,8 @@ function isActive(prop: CreatureProperty): boolean {
|
|||||||
if (prop.disabled) return false;
|
if (prop.disabled) return false;
|
||||||
if (isSpell(prop)) {
|
if (isSpell(prop)) {
|
||||||
return !!prop.prepared || !!prop.alwaysPrepared;
|
return !!prop.prepared || !!prop.alwaysPrepared;
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function childrenActive(prop): boolean {
|
function childrenActive(prop): boolean {
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
* before `spacesLeft` can be computed
|
* before `spacesLeft` can be computed
|
||||||
*/
|
*/
|
||||||
export default function computeSlotQuantityFilled(node, dependencyGraph) {
|
export default function computeSlotQuantityFilled(node, dependencyGraph) {
|
||||||
let slot = node.node;
|
let slot = node.doc;
|
||||||
if (slot.type !== 'propertySlot') return;
|
if (slot.type !== 'propertySlot') return;
|
||||||
slot.totalFilled = 0;
|
slot.totalFilled = 0;
|
||||||
node.children.forEach(child => {
|
node.children.forEach(child => {
|
||||||
let childProp = child.node;
|
let childProp = child.doc;
|
||||||
dependencyGraph.addLink(slot._id, childProp._id, 'slotFill');
|
dependencyGraph.addLink(slot._id, childProp._id, 'slotFill');
|
||||||
if (
|
if (
|
||||||
Number.isFinite(childProp.slotQuantityFilled)
|
Number.isFinite(childProp.slotQuantityFilled)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import walkDown from '/imports/api/engine/computation/utility/walkdown.js';
|
|||||||
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies.js';
|
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies.js';
|
||||||
|
|
||||||
export default function computeToggleDependencies(node, dependencyGraph, computation, forest) {
|
export default function computeToggleDependencies(node, dependencyGraph, computation, forest) {
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
// Only for toggles
|
// Only for toggles
|
||||||
if (prop.type !== 'toggle') return;
|
if (prop.type !== 'toggle') return;
|
||||||
|
|
||||||
@@ -11,12 +11,12 @@ export default function computeToggleDependencies(node, dependencyGraph, computa
|
|||||||
getEffectTagTargets(prop, computation).forEach(targetId => {
|
getEffectTagTargets(prop, computation).forEach(targetId => {
|
||||||
const target = forest.nodeIndex[targetId];
|
const target = forest.nodeIndex[targetId];
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
target.node._computationDetails.toggleAncestors.push(prop);
|
target.doc._computationDetails.toggleAncestors.push(prop);
|
||||||
dependencyGraph.addLink(target.node._id, prop._id, 'toggle');
|
dependencyGraph.addLink(target.doc._id, prop._id, 'toggle');
|
||||||
walkDown(target.children, child => {
|
walkDown(target.children, child => {
|
||||||
// The child nodes depend on the toggle
|
// The child nodes depend on the toggle
|
||||||
child.node._computationDetails.toggleAncestors.push(prop);
|
child.doc._computationDetails.toggleAncestors.push(prop);
|
||||||
dependencyGraph.addLink(child.node._id, prop._id, 'toggle');
|
dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ export default function computeToggleDependencies(node, dependencyGraph, computa
|
|||||||
|
|
||||||
walkDown(node.children, child => {
|
walkDown(node.children, child => {
|
||||||
// The child nodes depend on the toggle
|
// The child nodes depend on the toggle
|
||||||
child.node._computationDetails.toggleAncestors.push(prop);
|
child.doc._computationDetails.toggleAncestors.push(prop);
|
||||||
dependencyGraph.addLink(child.node._id, prop._id, 'toggle');
|
dependencyGraph.addLink(child.doc._id, prop._id, 'toggle');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export default function linkInventory(forest, dependencyGraph) {
|
|||||||
|
|
||||||
while (stack.length) {
|
while (stack.length) {
|
||||||
const top = stack[stack.length - 1];
|
const top = stack[stack.length - 1];
|
||||||
const prop = top.node;
|
const prop = top.doc;
|
||||||
if (prop._computationDetails.inventoryChildrenVisited) {
|
if (prop._computationDetails.inventoryChildrenVisited) {
|
||||||
if (prop.type === 'container') containerStack.pop();
|
if (prop.type === 'container') containerStack.pop();
|
||||||
stack.pop();
|
stack.pop();
|
||||||
@@ -18,7 +18,7 @@ export default function linkInventory(forest, dependencyGraph) {
|
|||||||
} else {
|
} else {
|
||||||
// Add all containers to the stack when we first visit them
|
// Add all containers to the stack when we first visit them
|
||||||
if (prop.type === 'container') {
|
if (prop.type === 'container') {
|
||||||
containerStack.push(top.node);
|
containerStack.push(top.doc);
|
||||||
}
|
}
|
||||||
// Push children onto the stack and mark this as children are visited
|
// Push children onto the stack and mark this as children are visited
|
||||||
stack.push(...top.children);
|
stack.push(...top.children);
|
||||||
|
|||||||
@@ -559,7 +559,7 @@ export default {
|
|||||||
const forest = nodeArrayToTree(allProps);
|
const forest = nodeArrayToTree(allProps);
|
||||||
const properties = { folder: {}, attribute: {}, skill: {} };
|
const properties = { folder: {}, attribute: {}, skill: {} };
|
||||||
walkDown(forest, node => {
|
walkDown(forest, node => {
|
||||||
const prop = node.node;
|
const prop = node.doc
|
||||||
const { propPath, skipChildren } = propertyHandlers[prop.type]?.(prop) ||
|
const { propPath, skipChildren } = propertyHandlers[prop.type]?.(prop) ||
|
||||||
{ propPath: prop.type };
|
{ propPath: prop.type };
|
||||||
if (propPath) {
|
if (propPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user