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:
parent
0f655bd89d
commit
f91dfd04a2
@ -11,7 +11,6 @@ import { RdDBonus } from "./rdd-bonus.js";
|
|||||||
import { Misc } from "./misc.js";
|
import { Misc } from "./misc.js";
|
||||||
import { RdDCombatManager } from "./rdd-combat.js";
|
import { RdDCombatManager } from "./rdd-combat.js";
|
||||||
import { RdDCarac } from "./rdd-carac.js";
|
import { RdDCarac } from "./rdd-carac.js";
|
||||||
import { RdDItem } from "./item.js";
|
|
||||||
import { DialogSplitItem } from "./dialog-split-item.js";
|
import { DialogSplitItem } from "./dialog-split-item.js";
|
||||||
import { ReglesOptionelles } from "./regles-optionelles.js";
|
import { ReglesOptionelles } from "./regles-optionelles.js";
|
||||||
import { DialogRepos } from "./dialog-repos.js";
|
import { DialogRepos } from "./dialog-repos.js";
|
||||||
@ -93,7 +92,7 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
formData.combat = duplicate(formData.armes ?? []);
|
formData.combat = duplicate(formData.armes ?? []);
|
||||||
RdDItemArme.computeNiveauArmes(formData.combat, formData.competences);
|
RdDItemArme.computeNiveauArmes(formData.combat, formData.competences);
|
||||||
RdDItemArme.ajoutCorpsACorps(formData.combat, formData.competences, formData.data.carac);
|
RdDItemArme.ajoutCorpsACorps(formData.combat, formData.competences, formData.data.carac);
|
||||||
formData.esquive = RdDItemCompetence.getEsquive(formData.competences);
|
formData.esquives = this.actor.getCompetences("Esquive").map(i => foundry.utils.deepClone(i.data));
|
||||||
formData.combat = RdDCombatManager.finalizeArmeList(formData.combat, formData.competences, formData.data.carac);
|
formData.combat = RdDCombatManager.finalizeArmeList(formData.combat, formData.competences, formData.data.carac);
|
||||||
|
|
||||||
this.armesList = formData.combat;
|
this.armesList = formData.combat;
|
||||||
|
@ -313,13 +313,19 @@ export class RdDActor extends Actor {
|
|||||||
return Misc.templateData(this).compteurs.surenc?.value ?? 0;
|
return Misc.templateData(this).compteurs.surenc?.value ?? 0;
|
||||||
}
|
}
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getCompetence(name) {
|
getCompetence(idOrName, options={}) {
|
||||||
return RdDItemCompetence.findCompetence(this.data.items, name);
|
return RdDItemCompetence.findCompetence(this.data.items, idOrName, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCompetences(name) {
|
||||||
|
return RdDItemCompetence.findCompetences(this.data.items, name);
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getObjet(id) {
|
getObjet(id) {
|
||||||
return id ? this.data.items.find(it => it.id == id) : undefined;
|
return id ? this.data.items.find(it => it.id == id) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
listItemsData(type) {
|
listItemsData(type) {
|
||||||
return this.filterItemsData(it => it.type == type);
|
return this.filterItemsData(it => it.type == type);
|
||||||
}
|
}
|
||||||
@ -329,16 +335,12 @@ export class RdDActor extends Actor {
|
|||||||
filterItems(filter) {
|
filterItems(filter) {
|
||||||
return this.data.items.filter(it => filter(Misc.data(it)));
|
return this.data.items.filter(it => filter(Misc.data(it)));
|
||||||
}
|
}
|
||||||
getItemOfType(id, type) {
|
|
||||||
if (id && type) {
|
getItemOfType(idOrName, type) {
|
||||||
let itemById = this.data.items.find(it => it.id == id);
|
return this.data.items.find(it => it.id == idOrName && it.type == type)
|
||||||
const itemData = Misc.data(itemById);
|
?? Misc.findFirstLike(idOrName, this.data.items,{filter: it => it.type == type, description: type});
|
||||||
if (itemData.type == type) {
|
|
||||||
return itemById;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMonnaie(id) {
|
getMonnaie(id) {
|
||||||
return this.getItemOfType(id, 'monnaie');
|
return this.getItemOfType(id, 'monnaie');
|
||||||
}
|
}
|
||||||
@ -3077,7 +3079,7 @@ export class RdDActor extends Actor {
|
|||||||
case 'chance-actuelle': case 'chance actuelle':
|
case 'chance-actuelle': case 'chance actuelle':
|
||||||
return carac.chance;
|
return carac.chance;
|
||||||
}
|
}
|
||||||
let entry = Misc.findFirstLike(name, Object.entries(carac), it => it[1].label, 'caractéristiques');
|
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.length>0 ? carac[entry[0]] : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,18 +79,12 @@ export class RdDItemCompetence extends Item {
|
|||||||
return Misc.data(competence)?.data.categorie;
|
return Misc.data(competence)?.data.categorie;
|
||||||
}
|
}
|
||||||
static isDraconic(competence) {
|
static isDraconic(competence) {
|
||||||
return Misc.data(competence).data.categorie == 'draconic';
|
return Misc.data(competence)?.data.categorie == 'draconic';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static getVoieDraconic(competences, voie) {
|
static getVoieDraconic(competences, voie) {
|
||||||
voie = Grammar.toLowerCaseNoAccent(voie);
|
return RdDItemCompetence.findCompetence(competences.filter(it => RdDItemCompetence.isDraconic(it) ), voie);
|
||||||
return competences.find(it => RdDItemCompetence.isDraconic(it) && Grammar.toLowerCaseNoAccent(Misc.data(it).name).includes(voie));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
|
||||||
static getEsquive(competences) {
|
|
||||||
return { name: 'Esquive', niveau: RdDItemCompetence.findCompetence(competences, 'Esquive')?.data.niveau ?? -6 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -208,8 +202,22 @@ export class RdDItemCompetence extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static findCompetence(list, name) {
|
static findCompetence(list, idOrName, options = {}) {
|
||||||
return Misc.findFirstLike(name, list, it => it.name, 'compétences');
|
options = mergeObject(options, {
|
||||||
|
filter: it => RdDItemCompetence.isCompetence(it),
|
||||||
|
description: 'compétence',
|
||||||
|
});
|
||||||
|
return list.find(it => it.id == idOrName && RdDItemCompetence.isCompetence(it))
|
||||||
|
?? Misc.findFirstLike(idOrName, list, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
static findCompetences(list, name) {
|
||||||
|
return Misc.findAllLike(name, list, { filter: it => RdDItemCompetence.isCompetence(it), description: 'compétence' });
|
||||||
|
}
|
||||||
|
|
||||||
|
static isCompetence(item) {
|
||||||
|
return item.type == 'competence' || item.type == 'competencecreature';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
@ -134,33 +134,57 @@ export class Misc {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static findPlayer(name) {
|
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') {
|
static findActor(name, actors = game.actors) {
|
||||||
return Misc.findFirstLike(name, actors, it=>it.name, description);
|
return Misc.findFirstLike(name, actors, { description: 'acteur' });
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static findFirstLike(value, elements, mapper = it=>it.name, description = 'valeurs') {
|
static findFirstLike(value, elements, options = {}) {
|
||||||
if (!value) {
|
options = mergeObject({
|
||||||
return undefined;
|
mapper: it => it.name,
|
||||||
}
|
preFilter: it => true,
|
||||||
value = Grammar.toLowerCaseNoAccent(value);
|
description: 'valeur',
|
||||||
const subset = elements.filter(it => Grammar.toLowerCaseNoAccent(mapper(it)).includes(value));
|
onMessage: m => ui.notifications.info(m)
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
const subset = this.findAllLike(value, elements, options);
|
||||||
if (subset.length == 0) {
|
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) {
|
if (!single) {
|
||||||
single = subset[0];
|
single = subset[0];
|
||||||
if (subset.length > 1) {
|
const choices = subset.map(it => options.mapper(it)).reduce((a, b) => `${a}<br>${b}`);
|
||||||
const choices = subset.map(it => 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)}`);
|
||||||
ui.notifications.info(`Plusieurs choix de ${description} possibles:<br>${choices}<br>Le premier sera choisi: ${mapper(single)}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user