Ajout de Misc.findFirstLike
Méthode de recherche de valeur "proche" dans une liste. Cherche un élément correspondant strictement, sinon cherche les éléments contenant la valeur, et retourne le premier. Notification si plusieurs valeurs peuvent correspondre.
This commit is contained in:
@ -209,20 +209,7 @@ export class RdDItemCompetence extends Item {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static findCompetence(list, name) {
|
||||
name = Grammar.toLowerCaseNoAccent(name);
|
||||
const competences = list.filter(it => Grammar.toLowerCaseNoAccent(it.name).includes(name) && (it.type == "competence" || it.type == "competencecreature"));
|
||||
if (competences.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
let competence = competences.find(it => Grammar.toLowerCaseNoAccent(it.name) == name);
|
||||
if (!competence) {
|
||||
competence = competences[0];
|
||||
if (competences.length > 1) {
|
||||
const names = competences.map(it => it.name).reduce((a, b) => `${a}<br>${b}`);
|
||||
ui.notifications.info(`Plusieurs compétences possibles:<br>${names}<br>La première sera choisie: ${competence.name}`);
|
||||
}
|
||||
}
|
||||
return competence;
|
||||
return Misc.findFirstLike(name, list, it => it.name, 'compétences');
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user