This commit is contained in:
WBHarry 2025-09-16 17:00:29 +02:00
parent e7a817f9c0
commit 6bc27ab07d

View file

@ -116,7 +116,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
if (refreshType === RefreshType.Countdown) this.render();
};
canPerformEdit() {
static canPerformEdit() {
if (game.user.isGM) return true;
const noGM = !game.users.find(x => x.isGM && x.active);
@ -140,7 +140,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
}
static async editCountdown(increase, target) {
if (!this.canPerformEdit()) return;
if (!DhCountdowns.canPerformEdit()) return;
const settings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
const countdown = settings.countdowns[target.id];
@ -172,4 +172,37 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
Hooks.off(socketEvent.Refresh, this.cooldownRefresh);
super.close(options);
}
static async updateCountdowns(progressType) {
const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
const updatedCountdowns = Object.keys(countdownSetting.countdowns).reduce((acc, key) => {
const countdown = countdownSetting.countdowns[key];
if (countdown.progress.type === progressType && countdown.progress.current > 0) {
acc.push(key);
}
return acc;
}, []);
const countdownData = countdownSetting.toObject();
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, {
...countdownData,
countdowns: Object.keys(countdownData.countdowns).reduce((acc, key) => {
const countdown = foundry.utils.deepClone(countdownData.countdowns[key]);
if (updatedCountdowns.includes(key)) {
countdown.progress.current -= 1;
}
acc[key] = countdown;
return acc;
}, {})
});
const data = { refreshType: RefreshType.Countdown };
await game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.Refresh,
data
});
Hooks.callAll(socketEvent.Refresh, data);
}
}