diff --git a/module/applications/dialogs/downtime.mjs b/module/applications/dialogs/downtime.mjs index 2ed2302c..f7bab430 100644 --- a/module/applications/dialogs/downtime.mjs +++ b/module/applications/dialogs/downtime.mjs @@ -1,3 +1,5 @@ +import { refreshIsAllowed } from '../../helpers/utils.mjs'; + const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV2) { @@ -94,11 +96,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV const actionItems = this.actor.items.reduce((acc, x) => { if (x.system.actions) { const recoverable = x.system.actions.reduce((acc, action) => { - if ( - action.uses.recovery && - ((action.uses.recovery === 'longRest' && !this.shortrest) || - action.uses.recovery === 'shortRest') - ) { + if (refreshIsAllowed([this.shortrest ? 'shortRest' : 'longRest'], action.uses.recovery)) { acc.push({ title: x.name, name: action.name, @@ -120,8 +118,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV if ( x.system.resource && x.system.resource.type && - ((x.system.resource.recovery === 'longRest') === !this.shortrest || - x.system.resource.recovery === 'shortRest') + refreshIsAllowed([this.shortrest ? 'shortRest' : 'longRest'], action.uses.recovery) ) { acc.push({ title: game.i18n.localize(`TYPES.Item.${x.type}`), diff --git a/module/applications/sidebar/tabs/daggerheartMenu.mjs b/module/applications/sidebar/tabs/daggerheartMenu.mjs index 4166614d..6c7a9df1 100644 --- a/module/applications/sidebar/tabs/daggerheartMenu.mjs +++ b/module/applications/sidebar/tabs/daggerheartMenu.mjs @@ -1,3 +1,5 @@ +import { refreshIsAllowed } from '../../../helpers/utils.mjs'; + const { HandlebarsApplicationMixin } = foundry.applications.api; const { AbstractSidebarTab } = foundry.applications.sidebar; /** @@ -58,7 +60,7 @@ export default class DaggerheartMenu extends HandlebarsApplicationMixin(Abstract if (['character', 'adversary'].includes(actor.type) && actor.prototypeToken.actorLink) { const updates = {}; for (let item of actor.items) { - if (item.system.metadata?.hasResource && types.includes(item.system.resource?.recovery)) { + if (item.system.metadata?.hasResource && refreshIsAllowed(types, item.system.resource?.recovery)) { if (!refreshedActors[actor.id]) refreshedActors[actor.id] = { name: actor.name, img: actor.img, refreshed: new Set() }; refreshedActors[actor.id].refreshed.add( @@ -79,7 +81,7 @@ export default class DaggerheartMenu extends HandlebarsApplicationMixin(Abstract if (item.system.metadata?.hasActions) { const refreshTypes = new Set(); const actions = item.system.actions.filter(action => { - if (types.includes(action.uses.recovery)) { + if (refreshIsAllowed(types, action.uses.recovery)) { refreshTypes.add(action.uses.recovery); return true; } diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index e2ce9904..40d88c5b 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -451,3 +451,20 @@ export async function waitForDiceSoNice(message) { await game.dice3d.waitFor3DAnimationByMessageID(message.id); } } + +export function refreshIsAllowed(allowedTypes, typeToCheck) { + switch (typeToCheck) { + case CONFIG.DH.GENERAL.refreshTypes.scene.id: + case CONFIG.DH.GENERAL.refreshTypes.session.id: + case CONFIG.DH.GENERAL.refreshTypes.longRest.id: + return allowedTypes.includes(typeToCheck); + case CONFIG.DH.GENERAL.refreshTypes.shortRest.id: + return allowedTypes.some( + x => + x === CONFIG.DH.GENERAL.refreshTypes.shortRest.id || + x === CONFIG.DH.GENERAL.refreshTypes.longRest.id + ); + default: + return false; + } +}