Replaced most properties in creature variables with links

instead of storing the entire property twice
This commit is contained in:
ThaumRystra
2023-11-09 23:05:05 +02:00
parent 84edd74ff3
commit 7eada9effe
8 changed files with 117 additions and 29 deletions

View File

@@ -1,10 +1,10 @@
import { CreatureLogSchema, insertCreatureLogWork } from '/imports/api/creature/log/CreatureLogs.js';
import {
getCreature, getVariables, getPropertiesOfType
getCreature, getVariables, getPropertiesOfType, replaceLinkedVariablesWithProps
} from '/imports/api/engine/loadCreatures.js';
import { groupBy, remove } from 'lodash';
export default class ActionContext{
export default class ActionContext {
constructor(creatureId, targetIds = [], method) {
// Get the creature
this.creature = getCreature(creatureId)
@@ -20,6 +20,7 @@ export default class ActionContext{
// Get the variables of the acting creature
this.creature.variables = getVariables(creatureId);
replaceLinkedVariablesWithProps(this.creature.variables);
delete this.creature.variables._id;
delete this.creature.variables._creatureId;
// Alias as scope
@@ -64,7 +65,7 @@ export default class ActionContext{
}
}
addLog(content) {
if (content.name || content.value){
if (content.name || content.value) {
this.log.content.push(content);
}
}

View File

@@ -8,7 +8,7 @@ import computedSchemas from '/imports/api/properties/computedPropertySchemasInde
import applyFnToKey from '/imports/api/engine/computation/utility/applyFnToKey.js';
import { get } from 'lodash';
import resolve, { map, toString } from '/imports/parser/resolve.js';
import symbol from '/imports/parser/parseTree/symbol.js';
import accessor from '/imports/parser/parseTree/accessor.js';
import logErrors from './shared/logErrors.js';
import { insertCreatureLog } from '/imports/api/creature/log/CreatureLogs.js';
import cyrb53 from '/imports/api/engine/computation/utility/cyrb53.js';
@@ -117,7 +117,7 @@ function crystalizeVariables({ propList, actionContext }) {
calcObj.parseNode = map(calcObj.parseNode, node => {
// Skip nodes that aren't symbols or accessors
if (
node.parseType !== 'accessor' && node.parseType !== 'symbol'
node.parseType !== 'accessor'
) return node;
// Handle variables
if (node.name === '~target') {
@@ -125,7 +125,7 @@ function crystalizeVariables({ propList, actionContext }) {
if (node.parseType === 'accessor') {
node.name = node.path.shift();
if (!node.path.length) {
return symbol.create({ name: node.name })
return accessor.create({ name: node.name })
}
} else {
// Can't strip symbols