forked from public/foundryvtt-reve-de-dragon
Configuration de la recherche
This commit is contained in:
@ -1,9 +1,8 @@
|
||||
import { RdDItem } from '../item.js';
|
||||
import { HtmlUtility } from '../html-utility.js';
|
||||
import { Misc } from "../misc.js";
|
||||
import { CompendiumTable, CompendiumTableHelpers, SystemCompendiums } from '../settings/system-compendiums.js';
|
||||
import { CompendiumTableHelpers } from '../settings/system-compendiums.js';
|
||||
import { RdDRaretes } from './raretes.js';
|
||||
import { SYSTEM_RDD } from '../constants.js';
|
||||
|
||||
const FILTER_GROUPS = [
|
||||
{ group: 'type', label: "Type d'objet" },
|
||||
@ -17,18 +16,17 @@ const FILTER_GROUPS = [
|
||||
]
|
||||
|
||||
const FILTERS = [
|
||||
{ group: 'comestible', code: 'pret', label: 'Préparé', check: item => item.getUtilisationCuisine() == 'pret' },
|
||||
{ group: 'comestible', code: 'comestible', label: 'Comestible', check: item => item.getUtilisation() == 'cuisine' },
|
||||
{ group: 'comestible', code: 'boisson', label: 'Boisson', check: item => item.isNourritureBoisson() && item.system.boisson },
|
||||
{ group: 'comestible', code: 'alcool', label: 'Alcool', check: item => item.isAlcool() },
|
||||
{ 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: 'non', label: 'Immangeable', check: item => item.isEnvironnement() && !item.getUtilisationCuisine() },
|
||||
{ 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: 'categorie', code: 'alchimie', label: 'Alchimique', check: item => item.isEnvironnement() && item.getUtilisation() == 'alchimie' },
|
||||
{ group: 'categorie', code: 'cuisine', label: 'Cuisine', check: item => item.isEnvironnement() && item.getUtilisation() == 'cuisine' },
|
||||
{ group: 'categorie', code: 'soins', label: 'Médical', check: item => item.isEnvironnement() && item.getUtilisation() == 'soins' },
|
||||
{ group: 'categorie', code: 'cpoison', label: 'Toxique', check: item => item.isEnvironnement() && item.getUtilisation() == 'poison' },
|
||||
{ group: 'categorie', code: 'autres', label: 'Autres', check: item => !item.isEnvironnement() || item.getUtilisation() == '' },
|
||||
{ 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: "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 },
|
||||
@ -45,13 +43,12 @@ const FILTERS = [
|
||||
{ group: "enc", code: "anemort", label: "Un âne mort (plus de 10)", check: item => 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) 1-9", check: item => item.isInventaire() && 0 < item.system.cout && item.system.cout < 0.1 },
|
||||
{ group: "prix", code: "bronze", label: "Bronzes 1-9", check: item => item.isInventaire() && 0.1 <= item.system.cout && item.system.cout < 1 },
|
||||
{ group: "prix", code: "sols", label: "Sols (argent) 1-9", check: item => item.isInventaire() && 1 <= item.system.cout && item.system.cout < 10 },
|
||||
{ group: "prix", code: "dragons", label: "Dragons (or) 1+ ", check: item => item.isInventaire() && 10 <= item.system.cout },
|
||||
{ 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 },
|
||||
]
|
||||
|
||||
const COMPENDIUMS_RECHERCHE = 'compendiums-recherche';
|
||||
|
||||
function $typeToFilter(type) { return { group: 'type', code: type, label: Misc.typeName('Item', type), check: item => item.type == type }; }
|
||||
|
||||
@ -66,12 +63,7 @@ function $filterRarete() {
|
||||
}
|
||||
|
||||
function $filterTypes() {
|
||||
return [
|
||||
{ group: 'type', code: 'inventaire', label: 'Inventaire', check: item => item.isInventaire() && !item.isEnvironnement() },
|
||||
]
|
||||
.concat(['arme', 'armure'].map(it => $typeToFilter(it)))
|
||||
.concat([{ group: 'type', code: 'environement', label: 'Faune, Flore, Ingrédients', check: item => item.isEnvironnement() }])
|
||||
.concat(RdDItem.getItemTypesEnvironnement().map(it => $typeToFilter(it)))
|
||||
return RdDItem.getItemTypesInventaire().map(it => $typeToFilter(it));
|
||||
}
|
||||
|
||||
function $getAllFilters(milieux) {
|
||||
@ -106,20 +98,6 @@ function $loadFilters(parameters) {
|
||||
|
||||
|
||||
export class FenetreRechercheTirage extends Application {
|
||||
|
||||
static init() {
|
||||
game.settings.register(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, {
|
||||
name: COMPENDIUMS_RECHERCHE,
|
||||
default: [
|
||||
SystemCompendiums.getCompendium('faune-flore-mineraux'),
|
||||
SystemCompendiums.getCompendium('equipement')
|
||||
],
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object
|
||||
});
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
template: "systems/foundryvtt-reve-de-dragon/templates/tirage/fenetre-recherche-tirage.hbs",
|
||||
@ -146,12 +124,6 @@ export class FenetreRechercheTirage extends Application {
|
||||
constructor(parameters, options) {
|
||||
super(options);
|
||||
this.parameters = parameters;
|
||||
this.buildCompendiumTables();
|
||||
}
|
||||
|
||||
buildCompendiumTables() {
|
||||
this.parameters.compendiums = game.settings.get(SYSTEM_RDD, COMPENDIUMS_RECHERCHE);
|
||||
this.parameters.compendiumTables = this.parameters.compendiums.map(it => new CompendiumTable(it, 'Item'));
|
||||
}
|
||||
|
||||
async getData() {
|
||||
@ -219,11 +191,7 @@ export class FenetreRechercheTirage extends Application {
|
||||
}
|
||||
|
||||
async buildTable() {
|
||||
const filter = this.buildCheckedItemsFilter();
|
||||
const allTables = await Promise.all(
|
||||
this.parameters.compendiumTables.map(async compTable => await compTable.buildTable(it => it.getFrequence(), filter))
|
||||
);
|
||||
return CompendiumTableHelpers.concatTables(...allTables);
|
||||
return await game.system.rdd.environnement.buildTable(it => it.getFrequence(), this.buildCheckedItemsFilter())
|
||||
}
|
||||
|
||||
buildCheckedItemsFilter() {
|
||||
@ -271,30 +239,21 @@ export class FenetreRechercheTirage extends Application {
|
||||
}
|
||||
|
||||
async configurer() {
|
||||
const itemPacks = game.packs.filter(it => it.metadata.type == 'Item');
|
||||
console.log('packs1', itemPacks);
|
||||
|
||||
const configuration = {
|
||||
compendiums: itemPacks.map(it => duplicate(it.metadata)).map(it => mergeObject(it, { selected: this.parameters.compendiums.includes(it.id) }))
|
||||
}
|
||||
FenetreRechercheConfiguration.create(configuration, c => this.setConfiguration(c));
|
||||
FenetreRechercheConfiguration.create();
|
||||
}
|
||||
|
||||
setConfiguration(configuration) {
|
||||
const compendiums = configuration.compendiums.filter(it => it.selected).map(it => it.id);
|
||||
game.settings.set(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, compendiums);
|
||||
this.buildCompendiumTables()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FenetreRechercheConfiguration extends Dialog {
|
||||
static async create(configuration, onSave) {
|
||||
static async create() {
|
||||
const configuration = {
|
||||
compendiums: game.packs.filter(it => it.metadata.type == 'Item').map(it => it.metadata)
|
||||
.map(it => mergeObject({ selected: game.system.rdd.environnement.compendiums.includes(it.id) }, it))
|
||||
}
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/tirage/fenetre-recherche-configuration.hbs", configuration);
|
||||
new FenetreRechercheConfiguration(html, configuration, onSave).render(true);
|
||||
new FenetreRechercheConfiguration(html).render(true);
|
||||
}
|
||||
|
||||
constructor(html, configuration, onSave) {
|
||||
constructor(html) {
|
||||
const options = {
|
||||
classes: ["fenetre-recherche-configuration"],
|
||||
width: 600,
|
||||
@ -307,12 +266,12 @@ class FenetreRechercheConfiguration extends Dialog {
|
||||
title: 'Configuration de la recherche',
|
||||
content: html,
|
||||
buttons: {
|
||||
"Sauvegarder": { label: "Sauvegarder", callback: async it => { await this.sauvegarder(); } }
|
||||
}
|
||||
};
|
||||
super(conf, options)
|
||||
this.configuration = configuration;
|
||||
this.onSave = onSave;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
this.html = html;
|
||||
super.activateListeners(html);
|
||||
@ -323,9 +282,7 @@ class FenetreRechercheConfiguration extends Dialog {
|
||||
const compendiumIds = jQuery.map(this.html.find("input.select-compendium:checked"), it => {
|
||||
return this.html.find(it).data('id');
|
||||
});
|
||||
this.configuration.compendiums.forEach(c => {
|
||||
c.selected = compendiumIds.includes(c.id)
|
||||
})
|
||||
this.onSave(this.configuration)
|
||||
await game.system.rdd.environnement.saveCompendiums(compendiumIds);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user