Fix recherche competence
La recherche de compétence cherchait dans tous les items (y compris les armes), ce qui affichait des messages ui
This commit is contained in:
@ -134,33 +134,57 @@ export class Misc {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static findPlayer(name) {
|
||||
return Misc.findFirstLike(name, game.users, it=>it.name,'joueurs');
|
||||
return Misc.findFirstLike(name, game.users, { description: 'joueur' });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static findActor(name, actors = game.actors, description= 'acteurs') {
|
||||
return Misc.findFirstLike(name, actors, it=>it.name, description);
|
||||
static findActor(name, actors = game.actors) {
|
||||
return Misc.findFirstLike(name, actors, { description: 'acteur' });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static findFirstLike(value, elements, mapper = it=>it.name, description = 'valeurs') {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
value = Grammar.toLowerCaseNoAccent(value);
|
||||
const subset = elements.filter(it => Grammar.toLowerCaseNoAccent(mapper(it)).includes(value));
|
||||
static findFirstLike(value, elements, options = {}) {
|
||||
options = mergeObject({
|
||||
mapper: it => it.name,
|
||||
preFilter: it => true,
|
||||
description: 'valeur',
|
||||
onMessage: m => ui.notifications.info(m)
|
||||
}, options);
|
||||
|
||||
const subset = this.findAllLike(value, elements, options);
|
||||
if (subset.length == 0) {
|
||||
ui.notifications.info(`Pas de ${description} correspondant à ${value}`);
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
let single = subset.find(it => Grammar.toLowerCaseNoAccent(mapper(it)) == value);
|
||||
if (subset.length == 1) {
|
||||
return subset[0]
|
||||
}
|
||||
let single = subset.find(it => Grammar.toLowerCaseNoAccent(options.mapper(it)) == Grammar.toLowerCaseNoAccent(value));
|
||||
if (!single) {
|
||||
single = subset[0];
|
||||
if (subset.length > 1) {
|
||||
const choices = subset.map(it => mapper(it)).reduce((a, b) => `${a}<br>${b}`);
|
||||
ui.notifications.info(`Plusieurs choix de ${description} possibles:<br>${choices}<br>Le premier sera choisi: ${mapper(single)}`);
|
||||
}
|
||||
const choices = subset.map(it => options.mapper(it)).reduce((a, b) => `${a}<br>${b}`);
|
||||
options.info(`Plusieurs choix de ${options.description}s possibles:<br>${choices}<br>Le premier sera choisi: ${mapToValue(single)}`);
|
||||
}
|
||||
return single;
|
||||
}
|
||||
|
||||
static findAllLike(value, elements, options = {}) {
|
||||
options = mergeObject({
|
||||
mapper: it => it.name,
|
||||
preFilter: it => true,
|
||||
description: 'valeur',
|
||||
onMessage: m => ui.notifications.info(m)
|
||||
}, options);
|
||||
|
||||
if (!value) {
|
||||
options.onMessage(`Pas de ${options.description} correspondant à une valeur vide`);
|
||||
return [];
|
||||
}
|
||||
value = Grammar.toLowerCaseNoAccent(value);
|
||||
const subset = elements.filter(options.preFilter)
|
||||
.filter(it => Grammar.toLowerCaseNoAccent(options.mapper(it)).includes(value));
|
||||
if (subset.length == 0) {
|
||||
options.onMessage(`Pas de ${options.description} correspondant à ${value}`);
|
||||
}
|
||||
return subset;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user