diff --git a/module/actor.js b/module/actor.js index 1b5dded2..fe0b46a5 100644 --- a/module/actor.js +++ b/module/actor.js @@ -35,6 +35,7 @@ import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE, HIDE_DICE, SHOW_DIC import { RdDConfirm } from "./rdd-confirm.js"; import { DialogValidationEncaissement } from "./dialog-validation-encaissement.js"; import { RdDRencontre } from "./item-rencontre.js"; +import { SystemCompendiums } from "./settings/system-compendiums.js"; import { Targets } from "./targets.js"; const POSSESSION_SANS_DRACONIC = { @@ -125,9 +126,9 @@ export class RdDActor extends Actor { } if (isPersonnage) { - const competences = await RdDUtility.loadItems(it => it.isCompetencePersonnage(), 'foundryvtt-reve-de-dragon.competences'); - actorData.items = competences.map(i => i.toObject()); - actorData.items = actorData.items.concat(Monnaie.monnaiesStandard()); + const competences = await SystemCompendiums.getCompetences(actorData.type); + actorData.items = competences.map(i => i.toObject()) + .concat(Monnaie.monnaiesStandard()); } else { actorData.items = []; diff --git a/module/item-competence.js b/module/item-competence.js index f61d1310..e5fbfab9 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -34,13 +34,6 @@ const categorieCompetences = { "lancer": { base: -8, label: "Lancer" } } -const compendiumCompetences = { - "personnage": "foundryvtt-reve-de-dragon.competences", - "creature": "foundryvtt-reve-de-dragon.competences-creatures", - "entite": "foundryvtt-reve-de-dragon.competences-entites" -}; - - function _buildCumulXP() { let cumulXP = { "-11": 0 }; let cumul = 0; @@ -55,12 +48,6 @@ function _buildCumulXP() { const competence_xp_cumul = _buildCumulXP(); export class RdDItemCompetence extends Item { - - /* -------------------------------------------- */ - static actorCompendium(actorType = undefined) { - return compendiumCompetences[actorType ?? 'personnage']; - } - /* -------------------------------------------- */ static getCategorieCompetences() { return categorieCompetences; diff --git a/module/item-sheet.js b/module/item-sheet.js index ee3fc769..da1d316d 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -8,6 +8,7 @@ import { HtmlUtility } from "./html-utility.js"; import { ReglesOptionelles } from "./settings/regles-optionelles.js"; import { SYSTEM_RDD } from "./constants.js"; import { RdDSheetUtility } from "./rdd-sheet-utility.js"; +import { SystemCompendiums } from "./settings/system-compendiums.js"; /** * Extend the basic ItemSheet with some very simple modifications @@ -83,17 +84,18 @@ export class RdDItemSheet extends ItemSheet { } } + const competences = await SystemCompendiums.getCompetences(this.actor?.type); formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences() if (this.item.type == 'tache' || this.item.type == 'livre' || this.item.type == 'meditation' || this.item.type == 'oeuvre') { formData.caracList = duplicate(game.system.model.Actor.personnage.carac) formData.caracList["reve-actuel"] = duplicate(game.system.model.Actor.personnage.reve.reve) - formData.competences = await RdDUtility.loadItems(it => it.isCompetencePersonnage(), RdDItemCompetence.actorCompendium(this.actor?.type)) + formData.competences = competences; } if (this.item.type == 'arme') { - formData.competences = await RdDUtility.loadItems(it => RdDItemCompetence.isCompetenceArme(it), RdDItemCompetence.actorCompendium(this.actor?.type)) + formData.competences = competences.filter(it => RdDItemCompetence.isCompetenceArme(it)); } if (['sort', 'sortreserve'].includes(this.item.type)) { - formData.competences = await RdDUtility.loadItems(it => RdDItemCompetence.isDraconic(it), RdDItemCompetence.actorCompendium(this.actor?.type)) + formData.competences = competences.filter(it => RdDItemCompetence.isDraconic(it)); } if (this.item.type == 'recettecuisine') { formData.ingredients = await TextEditor.enrichHTML(this.object.system.ingredients, {async: true}) diff --git a/module/rdd-herbes.js b/module/rdd-herbes.js index 8b091647..18b5fad5 100644 --- a/module/rdd-herbes.js +++ b/module/rdd-herbes.js @@ -1,6 +1,7 @@ import { RdDUtility } from "./rdd-utility.js"; import { RdDCalendrier } from "./rdd-calendrier.js"; import { Grammar } from "./grammar.js"; +import { SystemCompendiums } from "./settings/system-compendiums.js"; /* -------------------------------------------- */ export class RdDHerbes extends Item { @@ -12,9 +13,8 @@ export class RdDHerbes extends Item { } static async listCategorieHerbes(categorie) { - return await RdDUtility.loadItems( - it => it.type == 'herbe' && it.system.categorie.toLowerCase() == categorie.toLowerCase(), - 'foundryvtt-reve-de-dragon.botanique'); + const herbes = await SystemCompendiums.getWorldOrCompendiumItems('herbe', 'botanique'); + return herbes.filter(it => Grammar.equalsInsensitive(it.system.categorie, categorie)); } /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 30cc52b0..a9dff181 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -759,29 +759,6 @@ export class RdDUtility { return 0; } - /* -------------------------------------------- */ - static async loadItems(filter, compendium) { - let items = game.items.filter(filter); - if (compendium) { - const ids = items.map(it => it.id); - const names = items.map(it => it.name.toLowerCase()); - items = items.concat(await RdDUtility.loadCompendium(compendium, it => !ids.includes(it.id) && !names.includes(it.name.toLowerCase()) && filter(it))); - } - return items; - } - - /* -------------------------------------------- */ - static async loadCompendium(compendium, filter = it => true) { - let compendiumData = await RdDUtility.loadCompendiumData(compendium); - return compendiumData.filter(filter); - } - - /* -------------------------------------------- */ - static async loadCompendiumData(compendium) { - const pack = game.packs.get(compendium); - return await pack?.getDocuments() ?? []; - } - /* -------------------------------------------- */ static async responseNombreAstral(callData) { let actor = game.actors.get(callData.id); diff --git a/module/settings/system-compendiums.js b/module/settings/system-compendiums.js index bf95c55e..43e3af97 100644 --- a/module/settings/system-compendiums.js +++ b/module/settings/system-compendiums.js @@ -55,6 +55,29 @@ export class SystemCompendiums extends FormApplication { return []; } + static async getCompetences(actorType) { + switch (actorType ?? 'personnage') { + case 'personnage': return await SystemCompendiums.getWorldOrCompendiumItems('competence', 'competences'); + case 'creature': return await SystemCompendiums.getWorldOrCompendiumItems('competencecreature', 'competences-creatures'); + case 'entite': return await SystemCompendiums.getWorldOrCompendiumItems('competencecreature', 'competences-entites'); + case 'vehicule': return []; + } + } + /* -------------------------------------------- */ + static async getWorldOrCompendiumItems(itemType, compendium) { + let items = game.items.filter(it => it.type == itemType); + if (compendium) { + const ids = items.map(it => it.id); + const names = items.map(it => it.name.toLowerCase()); + const compendiumItems = await SystemCompendiums.getItems(compendium); + items = items.concat(compendiumItems + .filter(it => it.type == itemType) + .filter(it => !ids.includes(it.id)) + .filter(it => !names.includes(it.name.toLowerCase()))); + } + return items; + } + static async getItems(compendium, itemType = undefined) { const items = await SystemCompendiums.getContent(compendium, 'Item'); return itemType ? items.filter(it => it.type == itemType) : items;