From 3782ed9055339b32524b9bfe98cdec2ea47cdffc Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 7 Jan 2023 23:58:33 +0100 Subject: [PATCH] Gestion d'update de timestamp --- module/item-sheet.js | 8 +++++++- module/rdd-timestamp.js | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/module/item-sheet.js b/module/item-sheet.js index ca15056a..c5f96b64 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -186,7 +186,7 @@ export class RdDItemSheet extends ItemSheet { const jour = Number(this.html.find('input.date-enchantement[name="enchantement.jour"]').val()); const mois = RdDTimestamp.definition(this.html.find('select.date-enchantement[name="enchantement.mois"]').val()); const indexDate = game.system.rdd.calendrier.getIndexFromDate(jour, mois.heure); - this.item.update({'system.prdate': indexDate}); + this.item.update({ 'system.prdate': indexDate }); console.warn(`Date d'enchantement modifiée ${jour}/${mois.heure}: ${indexDate}`) }); @@ -212,6 +212,11 @@ export class RdDItemSheet extends ItemSheet { this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItemToChat()); this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor, async () => this.render(true))); + + const updateItemTimestamp = (path, timestamp) => this.item.update({ [path]: duplicate(timestamp) }) + + RdDTimestamp.handleTimestampEditor(this.html, 'system.temporel.debut', updateItemTimestamp); + RdDTimestamp.handleTimestampEditor(this.html, 'system.temporel.fin', updateItemTimestamp); } _getEventActor(event) { @@ -220,6 +225,7 @@ export class RdDItemSheet extends ItemSheet { return actor; } + /* -------------------------------------------- */ async _onSelectCategorie(event) { event.preventDefault(); diff --git a/module/rdd-timestamp.js b/module/rdd-timestamp.js index a9941b73..456f0141 100644 --- a/module/rdd-timestamp.js +++ b/module/rdd-timestamp.js @@ -86,6 +86,7 @@ export class RdDTimestamp { static formulesDuree() { return FORMULES_DUREE } + static formulesPeriode() { return FORMULES_PERIODE } @@ -98,6 +99,32 @@ export class RdDTimestamp { return `${signe.label}` } + static handleTimestampEditor(html, path, consumeTimestamp = async (path, timestamp) => {}) { + const fields = { + annee: html.find(`input[name="${path}.annee"]`), + mois: html.find(`select[name="${path}.mois"]`), + jourDuMois: html.find(`input[name="${path}.jourDuMois"]`), + heure: html.find(`select[name="${path}.heure"]`), + minute: html.find(`input[name="${path}.minute"]`) + }; + + async function onChangeTimestamp(fields, path) { + const annee = Number(fields.annee.val()); + const mois = fields.mois.val(); + const jour = Number(fields.jourDuMois.val()); + const heure = fields.heure.val(); + const minute = Number(fields.minute.val()); + await consumeTimestamp(path, RdDTimestamp.timestamp(annee, mois, jour, heure, minute)); + } + + fields.annee.change(async (event) => await onChangeTimestamp(fields, path)); + fields.mois.change(async (event) => await onChangeTimestamp(fields, path)); + fields.jourDuMois.change(async (event) => await onChangeTimestamp(fields, path)); + fields.heure.change(async (event) => await onChangeTimestamp(fields, path)); + fields.minute.change(async (event) => await onChangeTimestamp(fields, path)); + } + + static findHeure(heure) { heure = Grammar.toLowerCaseNoAccentNoSpace(heure); let parHeureOuLabel = DEFINITION_HEURES.filter(it => (it.heure) == parseInt(heure) % RDD_HEURES_PAR_JOUR || Grammar.toLowerCaseNoAccentNoSpace(it.label) == heure);