Fixed some bugs with characters not recomputing
TODO: remove .variables cache from creature document, it's not viable
This commit is contained in:
@@ -18,10 +18,9 @@ export default function applyDamage(node, {
|
||||
const prop = node.node;
|
||||
|
||||
// Skip if there is no parse node to work with
|
||||
if (!prop.amount.parseNode) return;
|
||||
if (!prop.amount?.parseNode) return;
|
||||
|
||||
// Choose target
|
||||
|
||||
let damageTargets = prop.target === 'self' ? [creature] : targets;
|
||||
// Determine if the hit is critical
|
||||
let criticalHit = scope['$criticalHit']?.value &&
|
||||
|
||||
@@ -79,7 +79,7 @@ const doAction = new ValidatedMethod({
|
||||
Creatures.update({
|
||||
_id: { $in: [creature._id, ...targetIds] }
|
||||
}, {
|
||||
dirty: true
|
||||
$set: {dirty: true},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -133,7 +133,7 @@ const doAction = new ValidatedMethod({
|
||||
Creatures.update({
|
||||
_id: { $in: [creature._id, ...targetIds] }
|
||||
}, {
|
||||
dirty: true
|
||||
$set: { dirty: true },
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -67,6 +67,7 @@ function getCreature(creatureId) {
|
||||
const creature = Creatures.findOne(creatureId, {
|
||||
denormalizedStats: 1,
|
||||
variables: 1,
|
||||
dirty: 1,
|
||||
});
|
||||
console.timeEnd(`Cache miss on Creature: ${creatureId}`);
|
||||
return creature;
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
import { EJSON } from 'meteor/ejson';
|
||||
import { omitBy } from 'lodash';
|
||||
|
||||
export default function writeScope(creatureId, computation) {
|
||||
const scope = computation.scope;
|
||||
const variables = computation.creature?.variables || {};
|
||||
let $set, $unset;
|
||||
|
||||
if (computation.creature.dirty) {
|
||||
$unset = { dirty: 1 };
|
||||
}
|
||||
|
||||
for (const key in scope){
|
||||
// Remove large properties that aren't likely to be accessed
|
||||
delete scope[key].parent;
|
||||
@@ -22,6 +27,10 @@ export default function writeScope(creatureId, computation) {
|
||||
if (!EJSON.equals(variables[key], scope[key])) {
|
||||
if (!$set) $set = {};
|
||||
// Set the changed key in the creature variables
|
||||
const diff = omitBy(variables[key], (v, k) => EJSON.equals(scope[key][k], v));
|
||||
for (let subkey in diff) {
|
||||
console.log(`${key}.${subkey}: ${variables[key][subkey]} => ${scope[key][subkey]}`)
|
||||
}
|
||||
$set[`variables.${key}`] = scope[key];
|
||||
}
|
||||
}
|
||||
@@ -35,6 +44,7 @@ export default function writeScope(creatureId, computation) {
|
||||
}
|
||||
|
||||
if ($set || $unset) {
|
||||
Creatures.update(creatureId, {$set, $unset});
|
||||
const updates = Creatures.update(creatureId, { $set, $unset });
|
||||
console.log('wrote scope: ', updates);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ const organizeDoc = new ValidatedMethod({
|
||||
Creatures.update({
|
||||
_id: { $in: creaturesToRecompute }
|
||||
}, {
|
||||
dirty: true
|
||||
$set: { dirty: true },
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -91,7 +91,7 @@ const reorderDoc = new ValidatedMethod({
|
||||
Creatures.update({
|
||||
_id: { $in: ancestors }
|
||||
}, {
|
||||
dirty: true
|
||||
$set: { dirty: true },
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user