diff --git a/module/item/sheet-conteneur.js b/module/item/sheet-conteneur.js index b5ff7855..fc0f7948 100644 --- a/module/item/sheet-conteneur.js +++ b/module/item/sheet-conteneur.js @@ -29,7 +29,6 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet { /* -------------------------------------------- */ prepareConteneurData(formData) { RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); - this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets); formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems; } @@ -44,7 +43,8 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet { const dragData = { actorId: this.actor.id, type: "Item", - data: item.system + data: item.system, + uuid: item.uuid }; event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); @@ -52,7 +52,8 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet { async _onDropItem(event, dragData) { if (this.actor) { - const dropParams = await RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur); + const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') ?? this.item.id + const dropParams = await RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur); await this.actor.processDropItem(dropParams); await this.render(true); } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index ef8a1000..d0b8ccb5 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -278,8 +278,9 @@ export class RdDUtility { Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str)); Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str)); Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args)); - Handlebars.registerHelper('buildConteneur', (objet, templateItem, options) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet, 1, templateItem, options)); }); - Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); }); + Handlebars.registerHelper('buildLigneInventaire', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildLigneInventaire(item, options)); }); + Handlebars.registerHelper('buildInventaireConteneur', (actorId, itemId, options) => { return new Handlebars.SafeString(RdDUtility.buildInventaireConteneur(actorId, itemId, options)); }); + Handlebars.registerHelper('buildContenuConteneur', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildContenuConteneur(item, options)); }); Handlebars.registerHelper('calculerPrixCommercant', item => item.calculerPrixCommercant()); Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); @@ -394,38 +395,58 @@ export class RdDUtility { return conteneurs.filter((conteneur, index, arr) => !conteneur.estContenu); } - /* -------------------------------------------- */ - /** Construit la structure récursive des conteneurs, avec imbrication potentielle - * - */ - static buildConteneur(objet, profondeur, templateItem, options) { - if (!profondeur) profondeur = 1; - if (!templateItem) templateItem = 'actor/inventaire-item.html' - objet.niveau = profondeur; - - const isConteneur = objet.type == 'conteneur'; - const isOuvert = isConteneur && this.getAfficheContenu(objet._id); - const isVide = isConteneur && objet.system.contenu.length == 0; - const conteneur = Handlebars.partials[`systems/foundryvtt-reve-de-dragon/templates/${templateItem}`]({ - item: objet, - vide: isVide, - ouvert: isOuvert, - options: options - }); - const contenu = isConteneur ? RdDUtility.buildContenu(objet, profondeur, isOuvert, templateItem, options) : ''; - return conteneur + contenu; + static prepareOptionsArbreInventaire(item, optionsArbre) { + if (!optionsArbre.profondeur) { + optionsArbre.profondeur = 1 + }; + if (!optionsArbre.templateItem) { + optionsArbre.templateItem = item.parent?.type == 'commerce' + ? "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html" + : "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html"; + } + item.niveau = optionsArbre.profondeur; } /* -------------------------------------------- */ - static buildContenu(objet, profondeur, afficherContenu, templateItem, options) { - if (!profondeur) profondeur = 1; - if (!templateItem) templateItem = 'actor/inventaire-item.html' - objet.niveau = profondeur; - const display = afficherContenu ? 'item-display-show' : 'item-display-hide'; - let strContenu = `