Fixed a lot broken with nested sets

This commit is contained in:
ThaumRystra
2023-12-18 23:12:39 +02:00
parent a891f26b63
commit 4a349ea906
32 changed files with 435 additions and 284 deletions

View File

@@ -18,7 +18,7 @@ interface Ammo extends Item {
adjustment: number
}
export default function applyAction(node: TreeNode<Action>, actionContext) {
export default async function applyAction(node: TreeNode<Action>, actionContext) {
applyNodeTriggers(node, 'before', actionContext);
const prop = node.doc;
if (prop.target === 'self') actionContext.targets = [actionContext.creature];
@@ -198,7 +198,7 @@ function applyCrits(value, scope) {
return { criticalHit, criticalMiss };
}
function spendResources(prop: Action, actionContext) {
async function spendResources(prop: Action, actionContext) {
// Check Uses
if (!prop.usesLeft || prop.usesLeft <= 0) {
if (!prop.silent) actionContext.addLog({

View File

@@ -2,7 +2,7 @@ import recalculateInlineCalculations from './shared/recalculateInlineCalculation
import applyChildren from '/imports/api/engine/actions/applyPropertyByType/shared/applyChildren';
import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers';
export default function applyNote(node, actionContext) {
export default async function applyNote(node, actionContext) {
applyNodeTriggers(node, 'before', actionContext);
const prop = node.doc

View File

@@ -6,7 +6,7 @@ import applyProperty from '/imports/api/engine/actions/applyProperty';
import { difference, intersection } from 'lodash';
import getEffectivePropTags from '/imports/api/engine/computation/utility/getEffectivePropTags';
export function applyNodeTriggers(node: TreeNode<any>, timing, actionContext) {
export async function applyNodeTriggers(node: TreeNode<any>, timing, actionContext) {
const prop = node.doc;
const type = prop.type;
const triggers = actionContext.triggers?.doActionProperty?.[type]?.[timing];

View File

@@ -1,4 +1,4 @@
import { docsToForest } from '/imports/api/parenting/parentingFunctions';
import { applyNestedSetProperties, calculateNestedSetOperations } from '/imports/api/parenting/parentingFunctions';
import { DenormalisedOnlyCreaturePropertySchema as denormSchema }
from '/imports/api/creature/creatureProperties/CreatureProperties';
import { getProperties, getCreature, getVariables } from '/imports/api/engine/loadCreatures';
@@ -85,8 +85,14 @@ export function buildComputationFromProps(properties, creature, variables) {
});
// Get all the properties as trees based on their ancestors
let forest = docsToForest(properties);
// Get all the properties as a forest, with their nested set properties set
const forest = applyNestedSetProperties(properties);
const ops = calculateNestedSetOperations(properties);
if (ops.length > 20) {
console.log(ops.length + ' operations to get fixed nested sets');
} else {
console.log(JSON.stringify(ops, null, 2));
}
// Walk the property trees computing things that need to be inherited
walkDown(forest, node => {
computeInactiveStatus(node);

View File

@@ -7,6 +7,7 @@ import propertySlot from './computeByType/computeSlot';
import container from './computeByType/computeContainer';
import spellList from './computeByType/computeSpellList';
import toggle from './computeByType/computeToggle';
import trigger from './computeByType/computeTrigger';
import _calculation from './computeByType/computeCalculation';
export default Object.freeze({

View File

@@ -23,6 +23,9 @@ export default function writeAlteredProperties(computation) {
'deactivatingToggleId',
'damage',
'dirty',
'left',
'right',
'parentId',
...schema.objectKeys(),
];
op = addChangedKeysToOp(op, keys, original, changed);

View File

@@ -56,6 +56,7 @@ export function getProperties(creatureId) {
const creature = loadedCreatures.get(creatureId);
if (creature) {
const props = Array.from(creature.properties.values());
props.sort((a, b) => a.left - b.left);
return EJSON.clone(props);
}
// console.time(`Cache miss on creature properties: ${creatureId}`)
@@ -78,6 +79,7 @@ export function getPropertiesOfType(creatureId, propType) {
props.push(prop);
}
}
props.sort((a, b) => a.left - b.left);
return EJSON.clone(props);
}
// console.time(`Cache miss on creature properties: ${creatureId}`)