From 4d5651c2d3872e9ba9f2982e8b5c44c71086e86d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 28 Jan 2023 15:43:31 +0100 Subject: [PATCH] Reprise de l'arbre d'inventaire MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Soucis lors de l'affichage dans la fenêtre d'un conteneur --- module/item/sheet-conteneur.js | 7 +- module/rdd-utility.js | 81 +++++++++++++++--------- templates/actor/commerce-inventaire.html | 9 ++- templates/actor/inventaire-item.html | 6 +- templates/actor/inventaire.html | 4 +- templates/item-conteneur-sheet.html | 5 +- 6 files changed, 66 insertions(+), 46 deletions(-) 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 = ` diff --git a/templates/actor/inventaire-item.html b/templates/actor/inventaire-item.html index a1f25f49..25e5984b 100644 --- a/templates/actor/inventaire-item.html +++ b/templates/actor/inventaire-item.html @@ -1,4 +1,4 @@ -{{#if (or @root.options.isObserver (ne item.type 'monnaie'))}} +{{#if (or options.isObserver (ne item.type 'monnaie'))}}
  • {{#if (eq item.type 'conteneur')}} @@ -21,7 +21,7 @@ {{numberFormat item.system.encTotal decimals=2}} - {{#if @root.options.isOwner}} + {{#if options.isOwner}} {{#unless item.estContenu}} {{#if (or (eq item.type 'arme') (eq item.type 'armure') )}} {{#if item.system.equipe}}{{else}}{{/if}} @@ -35,7 +35,7 @@ {{/if}} {{/if}} - {{#if @root.options.isOwner}} + {{#if options.isOwner}} {{#if item.system.actionPrincipale}} {{item.system.actionPrincipale}} {{/if}} diff --git a/templates/actor/inventaire.html b/templates/actor/inventaire.html index c080c069..ea39f4e8 100644 --- a/templates/actor/inventaire.html +++ b/templates/actor/inventaire.html @@ -20,11 +20,11 @@ {{#each objets as |item id|}} {{#unless item.estContenu}} {{#if (ne item.type 'conteneur')}} - {{> "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html" item=item vide=true ouvert=true options=@root.options}} + {{buildLigneInventaire item @root.options}} {{/if}} {{/unless}} {{/each}} {{#each conteneurs as |conteneur id|}} - {{buildConteneur this 'actor/inventaire-item.html' @root.options}} + {{buildLigneInventaire conteneur @root.options}} {{/each}} diff --git a/templates/item-conteneur-sheet.html b/templates/item-conteneur-sheet.html index 033e6f38..5ce7071e 100644 --- a/templates/item-conteneur-sheet.html +++ b/templates/item-conteneur-sheet.html @@ -13,10 +13,8 @@ {{>"systems/foundryvtt-reve-de-dragon/templates/item/partial-inventaire.html"}} - {{#if isOwned}}
    -
    • Nom @@ -24,7 +22,8 @@ Enc. Actions
    • - {{buildContenu this}} + {{log 'contenu conteneur-sheet' this}} + {{buildInventaireConteneur actorId id @root.options}}
    {{/if}}