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", "tough": "Tough",
"hard": "Hard" "hard": "Hard"
}, },
"drag": "Drag",
"edit": "Edit", "edit": "Edit",
"edge": "Edge",
"empty": "---", "empty": "---",
"equipped": "Equipped", "equipped": "Equipped",
"fate": "Fate", "fate": "Fate",

View file

@ -26,6 +26,8 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
actions: { actions: {
diceCountDelta: this.#diceCountDelta, diceCountDelta: this.#diceCountDelta,
targetDelta: this.#targetDelta, targetDelta: this.#targetDelta,
edgeDelta: this.#edgeDelta,
dragDelta: this.#dragDelta,
roll: this.#roll, roll: this.#roll,
}, },
}; };
@ -37,6 +39,12 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
target: { target: {
template: filePath(`templates/Apps/DicePool/target.hbs`), template: filePath(`templates/Apps/DicePool/target.hbs`),
}, },
drag: {
template: filePath(`templates/Apps/DicePool/drag.hbs`),
},
edge: {
template: filePath(`templates/Apps/DicePool/edge.hbs`),
},
buttons: { buttons: {
template: filePath(`templates/Apps/DicePool/buttons.hbs`), template: filePath(`templates/Apps/DicePool/buttons.hbs`),
}, },
@ -46,15 +54,20 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
// #region Instance Data // #region Instance Data
_diceCount; _diceCount;
_target; _target;
_drag;
_edge;
constructor({ constructor({
diceCount = 1, diceCount = 1,
target, target,
drag = 0, edge = 0,
flavor = ``, flavor = ``,
...opts ...opts
} = {}) { } = {}) {
super(opts); super(opts);
this._drag = drag;
this._edge = edge;
this._flavor = flavor; this._flavor = flavor;
this._diceCount = diceCount; this._diceCount = diceCount;
this._target = target ?? game.settings.get(`ripcrypt`, `dc`) ?? 1; this._target = target ?? game.settings.get(`ripcrypt`, `dc`) ?? 1;
@ -74,11 +87,19 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
switch (partId) { switch (partId) {
case `numberOfDice`: { case `numberOfDice`: {
this._prepareNumberOfDice(ctx); await this._prepareNumberOfDice(ctx);
break; break;
}; };
case `target`: { case `target`: {
this._prepareTarget(ctx); await this._prepareTarget(ctx);
break;
};
case `edge`: {
await this._prepareEdge(ctx);
break;
};
case `drag`: {
await this._prepareDrag(ctx);
break; break;
}; };
case `buttons`: { case `buttons`: {
@ -92,7 +113,7 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
async _prepareNumberOfDice(ctx) { async _prepareNumberOfDice(ctx) {
ctx.numberOfDice = this._diceCount; ctx.numberOfDice = this._diceCount;
ctx.decrementDisabled = this._diceCount <= 0; ctx.decrementDisabled = this._diceCount <= 1;
}; };
async _prepareTarget(ctx) { async _prepareTarget(ctx) {
@ -100,6 +121,18 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
ctx.incrementDisabled = this._target >= 8; ctx.incrementDisabled = this._target >= 8;
ctx.decrementDisabled = this._target <= 1; 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 // #endregion
// #region Actions // #region Actions
@ -137,8 +170,39 @@ export class DicePool extends GenericAppMixin(HandlebarsApplicationMixin(Applica
this.render({ parts: [`target`] }); 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() { 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}`); Logger.debug(`Attempting to roll formula: ${formula}`);
let flavor = this._flavor; 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; padding: 8px;
gap: 8px; gap: 8px;
width: 250px; width: 250px;
height: 185px;
} }
--button-background: var(--alt-row-background); --button-background: var(--alt-row-background);