From 0cb764f1f3d4f74b338151ff743f3232baa5e4fa Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Thu, 2 Apr 2026 09:29:27 +0200 Subject: [PATCH] Minor fixes and enhancements --- modules/hawkmoon-actor.js | 95 +++++++++++++++++++++---------------- modules/hawkmoon-utility.js | 42 +++++++++++----- 2 files changed, 84 insertions(+), 53 deletions(-) diff --git a/modules/hawkmoon-actor.js b/modules/hawkmoon-actor.js index 3ec7ddf..30df8a6 100644 --- a/modules/hawkmoon-actor.js +++ b/modules/hawkmoon-actor.js @@ -148,26 +148,32 @@ export class HawkmoonActor extends Actor { /* -------------------------------------------- */ getSkills() { - let comp = [] - for (let item of this.items) { - item = foundry.utils.duplicate(item) - if (item.type == "competence") { - item.system.attribut1total = item.system.niveau + (this.system.attributs[item.system.attribut1]?.value || 0) - item.system.attribut2total = item.system.niveau + (this.system.attributs[item.system.attribut2]?.value || 0) - item.system.attribut3total = item.system.niveau + (this.system.attributs[item.system.attribut3]?.value || 0) - if (item.system.niveau == 0) { - item.system.attribut1total -= 3 - item.system.attribut2total -= 3 - item.system.attribut3total -= 3 + // Utiliser filter et map pour éviter les duplications inutiles + const comp = this.items + .filter(item => item.type === "competence") + .map(item => { + const itemCopy = foundry.utils.duplicate(item); + const attrs = this.system.attributs; + + itemCopy.system.attribut1total = itemCopy.system.niveau + (attrs[itemCopy.system.attribut1]?.value || 0); + itemCopy.system.attribut2total = itemCopy.system.niveau + (attrs[itemCopy.system.attribut2]?.value || 0); + itemCopy.system.attribut3total = itemCopy.system.niveau + (attrs[itemCopy.system.attribut3]?.value || 0); + + if (itemCopy.system.niveau === 0) { + itemCopy.system.attribut1total -= 3; + itemCopy.system.attribut2total -= 3; + itemCopy.system.attribut3total -= 3; } - item.system.attribut1label = this.system.attributs[item.system.attribut1]?.label || "" - item.system.attribut2label = this.system.attributs[item.system.attribut2]?.label || "" - item.system.attribut3label = this.system.attributs[item.system.attribut3]?.label || "" - comp.push(item) - } - } - HawkmoonUtility.sortArrayObjectsByName(comp) - return comp + + itemCopy.system.attribut1label = attrs[itemCopy.system.attribut1]?.label || ""; + itemCopy.system.attribut2label = attrs[itemCopy.system.attribut2]?.label || ""; + itemCopy.system.attribut3label = attrs[itemCopy.system.attribut3]?.label || ""; + + return itemCopy; + }); + + HawkmoonUtility.sortArrayObjectsByName(comp); + return comp; } /* ----------------------- --------------------- */ @@ -745,41 +751,48 @@ export class HawkmoonActor extends Actor { /* -------------------------------------------- */ async rollArmeDegats(armeId, targetVigueur = undefined, rollDataInput = undefined) { - let arme = this.items.get(armeId) - if (!arme.system.equipped) { - ui.notifications.warn("Cette arme doit être équipée pour pouvoir infliger des dégâts !") - return + const arme = this.items.get(armeId); + if (!arme) { + ui.notifications.warn("Arme non trouvée !"); + return; } - if (arme.type == "arme") { - arme = this.prepareArme(arme) + + if (!arme.system?.equipped) { + ui.notifications.warn("Cette arme doit être équipée pour pouvoir infliger des dégâts !"); + return; } - console.log("DEGATS", arme, targetVigueur, rollDataInput) - let roll - let bonus = 0 - let bonus2 = 0 + + const preparedArme = arme.type === "arme" ? this.prepareArme(arme) : arme; + console.log("DEGATS", preparedArme, targetVigueur, rollDataInput); + + let roll; + let bonus = 0; + let bonus2 = 0; if (rollDataInput?.applyCoupDevastateur) { - bonus2 = Math.floor(this.system.attributs.pui.value / 2) - let talent = this.items.find(item => item.type == "talent" && item.name.toLowerCase() == "coup dévastateur") - this.updateEmbeddedDocuments('Item', [{ _id: talent.id, 'system.used': true }]) + bonus2 = Math.floor(this.system.attributs.pui.value / 2); + const talent = this.items.find(item => item.type === "talent" && item.name.toLowerCase() === "coup dévastateur"); + if (talent) { + await this.updateEmbeddedDocuments('Item', [{ _id: talent.id, 'system.used': true }]); + } } if (rollDataInput?.isHeroique) { if (rollDataInput?.attaqueCharge) { - bonus = 5 + bonus = 5; } if (rollDataInput?.chargeCavalerie) { - bonus = 6 + bonus = 6; } - roll = await new Roll("2d10rr10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll() + roll = await new Roll("2d10rr10+" + preparedArme.system.totalDegats + "+" + bonus + "+" + bonus2).roll(); } else { if (rollDataInput?.attaqueCharge) { - bonus = 3 + bonus = 3; } if (rollDataInput?.chargeCavalerie) { - bonus = 4 + bonus = 4; } - roll = await new Roll("1d10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll() + roll = await new Roll("1d10+" + preparedArme.system.totalDegats + "+" + bonus + "+" + bonus2).roll(); } await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode")); let nbEtatPerdus = 0 @@ -788,17 +801,17 @@ export class HawkmoonActor extends Actor { } //console.log(roll) let rollData = { - arme: arme, + arme: preparedArme, finalResult: roll.total, formula: roll.formula, alias: this.name, actorImg: this.img, actorId: this.id, defenderTokenId: rollDataInput?.defenderTokenId, - actionImg: arme.img, + actionImg: preparedArme.img, targetVigueur: targetVigueur, nbEtatPerdus: nbEtatPerdus - } + }; HawkmoonUtility.createChatWithRollMode(rollData.alias, { content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-hawkmoon-cyd/templates/chat-degats-result.hbs`, rollData) }) diff --git a/modules/hawkmoon-utility.js b/modules/hawkmoon-utility.js index c04521f..b3e7f3e 100644 --- a/modules/hawkmoon-utility.js +++ b/modules/hawkmoon-utility.js @@ -106,8 +106,17 @@ export class HawkmoonUtility { /* -------------------------------------------- */ static updatePauseLogo(html) { - let logoPause = "systems/fvtt-hawkmoon-cyd/assets/logos/" + game.settings.get("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo") + ".webp" - console.log("Hawkmoon | Updating pause logo to:", logoPause) + const validLogos = ["hawkmoon_logo", "logo_pause_resistance", "logo_pause_hawkmoon_stone", "logo_pause_hawkmoon_violet", "logo_pause_hawkmoon_beige", "logo_pause_hawkmoon_rouge"]; + let logoName = game.settings.get("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo"); + + // Validation du nom du logo + if (!validLogos.includes(logoName)) { + console.error("Hawkmoon | Invalid logo name:", logoName); + return; + } + + let logoPause = "systems/fvtt-hawkmoon-cyd/assets/logos/" + logoName + ".webp"; + console.log("Hawkmoon | Updating pause logo to:", logoPause); // Supprimer l'ancien style s'il existe let oldStyle = document.getElementById('hawkmoon-pause-logo-override') @@ -138,13 +147,6 @@ export class HawkmoonUtility { } /* -------------------------------------------- */ - static createDirectOptionList(min, max) { - let options = {}; - for (let i = min; i <= max; i++) { - options[`${i}`] = `${i}`; - } - return options; - } static createArrayOptionList(min, max) { let options = []; for (let i = min; i <= max; i++) { @@ -161,8 +163,19 @@ export class HawkmoonUtility { /* -------------------------------------------- */ static async loadCompendium(compendium, filter = item => true) { - let compendiumData = await HawkmoonUtility.loadCompendiumData(compendium); - return compendiumData.filter(filter); + const pack = game.packs.get(compendium); + if (!pack) { + console.warn(`Hawkmoon | Compendium not found: ${compendium}`); + return []; + } + + try { + const compendiumData = await pack.getDocuments(); + return compendiumData.filter(filter); + } catch (error) { + console.error(`Hawkmoon | Error loading compendium ${compendium}:`, error); + return []; + } } /* -------------------------------------------- */ @@ -366,6 +379,12 @@ export class HawkmoonUtility { /* -------------------------------------------- */ static computeResult(rollData) { + // Validation des données de roll + if (!rollData.roll?.terms?.[0]?.results?.[0]?.result) { + console.error("Hawkmoon | Invalid roll data:", rollData); + return; + } + rollData.diceResult = rollData.roll.terms[0].results[0].result if (rollData.mainDice.includes("d20")) { let diceValue = rollData.roll.terms[0].results[0].result @@ -379,7 +398,6 @@ export class HawkmoonUtility { } } - //console.log("Result : ", rollData this.computeResultQuality(rollData) }