mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 07:36:26 +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.moveData = this.moveData;
|
||||
|
||||
const shortRestMovesSelected = Object.values(this.moveData.shortRest.moves).reduce(
|
||||
(acc, x) => acc + (x.selected ?? 0),
|
||||
0
|
||||
);
|
||||
const longRestMovesSelected = Object.values(this.moveData.longRest.moves).reduce(
|
||||
(acc, x) => acc + (x.selected ?? 0),
|
||||
0
|
||||
);
|
||||
const shortRestMovesSelected = this.#nrSelectedMoves('shortRest');
|
||||
const longRestMovesSelected = this.#nrSelectedMoves('longRest');
|
||||
context.nrChoices = {
|
||||
...this.nrChoices,
|
||||
shortRest: {
|
||||
|
|
@ -95,7 +89,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
static selectMove(_, target) {
|
||||
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) {
|
||||
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.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