forked from public/foundryvtt-reve-de-dragon
Recherche dans l'inventaire
Par nom ou par type, et dans les contenants
This commit is contained in:
@ -52,10 +52,30 @@ export class RdDBaseActorSheet extends ActorSheet {
|
||||
|
||||
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
|
||||
|
||||
this._appliquerRechercheObjets(formData.objets, formData.conteneurs, this.options.recherche);
|
||||
return formData;
|
||||
}
|
||||
|
||||
_appliquerRechercheObjets(objets, conteneurs, recherche) {
|
||||
if (recherche) {
|
||||
this._setConteneursVisibles(objets, conteneurs);
|
||||
}
|
||||
}
|
||||
|
||||
_setConteneursVisibles(objets, conteneurs) {
|
||||
const recherche = this.options.recherche;
|
||||
const allVisible = objets.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id);
|
||||
let addVisible = conteneurs.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id)
|
||||
do {
|
||||
allVisible.push(...addVisible)
|
||||
const parentsIds = conteneurs.filter(it => it.system.contenu.find(id => allVisible.includes(id))).map(it => it.id)
|
||||
addVisible = parentsIds.filter(id => !allVisible.includes(id))
|
||||
}
|
||||
while (addVisible.length > 0)
|
||||
objets.forEach(it => it.system.isHidden = !allVisible.includes(it.id))
|
||||
conteneurs.forEach(it => it.system.isHidden = !allVisible.includes(it.id))
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static filterItemsPerTypeForSheet(formData, itemTypes) {
|
||||
formData.recettescuisine = Misc.arrayOrEmpty(itemTypes['recettecuisine']);
|
||||
@ -140,6 +160,38 @@ export class RdDBaseActorSheet extends ActorSheet {
|
||||
this.html.find('.monnaie-moins').click(async event => {
|
||||
this.actor.monnaieIncDec(this.getItemId(event), -1);
|
||||
});
|
||||
this.html.find('.recherche')
|
||||
.each((index, field) => {
|
||||
this._rechercheSelectArea(field);
|
||||
})
|
||||
.keyup(async event => {
|
||||
this._rechercherKeyup(event);
|
||||
})
|
||||
.change(async event =>
|
||||
this.options.recherche = this._optionRecherche(event.currentTarget)
|
||||
);
|
||||
}
|
||||
|
||||
_rechercherKeyup(event) {
|
||||
const currentTarget = event.currentTarget;
|
||||
const nouvelleRecherche = this._optionRecherche(currentTarget);
|
||||
if (this.options.recherche?.text != nouvelleRecherche?.text) {
|
||||
this.options.recherche = nouvelleRecherche;
|
||||
if (this.timerRecherche) {
|
||||
clearTimeout(this.timerRecherche);
|
||||
}
|
||||
this.timerRecherche = setTimeout(() => {
|
||||
this.timerRecherche = undefined;
|
||||
this.render(true);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
_rechercheSelectArea(field) {
|
||||
if (this.options.recherche) {
|
||||
field.focus();
|
||||
field.setSelectionRange(this.options.recherche.start, this.options.recherche.end);
|
||||
}
|
||||
}
|
||||
|
||||
getItemId(event) {
|
||||
@ -150,6 +202,16 @@ export class RdDBaseActorSheet extends ActorSheet {
|
||||
return RdDSheetUtility.getItem(event, this.actor);
|
||||
}
|
||||
|
||||
_optionRecherche(target) {
|
||||
if (!target.value?.length) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
text: target.value,
|
||||
start: target.selectionStart,
|
||||
end: target.selectionEnd,
|
||||
};
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_getHeaderButtons() {
|
||||
let buttons = super._getHeaderButtons();
|
||||
|
Reference in New Issue
Block a user