From 388629d36ebfed39a00f55f4ff126e5c78f1a977 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 7 Jan 2023 19:46:27 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20=C3=A9dition=20des=20comp=C3=A9tences=20?= =?UTF-8?q?de=20cr=C3=A9atures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-entite-sheet.js | 34 +++++++++++++++--------------- module/actor.js | 22 +++++++++++-------- styles/simple.css | 2 ++ templates/actor/comp-creature.html | 6 +++--- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/module/actor-entite-sheet.js b/module/actor-entite-sheet.js index 0b0e54c2..d7a96ce0 100644 --- a/module/actor-entite-sheet.js +++ b/module/actor-entite-sheet.js @@ -3,20 +3,20 @@ import { RdDActorSheet } from "./actor-sheet.js"; export class RdDActorEntiteSheet extends RdDActorSheet { /** @override */ - static get defaultOptions() { - return mergeObject(super.defaultOptions, { - classes: ["rdd", "sheet", "actor"], - template: "systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html", + static get defaultOptions() { + return mergeObject(super.defaultOptions, { + classes: ["rdd", "sheet", "actor"], + template: "systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html", width: 640, height: 720, - tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac"}], - dragDrop: [{dragSelector: ".item-list .item", dropSelector: undefined}] + tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }], + dragDrop: [{ dragSelector: ".item-list .item", dropSelector: undefined }] }); } /* -------------------------------------------- */ /** @override */ - activateListeners(html) { + activateListeners(html) { super.activateListeners(html); // Everything below here is only needed if the sheet is editable @@ -24,17 +24,17 @@ export class RdDActorEntiteSheet extends RdDActorSheet { // On competence change this.html.find('.creature-carac').change(async event => { - let compName = event.currentTarget.attributes.compname.value; - this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) ); - } ); + let compName = event.currentTarget.attributes.compname.value; + this.actor.updateCreatureCompetence(compName, "carac_value", parseInt(event.target.value)); + }); this.html.find('.creature-niveau').change(async event => { - let compName = event.currentTarget.attributes.compname.value; - this.actor.updateCreatureCompetence( compName, "niveau", parseInt(event.target.value) ); - } ); - this.html.find('.creature-dommages').change(async event => { - let compName = event.currentTarget.attributes.compname.value; - this.actor.updateCreatureCompetence( compName, "dommages", parseInt(event.target.value) ); - } ); + let compName = event.currentTarget.attributes.compname.value; + this.actor.updateCreatureCompetence(compName, "niveau", parseInt(event.target.value)); + }); + this.html.find('.creature-dommages').change(async event => { + let compName = event.currentTarget.attributes.compname.value; + this.actor.updateCreatureCompetence(compName, "dommages", parseInt(event.target.value)); + }); } } diff --git a/module/actor.js b/module/actor.js index 83d366c8..dcf92e44 100644 --- a/module/actor.js +++ b/module/actor.js @@ -847,17 +847,21 @@ export class RdDActor extends RdDBaseActor { } /* -------------------------------------------- */ - async updateCreatureCompetence(idOrName, fieldName, compValue) { + async updateCreatureCompetence(idOrName, fieldName, value) { let competence = this.getCompetence(idOrName); if (competence) { - const update = { _id: competence.id } - if (fieldName == "niveau") - update['system.niveau'] = compValue; - else if (fieldName == "dommages") - update['system.dommages'] = compValue; - else - update['system.carac_value'] = compValue; - await this.updateEmbeddedDocuments('Item', [update]); // updates one EmbeddedEntity + function getPath(fieldName) { + switch (fieldName) { + case "niveau": return 'system.niveau'; + case "dommages": return 'system.dommages'; + case "carac_value": return 'system.carac_value'; + } + return undefined + } + const path = getPath(fieldName); + if (path){ + await this.updateEmbeddedDocuments('Item', [{ _id: competence.id, [path]: value }]); // updates one EmbeddedEntity + } } } diff --git a/styles/simple.css b/styles/simple.css index df57b1a7..b72ee6a6 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1158,6 +1158,8 @@ div.competence-column div.categorie-competence{ margin-left: 4px; } .sante-value, +.competence-carac, +.competence-damage, .competence-value { flex-grow: 0; flex-basis: 2rem; diff --git a/templates/actor/comp-creature.html b/templates/actor/comp-creature.html index 7628e807..39122cab 100644 --- a/templates/actor/comp-creature.html +++ b/templates/actor/comp-creature.html @@ -6,13 +6,13 @@ {{comp.name}} - - - {{#if @root.options.vueDetaillee}}