Recherche dans l'inventaire

Par nom ou par type, et dans les contenants
This commit is contained in:
Vincent Vandemeulebrouck 2023-02-05 20:26:44 +01:00
parent 703ab2579d
commit fbcc167272
9 changed files with 86 additions and 50 deletions

View File

@ -66,9 +66,9 @@ export class RdDActorSheet extends RdDBaseActorSheet {
formData.calc.fatigue = RdDUtility.calculFatigueHtml(formData.system.sante.fatigue.value, formData.system.sante.endurance.max);
formData.competences.forEach(item => {
item.system.isVisible = this.options.recherche
? RdDItemCompetence.nomContientTexte(item, this.options.recherche.text)
: (!this.options.showCompNiveauBase || !RdDItemCompetence.isNiveauBase(item));
item.system.isHidden = this.options.recherche
? !item.isNomLike(this.options.recherche.text)
: (this.options.showCompNiveauBase && RdDItemCompetence.isNiveauBase(item));
RdDItemCompetence.levelUp(item, formData.system.compteurs.experience.value);
});
@ -354,29 +354,6 @@ export class RdDActorSheet extends RdDBaseActorSheet {
this.render(true);
});
this.html.find('.recherche')
.each((index, field) => {
if (this.options.recherche) {
field.focus();
field.setSelectionRange(this.options.recherche.start, this.options.recherche.end);
}
})
.keyup(async event => {
const nouvelleRecherche = this._optionRecherche(event.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);
}
})
.change(async event =>
this.options.recherche = this._optionRecherche(event.currentTarget)
);
this.html.find('.vue-detaillee').click(async event => {
this.options.vueDetaillee = !this.options.vueDetaillee;
this.render(true);
@ -486,16 +463,6 @@ export class RdDActorSheet extends RdDBaseActorSheet {
async createEmptyTache() {
await this.actor.createItem('tache', 'Nouvelle tache');
}
_optionRecherche(target) {
if (!target.value?.length) {
return undefined;
}
return {
text: target.value,
start: target.selectionStart,
end: target.selectionEnd,
};
}
_getEventArmeCombat(event) {
const li = this.html.find(event.currentTarget)?.parents(".item");

View File

@ -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();

View File

@ -190,15 +190,6 @@ export class RdDItemCompetence extends Item {
}
}
/* -------------------------------------------- */
static isVisible(item) {
return Number(item.system.niveau) != RdDItemCompetence.getNiveauBase(item.system.categorie);
}
static nomContientTexte(item, texte) {
return Grammar.toLowerCaseNoAccent(item.name).includes(Grammar.toLowerCaseNoAccent(texte))
}
/* -------------------------------------------- */
static isNiveauBase(item) {
return Number(item.system.niveau) == RdDItemCompetence.getNiveauBase(item.system.categorie);
@ -279,7 +270,7 @@ export class RdDItemCompetence extends Item {
/* -------------------------------------------- */
static triVisible(competences) {
return competences.filter(it => it.system.isVisible)
return competences.filter(it => !it.system.isHidden)
.sort((a, b) => RdDItemCompetence.compare(a, b))
}

View File

@ -304,6 +304,13 @@ export class RdDItem extends Item {
return this.parent?.type == 'commerce';
}
isNomLike(texte) {
return Grammar.includesLowerCaseNoAccent(this.name, texte)
}
isNomTypeLike(texte) {
return this.isNomLike(texte) || Grammar.includesLowerCaseNoAccent(Misc.typeName(this.type, 'Item'), texte)
}
getQuantite() {
return this.isService() ? undefined : Math.round(this.system.quantite ?? 0)
}

View File

@ -1005,6 +1005,10 @@ ul, li {
max-height: 1.2rem;
}
span.embed-inline {
display: inline-flex;
}
.alterne-list > .list-item:hover {
background: rgba(100, 100, 50, 0.25);
}

View File

@ -61,7 +61,7 @@
<i class="fa-regular fa-filter"></i> Filtrer
{{/if}}
</a></span>
<span>
<span class="embed-inline">
<input class="recherche flex-grow" type="text" value="{{options.recherche.text}}" name="recherche" size="8" data-dtype="String" placeholder=""/>
</span>
<span>

View File

@ -1,4 +1,4 @@
{{#if system.isVisible}}
{{#unless system.isHidden}}
<li class="item flexrow list-item {{#if system.isLevelUp}}xp-level-up tooltip{{/if}}" data-item-id="{{_id}}">
<a class="competence-label" name="{{name}}">
<img class="sheet-competence-img" src="{{img}}"/>
@ -49,4 +49,4 @@
</div>
{{/if}}
</li>
{{/if}}
{{/unless}}

View File

@ -1,3 +1,4 @@
{{#unless item.system.isHidden}}
{{#if (or options.isObserver (ne item.type 'monnaie'))}}
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
<span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} ">
@ -43,3 +44,4 @@
</span>
</li>
{{/if}}
{{/unless}}

View File

@ -6,6 +6,9 @@
{{#if options.isGM}}
<a class="chat-card-button nettoyer-conteneurs">Tout vider</a>
{{/if}}
<span class="embed-inline">
<input class="recherche flex-grow" type="text" value="{{options.recherche.text}}" name="recherche" size="8" data-dtype="String" placeholder=""/>
</span>
{{#if calc.surEncombrementMessage}}<b>{{calc.surEncombrementMessage}}</b> &hyphen;{{/if}}
Encombrement: {{numberFormat calc.encTotal decimals=2}} (max: {{system.attributs.encombrement.value}})
{{#if (regle-optionnelle 'afficher-prix-joueurs')}}