Added reset task, fixed sheet reset buttons

This commit is contained in:
ThaumRystra
2024-05-02 20:41:04 +02:00
parent 9cd6ca5c6e
commit 7e3a16c96d
7 changed files with 237 additions and 57 deletions

View File

@@ -94,6 +94,36 @@ export function getPropertiesOfType(creatureId, propType) {
return props;
}
/**
* Get the properties of a creature that matches the filters given
* @param creatureId The id of the creature
* @param filterFn A function that returns true if the given prop matches the filter
* @param mongoFilter A mongo selector that is exactly equal to the above function
*/
export function getPropertiesByFilter(creatureId, filterFn: (any) => boolean, mongoFilter: Mongo.Selector<object>) {
const creature = loadedCreatures.get(creatureId);
if (creature) {
const props: CreatureProperty[] = []
for (const prop of creature.properties.values()) {
if (filterFn(prop)) {
props.push(prop);
}
}
props.sort((a, b) => a.left - b.left);
return EJSON.clone(props);
}
// console.time(`Cache miss on creature properties: ${creatureId}`)
const props = CreatureProperties.find({
'root.id': creatureId,
'removed': { $ne: true },
...mongoFilter
}, {
sort: { left: 1 },
}).fetch();
// console.timeEnd(`Cache miss on creature properties: ${creatureId}`);
return props;
}
export function getCreature(creatureId: string) {
const loadedCreature = loadedCreatures.get(creatureId);
const loadedCreatureDoc = loadedCreature?.creature;