Extract the Sands changing into a function of the public API for the HUD

This commit is contained in:
Eldritch-Oliver 2025-10-05 23:46:39 -06:00
parent 5c95fec201
commit 92e844341d

View file

@ -189,18 +189,7 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) {
/** @this {DelveDiceHUD} */ /** @this {DelveDiceHUD} */
static async #tourDelta(_event, element) { static async #tourDelta(_event, element) {
const delta = parseInt(element.dataset.delta); const delta = parseInt(element.dataset.delta);
const initial = game.settings.get(`ripcrypt`, `sandsOfFateInitial`); await this.sandsOfFateDelta(delta);
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();
};
switch (Math.sign(delta)) { switch (Math.sign(delta)) {
case -1: { case -1: {
@ -212,9 +201,6 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) {
break; break;
} }
}; };
this.#animateSandsTo(newSands);
game.settings.set(`ripcrypt`, `sandsOfFate`, newSands);
}; };
/** @this {DelveDiceHUD} */ /** @this {DelveDiceHUD} */
@ -247,5 +233,27 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) {
game.togglePause(true, { broadcast: true }); 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 // #endregion
}; };