Get the DicePool to support edge/drag modifications
This commit is contained in:
parent
43fe433900
commit
40ba46fc6b
5 changed files with 126 additions and 5 deletions
|
|
@ -26,6 +26,8 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
actions: {
|
||||
diceCountDelta: this.#diceCountDelta,
|
||||
targetDelta: this.#targetDelta,
|
||||
edgeDelta: this.#edgeDelta,
|
||||
dragDelta: this.#dragDelta,
|
||||
roll: this.#roll,
|
||||
},
|
||||
};
|
||||
|
|
@ -37,6 +39,12 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
target: {
|
||||
template: filePath(`templates/Apps/DicePool/target.hbs`),
|
||||
},
|
||||
drag: {
|
||||
template: filePath(`templates/Apps/DicePool/drag.hbs`),
|
||||
},
|
||||
edge: {
|
||||
template: filePath(`templates/Apps/DicePool/edge.hbs`),
|
||||
},
|
||||
buttons: {
|
||||
template: filePath(`templates/Apps/DicePool/buttons.hbs`),
|
||||
},
|
||||
|
|
@ -46,15 +54,20 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
// #region Instance Data
|
||||
_diceCount;
|
||||
_target;
|
||||
_drag;
|
||||
_edge;
|
||||
|
||||
constructor({
|
||||
diceCount = 1,
|
||||
target,
|
||||
drag = 0, edge = 0,
|
||||
flavor = ``,
|
||||
...opts
|
||||
} = {}) {
|
||||
super(opts);
|
||||
|
||||
this._drag = drag;
|
||||
this._edge = edge;
|
||||
this._flavor = flavor;
|
||||
this._diceCount = diceCount;
|
||||
this._target = target ?? game.settings.get(`ripcrypt`, `dc`) ?? 1;
|
||||
|
|
@ -74,11 +87,19 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
|
||||
switch (partId) {
|
||||
case `numberOfDice`: {
|
||||
this._prepareNumberOfDice(ctx);
|
||||
await this._prepareNumberOfDice(ctx);
|
||||
break;
|
||||
};
|
||||
case `target`: {
|
||||
this._prepareTarget(ctx);
|
||||
await this._prepareTarget(ctx);
|
||||
break;
|
||||
};
|
||||
case `edge`: {
|
||||
await this._prepareEdge(ctx);
|
||||
break;
|
||||
};
|
||||
case `drag`: {
|
||||
await this._prepareDrag(ctx);
|
||||
break;
|
||||
};
|
||||
case `buttons`: {
|
||||
|
|
@ -92,7 +113,7 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
|
||||
async _prepareNumberOfDice(ctx) {
|
||||
ctx.numberOfDice = this._diceCount;
|
||||
ctx.decrementDisabled = this._diceCount <= 0;
|
||||
ctx.decrementDisabled = this._diceCount <= 1;
|
||||
};
|
||||
|
||||
async _prepareTarget(ctx) {
|
||||
|
|
@ -100,6 +121,18 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
ctx.incrementDisabled = this._target >= 8;
|
||||
ctx.decrementDisabled = this._target <= 1;
|
||||
};
|
||||
|
||||
async _prepareEdge(ctx) {
|
||||
ctx.edge = this._edge;
|
||||
ctx.incrementDisabled = false;
|
||||
ctx.decrementDisabled = this._edge <= 0;
|
||||
};
|
||||
|
||||
async _prepareDrag(ctx) {
|
||||
ctx.drag = this._drag;
|
||||
ctx.incrementDisabled = false;
|
||||
ctx.decrementDisabled = this._drag <= 0;
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Actions
|
||||
|
|
@ -137,8 +170,39 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
this.render({ parts: [`target`] });
|
||||
};
|
||||
|
||||
static async #edgeDelta(_event, element) {
|
||||
const delta = parseInt(element.dataset.delta);
|
||||
if (Number.isNaN(delta)) {
|
||||
ui.notifications.error(
|
||||
localizer(`RipCrypt.notifs.error.invalid-delta`, { name: `@RipCrypt.common.edge` }),
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
this._edge += delta;
|
||||
this.render({ parts: [`edge`] });
|
||||
};
|
||||
|
||||
static async #dragDelta(_event, element) {
|
||||
const delta = parseInt(element.dataset.delta);
|
||||
if (Number.isNaN(delta)) {
|
||||
ui.notifications.error(
|
||||
localizer(`RipCrypt.notifs.error.invalid-delta`, { name: `@RipCrypt.common.drag` }),
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
this._drag += delta;
|
||||
this.render({ parts: [`drag`] });
|
||||
};
|
||||
|
||||
static async #roll() {
|
||||
const formula = `${this._diceCount}d8rc${this._target}`;
|
||||
let target = this._target;
|
||||
target -= this._edge;
|
||||
target += this._drag;
|
||||
target = Math.max(target, 1);
|
||||
|
||||
const formula = `${this._diceCount}d8rc${target}`;
|
||||
Logger.debug(`Attempting to roll formula: ${formula}`);
|
||||
|
||||
let flavor = this._flavor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue