Fenetre de recherche et tirage

This commit is contained in:
2023-01-13 04:54:29 +01:00
parent 0c36cf3c47
commit 162a6a04b8
14 changed files with 464 additions and 55 deletions

View File

@ -177,7 +177,7 @@ export class SystemCompendiums extends FormApplication {
*/
export class CompendiumTable {
constructor(compendium, type, subTypes, sorting = undefined) {
constructor(compendium, type, subTypes = undefined, sorting = undefined) {
this.compendium = compendium;
this.type = type;
this.subTypes = subTypes;
@ -187,13 +187,13 @@ export class CompendiumTable {
async getContent(itemFrequence = it => it.system.frequence, filter = it => true) {
return await SystemCompendiums.getContent(this.compendium,
this.type,
it => this.subTypes.includes(it.type) && filter(it),
it => (!this.subTypes || this.subTypes.includes(it.type)) && filter(it),
itemFrequence,
this.sorting);
}
async buildTable(itemFrequence = it => it.system.frequence, filter = it => true) {
const elements = await this.getContent(filter, itemFrequence);
const elements = await this.getContent(itemFrequence, filter);
return CompendiumTableHelpers.buildTable(elements, itemFrequence);
}
@ -225,9 +225,23 @@ export class CompendiumTableHelpers {
});
}
static async getRandom(table, type, subTypes, forcedRoll = undefined, localisation = undefined) {
static concatTables(...tables) {
const rows = tables.reduce((a, b) => a.concat(b));
let max = 0;
const total = rows.map(it => it.frequence).reduce(Misc.sum(), 0);
return rows.map(row => {
const frequence = row.frequence;
row.min = max + 1;
row.max = max + frequence;
row.total = total
max += frequence;
return row;
})
}
static async getRandom(table, type, subTypes = ['objet'], forcedRoll = undefined, localisation = undefined) {
if (table.length == 0) {
ui.notifications.warn(`Aucun ${Misc.typeName(type, subTypes[0])} trouvé dans ${localisation ?? ' les compendiums'}`);
const typeName = Misc.typeName(type, subTypes[0]);
ui.notifications.warn(`Aucun ${typeName} trouvé dans ${localisation ?? ' les compendiums'}`);
return undefined;
}
return await CompendiumTableHelpers.selectRow(table, forcedRoll);
@ -260,7 +274,7 @@ export class CompendiumTableHelpers {
roll: row.roll,
document: row.document,
percentages,
typeName: Misc.typeName(type, row.document.type),
typeName: Misc.typeName(type, row.document?.type ?? 'objet'),
isGM: game.user.isGM,
});
const messageData = {