Fix fiche creature

This commit is contained in:
2026-06-07 23:51:31 +02:00
parent 6dea5ba479
commit 939247e731
80 changed files with 233 additions and 261 deletions
@@ -81,6 +81,47 @@ export default class MournbladeCYD2ActorSheetV2 extends HandlebarsApplicationMix
tabGroups = { primary: "stats" };
/**
* Intercept form data before ActorSheetV2 validates it, to sanitize
* empty numeric fields that would otherwise fail DataModel validation.
* Mirrors the same logic in MournbladeCYD2Actor._preUpdate.
* @override
*/
_prepareSubmitData(event, form, formData) {
const fd = formData ?? new foundry.applications.ux.FormDataExtended(form);
const data = {};
for (const [k, v] of fd) {
foundry.utils.setProperty(data, k, v);
}
this._sanitizeNumericData(data);
this.document.validate(data, { partial: true });
return data;
}
/**
* Walk submitted data and convert empty/invalid values in NumberField
* paths to 0 so schema validation passes.
* @param {object} data
*/
_sanitizeNumericData(data) {
if (!data?.system || typeof data.system !== "object") return;
const fields = this.document.system.schema.fields;
for (const [schemaPath, schemaField] of Object.entries(fields)) {
if (!(schemaField instanceof foundry.data.fields.SchemaField)) continue;
const branch = data.system[schemaPath];
if (!branch || typeof branch !== "object") continue;
for (const [key, value] of Object.entries(branch)) {
if (schemaField.fields[key] instanceof foundry.data.fields.NumberField) {
if (value === "" || value === null || value === undefined || isNaN(value)) {
data.system[schemaPath][key] = 0;
} else {
data.system[schemaPath][key] = Number(value);
}
}
}
}
}
/** @override */
async _prepareContext() {
const actor = this.document;