Get the DicePool to support edge/drag modifications

This commit is contained in:
Oliver-Akins 2025-02-20 00:29:02 -07:00
parent 43fe433900
commit 40ba46fc6b
5 changed files with 126 additions and 5 deletions

View file

@ -64,7 +64,9 @@
"tough": "Tough",
"hard": "Hard"
},
"drag": "Drag",
"edit": "Edit",
"edge": "Edge",
"empty": "---",
"equipped": "Equipped",
"fate": "Fate",

View file

@ -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;

View file

@ -0,0 +1,28 @@
<div>
<rc-border
var:border-color="var(--accent-1)"
>
<div slot="title">
{{ rc-i18n "RipCrypt.common.drag" }}
</div>
<div slot="content">
<button
type="button"
data-action="dragDelta"
data-delta="-1"
{{#if decrementDisabled}}disabled{{/if}}
>
-
</button>
<span>{{drag}}</span>
<button
type="button"
data-action="dragDelta"
data-delta="1"
{{#if incrementDisabled}}disabled{{/if}}
>
+
</button>
</div>
</rc-border>
</div>

View file

@ -0,0 +1,28 @@
<div>
<rc-border
var:border-color="var(--accent-1)"
>
<div slot="title">
{{ rc-i18n "RipCrypt.common.edge" }}
</div>
<div slot="content">
<button
type="button"
data-action="edgeDelta"
data-delta="-1"
{{#if decrementDisabled}}disabled{{/if}}
>
-
</button>
<span>{{edge}}</span>
<button
type="button"
data-action="edgeDelta"
data-delta="not a number"
{{#if incrementDisabled}}disabled{{/if}}
>
+
</button>
</div>
</rc-border>
</div>

View file

@ -7,7 +7,6 @@
padding: 8px;
gap: 8px;
width: 250px;
height: 185px;
}
--button-background: var(--alt-row-background);