From 8db631357406ad03a73ed0d5cc11c6228a664a69 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 26 Jan 2021 19:47:18 +0100 Subject: [PATCH] Fix /astro avec ou sans accents --- module/grammar.js | 5 +++++ module/rdd-calendrier.js | 6 ++++-- module/rdd-utility.js | 13 +++++++++---- module/tmr-utility.js | 3 ++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/module/grammar.js b/module/grammar.js index c840cd94..a5bb7472 100644 --- a/module/grammar.js +++ b/module/grammar.js @@ -12,7 +12,12 @@ export class Grammar { } return article + ' ' + word; } + static startsWithVoyel(word) { return word.match(/^[aeiouy]/i) } + + static toLowerCaseNoAccent(words) { + return words?.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") ?? words; + } } \ No newline at end of file diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index b1a13ebd..18facb1e 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -4,6 +4,7 @@ import { RdDAstrologieEditeur } from "./rdd-astrologie-editeur.js"; import { HtmlUtility } from "./html-utility.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDUtility } from "./rdd-utility.js"; +import { Grammar } from "./grammar.js"; /* -------------------------------------------- */ const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/' @@ -274,8 +275,9 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ getAjustementAstrologique(heureNaissance, name='inconnu') { - if (heureNaissance && heuresDef[heureNaissance]) { - let hn = heuresDef[heureNaissance].heure; + let heure = Grammar.toLowerCaseNoAccent(heureNaissance); + if (heure && heuresDef[heure]) { + let hn = heuresDef[heure].heure; let chiffreAstral = this.getCurrentNombreAstral(); let heureCourante = this.calendrier.heureRdD; let ecartChance = (hn + chiffreAstral - heureCourante)%12; diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 0e11e0bb..f3291c69 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -926,11 +926,16 @@ export class RdDUtility { /* -------------------------------------------- */ static afficherHeuresChanceMalchance( heureNaissance ) { - let ajustement = game.system.rdd.calendrier.getAjustementAstrologique(heureNaissance.toLowerCase()); - ChatMessage.create( { - content: `Pour l'heure ${game.system.rdd.calendrier.getCurrentHeure()}, le modificateur de Chance/Malchance est de : ${ajustement}.`, - whisper: ChatMessage.getWhisperRecipients("MJ") + if (heureNaissance) { + let ajustement = game.system.rdd.calendrier.getAjustementAstrologique(heureNaissance); + ChatMessage.create( { + content: `A l'heure ${game.system.rdd.calendrier.getCurrentHeure()}, le modificateur de Chance/Malchance pour l'heure de naissance ${heureNaissance} est de : ${ajustement}.`, + whisper: ChatMessage.getWhisperRecipients("MJ") } ); + } + else{ + ui.notifications.warn("Pas d'heure de naissance selectionnée") + } } } diff --git a/module/tmr-utility.js b/module/tmr-utility.js index ebde45cb..bef288ca 100644 --- a/module/tmr-utility.js +++ b/module/tmr-utility.js @@ -1,4 +1,5 @@ import { DeDraconique } from "./de-draconique.js"; +import { Grammar } from "./grammar.js"; /* -------------------------------------------- */ const TMRMapping = { @@ -383,7 +384,7 @@ export class TMRUtility { roll = new Roll("1d100").roll().total; console.log("rencontreTMRTypeCase", roll); } - typeTMR = typeTMR.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""); + typeTMR = Grammar.toLowerCaseNoAccent(typeTMR); for( let rencontre of rencontresTable) { console.log("TMR !!!", typeTMR, roll); let scoreDef = rencontre.data[typeTMR];