|
|
|
@ -8,7 +8,6 @@ const FILTER_GROUPS = [
|
|
|
|
|
{ group: 'type', label: "Type d'objet" },
|
|
|
|
|
{ group: 'comestible', label: 'Alimentaire' },
|
|
|
|
|
{ group: 'categorie', label: 'Utilisation' },
|
|
|
|
|
{ group: 'milieu', label: 'Milieu' },
|
|
|
|
|
{ group: 'rarete', label: 'Rarete' },
|
|
|
|
|
{ group: 'qualite', label: 'Qualité' },
|
|
|
|
|
{ group: 'enc', label: 'Encombrement' },
|
|
|
|
@ -16,60 +15,77 @@ const FILTER_GROUPS = [
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const FILTERS = [
|
|
|
|
|
{ group: 'comestible', code: 'comestible', label: 'Comestible', check: item => item.getUtilisation() == 'cuisine' },
|
|
|
|
|
{ group: 'comestible', code: 'pret', label: 'Préparé', check: item => item.getUtilisationCuisine() == 'pret' },
|
|
|
|
|
{ group: 'comestible', code: 'brut', label: 'A préparer', check: item => item.getUtilisationCuisine() == 'brut' },
|
|
|
|
|
{ group: 'comestible', code: 'boisson', label: 'Boisson', check: item => item.isBoisson() },
|
|
|
|
|
{ group: 'comestible', code: 'alcool', label: 'Alcool', check: item => item.isAlcool() },
|
|
|
|
|
{ group: 'comestible', code: 'immangeable', label: 'Immangeable', check: item => item.isInventaire() && item.getUtilisation() != 'cuisine' },
|
|
|
|
|
{ group: 'comestible', code: 'comestible', label: 'Comestible', check: (item, milieux) => item.getUtilisation() == 'cuisine' },
|
|
|
|
|
{ group: 'comestible', code: 'pret', label: 'Préparé', check: (item, milieux) => item.getUtilisationCuisine() == 'pret' },
|
|
|
|
|
{ group: 'comestible', code: 'brut', label: 'A préparer', check: (item, milieux) => item.getUtilisationCuisine() == 'brut' },
|
|
|
|
|
{ group: 'comestible', code: 'boisson', label: 'Boisson', check: (item, milieux) => item.isBoisson() },
|
|
|
|
|
{ group: 'comestible', code: 'alcool', label: 'Alcool', check: (item, milieux) => item.isAlcool() },
|
|
|
|
|
{ group: 'comestible', code: 'immangeable', label: 'Immangeable', check: (item, milieux) => item.isInventaire() && item.getUtilisation() != 'cuisine' },
|
|
|
|
|
|
|
|
|
|
{ group: 'categorie', code: 'alchimie', label: 'Alchimique', check: item => item.isInventaire() && item.getUtilisation() == 'alchimie' },
|
|
|
|
|
{ group: 'categorie', code: 'soins', label: 'Médical', check: item => item.isInventaire() && item.getUtilisation() == 'soins' },
|
|
|
|
|
{ group: 'categorie', code: 'poison', label: 'Toxique', check: item => item.isInventaire() && item.getUtilisation() == 'poison' },
|
|
|
|
|
{ group: 'categorie', code: 'autres', label: 'Autres', check: item => !item.isInventaire() || item.getUtilisation() == '' },
|
|
|
|
|
{ group: 'categorie', code: 'alchimie', label: 'Alchimique', check: (item, milieux) => item.isInventaire() && item.getUtilisation() == 'alchimie' },
|
|
|
|
|
{ group: 'categorie', code: 'soins', label: 'Médical', check: (item, milieux) => item.isInventaire() && item.getUtilisation() == 'soins' },
|
|
|
|
|
{ group: 'categorie', code: 'poison', label: 'Toxique', check: (item, milieux) => item.isInventaire() && item.getUtilisation() == 'poison' },
|
|
|
|
|
{ group: 'categorie', code: 'autres', label: 'Autres', check: (item, milieux) => !item.isInventaire() || item.getUtilisation() == '' },
|
|
|
|
|
|
|
|
|
|
{ group: "qualite", code: "mauvaise", label: "Mauvaise (négative)", check: item => item.isInventaire() && item.system.qualite < 0 },
|
|
|
|
|
{ group: "qualite", code: "quelconque", label: "Quelconque (0)", check: item => item.isInventaire() && item.system.qualite == 0 },
|
|
|
|
|
{ group: "qualite", code: "correcte", label: "Correcte (1-3)", check: item => item.isInventaire() && 1 <= item.system.qualite && item.system.qualite <= 3 },
|
|
|
|
|
{ group: "qualite", code: "bonne", label: "Bonne (4-6)", check: item => item.isInventaire() && 4 <= item.system.qualite && item.system.qualite <= 6 },
|
|
|
|
|
{ group: "qualite", code: "excellente", label: "Excellente (7-9)", check: item => item.isInventaire() && 7 <= item.system.qualite && item.system.qualite <= 9 },
|
|
|
|
|
{ group: "qualite", code: "mythique", label: "Mythique (10+)", check: item => item.isInventaire() && 10 <= item.system.qualite },
|
|
|
|
|
{ group: "qualite", code: "mauvaise", label: "Mauvaise (négative)", check: (item, milieux) => item.isInventaire() && item.system.qualite < 0 },
|
|
|
|
|
{ group: "qualite", code: "quelconque", label: "Quelconque (0)", check: (item, milieux) => item.isInventaire() && item.system.qualite == 0 },
|
|
|
|
|
{ group: "qualite", code: "correcte", label: "Correcte (1-3)", check: (item, milieux) => item.isInventaire() && 1 <= item.system.qualite && item.system.qualite <= 3 },
|
|
|
|
|
{ group: "qualite", code: "bonne", label: "Bonne (4-6)", check: (item, milieux) => item.isInventaire() && 4 <= item.system.qualite && item.system.qualite <= 6 },
|
|
|
|
|
{ group: "qualite", code: "excellente", label: "Excellente (7-9)", check: (item, milieux) => item.isInventaire() && 7 <= item.system.qualite && item.system.qualite <= 9 },
|
|
|
|
|
{ group: "qualite", code: "mythique", label: "Mythique (10+)", check: (item, milieux) => item.isInventaire() && 10 <= item.system.qualite },
|
|
|
|
|
|
|
|
|
|
{ group: "enc", code: "negligeable", label: "Négligeable (jusqu'à 0.1)", check: item => item.isInventaire() && item.system.encombrement <= 0.1 },
|
|
|
|
|
{ group: "enc", code: "leger", label: "Léger (0.1 à 0.5)", check: item => item.isInventaire() && 0.1 < item.system.encombrement && item.system.encombrement <= 0.5 },
|
|
|
|
|
{ group: "enc", code: "moyen", label: "Moyen (0.5 à 1.5)", check: item => item.isInventaire() && 0.5 < item.system.encombrement && item.system.encombrement <= 1.5 },
|
|
|
|
|
{ group: "enc", code: "lourd", label: "Lourd (1.5 à 3)", check: item => item.isInventaire() && 1.5 < item.system.encombrement && item.system.encombrement <= 3 },
|
|
|
|
|
{ group: "enc", code: "massif", label: "Massif (3 à 10)", check: item => item.isInventaire() && 3 < item.system.encombrement && item.system.encombrement <= 10 },
|
|
|
|
|
{ group: "enc", code: "anemort", label: "Un âne mort (plus de 10)", check: item => item.isInventaire() && 10 < item.system.encombrement },
|
|
|
|
|
{ group: "enc", code: "negligeable", label: "Négligeable (jusqu'à 0.1)", check: (item, milieux) => item.isInventaire() && item.system.encombrement <= 0.1 },
|
|
|
|
|
{ group: "enc", code: "leger", label: "Léger (0.1 à 0.5)", check: (item, milieux) => item.isInventaire() && 0.1 < item.system.encombrement && item.system.encombrement <= 0.5 },
|
|
|
|
|
{ group: "enc", code: "moyen", label: "Moyen (0.5 à 1.5)", check: (item, milieux) => item.isInventaire() && 0.5 < item.system.encombrement && item.system.encombrement <= 1.5 },
|
|
|
|
|
{ group: "enc", code: "lourd", label: "Lourd (1.5 à 3)", check: (item, milieux) => item.isInventaire() && 1.5 < item.system.encombrement && item.system.encombrement <= 3 },
|
|
|
|
|
{ group: "enc", code: "massif", label: "Massif (3 à 10)", check: (item, milieux) => item.isInventaire() && 3 < item.system.encombrement && item.system.encombrement <= 10 },
|
|
|
|
|
{ group: "enc", code: "anemort", label: "Un âne mort (plus de 10)", check: (item, milieux) => item.isInventaire() && 10 < item.system.encombrement },
|
|
|
|
|
|
|
|
|
|
{ group: "prix", code: "gratuit", label: "Gratuit", check: item => item.isInventaire() && item.system.cout == 0 },
|
|
|
|
|
{ group: "prix", code: "deniers", label: "Deniers (étain)", check: item => item.isInventaire() && 0 < item.system.cout && item.system.cout < 0.1 },
|
|
|
|
|
{ group: "prix", code: "bronze", label: "Sous (bronze)", check: item => item.isInventaire() && 0.1 <= item.system.cout && item.system.cout < 1 },
|
|
|
|
|
{ group: "prix", code: "sols", label: "Sols (argent)", check: item => item.isInventaire() && 1 <= item.system.cout && item.system.cout < 10 },
|
|
|
|
|
{ group: "prix", code: "dragons", label: "Dragons (or)", check: item => item.isInventaire() && 10 <= item.system.cout },
|
|
|
|
|
{ group: "prix", code: "gratuit", label: "Gratuit", check: (item, milieux) => item.isInventaire() && item.system.cout == 0 },
|
|
|
|
|
{ group: "prix", code: "deniers", label: "Deniers (étain)", check: (item, milieux) => item.isInventaire() && 0 < item.system.cout && item.system.cout < 0.1 },
|
|
|
|
|
{ group: "prix", code: "bronze", label: "Sous (bronze)", check: (item, milieux) => item.isInventaire() && 0.1 <= item.system.cout && item.system.cout < 1 },
|
|
|
|
|
{ group: "prix", code: "sols", label: "Sols (argent)", check: (item, milieux) => item.isInventaire() && 1 <= item.system.cout && item.system.cout < 10 },
|
|
|
|
|
{ group: "prix", code: "dragons", label: "Dragons (or)", check: (item, milieux) => item.isInventaire() && 10 <= item.system.cout },
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function $typeToFilter(type) { return { group: 'type', code: type, label: Misc.typeName('Item', type), check: item => item.type == type }; }
|
|
|
|
|
|
|
|
|
|
function $filterMilieux(milieux) {
|
|
|
|
|
return milieux.map(m => { return { group: 'milieu', code: m, label: m, check: item => item.isPresentDansMilieux(m) } })
|
|
|
|
|
return milieux.map(m => {
|
|
|
|
|
return {
|
|
|
|
|
code: m,
|
|
|
|
|
label: m,
|
|
|
|
|
check: (item, milieux) => item.isPresentDansMilieux(m)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function $filterRarete() {
|
|
|
|
|
return RdDRaretes.raretes()
|
|
|
|
|
.filter(it => it.frequence > 0)
|
|
|
|
|
.map(r => { return { group: 'rarete', code: r.code, label: r.label, check: item => item.getRarete()?.code == r.code }; });
|
|
|
|
|
.map(r => {
|
|
|
|
|
return {
|
|
|
|
|
group: 'rarete',
|
|
|
|
|
code: r.code,
|
|
|
|
|
label: r.label,
|
|
|
|
|
check: (item, milieux) => item.getRaretes(milieux).map(it => it.code).includes(r.code)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function $filterTypes() {
|
|
|
|
|
return RdDItem.getItemTypesInventaire().map(it => $typeToFilter(it));
|
|
|
|
|
return RdDItem.getItemTypesInventaire().map(type => {
|
|
|
|
|
return {
|
|
|
|
|
group: 'type',
|
|
|
|
|
code: type,
|
|
|
|
|
label: Misc.typeName('Item', type),
|
|
|
|
|
check: (item, milieux) => item.type == type
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function $getAllFilters(milieux) {
|
|
|
|
|
function $getAllFilters() {
|
|
|
|
|
return FILTERS
|
|
|
|
|
.concat($filterTypes())
|
|
|
|
|
.concat($filterMilieux(milieux))
|
|
|
|
|
.concat($filterRarete());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,8 +127,10 @@ export class FenetreRechercheTirage extends Application {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async create() {
|
|
|
|
|
const milieux = await game.system.rdd.environnement.milieux();
|
|
|
|
|
const parameters = {
|
|
|
|
|
milieux: await game.system.rdd.environnement.milieux(),
|
|
|
|
|
milieux: milieux,
|
|
|
|
|
filterMilieux: $filterMilieux(milieux),
|
|
|
|
|
filterGroups: duplicate(FILTER_GROUPS).filter(it => it.group),
|
|
|
|
|
}
|
|
|
|
|
const options = {}
|
|
|
|
@ -127,17 +145,12 @@ export class FenetreRechercheTirage extends Application {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getData() {
|
|
|
|
|
let formData = super.getData();
|
|
|
|
|
mergeObject(formData, this.parameters)
|
|
|
|
|
return formData;
|
|
|
|
|
return mergeObject(await super.getData(), this.parameters)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_canDragStart() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
_onDragStart(event) {
|
|
|
|
|
console.log('_onDragStart', event)
|
|
|
|
|
}
|
|
|
|
|
_canDragStart() { return true; }
|
|
|
|
|
_onDragStart(event) { }
|
|
|
|
|
|
|
|
|
|
_getHeaderButtons() {
|
|
|
|
|
let buttons = super._getHeaderButtons();
|
|
|
|
|
if (game.user.isGM) {
|
|
|
|
@ -155,17 +168,15 @@ export class FenetreRechercheTirage extends Application {
|
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
this.html = html;
|
|
|
|
|
|
|
|
|
|
HtmlUtility.showControlWhen(this.html.find('div.group-filters'), false);
|
|
|
|
|
HtmlUtility.showControlWhen(this.html.find('i.filter-group-hide'), false);
|
|
|
|
|
HtmlUtility.showControlWhen(this.html.find('i.filter-group-show'), true);
|
|
|
|
|
this.showFilterGroup(this.html, false);
|
|
|
|
|
|
|
|
|
|
this.html.find("a.filter-group-toggle").click(event => {
|
|
|
|
|
const groupDiv = this.html.find(event.currentTarget)?.parents('div.filter-group').first();
|
|
|
|
|
const visible = groupDiv.find('div.group-filters').first().is(":visible");
|
|
|
|
|
this.html.find("a.section-filters-toggle").click(event => {
|
|
|
|
|
const groupDiv = this.html.find(event.currentTarget)?.parents('div.section-filters-root').first();
|
|
|
|
|
const visible = groupDiv.find('div.section-filters-content').first().is(":visible");
|
|
|
|
|
this.showFilterGroup(groupDiv, !visible)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.html.find("input.activate-filter").change(event => this.changeListeFiltresActifs())
|
|
|
|
|
this.html.find("input:is(.activate-filter-group,.activate-filter-milieu)").change(event => this.changeListeFiltresActifs())
|
|
|
|
|
|
|
|
|
|
this.html.find("a.supprimer-filtres").click(async event => this.supprimerFiltres())
|
|
|
|
|
|
|
|
|
@ -178,9 +189,18 @@ export class FenetreRechercheTirage extends Application {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showFilterGroup(groupDiv, show) {
|
|
|
|
|
if (groupDiv) {
|
|
|
|
|
HtmlUtility.showControlWhen(groupDiv.find('div.section-filters-content'), show);
|
|
|
|
|
HtmlUtility.showControlWhen(groupDiv.find('i.section-filters-hide'), show);
|
|
|
|
|
HtmlUtility.showControlWhen(groupDiv.find('i.section-filters-show'), !show);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
supprimerFiltres() {
|
|
|
|
|
this.html.find('input:is(.activate-filter-group,.activate-filter-milieu)').prop("checked", false);
|
|
|
|
|
this.html.find('div.liste-resultats').html('');
|
|
|
|
|
return this.html.find('input.activate-filter:checked').prop("checked", false);
|
|
|
|
|
this.changeListeFiltresActifs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async recherche() {
|
|
|
|
@ -191,53 +211,72 @@ export class FenetreRechercheTirage extends Application {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async buildTable() {
|
|
|
|
|
return await game.system.rdd.environnement.buildTable(it => it.getFrequence(), this.buildCheckedItemsFilter())
|
|
|
|
|
const milieux = this.getSelectedMilieux();
|
|
|
|
|
const filterItemMilieux = this.buildCheckedGroupFilter(milieux);
|
|
|
|
|
const filter = it => filterItemMilieux(it, milieux);
|
|
|
|
|
const itemFrequence = it => it.getFrequence(milieux);
|
|
|
|
|
return await game.system.rdd.environnement.buildTable(itemFrequence, filter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildCheckedItemsFilter() {
|
|
|
|
|
const byGroup = this.getCheckedFiltersByGroup();
|
|
|
|
|
const groupSummaries = Object.entries(byGroup).map(([key, list]) => {
|
|
|
|
|
const group = this.parameters.filterGroups.find(g => key == g.group);
|
|
|
|
|
const filters = list.map(it => it.code).map(code => group.filters.find(f => code == f.code))
|
|
|
|
|
return filters
|
|
|
|
|
.map(f => f.check)
|
|
|
|
|
.reduce((a, b) => { return it => a(it) || b(it) });;
|
|
|
|
|
});
|
|
|
|
|
if (groupSummaries.length == 0) {
|
|
|
|
|
return it => true;
|
|
|
|
|
buildMilieuxFilter(milieux) {
|
|
|
|
|
if (milieux) {
|
|
|
|
|
return this.buildOrFilter(this.parameters.filterMilieux.filter(it => milieux.includes(it.code)).map(f => f.check));
|
|
|
|
|
}
|
|
|
|
|
return groupSummaries.reduce((a, b) => { return it => a(it) && b(it) })
|
|
|
|
|
return (it, mi) => true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showFilterGroup(groupDiv, show) {
|
|
|
|
|
if (groupDiv) {
|
|
|
|
|
HtmlUtility.showControlWhen(groupDiv.find('div.group-filters'), show);
|
|
|
|
|
HtmlUtility.showControlWhen(groupDiv.find('i.filter-group-hide'), show);
|
|
|
|
|
HtmlUtility.showControlWhen(groupDiv.find('i.filter-group-show'), !show);
|
|
|
|
|
buildCheckedGroupFilter(milieux) {
|
|
|
|
|
const filtersList = this.getGroupCheckedFilters()
|
|
|
|
|
.map(gf => this.buildOrFilter(gf.filters.map(f => f.check)));
|
|
|
|
|
if (milieux) {
|
|
|
|
|
filtersList.push(this.buildMilieuxFilter(milieux));
|
|
|
|
|
}
|
|
|
|
|
return this.buildAndFilter(filtersList)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildAndFilter(filters) { return filters.reduce((f1, f2) => { return (it, mi) => f1(it, mi) && f2(it, mi); }); }
|
|
|
|
|
buildOrFilter(filters) { return filters.reduce((f1, f2) => { return (it, mi) => f1(it, mi) || f2(it, mi); }); }
|
|
|
|
|
|
|
|
|
|
changeListeFiltresActifs() {
|
|
|
|
|
const byGroup = this.getCheckedFiltersByGroup();
|
|
|
|
|
const groupSummaries = Object.entries(byGroup).map(([key, list]) => {
|
|
|
|
|
const group = this.parameters.filterGroups.find(g => key == g.group);
|
|
|
|
|
const filters = list.map(it => it.code).map(code => group.filters.find(f => code == f.code))
|
|
|
|
|
return group.label + ': ' + filters
|
|
|
|
|
.map(f => f.label)
|
|
|
|
|
.reduce(Misc.joining(', '));;
|
|
|
|
|
});
|
|
|
|
|
const fullText = groupSummaries.length == 0 ? "" : groupSummaries.reduce(Misc.joining(' - '));
|
|
|
|
|
const milieux = this.getSelectedMilieux();
|
|
|
|
|
const summariesList = this.getGroupCheckedFilters()
|
|
|
|
|
.map(gf => {
|
|
|
|
|
return gf.group.label + ': ' + gf.filters
|
|
|
|
|
.map(f => f.label)
|
|
|
|
|
.reduce(Misc.joining(', '))
|
|
|
|
|
});
|
|
|
|
|
if (milieux) {
|
|
|
|
|
summariesList.push('Milieux: ' + this.parameters.filterMilieux.filter(f => milieux.includes(f.code)).map(f => f.label).reduce(Misc.joining(', ')))
|
|
|
|
|
}
|
|
|
|
|
const fullText = summariesList.length == 0 ? "" : summariesList.reduce(Misc.joining(' - '));
|
|
|
|
|
this.html.find('span.liste-filtres-actifs').text(fullText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getCheckedFiltersByGroup() {
|
|
|
|
|
const selectedFilters = jQuery.map(this.html.find('input.activate-filter:checked'), it => {
|
|
|
|
|
const element = this.html.find(it);
|
|
|
|
|
return { group: element.data('group'), code: element.data('code') };
|
|
|
|
|
getGroupCheckedFilters() {
|
|
|
|
|
const checkedGroupFilters = jQuery.map(this.html.find('input.activate-filter-group:checked'), it => this.html.find(it))
|
|
|
|
|
.map(element => {
|
|
|
|
|
return {
|
|
|
|
|
group: element.data('group'),
|
|
|
|
|
code: element.data('code')
|
|
|
|
|
};
|
|
|
|
|
}).filter(it => it.group);
|
|
|
|
|
|
|
|
|
|
const entries = Object.entries(Misc.classify(checkedGroupFilters, it => it.group));
|
|
|
|
|
return entries.map(([key, list]) => {
|
|
|
|
|
const group = this.parameters.filterGroups.find(g => g.group == key);
|
|
|
|
|
const filters = list.map(it => group.filters.find(f => it.code == f.code));
|
|
|
|
|
return { group, filters };
|
|
|
|
|
});
|
|
|
|
|
return Misc.classify(selectedFilters, it => it.group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSelectedMilieux() {
|
|
|
|
|
const milieux = jQuery.map(this.html.find('input.activate-filter-milieu:checked'), it => {
|
|
|
|
|
return this.html.find(it).data('code');
|
|
|
|
|
});
|
|
|
|
|
return milieux.length == 0 ? undefined : milieux
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async configurer() {
|
|
|
|
|
FenetreRechercheConfiguration.create();
|
|
|
|
|
}
|
|
|
|
|