From b4ca941065bab12e36ee67915314766da72979ad Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 28 Sep 2022 01:24:20 +0200 Subject: [PATCH] =?UTF-8?q?Nettoyage=20de=20journal=20d'exp=C3=A9rience=20?= =?UTF-8?q?pour=20MJ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Permet au MJ de vider les anciennes entrées du journal d'expérience (jusqu'à une entrée, comprise) Permet de supprimer une entrée spécifique --- module/actor-sheet.js | 12 ++++++++++-- module/actor.js | 12 +++++++++++- templates/actor/xp-journal.html | 20 +++++++++++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 601df81e..8e1fc851 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -191,7 +191,6 @@ export class RdDActorSheet extends ActorSheet { const item = RdDSheetUtility.getItem(event, this.actor); item?.postItem(); }); - html.find('.item-action').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor) this.actor.actionItem(item); @@ -204,7 +203,16 @@ export class RdDActorSheet extends ActorSheet { RdDUtility.confirmerSuppressionSubacteur(this, subActor, li); } }); - + html.find('.experiencelog-delete').click(async event => { + const li = $(event.currentTarget)?.parents(".experiencelog"); + const key = Number(li.data("key") ?? -1); + await this.actor.deleteExperienceLog(key, 1); + }); + html.find('.experiencelog-delete-previous').click(async event => { + const li = $(event.currentTarget)?.parents(".experiencelog"); + const key = Number(li.data("key") ?? -1); + await this.actor.deleteExperienceLog(0, key + 1); + }); html.find('.encaisser-direct').click(async event => { this.actor.encaisser(); }) diff --git a/module/actor.js b/module/actor.js index dcb55db6..9ad0b47b 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1020,10 +1020,20 @@ export class RdDActor extends Actor { let expLog = duplicate(this.system.experiencelog); expLog.push({ mode: Misc.upperFirst(modeXP), valeur: valeurXP, raison: Misc.upperFirst(raisonXP), - daterdd: game.system.rdd.calendrier.getDateFromIndex(), datereel: `${d.getDate()}/${d.getMonth() + 1}/${d.getFullYear()}` + daterdd: game.system.rdd.calendrier.getDateFromIndex(), + datereel: `${d.getDate()}/${d.getMonth() + 1}/${d.getFullYear()}` }); await this.update({ [`system.experiencelog`]: expLog }); } + + async deleteExperienceLog(from, count) { + if (from >= 0 && count > 0) { + let expLog = duplicate(this.system.experiencelog); + expLog.splice(from, count); + await this.update({ [`system.experiencelog`]: expLog }); + } + } + /* -------------------------------------------- */ async updateCompteurValue(fieldName, fieldValue, raison = 'Inconnue') { diff --git a/templates/actor/xp-journal.html b/templates/actor/xp-journal.html index 15c509b9..ce0eb427 100644 --- a/templates/actor/xp-journal.html +++ b/templates/actor/xp-journal.html @@ -2,11 +2,21 @@