Fixed adding creatures from libraries -> tabletops

This commit is contained in:
Thaum Rystra
2024-06-05 17:29:50 +02:00
parent a00292a523
commit 4921a34dfe
5 changed files with 158 additions and 91 deletions

View File

@@ -8,6 +8,7 @@ import LibraryNodes from '/imports/api/library/LibraryNodes';
import { getFilter, renewDocIds } from '/imports/api/parenting/parentingFunctions';
import { reifyNodeReferences, storeLibraryNodeReferences } from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables';
const addCreaturesFromLibraryToTabletop = new ValidatedMethod({
@@ -58,14 +59,25 @@ const addCreaturesFromLibraryToTabletop = new ValidatedMethod({
}
}
// Insert the creature
const creatureId = Creatures.insert({
...creatureNode,
_id: Random.id(),
type: 'monster',
tabletopId,
owner: this.userId,
readers: [],
writers: [this.userId],
public: false,
dirty: true,
settings: {},
});
// Insert the creature variables
CreatureVariables.insert({
_creatureId: creatureId,
});
insertSubProperties(creatureNode, creatureId);
}
},
@@ -98,7 +110,7 @@ function insertSubProperties(node, creatureId: string) {
// Insert the creature properties
// @ts-expect-error Batch insert not defined
CreatureProperties.batchInsert(nodes);
if (nodes.length) CreatureProperties.batchInsert(nodes);
return node;
}