Sync countdown current with max when equal (#1221)

This commit is contained in:
Carlos Fernandez 2025-10-19 09:16:18 -04:00 committed by GitHub
parent 5fc04909de
commit ffac498609
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View file

@ -110,6 +110,18 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
static async updateData(_event, _, formData) {
const { hideNewCountdowns, ...settingsData } = foundry.utils.expandObject(formData.object);
// Sync current and max if max is changing and they were equal before
for (const [id, countdown] of Object.entries(settingsData.countdowns ?? {})) {
const existing = this.data.countdowns[id];
const wasEqual = existing && existing.progress.current === existing.progress.max;
if (wasEqual && countdown.progress.max !== existing.progress.max) {
countdown.progress.current = countdown.progress.max;
} else {
countdown.progress.current = Math.min(countdown.progress.current, countdown.progress.max);
}
}
this.hideNewCountdowns = hideNewCountdowns;
this.updateSetting(settingsData);
}