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,3 +1,5 @@
import { getSingleProperty } from '/imports/api/engine/loadCreatures';
//set up the collection for creature variables
let CreatureVariables = new Mongo.Collection('creatureVariables');
@@ -7,15 +9,29 @@ if (Meteor.isServer) {
}
/** No schema because the structure isn't known until compute time
* Expect documents to looke like:
* Expect documents to look like:
* {
* _id: "nE8Ngd6K4L4jSxLY2",
* _creatureId: "nE8Ngd6K4L4jSxLY2", // indexed reference to the creature
* explicitlyDefinedVariableName: {...some creatureProperty}
* explicitlyDefinedVariableName: {...some creatureProperty},
* // Must be found in CreatureProperties before using:
* linkedProperty: { _propId: "nE8Ngd6K1234SxLY2" }
* implicitVariableName: {value: 10},
* undefinedVariableName: {},
* }
* Where top level fields that don't start with `_` are variables on the sheet
**/
/**
* Get the property from the given scope, respecting properties that are just a link to the actual
* property document
*/
export function getFromScope(name, scope) {
let value = scope?.[name];
if (value?._propId) {
value = getSingleProperty(scope._creatureId, value._propId);
}
return value;
}
export default CreatureVariables;