Working on 0.8.x

- Title's Advancements are now reflected on actor
- Migration update
This commit is contained in:
Vlyan
2021-05-22 17:20:17 +02:00
parent 4f9b72c63f
commit 53f04e6cef
33 changed files with 423 additions and 281 deletions

View File

@@ -287,11 +287,14 @@ export class TwentyQuestions {
// Clear and add items to actor
const deleteIds = actor.data.items.map((e) => e.id);
await actor.deleteEmbeddedDocuments("Item", deleteIds);
if (deleteIds.length > 0) {
await actor.deleteEmbeddedDocuments("Item", deleteIds);
}
// Add items in 20Q to actor
for (const types of Object.values(itemsCache)) {
for (const item of types) {
const newItemsData = [];
Object.values(itemsCache).forEach((types) => {
types.forEach((item) => {
const itemData = foundry.utils.duplicate(item.data);
if (itemData.data?.bought_at_rank) {
itemData.data.bought_at_rank = 0;
@@ -299,8 +302,11 @@ export class TwentyQuestions {
if (itemData.data?.xp_spent) {
itemData.data.xp_spent = 0;
}
await actor.createEmbeddedDocuments("Item", [itemData]);
}
newItemsData.push(itemData);
});
});
if (newItemsData.length > 0) {
await actor.createEmbeddedDocuments("Item", newItemsData);
}
// Update actor