From 7557d33c73a1b72f14bb6dcc1d8599ff3d3fc80b Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 28 Nov 2022 21:01:28 +0100 Subject: [PATCH] =?UTF-8?q?Feuille=20de=20v=C3=A9hicule=20avec=20compteurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-vehicule-sheet.js | 17 +++++++++++ module/actor.js | 12 ++++++++ templates/actor-vehicule-sheet.html | 46 +++++++++++++++++------------ 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 2729f2af..5803f3f7 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -18,5 +18,22 @@ export class RdDActorVehiculeSheet extends RdDActorSheet { }); } + activateListeners(html) { + super.activateListeners(html); + if (!this.options.editable) return; + + html.find('.resistance-moins').click(async event => { + this.actor.vehicleIncDec("resistance", -1); + }); + html.find('.resistance-plus').click(async event => { + this.actor.vehicleIncDec("resistance", 1); + }); + html.find('.structure-moins').click(async event => { + this.actor.vehicleIncDec("structure", -1); + }); + html.find('.structure-plus').click(async event => { + this.actor.vehicleIncDec("structure", 1); + }); + } } diff --git a/module/actor.js b/module/actor.js index a49c3a25..d9af9b98 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1779,6 +1779,18 @@ export class RdDActor extends Actor { } return result; } + + async vehicleIncDec(name, inc) { + if (!this.isVehicule() || !['resistance', 'structure'].includes(name)) { + return + } + const value = this.system.etat[name].value; + const max = this.system.etat[name].max; + const newValue = value + inc; + if (0 <= newValue && newValue <=max) { + await this.update({ [`system.etat.${name}.value`]: newValue }) + } + } isDead() { return !this.isEntite() && this.system.sante.vie.value < -this.getSConst() diff --git a/templates/actor-vehicule-sheet.html b/templates/actor-vehicule-sheet.html index 3c3f60db..e21924c5 100644 --- a/templates/actor-vehicule-sheet.html +++ b/templates/actor-vehicule-sheet.html @@ -2,13 +2,37 @@ {{!-- Sheet Header --}}
-
-

+ +
+

+
+
+
    +
  • + RĂ©sistance + + + / + + +
  • +
  • + Structure + + + / + + +
  • +
+
+
+
-
+ {{!-- Sheet Tab Navigation --}}