Chargement depuis les compendium sélectionnés

Fix, les compendiums systèmes n'étaient pas utilisés pour les herbes
et les compétences
This commit is contained in:
Vincent Vandemeulebrouck 2022-11-23 22:39:48 +01:00
parent 97ee5bc331
commit e78ae3b292
6 changed files with 35 additions and 45 deletions

View File

@ -35,6 +35,7 @@ import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE, HIDE_DICE, SHOW_DIC
import { RdDConfirm } from "./rdd-confirm.js";
import { DialogValidationEncaissement } from "./dialog-validation-encaissement.js";
import { RdDRencontre } from "./item-rencontre.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
import { Targets } from "./targets.js";
const POSSESSION_SANS_DRACONIC = {
@ -125,9 +126,9 @@ export class RdDActor extends Actor {
}
if (isPersonnage) {
const competences = await RdDUtility.loadItems(it => it.isCompetencePersonnage(), 'foundryvtt-reve-de-dragon.competences');
actorData.items = competences.map(i => i.toObject());
actorData.items = actorData.items.concat(Monnaie.monnaiesStandard());
const competences = await SystemCompendiums.getCompetences(actorData.type);
actorData.items = competences.map(i => i.toObject())
.concat(Monnaie.monnaiesStandard());
}
else {
actorData.items = [];

View File

@ -34,13 +34,6 @@ const categorieCompetences = {
"lancer": { base: -8, label: "Lancer" }
}
const compendiumCompetences = {
"personnage": "foundryvtt-reve-de-dragon.competences",
"creature": "foundryvtt-reve-de-dragon.competences-creatures",
"entite": "foundryvtt-reve-de-dragon.competences-entites"
};
function _buildCumulXP() {
let cumulXP = { "-11": 0 };
let cumul = 0;
@ -55,12 +48,6 @@ function _buildCumulXP() {
const competence_xp_cumul = _buildCumulXP();
export class RdDItemCompetence extends Item {
/* -------------------------------------------- */
static actorCompendium(actorType = undefined) {
return compendiumCompetences[actorType ?? 'personnage'];
}
/* -------------------------------------------- */
static getCategorieCompetences() {
return categorieCompetences;

View File

@ -8,6 +8,7 @@ import { HtmlUtility } from "./html-utility.js";
import { ReglesOptionelles } from "./settings/regles-optionelles.js";
import { SYSTEM_RDD } from "./constants.js";
import { RdDSheetUtility } from "./rdd-sheet-utility.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
/**
* Extend the basic ItemSheet with some very simple modifications
@ -83,17 +84,18 @@ export class RdDItemSheet extends ItemSheet {
}
}
const competences = await SystemCompendiums.getCompetences(this.actor?.type);
formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences()
if (this.item.type == 'tache' || this.item.type == 'livre' || this.item.type == 'meditation' || this.item.type == 'oeuvre') {
formData.caracList = duplicate(game.system.model.Actor.personnage.carac)
formData.caracList["reve-actuel"] = duplicate(game.system.model.Actor.personnage.reve.reve)
formData.competences = await RdDUtility.loadItems(it => it.isCompetencePersonnage(), RdDItemCompetence.actorCompendium(this.actor?.type))
formData.competences = competences;
}
if (this.item.type == 'arme') {
formData.competences = await RdDUtility.loadItems(it => RdDItemCompetence.isCompetenceArme(it), RdDItemCompetence.actorCompendium(this.actor?.type))
formData.competences = competences.filter(it => RdDItemCompetence.isCompetenceArme(it));
}
if (['sort', 'sortreserve'].includes(this.item.type)) {
formData.competences = await RdDUtility.loadItems(it => RdDItemCompetence.isDraconic(it), RdDItemCompetence.actorCompendium(this.actor?.type))
formData.competences = competences.filter(it => RdDItemCompetence.isDraconic(it));
}
if (this.item.type == 'recettecuisine') {
formData.ingredients = await TextEditor.enrichHTML(this.object.system.ingredients, {async: true})

View File

@ -1,6 +1,7 @@
import { RdDUtility } from "./rdd-utility.js";
import { RdDCalendrier } from "./rdd-calendrier.js";
import { Grammar } from "./grammar.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
/* -------------------------------------------- */
export class RdDHerbes extends Item {
@ -12,9 +13,8 @@ export class RdDHerbes extends Item {
}
static async listCategorieHerbes(categorie) {
return await RdDUtility.loadItems(
it => it.type == 'herbe' && it.system.categorie.toLowerCase() == categorie.toLowerCase(),
'foundryvtt-reve-de-dragon.botanique');
const herbes = await SystemCompendiums.getWorldOrCompendiumItems('herbe', 'botanique');
return herbes.filter(it => Grammar.equalsInsensitive(it.system.categorie, categorie));
}
/* -------------------------------------------- */

View File

@ -759,29 +759,6 @@ export class RdDUtility {
return 0;
}
/* -------------------------------------------- */
static async loadItems(filter, compendium) {
let items = game.items.filter(filter);
if (compendium) {
const ids = items.map(it => it.id);
const names = items.map(it => it.name.toLowerCase());
items = items.concat(await RdDUtility.loadCompendium(compendium, it => !ids.includes(it.id) && !names.includes(it.name.toLowerCase()) && filter(it)));
}
return items;
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = it => true) {
let compendiumData = await RdDUtility.loadCompendiumData(compendium);
return compendiumData.filter(filter);
}
/* -------------------------------------------- */
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium);
return await pack?.getDocuments() ?? [];
}
/* -------------------------------------------- */
static async responseNombreAstral(callData) {
let actor = game.actors.get(callData.id);

View File

@ -55,6 +55,29 @@ export class SystemCompendiums extends FormApplication {
return [];
}
static async getCompetences(actorType) {
switch (actorType ?? 'personnage') {
case 'personnage': return await SystemCompendiums.getWorldOrCompendiumItems('competence', 'competences');
case 'creature': return await SystemCompendiums.getWorldOrCompendiumItems('competencecreature', 'competences-creatures');
case 'entite': return await SystemCompendiums.getWorldOrCompendiumItems('competencecreature', 'competences-entites');
case 'vehicule': return [];
}
}
/* -------------------------------------------- */
static async getWorldOrCompendiumItems(itemType, compendium) {
let items = game.items.filter(it => it.type == itemType);
if (compendium) {
const ids = items.map(it => it.id);
const names = items.map(it => it.name.toLowerCase());
const compendiumItems = await SystemCompendiums.getItems(compendium);
items = items.concat(compendiumItems
.filter(it => it.type == itemType)
.filter(it => !ids.includes(it.id))
.filter(it => !names.includes(it.name.toLowerCase())));
}
return items;
}
static async getItems(compendium, itemType = undefined) {
const items = await SystemCompendiums.getContent(compendium, 'Item');
return itemType ? items.filter(it => it.type == itemType) : items;