From 425c6af6725c3ef321099f50cbae59755d06d87d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 15 Jan 2025 22:26:18 +0100 Subject: [PATCH] Correction ouverture feuille de conteneur --- module/actor/base-actor-sheet.js | 25 ++++++------------- module/item.js | 2 +- module/item/sheet-conteneur.js | 5 ++-- module/rdd-utility.js | 41 +++++++++++++++++++++++++------- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index 89f2fa1f..6e99e08c 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -43,7 +43,7 @@ export class RdDBaseActorSheet extends ActorSheet { effects: this.actor.effects } - RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); + RdDUtility.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); formData.calc = { fortune: Monnaie.toSolsDeniers(this.actor.getFortune()), prixTotalEquipement: this.actor.computePrixTotalEquipement(), @@ -79,22 +79,6 @@ export class RdDBaseActorSheet extends ActorSheet { } } - /* -------------------------------------------- */ - static filterItemsPerTypeForSheet(formData, itemTypes) { - Object.values(ITEM_TYPES).forEach(t => { - formData[t + 's'] = Misc.arrayOrEmpty(itemTypes[t]) - }) - - formData.maladiesPoisons = formData.maladies.concat(formData.poisons) - formData.competences = formData.competences.concat(formData.competencecreatures) - formData.monnaies = formData.monnaies.sort(Monnaie.triValeurEntiere()) - - formData.inventaires = RdDItem.getItemTypesInventaire('all') - .map(t => Misc.arrayOrEmpty(itemTypes[t])) - .reduce((a, b) => a.concat(b), []) - .sort(Misc.ascending(it => it.name)); - } - /* -------------------------------------------- */ /** @override */ activateListeners(html) { super.activateListeners(html); @@ -105,7 +89,7 @@ export class RdDBaseActorSheet extends ActorSheet { this.render(true); }); this.html.find('.actor-montrer').click(async event => this.actor.postActorToChat()); - this.html.find('.item-edit').click(async event => this.getItem(event)?.sheet.render(true)) + this.html.find('.item-edit').click(async event => this.itemActionEdit(event)) this.html.find('.item-montrer').click(async event => this.getItem(event)?.postItemToChat()); this.html.find('.recherche') @@ -147,6 +131,11 @@ export class RdDBaseActorSheet extends ActorSheet { }); } + itemActionEdit(event) { + const item = this.getItem(event); + return item?.sheet.render(true); + } + _rechercherKeyup(event) { const currentTarget = event.currentTarget; const nouvelleRecherche = this._optionRecherche(currentTarget); diff --git a/module/item.js b/module/item.js index f94cff23..6b545694 100644 --- a/module/item.js +++ b/module/item.js @@ -1,4 +1,4 @@ -import { ACTOR_TYPES, ITEM_TYPES } from "./constants.js"; +import { ITEM_TYPES } from "./constants.js"; import { DialogItemVente } from "./achat-vente/dialog-item-vente.js"; import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; diff --git a/module/item/sheet-conteneur.js b/module/item/sheet-conteneur.js index effa355c..46966473 100644 --- a/module/item/sheet-conteneur.js +++ b/module/item/sheet-conteneur.js @@ -29,9 +29,10 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet { /* -------------------------------------------- */ prepareConteneurData(formData) { - RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); + RdDUtility.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.inventaires); - formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems; + const subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems; + formData.subItems = subItems } async _onDragStart(event) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 4504ebfe..c7aeeb6d 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -19,10 +19,11 @@ import { RdDEmpoignade } from "./rdd-empoignade.js"; import { ExperienceLog } from "./actor/experience-log.js"; import { RdDCoeur } from "./coeur/rdd-coeur.js"; import { APP_ASTROLOGIE_REFRESH } from "./sommeil/app-astrologie.js"; -import { RDD_CONFIG } from "./constants.js"; +import { ITEM_TYPES, RDD_CONFIG } from "./constants.js"; import { RdDBaseActor } from "./actor/base-actor.js"; import { RdDCarac } from "./rdd-carac.js"; import { RdDTextEditor } from "./apps/rdd-text-roll-editor.js"; +import { Monnaie } from "./item-monnaie.js"; /* -------------------------------------------- */ // This table starts at 0 -> niveau -10 @@ -264,7 +265,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html' ]; - + // foundry et options Handlebars.registerHelper('RDD_CONFIG', path => RDD_CONFIG[path]) Handlebars.registerHelper('linkCompendium', (pack, id, name) => RdDUtility.linkCompendium(pack, id, name)); @@ -279,7 +280,7 @@ export class RdDUtility { const html = options.fn(this); return html.replace(rgx, "$& selected"); }) - + // logic Handlebars.registerHelper('either', (a, b) => a ?? b); // string manipulation @@ -295,9 +296,9 @@ export class RdDUtility { // math Handlebars.registerHelper('min', (...args) => Math.min(...args.slice(0, -1))); - Handlebars.registerHelper('repeat', function(n, block) { + Handlebars.registerHelper('repeat', function (n, block) { let accum = ''; - for(let i = 0; i < n; ++i){ + for (let i = 0; i < n; ++i) { accum += block.fn(i) } return accum @@ -465,13 +466,37 @@ export class RdDUtility { return ligneObjet; } + static filterItemsPerTypeForSheet(formData, itemTypes) { + Object.values(ITEM_TYPES).forEach(t => { + formData[t + 's'] = Misc.arrayOrEmpty(itemTypes[t]) + }) + + formData.maladiesPoisons = formData.maladies.concat(formData.poisons) + formData.competences = formData.competences.concat(formData.competencecreatures) + formData.monnaies = formData.monnaies.sort(Monnaie.triValeurEntiere()) + + formData.inventaires = RdDUtility.prepareInventaire(itemTypes) + } + static buildInventaireConteneur(actorId, itemId, options) { const actor = game.actors.get(actorId) const item = actor?.items.get(itemId) - if (item) { - return RdDUtility.buildContenuConteneur(item, options, { ouvert: true, profondeur: 1 }); + if (item?.type == ITEM_TYPES.conteneur) { + const formData = {} + RdDUtility.filterItemsPerTypeForSheet(formData, actor.itemTypes); + RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.inventaires); + item.subItems = formData.conteneurs.find(it => it._id == itemId)?.subItems; + + return RdDUtility.buildContenuConteneur(item, options, { ouvert: true, profondeur: 1 }) } - return ''; + return '' + } + + static prepareInventaire(itemTypes) { + return RdDItem.getItemTypesInventaire('all') + .map(t => Misc.arrayOrEmpty(itemTypes[t])) + .reduce((a, b) => a.concat(b), []) + .sort(Misc.ascending(it => it.name)) } /* -------------------------------------------- */