mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Extract method for repeated calculation.
In the downtime dialog, we need to calculate the number of selected moves in several places. This commit extracts a method to handle that, which reduces repetition and hopefully makes the code more readable.
This commit is contained in:
parent
26d412815a
commit
343ee4978b
1 changed files with 7 additions and 9 deletions
|
|
@ -64,14 +64,8 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
||||||
context.selectedActivity = this.selectedActivity;
|
context.selectedActivity = this.selectedActivity;
|
||||||
context.moveData = this.moveData;
|
context.moveData = this.moveData;
|
||||||
|
|
||||||
const shortRestMovesSelected = Object.values(this.moveData.shortRest.moves).reduce(
|
const shortRestMovesSelected = this.#nrSelectedMoves('shortRest');
|
||||||
(acc, x) => acc + (x.selected ?? 0),
|
const longRestMovesSelected = this.#nrSelectedMoves('longRest');
|
||||||
0
|
|
||||||
);
|
|
||||||
const longRestMovesSelected = Object.values(this.moveData.longRest.moves).reduce(
|
|
||||||
(acc, x) => acc + (x.selected ?? 0),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
context.nrChoices = {
|
context.nrChoices = {
|
||||||
...this.nrChoices,
|
...this.nrChoices,
|
||||||
shortRest: {
|
shortRest: {
|
||||||
|
|
@ -95,7 +89,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
||||||
static selectMove(_, target) {
|
static selectMove(_, target) {
|
||||||
const { category, move } = target.dataset;
|
const { category, move } = target.dataset;
|
||||||
|
|
||||||
const nrSelected = Object.values(this.moveData[category].moves).reduce((acc, x) => acc + (x.selected ?? 0), 0);
|
const nrSelected = this.#nrSelectedMoves(category);
|
||||||
|
|
||||||
if (nrSelected + this.nrChoices[category].taken >= this.nrChoices[category].max) {
|
if (nrSelected + this.nrChoices[category].taken >= this.nrChoices[category].max) {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noMoreMoves'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noMoreMoves'));
|
||||||
|
|
@ -181,4 +175,8 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
||||||
this.customActivity = foundry.utils.mergeObject(this.customActivity, formData.object);
|
this.customActivity = foundry.utils.mergeObject(this.customActivity, formData.object);
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nrSelectedMoves(category) {
|
||||||
|
return Object.values(this.moveData[category].moves).reduce((acc, x) => acc + (x.selected ?? 0), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue