ALl features OK, excetp creatures sub-type, WIP3
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user