From 1a346a21c350eafb3a0181c0d708e732b1a02ef4 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 7 Feb 2023 18:05:25 +0100 Subject: [PATCH] Recherche dans les commerces --- module/actor/base-actor-sheet.js | 42 +++++++++---------- templates/actor/commerce-inventaire-item.html | 2 + templates/actor/commerce-inventaire.html | 3 ++ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index c4d09424..ea512b1c 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -52,28 +52,28 @@ export class RdDBaseActorSheet extends ActorSheet { this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets); formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs); - this._appliquerRechercheObjets(formData.objets, formData.conteneurs, this.options.recherche); + this._appliquerRechercheObjets(formData.objets, formData.conteneurs); return formData; } - _appliquerRechercheObjets(objets, conteneurs, recherche) { - if (recherche) { - this._setConteneursVisibles(objets, conteneurs); + _appliquerRechercheObjets(objets, conteneurs) { + if (this.options.recherche?.text) { + const recherche = this.options.recherche; + const allVisible = objets.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id); + let addVisible = conteneurs.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id) + do { + allVisible.push(...addVisible) + const parentsIds = conteneurs.filter(it => it.system.contenu.find(id => allVisible.includes(id))).map(it => it.id) + addVisible = parentsIds.filter(id => !allVisible.includes(id)) + } + while (addVisible.length > 0) + objets.forEach(it => it.system.isHidden = !allVisible.includes(it.id)) + conteneurs.forEach(it => it.system.isHidden = !allVisible.includes(it.id)) } - } - - _setConteneursVisibles(objets, conteneurs) { - const recherche = this.options.recherche; - const allVisible = objets.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id); - let addVisible = conteneurs.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id) - do { - allVisible.push(...addVisible) - const parentsIds = conteneurs.filter(it => it.system.contenu.find(id => allVisible.includes(id))).map(it => it.id) - addVisible = parentsIds.filter(id => !allVisible.includes(id)) + else { + objets.forEach(it => it.system.isHidden = false) + conteneurs.forEach(it => it.system.isHidden = false) } - while (addVisible.length > 0) - objets.forEach(it => it.system.isHidden = !allVisible.includes(it.id)) - conteneurs.forEach(it => it.system.isHidden = !allVisible.includes(it.id)) } /* -------------------------------------------- */ @@ -164,12 +164,8 @@ export class RdDBaseActorSheet extends ActorSheet { .each((index, field) => { this._rechercheSelectArea(field); }) - .keyup(async event => { - this._rechercherKeyup(event); - }) - .change(async event => - this.options.recherche = this._optionRecherche(event.currentTarget) - ); + .keyup(async event => this._rechercherKeyup(event)) + .change(async event => this._rechercherKeyup(event)); } _rechercherKeyup(event) { diff --git a/templates/actor/commerce-inventaire-item.html b/templates/actor/commerce-inventaire-item.html index e057f84c..5a8683ce 100644 --- a/templates/actor/commerce-inventaire-item.html +++ b/templates/actor/commerce-inventaire-item.html @@ -1,3 +1,4 @@ +{{#unless item.system.isHidden}} {{#if (ne item.type 'monnaie')}}
  • @@ -57,3 +58,4 @@
  • {{/if}} +{{/unless}} \ No newline at end of file diff --git a/templates/actor/commerce-inventaire.html b/templates/actor/commerce-inventaire.html index f4fc2b81..16f95c72 100644 --- a/templates/actor/commerce-inventaire.html +++ b/templates/actor/commerce-inventaire.html @@ -4,6 +4,9 @@ Nouvel objet Tout vider {{/if}} + + + {{#unless system.illimite}} {{#if calc.surEncombrementMessage}}{{calc.surEncombrementMessage}} ‐{{/if}}