From 92e844341da1077f6e71a17cb2c7336fbc6a6a59 Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Sun, 5 Oct 2025 23:46:39 -0600 Subject: [PATCH] Extract the Sands changing into a function of the public API for the HUD --- module/Apps/DelveDiceHUD.mjs | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/module/Apps/DelveDiceHUD.mjs b/module/Apps/DelveDiceHUD.mjs index dfa14a5..2be2f59 100644 --- a/module/Apps/DelveDiceHUD.mjs +++ b/module/Apps/DelveDiceHUD.mjs @@ -189,18 +189,7 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) { /** @this {DelveDiceHUD} */ static async #tourDelta(_event, element) { const delta = parseInt(element.dataset.delta); - const initial = game.settings.get(`ripcrypt`, `sandsOfFateInitial`); - let newSands = this._sandsOfFate + delta; - - if (newSands > initial) { - Logger.info(`Cannot go to a previous Delve Tour above the initial value`); - return; - }; - - if (newSands === 0) { - newSands = initial; - await this.alertCrypticEvent(); - }; + await this.sandsOfFateDelta(delta); switch (Math.sign(delta)) { case -1: { @@ -212,9 +201,6 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) { break; } }; - - this.#animateSandsTo(newSands); - game.settings.set(`ripcrypt`, `sandsOfFate`, newSands); }; /** @this {DelveDiceHUD} */ @@ -247,5 +233,27 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) { game.togglePause(true, { broadcast: true }); }; }; + + /** + * Changes the current Sands of Fate by an amount provided, animating the + * @param {number} delta The amount of change + */ + async sandsOfFateDelta(delta) { + const initial = game.settings.get(`ripcrypt`, `sandsOfFateInitial`); + let newSands = this._sandsOfFate + delta; + + if (newSands > initial) { + Logger.info(`Cannot increase the Sands of Fate to a value about the initial`); + return; + }; + + if (newSands === 0) { + newSands = initial; + await this.alertCrypticEvent(); + }; + + this.#animateSandsTo(newSands); + game.settings.set(`ripcrypt`, `sandsOfFate`, newSands); + }; // #endregion };