Paramétrage des compendiums de recherche
This commit is contained in:
parent
f7595a1bfe
commit
f4d074fa31
@ -99,8 +99,7 @@ export class Environnement {
|
||||
if (!milieux) {
|
||||
milieux = await this.milieux()
|
||||
}
|
||||
const frequence = item => item.getRarete(milieux)?.frequence ?? 0;
|
||||
return await this.table.buildTable(frequence, it => frequence(it) > 0 && filter(it));
|
||||
return await this.table.buildTable(it => it.getFrequence(), filter);
|
||||
}
|
||||
|
||||
async getElements(itemFrequence, filter) {
|
||||
|
@ -186,28 +186,19 @@ export class RdDItem extends Item {
|
||||
? this.system?.environnement.filter(env => !milieux || milieux.includes(env.milieu))
|
||||
: []
|
||||
}
|
||||
getEnvRarete(milieux = undefined) {
|
||||
if (this.isEnvironnement()) {
|
||||
const list = this.getEnvironnements(milieux);
|
||||
const frequenceMax = Math.max(...list.map(env => env.frequence));
|
||||
return list.find(env => env.frequence == frequenceMax);
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
getRarete(milieux = undefined) {
|
||||
if (this.isEnvironnement()) {
|
||||
const env = this.getEnvRarete(milieux);
|
||||
return RdDRaretes.getRarete(env.rarete);
|
||||
return RdDRaretes.rareteEnvironnement(this, milieux)
|
||||
}
|
||||
if (this.isInventaire()) {
|
||||
return RdDRaretes.rareteEquipement(this)
|
||||
}
|
||||
return RdDRaretes.getRareteFrequente();
|
||||
return RdDRaretes.rareteFrequente();
|
||||
}
|
||||
|
||||
getFrequence(milieux = undefined) {
|
||||
const frequence = this.getRarete(milieux)?.frequence;
|
||||
return frequence == undefined ? 1 : frequence;
|
||||
return this.getRarete(milieux)?.frequence ?? 0;
|
||||
}
|
||||
|
||||
getItemGroup() {
|
||||
|
@ -511,7 +511,7 @@ export class RdDCommands {
|
||||
}
|
||||
|
||||
async tirage() {
|
||||
new FenetreRechercheTirage({}).render(true);
|
||||
FenetreRechercheTirage.create();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ import { RdDConteneurItemSheet } from "./item-conteneur-sheet.js";
|
||||
import { RdDSigneDraconiqueItemSheet } from "./item-signedraconique-sheet.js";
|
||||
|
||||
import { TMRRencontres } from "./tmr-rencontres.js";
|
||||
import { FenetreRechercheTirage } from "./tirage/fenetre-recherche-tirage.js";
|
||||
|
||||
/**
|
||||
* RdD system
|
||||
@ -182,6 +183,7 @@ export class SystemReveDeDragon {
|
||||
RdDPossession.init();
|
||||
TMRRencontres.init();
|
||||
Environnement.init();
|
||||
FenetreRechercheTirage.init();
|
||||
|
||||
Hooks.once('ready', () => this.onReady());
|
||||
}
|
||||
@ -265,7 +267,7 @@ export class SystemReveDeDragon {
|
||||
let sidebar = document.getElementById("sidebar");
|
||||
sidebar.style.width = "min-content";
|
||||
}
|
||||
|
||||
|
||||
if (Misc.isUniqueConnectedGM()) {
|
||||
new Migrations().migrate();
|
||||
}
|
||||
@ -296,9 +298,9 @@ export class SystemReveDeDragon {
|
||||
this.registerUsageCount(SYSTEM_RDD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
messageDeBienvenue() {
|
||||
messageDeBienvenue() {
|
||||
if (game.user.isGM) {
|
||||
ChatUtility.removeChatMessageContaining('<div id="message-bienvenue-rdd">');
|
||||
ChatMessage.create({
|
||||
|
@ -52,6 +52,10 @@ export class SystemCompendiums extends FormApplication {
|
||||
}
|
||||
|
||||
static getPack(compendium) {
|
||||
const pack = game.packs.get(compendium);
|
||||
if (pack) {
|
||||
return pack;
|
||||
}
|
||||
return game.packs.get(SystemCompendiums.getCompendium(compendium)) ?? game.packs.get(SystemCompendiums._getDefaultCompendium(compendium));
|
||||
}
|
||||
|
||||
@ -187,7 +191,7 @@ export class CompendiumTable {
|
||||
async getContent(itemFrequence = it => it.system.frequence, filter = it => true) {
|
||||
return await SystemCompendiums.getContent(this.compendium,
|
||||
this.type,
|
||||
it => (!this.subTypes || this.subTypes.includes(it.type)) && filter(it),
|
||||
it => (!this.subTypes || this.subTypes.includes(it.type)) && itemFrequence(it) > 0 && filter(it),
|
||||
itemFrequence,
|
||||
this.sorting);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import { HtmlUtility } from '../html-utility.js';
|
||||
import { Misc } from "../misc.js";
|
||||
import { CompendiumTable, CompendiumTableHelpers, SystemCompendiums } 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" },
|
||||
@ -50,8 +51,75 @@ const FILTERS = [
|
||||
{ group: "prix", code: "dragons", label: "Dragons (or) 1+ ", 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 }; }
|
||||
|
||||
function $filterMilieux(milieux) {
|
||||
return milieux.map(m => { return { group: 'milieu', code: m, label: m, check: item => 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 }; });
|
||||
}
|
||||
|
||||
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)))
|
||||
}
|
||||
|
||||
function $getAllFilters(milieux) {
|
||||
return FILTERS
|
||||
.concat($filterTypes())
|
||||
.concat($filterMilieux(milieux))
|
||||
.concat($filterRarete());
|
||||
}
|
||||
|
||||
function $addFilterToGroup(groups, filter) {
|
||||
if (filter.group && filter.code && filter.label) {
|
||||
let fg = groups.find(g => g.group == filter.group);
|
||||
if (fg == undefined) {
|
||||
groups.push({ group: filter.group, label: filter.group, filters: [filter] })
|
||||
}
|
||||
else if (fg.filters == undefined) {
|
||||
fg.filters = [filter];
|
||||
}
|
||||
else {
|
||||
fg.filters.push(filter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.warn("Filtre incorrect, pas de groupe/code/label", filter);
|
||||
}
|
||||
}
|
||||
|
||||
function $loadFilters(parameters) {
|
||||
$getAllFilters(parameters.milieux).forEach(f => $addFilterToGroup(parameters.filterGroups, f));
|
||||
}
|
||||
|
||||
|
||||
|
||||
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",
|
||||
@ -64,72 +132,32 @@ export class FenetreRechercheTirage extends Application {
|
||||
});
|
||||
}
|
||||
|
||||
static async $filterMilieux() {
|
||||
const milieux = await game.system.rdd.environnement.milieux();
|
||||
return milieux.map(m => { return { group: 'milieu', code: m, label: m, check: item => item.isPresentDansMilieux(m) } })
|
||||
static async create() {
|
||||
const parameters = {
|
||||
milieux: await game.system.rdd.environnement.milieux(),
|
||||
filterGroups: duplicate(FILTER_GROUPS).filter(it => it.group),
|
||||
}
|
||||
const options = {}
|
||||
$loadFilters(parameters);
|
||||
|
||||
new FenetreRechercheTirage(parameters, options).render(true);
|
||||
}
|
||||
|
||||
static $filterRarete() {
|
||||
return RdDRaretes.raretes()
|
||||
.map(r => { return { group: 'rarete', code: r.code, label: r.label, check: item => item.getRarete()?.code == r.code }; });
|
||||
}
|
||||
|
||||
static $filterTypes() {
|
||||
return [
|
||||
{ group: 'type', code: 'inventaire', label: 'Inventaire', check: item => item.isInventaire() && !item.isEnvironnement() },
|
||||
]
|
||||
.concat(['arme', 'armure'].map(it => FenetreRechercheTirage.$typeToFilter(it)))
|
||||
.concat([{ group: 'type', code: 'environement', label: 'Faune, Flore, Ingrédients', check: item => item.isEnvironnement() }])
|
||||
.concat(RdDItem.getItemTypesEnvironnement().map(it => FenetreRechercheTirage.$typeToFilter(it)))
|
||||
}
|
||||
static $typeToFilter(type) { return { group: 'type', code: type, label: Misc.typeName('Item', type), check: item => item.type == type }; }
|
||||
|
||||
static async create(options) {
|
||||
new FenetreRechercheTirage(options).render(true);
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
constructor(parameters, options) {
|
||||
super(options);
|
||||
this.tirage = {};
|
||||
this.compendiums = [
|
||||
SystemCompendiums.getCompendium('faune-flore-mineraux'),
|
||||
SystemCompendiums.getCompendium('equipement')
|
||||
]
|
||||
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() {
|
||||
const filterGroups = duplicate(FILTER_GROUPS);
|
||||
FILTERS
|
||||
.concat(FenetreRechercheTirage.$filterTypes())
|
||||
.concat(await FenetreRechercheTirage.$filterMilieux())
|
||||
.concat(FenetreRechercheTirage.$filterRarete())
|
||||
.forEach(f => addFilterToGroup(filterGroups, f))
|
||||
mergeObject(this.tirage,
|
||||
{
|
||||
filterGroups: filterGroups.filter(it => it.group)
|
||||
})
|
||||
|
||||
let formData = super.getData();
|
||||
mergeObject(formData, this.tirage)
|
||||
mergeObject(formData, this.parameters)
|
||||
return formData;
|
||||
|
||||
function addFilterToGroup(filterGroups, filter) {
|
||||
if (filter.group && filter.code && filter.label) {
|
||||
let fg = filterGroups.find(g => g.group == filter.group);
|
||||
if (fg == undefined) {
|
||||
filterGroups.push({ group: filter.group, label: filter.group, filters: [filter] })
|
||||
}
|
||||
else if (fg.filters == undefined) {
|
||||
fg.filters = [filter];
|
||||
}
|
||||
else {
|
||||
fg.filters.push(filter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.warn("Filtre incorrect, pas de groupe/code/label", filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_canDragStart() {
|
||||
@ -138,6 +166,18 @@ export class FenetreRechercheTirage extends Application {
|
||||
_onDragStart(event) {
|
||||
console.log('_onDragStart', event)
|
||||
}
|
||||
_getHeaderButtons() {
|
||||
let buttons = super._getHeaderButtons();
|
||||
if (game.user.isGM) {
|
||||
buttons.unshift({
|
||||
class: "configurer",
|
||||
label: "Configurer",
|
||||
icon: "fas fa-cogs",
|
||||
onclick: ev => this.configurer()
|
||||
});
|
||||
}
|
||||
return buttons
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
@ -179,17 +219,17 @@ export class FenetreRechercheTirage extends Application {
|
||||
}
|
||||
|
||||
async buildTable() {
|
||||
const filter = this.getSelectedItemsFilter();
|
||||
const equipementCompendiumTable = new CompendiumTable('equipement', 'Item');
|
||||
const equipements = await equipementCompendiumTable.buildTable(it => it.getFrequence(), filter)
|
||||
const environnements = await game.system.rdd.environnement.buildEnvironnementTable(undefined, filter);
|
||||
return CompendiumTableHelpers.concatTables(environnements, equipements);
|
||||
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);
|
||||
}
|
||||
|
||||
getSelectedItemsFilter() {
|
||||
const byGroup = this.getSelectedFiltersByGroup();
|
||||
buildCheckedItemsFilter() {
|
||||
const byGroup = this.getCheckedFiltersByGroup();
|
||||
const groupSummaries = Object.entries(byGroup).map(([key, list]) => {
|
||||
const group = this.tirage.filterGroups.find(g => key == g.group);
|
||||
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)
|
||||
@ -210,9 +250,9 @@ export class FenetreRechercheTirage extends Application {
|
||||
}
|
||||
|
||||
changeListeFiltresActifs() {
|
||||
const byGroup = this.getSelectedFiltersByGroup();
|
||||
const byGroup = this.getCheckedFiltersByGroup();
|
||||
const groupSummaries = Object.entries(byGroup).map(([key, list]) => {
|
||||
const group = this.tirage.filterGroups.find(g => key == g.group);
|
||||
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)
|
||||
@ -222,12 +262,70 @@ export class FenetreRechercheTirage extends Application {
|
||||
this.html.find('span.liste-filtres-actifs').text(fullText);
|
||||
}
|
||||
|
||||
getSelectedFiltersByGroup() {
|
||||
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') };
|
||||
});
|
||||
const byGroup = Misc.classify(selectedFilters, it => it.group);
|
||||
return byGroup;
|
||||
return Misc.classify(selectedFilters, it => it.group);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/tirage/fenetre-recherche-configuration.hbs", configuration);
|
||||
new FenetreRechercheConfiguration(html, configuration, onSave).render(true);
|
||||
}
|
||||
|
||||
constructor(html, configuration, onSave) {
|
||||
const options = {
|
||||
classes: ["fenetre-recherche-configuration"],
|
||||
width: 600,
|
||||
height: 'fit-content',
|
||||
'max-height': 600,
|
||||
height: 'fit-content',
|
||||
'z-index': 99999
|
||||
};
|
||||
const conf = {
|
||||
title: 'Configuration de la recherche',
|
||||
content: html,
|
||||
buttons: {
|
||||
}
|
||||
};
|
||||
super(conf, options)
|
||||
this.configuration = configuration;
|
||||
this.onSave = onSave;
|
||||
}
|
||||
activateListeners(html) {
|
||||
this.html = html;
|
||||
super.activateListeners(html);
|
||||
this.html.find("button.configuration-save").click(event => this.sauvegarder())
|
||||
}
|
||||
|
||||
async sauvegarder() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,21 @@
|
||||
const RARETE_COMMUNE = { code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 };
|
||||
const RARETE_FREQUENTE = { code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 };
|
||||
const RARETE_RARE = { code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 };
|
||||
const RARETE_RARISSIME = { code: 'Rarissime', label: 'Rarissime', frequence: 2, min: 1, max: 4 };
|
||||
const RARETE_INEXISTANT = { code: 'Inexistant', label: 'Inexistant', frequence: 0, min: 0, max: 0 };
|
||||
|
||||
const RARETES = [
|
||||
{ code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 },
|
||||
{ code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 },
|
||||
{ code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 },
|
||||
{ code: 'Rarissime', label: 'Rarissime', frequence: 2, min: 1, max: 4 }]
|
||||
const DEFAULT_RARETE = 1;
|
||||
RARETE_COMMUNE,
|
||||
RARETE_FREQUENTE,
|
||||
RARETE_RARE,
|
||||
RARETE_RARISSIME,
|
||||
RARETE_INEXISTANT,
|
||||
]
|
||||
|
||||
export class RdDRaretes {
|
||||
|
||||
static getRarete(code = undefined) {
|
||||
return RARETES.find(it => it.code == code) ?? RARETES[DEFAULT_RARETE];
|
||||
return RARETES.find(it => it.code == code) ?? RARETE_FREQUENTE;
|
||||
}
|
||||
|
||||
static getChamp(rarete, field = undefined) {
|
||||
@ -17,8 +23,8 @@ export class RdDRaretes {
|
||||
return field ? selected[field] : selected[frequence];
|
||||
}
|
||||
|
||||
static getRareteFrequente() {
|
||||
return RARETES[DEFAULT_RARETE];
|
||||
static rareteFrequente() {
|
||||
return RARETE_FREQUENTE;
|
||||
}
|
||||
|
||||
static raretes() {
|
||||
@ -29,17 +35,28 @@ export class RdDRaretes {
|
||||
return RdDRaretes.rareteEquipement(item).frequence
|
||||
}
|
||||
|
||||
|
||||
static rareteEnvironnement(item, milieux = undefined) {
|
||||
const list = item.getEnvironnements(milieux);
|
||||
const freqMax = Math.max(0, ...list.map(env => env.frequence));
|
||||
const env = list.find(env => env.frequence == freqMax);
|
||||
return env ? RdDRaretes.getRarete(env.rarete) : RARETE_INEXISTANT;
|
||||
|
||||
}
|
||||
static rareteEquipement(item) {
|
||||
const qualite = item.system.qualite ?? 0;
|
||||
if (qualite <= 0) {
|
||||
return RARETES[0]
|
||||
return RARETE_COMMUNE
|
||||
}
|
||||
if (qualite <= 3) {
|
||||
return RARETES[1]
|
||||
return RARETE_FREQUENTE
|
||||
}
|
||||
if (qualite <= 6) {
|
||||
return RARETES[2]
|
||||
return RARETE_RARE
|
||||
}
|
||||
return RARETES[3]
|
||||
if (qualite <= 9) {
|
||||
return RARETE_RARISSIME
|
||||
}
|
||||
return RARETE_INEXISTANT
|
||||
}
|
||||
}
|
22
templates/tirage/fenetre-recherche-configuration.hbs
Normal file
22
templates/tirage/fenetre-recherche-configuration.hbs
Normal file
@ -0,0 +1,22 @@
|
||||
<form class="fenetre-recherche-configuration" autocomplete="off" onsubmit="event.preventDefault();">
|
||||
<div class="form-group">
|
||||
<h3>Recherche dans les compendiums</h3>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<ul>
|
||||
{{#each compendiums as |compendium|}}
|
||||
<li class="flexrow">
|
||||
<input type="checkbox" class="select-compendium" name="{{compendium.id}}"
|
||||
data-id="{{compendium.id}}" {{#if compendium.selected}}checked{{/if}}/>
|
||||
<label for="{{compendium.id}}">{{compendium.label}}
|
||||
<label class="poesie-reference">({{compendium.id}})</label>
|
||||
</label>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="configuration-save">Sauvegarder</button>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user