Extract the Sands changing into a function of the public API for the HUD
This commit is contained in:
parent
5c95fec201
commit
92e844341d
1 changed files with 23 additions and 15 deletions
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue