Skip to content

Commit 667e822

Browse files
committed
FIX - effects secondaries
1 parent 758bb30 commit 667e822

26 files changed

Lines changed: 769 additions & 1009 deletions

src/module/actor/ABFActorSheet.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ export default class ABFActorSheet extends ActorSheet {
6666
return 'systems/animabf/templates/actor/actor-sheet.hbs';
6767
}
6868

69-
async close(options) {
70-
super.close(options);
69+
async close(options = {}) {
70+
// Cancel any pending debounced update
71+
this._flushPendingUpdate?.cancel?.();
72+
this._pendingUpdate = {};
73+
74+
await super.close({ ...options, submit: false });
7175

7276
this.position.width = this.getWidthDependingFromContent();
7377
}
@@ -151,8 +155,9 @@ export default class ABFActorSheet extends ActorSheet {
151155
}
152156

153157
_setupDebouncedSheetUpdates(html) {
154-
this._pendingUpdate = this._pendingUpdate ?? {};
158+
this._pendingUpdate = {};
155159

160+
// Build debounce once
156161
this._flushPendingUpdate =
157162
this._flushPendingUpdate ??
158163
foundry.utils.debounce(async () => {
@@ -170,29 +175,21 @@ export default class ABFActorSheet extends ActorSheet {
170175
}
171176
}, 150);
172177

173-
html.on('change', 'input, select, textarea', ev => {
178+
// IMPORTANT: remove previous handlers for this sheet instance
179+
html.off('change.animabf');
180+
181+
html.on('change.animabf', 'input, select, textarea', ev => {
174182
const el = ev.currentTarget;
175183
if (!el?.name) return;
176184

177-
let value;
178-
179-
if (el.type === 'checkbox') {
180-
value = el.checked;
181-
} else {
182-
value = el.value;
183-
}
185+
let value = el.type === 'checkbox' ? el.checked : el.value;
184186

185-
// Respect Foundry-style dtype (works for <select> too)
186187
const dtype = el.dataset?.dtype;
187-
188-
if (dtype === 'Number') {
188+
if (dtype === 'Number' || el.type === 'number') {
189189
const n = Number(value);
190190
value = Number.isFinite(n) ? n : 0;
191191
} else if (dtype === 'Boolean') {
192192
value = value === 'true' || value === true;
193-
} else if (el.type === 'number') {
194-
const n = Number(value);
195-
value = Number.isFinite(n) ? n : 0;
196193
}
197194

198195
this._pendingUpdate[el.name] = value;

0 commit comments

Comments
 (0)