diff --git a/module/applications/dialogs/downtime.mjs b/module/applications/dialogs/downtime.mjs index d046146a..163af03e 100644 --- a/module/applications/dialogs/downtime.mjs +++ b/module/applications/dialogs/downtime.mjs @@ -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); + } }