From a9b7dff83af01d5873b8ca7b45501adef08aef5c Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 11 Dec 2024 23:29:01 +0100 Subject: [PATCH] =?UTF-8?q?Affichage=20du=20co=C3=BBt=20de=20seuil=20sur?= =?UTF-8?q?=20les=20sorts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/rdd-utility.js | 80 ++++++++++++++++++++++------------- templates/actor/hr-sorts.html | 7 ++- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 8e9ed24a..d3939bc8 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -261,8 +261,25 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html' ]; + + // foundry et options + Handlebars.registerHelper('RDD_CONFIG', path => RDD_CONFIG[path]) + Handlebars.registerHelper('linkCompendium', (pack, id, name) => RdDUtility.linkCompendium(pack, id, name)); + Handlebars.registerHelper('regle-optionnelle', (option) => ReglesOptionnelles.isUsing(option)); + Handlebars.registerHelper('plusMoins', diff => (diff > 0 ? '+' : '') + Math.round(diff)) + + // Handle v12 removal of this helper + Handlebars.registerHelper('select', function (selected, options) { + const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected)); + const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']'); + const html = options.fn(this); + return html.replace(rgx, "$& selected"); + }) + + // logic Handlebars.registerHelper('either', (a, b) => a ?? b); + // string manipulation Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null')); Handlebars.registerHelper('lowerFirst', str => Misc.lowerFirst(str ?? 'Null')); Handlebars.registerHelper('uppercase', str => str?.toUpperCase() ?? ''); @@ -271,48 +288,53 @@ export class RdDUtility { Handlebars.registerHelper('grammar-apostrophe', (article, str) => Grammar.apostrophe(article, str)); Handlebars.registerHelper('grammar-un', str => Grammar.articleIndetermine(str)); Handlebars.registerHelper('grammar-accord', (genre, ...args) => Grammar.accord(genre, args)); - - Handlebars.registerHelper('RDD_CONFIG', path => RDD_CONFIG[path]) + + // math + Handlebars.registerHelper('min', (...args) => Math.min(...args.slice(0, -1))); + Handlebars.registerHelper('repeat', function(n, block) { + let accum = ''; + for(let i = 0; i < n; ++i){ + accum += block.fn(i) + } + return accum + }) + + // tableaux, listes + Handlebars.registerHelper('array-includes', (array, value) => array.includes(value)); + Handlebars.registerHelper('isLastIndex', (index, list) => index + 1 >= list.length); + Handlebars.registerHelper('trier', list => list.sort((a, b) => a.name.localeCompare(b.name))); + + // table de résolution Handlebars.registerHelper('computeResolutionScore', (row, col) => RdDResolutionTable.computePercentage(row, col)); Handlebars.registerHelper('computeResolutionChances', (row, col) => RdDResolutionTable.computeChances(row, col)); - Handlebars.registerHelper('buildLigneInventaire', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildLigneInventaire(item, options)); }); - Handlebars.registerHelper('buildInventaireConteneur', (actorId, itemId, options) => { return new Handlebars.SafeString(RdDUtility.buildInventaireConteneur(actorId, itemId, options)); }); - Handlebars.registerHelper('buildContenuConteneur', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildContenuConteneur(item, options)); }); - Handlebars.registerHelper('calculerPrixCommercant', item => item.calculerPrixCommercant()); - Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); - Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); - Handlebars.registerHelper('typeTmr-name', type => TMRUtility.typeTmrName(type)); - Handlebars.registerHelper('effetRencontre-name', coord => TMRUtility.typeTmrName(coord)); + // gestion des dates et heures Handlebars.registerHelper('timestamp-imgSigneHeure', (heure) => { return new Handlebars.SafeString(RdDTimestamp.imgSigneHeure(heure)) }); Handlebars.registerHelper('timestamp-imgSigne', (heure) => { return new Handlebars.SafeString(RdDTimestamp.imgSigne(heure)) }); Handlebars.registerHelper('timestamp-extract', timestamp => new RdDTimestamp(timestamp).toCalendrier()); Handlebars.registerHelper('timestamp-formulesDuree', () => RdDTimestamp.formulesDuree()); Handlebars.registerHelper('timestamp-formulesPeriode', () => RdDTimestamp.formulesPeriode()); - + + // informations sur les acteurs Handlebars.registerHelper('actor-default', (actorType, ...path) => RdDBaseActor.getDefaultValue(actorType, path.slice(0, -1))); - - Handlebars.registerHelper('array-includes', (array, value) => array.includes(value)); - Handlebars.registerHelper('min', (...args) => Math.min(...args.slice(0, -1))); - Handlebars.registerHelper('isLastIndex', (index, list) => index + 1 >= list.length); - Handlebars.registerHelper('regle-optionnelle', (option) => ReglesOptionnelles.isUsing(option)); - Handlebars.registerHelper('trier', list => list.sort((a, b) => a.name.localeCompare(b.name))); Handlebars.registerHelper('filtreTriCompetences', competences => RdDItemCompetence.triVisible(competences)); - Handlebars.registerHelper('linkCompendium', (pack, id, name) => RdDUtility.linkCompendium(pack, id, name)); + Handlebars.registerHelper('experienceLog-topic', topic => ExperienceLog.labelTopic(topic)); + + // inventaire et marchands + Handlebars.registerHelper('buildLigneInventaire', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildLigneInventaire(item, options)); }); + Handlebars.registerHelper('buildInventaireConteneur', (actorId, itemId, options) => { return new Handlebars.SafeString(RdDUtility.buildInventaireConteneur(actorId, itemId, options)); }); + Handlebars.registerHelper('buildContenuConteneur', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildContenuConteneur(item, options)); }); + Handlebars.registerHelper('calculerPrixCommercant', item => item.calculerPrixCommercant()); Handlebars.registerHelper('uniteQuantite', (itemId, actorId) => RdDUtility.getItem(itemId, actorId)?.getUniteQuantite()); Handlebars.registerHelper('isFieldInventaireModifiable', (type, field) => RdDItem.isFieldInventaireModifiable(type, field)); + // Items Handlebars.registerHelper('rarete-getChamp', (rarete, field) => RdDRaretes.getChamp(rarete, field)); - - Handlebars.registerHelper('plusMoins', diff => (diff > 0 ? '+' : '') + Math.round(diff)) - Handlebars.registerHelper('experienceLog-topic', topic => ExperienceLog.labelTopic(topic)); - - // Handle v12 removal of this helper - Handlebars.registerHelper('select', function (selected, options) { - const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected)); - const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']'); - const html = options.fn(this); - return html.replace(rgx, "$& selected"); - }); + + // TMRs + Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); + Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); + Handlebars.registerHelper('typeTmr-name', type => TMRUtility.typeTmrName(type)); + Handlebars.registerHelper('effetRencontre-name', coord => TMRUtility.typeTmrName(coord)); return loadTemplates(templatePaths); } diff --git a/templates/actor/hr-sorts.html b/templates/actor/hr-sorts.html index 578d57fd..0f9d1c72 100644 --- a/templates/actor/hr-sorts.html +++ b/templates/actor/hr-sorts.html @@ -2,11 +2,14 @@

Sorts