diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index 2ecc4948..2ffd5991 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -220,16 +220,16 @@ export class RdDBaseActor extends Actor { await this.delayedRenderSheet('_preUpdate', changed, options) return super._preUpdate(changed, options, user) } - + _onUpdate(changed, options, userId) { super._onUpdate(changed, options, userId) - if (userId == game.user.id){ + if (userId == game.user.id) { this.delayedRenderSheet('_onUpdate', changed, options) } } async delayedRenderSheet(caller, data, options) { - this.refreshDelayCounter = (this.refreshDelayCounter ?? 0)+1 + this.refreshDelayCounter = (this.refreshDelayCounter ?? 0) + 1 if (this.refreshDelayCounter == 1) { this.renderAfterDelay(this.refreshDelayCounter) } @@ -628,17 +628,20 @@ export class RdDBaseActor extends Actor { return } - const isItemEmpilable = "quantite" in item.system; const baseItem = { + id: undefined, type: item.type, img: item.img, name: item.name, - system: foundry.utils.mergeObject(item.system, { quantite: isItemEmpilable ? quantite : undefined }, { inplace: false }) + system: foundry.utils.duplicate(item.system) } + const createItemArray = "quantite" in item.system + ? (it, qt) => { it.system.quantite = qt; return [it] } + : (it, qt) => Array.from({ length: qt }, (_, i) => it) - const newItems = isItemEmpilable ? [baseItem] : Array.from({ length: quantite }, (_, i) => baseItem); - const items = await this.createEmbeddedDocuments("Item", newItems); - return newItems.length > 0 ? items[0].id : undefined; + const newItems = createItemArray(baseItem, quantite) + const items = await this.createEmbeddedDocuments("Item", newItems) + return items.length > 0 ? items[0].id : undefined; } /* -------------------------------------------- */