ALl features OK, excetp creatures sub-type, WIP3

This commit is contained in:
2026-06-07 23:29:02 +02:00
parent 494ec3ea84
commit 6dea5ba479
86 changed files with 497 additions and 234 deletions
+30
View File
@@ -273,6 +273,36 @@ export class MournbladeCYD2Actor extends Actor {
/* -------------------------------------------- */
_preUpdate(changed, options, user) {
// Clean up numeric fields in various schemas to ensure they are valid numbers
const numericCleanup = (schemaPath, dataPath) => {
if (changed?.system?.[dataPath]) {
const schema = foundry.utils.getProperty(this.system.schema.fields, schemaPath);
if (schema) {
for (const [key, value] of Object.entries(changed.system[dataPath])) {
if (schema.fields[key] instanceof foundry.data.fields.NumberField) {
if (value === "" || value === null || value === undefined || isNaN(value)) {
changed.system[dataPath][key] = 0;
} else {
changed.system[dataPath][key] = Number(value);
}
}
}
}
}
};
// Apply cleanup to schemas that may have numeric fields submitted from forms
numericCleanup("sante", "sante");
numericCleanup("ame", "ame");
numericCleanup("combat", "combat");
numericCleanup("balance", "balance");
numericCleanup("adversite", "adversite");
numericCleanup("vitesse", "vitesse");
numericCleanup("ressources", "ressources");
numericCleanup("eclat", "eclat");
numericCleanup("bonneaventure", "bonneaventure");
numericCleanup("experience", "experience");
if (changed?.system?.sante?.etat !== undefined && changed.system.sante.etat != this.system.sante.etat) {
const oldEtat = this.system.sante.etat
setTimeout(() => {