From de56fa909acb6c7c4b36823acb08405bced9f2a8 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 30 Mar 2023 02:56:06 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20bouton=20Item=20diminuer=20quantit?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pour diminuer la quantité des objets multiples sans avoir à éditer --- module/actor/base-actor-sheet.js | 8 ++------ module/actor/base-actor.js | 10 +++++----- module/item-sheet.js | 8 ++++++++ templates/actor/inventaire-item.html | 6 +++++- templates/actor/inventaire-monnaie.html | 4 ++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index 11429c01..e6af9247 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -152,6 +152,8 @@ export class RdDBaseActorSheet extends ActorSheet { const item = this.getItem(event); RdDSheetUtility.splitItem(item, this.actor); }); + this.html.find('.item-quantite-plus').click(async event => this.actor.itemQuantiteIncDec(this.getItemId(event), 1)); + this.html.find('.item-quantite-moins').click(async event => this.actor.itemQuantiteIncDec(this.getItemId(event), -1)); this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, this.getItem(event))); this.html.find('.item-vendre').click(async event => this.vendre(this.getItem(event))); @@ -161,12 +163,6 @@ export class RdDBaseActorSheet extends ActorSheet { this.html.find('.nettoyer-conteneurs').click(async event => { this.actor.nettoyerConteneurs(); }); - this.html.find('.monnaie-plus').click(async event => { - this.actor.monnaieIncDec(this.getItemId(event), 1); - }); - this.html.find('.monnaie-moins').click(async event => { - this.actor.monnaieIncDec(this.getItemId(event), -1); - }); } _rechercherKeyup(event) { diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index 769bc76e..c4c4182f 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -150,11 +150,11 @@ export class RdDBaseActor extends Actor { } /* -------------------------------------------- */ - async monnaieIncDec(id, value) { - let monnaie = this.getMonnaie(id); - if (monnaie) { - const quantite = Math.max(0, monnaie.system.quantite + value); - await this.updateEmbeddedDocuments('Item', [{ _id: monnaie.id, 'system.quantite': quantite }]); + async itemQuantiteIncDec(id, value) { + let item = this.getItem(id); + if (item && item.isInventaire()) { + const quantite = Math.max(0, item.system.quantite + value); + await this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'system.quantite': quantite }]); } } diff --git a/module/item-sheet.js b/module/item-sheet.js index 2cbbf815..62add209 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -209,6 +209,14 @@ export class RdDItemSheet extends ItemSheet { this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItemToChat()); this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor, async () => this.render(true))); + this.html.find('.item-quantite-plus').click(async event => { + await this.actor.itemQuantiteIncDec(RdDSheetUtility.getItemId(event), 1) + this.render(); + }); + this.html.find('.item-quantite-moins').click(async event => { + await this.actor.itemQuantiteIncDec(RdDSheetUtility.getItemId(event), -1) + this.render(); + }); const updateItemTimestamp = (path, timestamp) => this.item.update({ [path]: duplicate(timestamp) }) diff --git a/templates/actor/inventaire-item.html b/templates/actor/inventaire-item.html index 71aac1ba..a658fb12 100644 --- a/templates/actor/inventaire-item.html +++ b/templates/actor/inventaire-item.html @@ -15,7 +15,11 @@ {{/if}} - {{item.system.quantite}} + + {{#if (gt item.system.quantite 1)}} + + {{/if}} + {{item.system.quantite}} {{#if (gt item.system.quantite 1)}} {{/if}} diff --git a/templates/actor/inventaire-monnaie.html b/templates/actor/inventaire-monnaie.html index ddb413ad..e9b73518 100644 --- a/templates/actor/inventaire-monnaie.html +++ b/templates/actor/inventaire-monnaie.html @@ -10,7 +10,7 @@ {{#if @root.options.isOwner}} - + {{/if}} @@ -18,7 +18,7 @@ {{#if @root.options.isOwner}} - + {{/if}}