From 2ca601b5f800e2e5d8dabd04d2250cd774732436 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sun, 1 Jan 2023 22:18:18 +0100 Subject: [PATCH] onDrop depuis compendium async Permettre de retrouver l'Item du compendium pour tester si un acteur peut le recevoir --- module/actor/base-actor-sheet.js | 2 +- module/item-conteneur-sheet.js | 2 +- module/rdd-sheet-utility.js | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index 98cd8650..30dcf9a7 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -185,7 +185,7 @@ export class RdDBaseActorSheet extends ActorSheet { /* -------------------------------------------- */ async _onDropItem(event, dragData) { const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') - const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur) + const dropParams = await RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur) if (dropParams) { const callSuper = await this.actor.processDropItem(dropParams) if (callSuper) { diff --git a/module/item-conteneur-sheet.js b/module/item-conteneur-sheet.js index 0df3121a..e545cadf 100644 --- a/module/item-conteneur-sheet.js +++ b/module/item-conteneur-sheet.js @@ -51,7 +51,7 @@ export class RdDConteneurItemSheet extends RdDItemSheet { async _onDropItem(event, dragData) { if (this.actor) { - const dropParams = RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur); + const dropParams = await RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur); await this.actor.processDropItem(dropParams); await this.render(true); } diff --git a/module/rdd-sheet-utility.js b/module/rdd-sheet-utility.js index faa6856d..e1090a04 100644 --- a/module/rdd-sheet-utility.js +++ b/module/rdd-sheet-utility.js @@ -1,4 +1,6 @@ import { DialogSplitItem } from "./dialog-split-item.js"; +import { RdDItem } from "./item.js"; +import { SystemCompendiums } from "./settings/system-compendiums.js"; export class RdDSheetUtility { @@ -19,8 +21,11 @@ export class RdDSheetUtility { return $(event.currentTarget)?.parents(".item"); } - static prepareItemDropParameters(destItemId, actor, dragData, objetVersConteneur) { - const item = fromUuidSync(dragData.uuid) + static async prepareItemDropParameters(destItemId, actor, dragData, objetVersConteneur) { + let item = fromUuidSync(dragData.uuid); + if (item.pack && !item.system){ + item = await RdDItem.getCorrespondingItem(item); + } if (actor.canReceive(item)) { return { destId: destItemId,