Quelques petits fixes #541

Merged
uberwald merged 2 commits from VincentVk/foundryvtt-reve-de-dragon:v1.5 into v1.5 2022-07-09 08:55:49 +02:00
4 changed files with 12 additions and 7 deletions
Showing only changes of commit bafc52a151 - Show all commits

View File

@ -3148,7 +3148,7 @@ export class RdDActor extends Actor {
return carac.chance; return carac.chance;
} }
let entry = Misc.findFirstLike(name, Object.entries(carac), { mapper: it => it[1].label, description: 'caractéristique' }); let entry = Misc.findFirstLike(name, Object.entries(carac), { mapper: it => it[1].label, description: 'caractéristique' });
return entry.length > 0 ? carac[entry[0]] : undefined; return entry && entry.length > 0 ? carac[entry[0]] : undefined;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -212,8 +212,11 @@ export class RdDItemCompetence extends Item {
/* -------------------------------------------- */ /* -------------------------------------------- */
static findCompetence(list, idOrName, options = {}) { static findCompetence(list, idOrName, options = {}) {
if (idOrName == undefined) {
return undefined;
}
options = mergeObject(options, { options = mergeObject(options, {
filter: it => RdDItemCompetence.isCompetence(it), preFilter: it => RdDItemCompetence.isCompetence(it),
description: 'compétence', description: 'compétence',
}); });
return list.find(it => it.id == idOrName && RdDItemCompetence.isCompetence(it)) return list.find(it => it.id == idOrName && RdDItemCompetence.isCompetence(it))

View File

@ -192,7 +192,7 @@ export class Misc {
if (!single) { if (!single) {
single = subset[0]; single = subset[0];
const choices = Misc.join(subset.map(it => options.mapper(it)), '<br>'); const choices = Misc.join(subset.map(it => options.mapper(it)), '<br>');
options.info(`Plusieurs choix de ${options.description}s possibles:<br>${choices}<br>Le premier sera choisi: ${mapToValue(single)}`); options.onMessage(`Plusieurs choix de ${options.description}s possibles:<br>${choices}<br>Le premier sera choisi: ${options.mapper(single)}`);
} }
return single; return single;
} }
@ -211,7 +211,7 @@ export class Misc {
} }
value = Grammar.toLowerCaseNoAccent(value); value = Grammar.toLowerCaseNoAccent(value);
const subset = elements.filter(options.preFilter) const subset = elements.filter(options.preFilter)
.filter(it => Grammar.toLowerCaseNoAccent(options.mapper(it)).includes(value)); .filter(it => Grammar.toLowerCaseNoAccent(options.mapper(it))?.includes(value));
if (subset.length == 0) { if (subset.length == 0) {
options.onMessage(`Pas de ${options.description} correspondant à ${value}`); options.onMessage(`Pas de ${options.description} correspondant à ${value}`);
} }

View File

@ -276,9 +276,11 @@ export class RdDCommands {
diff = 0; diff = 0;
} }
const caracName = params[0]; const caracName = params[0];
const compName = length > 1 ? Misc.join(params.slice(1, length), ' ') : undefined; let competence = length > 1 ? actors[0].getCompetence(Misc.join(params.slice(1, length), ' ')) : undefined;
if (competence) {
for (let actor of actors) { for (let actor of actors) {
await actor.rollCaracCompetence(caracName, compName, diff); await actor.rollCaracCompetence(caracName, competence.name, diff);
}
} }
return; return;
} }