From 286eaafe4ebbcc4657a376ff78b46ca7ae223f6e Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 24 May 2021 00:43:46 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liorer=20le=20choix=20du=20type=20d'obj?= =?UTF-8?q?et=20=C3=A0=20cr=C3=A9er=20#143?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Utilisation du fichier de langue Utilisation de la même référence pour les compendiums Fix sur les compendium, le type n'apparaissait pas toujours --- lang/fr.json | 44 +++++++++++++++++++++++++ module/misc.js | 10 ++++++ module/rdd-compendium-organiser.js | 52 +++++++----------------------- styles/simple.css | 4 +++ system.json | 5 ++- 5 files changed, 73 insertions(+), 42 deletions(-) create mode 100644 lang/fr.json diff --git a/lang/fr.json b/lang/fr.json new file mode 100644 index 00000000..58483e89 --- /dev/null +++ b/lang/fr.json @@ -0,0 +1,44 @@ +{ + "ACTOR": { + "TypePersonnage": "Personnage", + "TypeCreature": "Créature", + "TypeEntite": "Entité de cauchemar", + "TypeVehicule": "Véhicule" + }, + "ITEM": { + "TypeObjet": "Objet", + "TypeCompetence": "Compétence", + "TypeCompetencecreature": "Compétence de créature", + "TypeMaladie": "Maladie", + "TypePoison": "Poison", + "TypeNombreastral": "Nombre astral", + "TypeTarot": "Carte de tarot", + "TypeCasetmr": "TMR spéciale", + "TypeRencontresTMR": "Rencontre TMR", + "TypeMunition": "Munition", + "TypeMonnaie": "Monnaie", + "TypeHerbe": "Herbe ou plante", + "TypeIngredient": "Ingrédient", + "TypeLivre": "Livre", + "TypePotion": "Potion", + "TypeArme": "Arme", + "TypeArmure": "Armure", + "TypeConteneur": "Conteneur", + "TypeNourritureboisson": "Nourriture & boisson", + "TypeChant": "Chant", + "TypeDanse": "Danse", + "TypeMusique": "Musique", + "TypeOeuvre": "Oeuvre", + "TypeTache": "Tâche", + "TypeJeu": "Jeu", + "TypeRecettealchimique": "Recette alchimique", + "TypeRecettecuisine": "Recette de cuisine", + "TypeSort": "Sort", + "TypeMeditation": "Méditation", + "TypeSignedraconique": "Signe draconique", + "TypeQueue": "Queue de Dragon", + "TypeOmbre": "Ombre de Thanatos", + "TypeSouffle": "Souffle de Dragon", + "TypeTete": "Tête de Dragon" + } +} diff --git a/module/misc.js b/module/misc.js index 09114a98..3c115740 100644 --- a/module/misc.js +++ b/module/misc.js @@ -108,6 +108,16 @@ export class Misc { return Misc.data(it)?.data ?? {} } + static getEntityTypeLabel(entity) { + const documentName = entity?.documentName; + const type = entity?.data.type; + if (documentName === 'Actor' || documentName === 'Item') { + const label = CONFIG[documentName]?.typeLabels?.[type] ?? type; + return game.i18n.has(label) ? game.i18n.localize(label) : t; + } + return type; + } + static connectedGMOrUser(ownerId = undefined) { if (ownerId && game.user.id == ownerId) { return ownerId; diff --git a/module/rdd-compendium-organiser.js b/module/rdd-compendium-organiser.js index 1bc56339..91611194 100644 --- a/module/rdd-compendium-organiser.js +++ b/module/rdd-compendium-organiser.js @@ -1,36 +1,5 @@ import { Misc } from "./misc.js"; -/* -------------------------------------------- */ -/** - * Mapping des types d'Item/Actor vers le nom d'affichage. - * Par défaut, on prend le type avec la première lettre - * majuscule, pas besoin d'ajouter tous les types. - */ -const typeDisplayName = { - "competence": "Compétence", - "herbe": "Plante", - "ingredient": "Ingrédient", - "queue": "Queue de Dragon", - "ombre": "Ombre de Thanatos", - "souffle": "Souffle de Dragon", - "tete": "Tête de Dragon", - "nourritureboisson": "Nourriture & boisson", - "rencontresTMR": "Rencontre des TMR", - "competencecreature": "Compétence de créature", - "nombreastral": "Nombre astral", - "casetmr": "Effet sur TMR", - "recettealchimique": "Recette alchimique", - "recettecuisine": "Recette de cuisine", - "tarot": "Carte de tarot draconique", - "tache": "Tâche", - "meditation": "Méditation", - "musique": "Mélodie", - "chant": "Chanson", - "creature": "Créature", - "entite": "Entité", - "vehicule": "Véhicule" -} - export class RddCompendiumOrganiser { static init() { Hooks.on('renderCompendium', async (pack, html, data) => RddCompendiumOrganiser.onRenderCompendium(pack, html, data)) @@ -38,22 +7,23 @@ export class RddCompendiumOrganiser { static async onRenderCompendium(compendium, html, data) { console.log('onRenderCompendium', compendium, html, data); - let pack = compendium.collection + const pack = compendium.collection if (pack.metadata.system === 'foundryvtt-reve-de-dragon') { html.find('.directory-item').each((i, element) => { - const entity = pack.get(element.dataset.documentId); - const entityName = entity?.documentName; - if (entityName === 'Actor' || entityName === 'Item') { - const entityType = entity.data.type; - const typeName = typeDisplayName[entityType] ?? Misc.upperFirst(entitytype); - RddCompendiumOrganiser.insertEntityType(element, typeName); - } + RddCompendiumOrganiser.setEntityTypeName(pack, element); }); } } - static insertEntityType(element, type) { - element.children[1].insertAdjacentHTML('afterbegin', ``); + static async setEntityTypeName(pack, element) { + const label = Misc.getEntityTypeLabel(await pack.getDocument(element.dataset.documentId)); + RddCompendiumOrganiser.insertEntityType(element, label); + } + + static insertEntityType(element, label) { + if (label) { + element.children[1].insertAdjacentHTML('afterbegin', ``); + } } } \ No newline at end of file diff --git a/styles/simple.css b/styles/simple.css index 5b6b0073..13fa3dc3 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -530,6 +530,10 @@ table {border: 1px solid #7a7971;} overflow: visible; } +.type-compendium{ + font-size: 0.60rem; +} + /* ======================================== */ /* Sheet */ .window-app.sheet .window-content .sheet-header{ diff --git a/system.json b/system.json index abff3cd8..c1e29cf0 100644 --- a/system.json +++ b/system.json @@ -320,7 +320,10 @@ } ], "library": false, - "languages": [], + "languages": [ + { "lang": "en", "name": "English", "path": "lang/fr.json", "unreal": "this is a trick"}, + { "lang": "fr", "name": "Français", "path": "lang/fr.json" } + ], "gridDistance": 1, "gridUnits": "m", "primaryTokenAttribute": "sante.vie",