From 4fb34b51a32968df51386abd9cf2f3b8dd602908 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 26 Jan 2021 00:25:41 +0100 Subject: [PATCH] Ajout du type dans le compendium --- module/rdd-compendium-organiser.js | 65 ++++++++++++++++++++++++++++++ module/rdd-main.js | 2 + 2 files changed, 67 insertions(+) create mode 100644 module/rdd-compendium-organiser.js diff --git a/module/rdd-compendium-organiser.js b/module/rdd-compendium-organiser.js new file mode 100644 index 00000000..2017af97 --- /dev/null +++ b/module/rdd-compendium-organiser.js @@ -0,0 +1,65 @@ +import { Misc } from "./misc.js"; + +const typeDisplayName = { + "objet": "Objet", + "arme": "Arme", + "armure": "Armure", + "conteneur": "Conteneur", + "competence": "Compétence", + "sort": "Sort", + "herbe": "Plante", + "ingredient": "Ingrédient", + "livre": "Livre", + "potion": "Potion", + "munition": "Munition", + "queue": "Queue de dragon", + "ombre": "Ombre de Thanatos", + "souffle": "Souffle de Dragon", + "tete": "Tête de Dragon", + "ingredient": "Ingrédient", + "rencontresTMR": "Rencontre des TMR", + "competencecreature": "Compétence de créature", + "nombreastral": "Nombre astral", + "casetmr": "Case des TMR", + "recettealchimique": "Recette alchimique", + "recettecuisine": "Recette de cuisine", + "tarot": "Carte de tarot draconique", + "tache": "Tâche", + "meditation": "Méditation", + "monnaie": "Monnaie", + "musique": "Morceau de musique", + "chant": "Chanson", + "danse": "Danse", + "jeu": "Jeu", + "personnage": "Personnage", + "creature": "Créature", + "entite": "Entité de cauchemar", + "vehicule": "Véhicule" +} + +export class RddCompendiumOrganiser { + static init() { + Hooks.on('renderCompendium', async (pack, html, data) => RddCompendiumOrganiser.onRenderCompendium(pack, html, data)) + } + + static async onRenderCompendium(pack, html, data) { + console.log('onRenderCompendium', pack, html, data); + if (pack.metadata.system === 'foundryvtt-reve-de-dragon') { + const content = await pack.getContent(); + + html.find('.directory-item').each((i, element) => { + let entity = content.find(it => it._id === element.dataset.entryId); + + if (entity?.entity === 'Actor' || entity?.entity === 'Item') { + const typeName = typeDisplayName[entity.data.type] ?? Misc.upperFirst(entity.data.type); + RddCompendiumOrganiser.insertEntityType(element, typeName); + } + }); + } + } + + static insertEntityType(element, type) { + element.children[1].insertAdjacentHTML('afterbegin', ``); + } + +} \ No newline at end of file diff --git a/module/rdd-main.js b/module/rdd-main.js index 5f0860b4..d06d66ad 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -24,6 +24,7 @@ import { RdDCombat } from "./rdd-combat.js"; import { ChatUtility } from "./chat-utility.js"; import { RdDItemCompetence } from "./item-competence.js"; import { StatusEffects } from "./status-effects.js"; +import { RddCompendiumOrganiser } from "./rdd-compendium-organiser.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -220,6 +221,7 @@ Hooks.once("init", async function () { RdDCombat.init(); RdDTokenHud.init(); RdDActor.init(); + RddCompendiumOrganiser.init(); }); /* -------------------------------------------- */