From e58d88fab607a12375f7b75940a8faccbbf7f203 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 12 Jul 2023 00:39:21 +0200 Subject: [PATCH] Fix: filterItem ne marchait plus sans type --- module/actor.js | 18 ++++++++++-------- module/actor/base-actor.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/module/actor.js b/module/actor.js index 8c0f2581..725e4582 100644 --- a/module/actor.js +++ b/module/actor.js @@ -298,7 +298,7 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ async verifierPotionsEnchantees() { - let potionsEnchantees = this.filterItems(it => it.type == 'potion' && it.system.categorie.toLowerCase().includes('enchant')); + let potionsEnchantees = this.filterItems(it => it.system.categorie.toLowerCase().includes('enchant'), 'potion'); for (let potion of potionsEnchantees) { if (!potion.system.prpermanent) { console.log(potion); @@ -1124,7 +1124,7 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ async computeMalusArmure() { if (this.isPersonnage()) { - const malusArmure = this.filterItems(it => it.type == 'armure' && it.system.equipe) + const malusArmure = this.filterItems(it => it.system.equipe, 'armure') .map(it => it.system.malus ?? 0) .reduce(Misc.sum(), 0); // Mise à jour éventuelle du malus armure @@ -1297,8 +1297,7 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ buildTMRInnaccessible() { - const tmrInnaccessibles = this.filterItems(it => Draconique.isCaseTMR(it) && - EffetsDraconiques.isInnaccessible(it)); + const tmrInnaccessibles = this.filterItems(it => Draconique.isCaseTMR(it) && EffetsDraconiques.isInnaccessible(it)); return tmrInnaccessibles.map(it => it.system.coord); } @@ -2363,8 +2362,7 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ async creerTacheDepuisLivre(item, options = { renderSheet: true }) { const nomTache = "Lire " + item.name; - const filterTacheLecture = it => it.type == 'tache' && it.name == nomTache; - let tachesExistantes = this.filterItems(filterTacheLecture); + let tachesExistantes = findTache(nomTache); if (tachesExistantes.length == 0) { const tache = { name: nomTache, type: 'tache', @@ -2380,13 +2378,17 @@ export class RdDActor extends RdDBaseActor { } } await this.createEmbeddedDocuments('Item', [tache], options); - tachesExistantes = this.filterItems(filterTacheLecture); + tachesExistantes = findTache(nomTache) } return tachesExistantes.length > 0 ? tachesExistantes[0] : undefined; + + function findTache(name) { + return this.filterItems(it => it.name == name, 'tache'); + } } blessuresASoigner() { - // TODO or not TODO: filtrer les blessures poour lesquels on ne peut plus faire de premiers soins? + // TODO or not TODO: filtrer les blessures pour lesquelles on ne peut plus faire de premiers soins? return this.filterItems(it => it.system.gravite > 0 && it.system.gravite <= 6 && !(it.system.premierssoins.done && it.system.soinscomplets.done), 'blessure') } diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index 29e82b7e..ae7c35ff 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -119,7 +119,7 @@ export class RdDBaseActor extends Actor { } listItems(type = undefined) { return (type ? this.itemTypes[type] : this.items); } - filterItems(filter, type = undefined) { return type ? this.itemTypes[type]?.filter(filter) ?? [] : []; } + filterItems(filter, type = undefined) { return (type ? this.itemTypes[type] : this.items)?.filter(filter); } findItemLike(idOrName, type) { return this.getItem(idOrName, type) ?? Misc.findFirstLike(idOrName, this.listItems(type), { description: Misc.typeName('Item', type) });