mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-30 02:31:41 -04:00
[#46] Fix sheets entering an inconsistent state if they throw an error during form data marshalling.
This commit is contained in:
parent
0996cf810c
commit
2bd28e939d
2 changed files with 17 additions and 5 deletions
|
@ -16,6 +16,7 @@
|
|||
"SIMPLE.NotifyGroupAlphanumeric": "Attribute group names may not contain spaces or periods.",
|
||||
"SIMPLE.NotifyGroupReserved": "Attribute group \"{key}\" is reserved and cannot be used.",
|
||||
"SIMPLE.NotifyAttrDuplicate": "Attribute key already exists as a group.",
|
||||
"SIMPLE.NotifyAttrInvalid": "Attribute keys may not contain spaces or periods.",
|
||||
|
||||
"SIMPLE.ResourceMin": "Min",
|
||||
"SIMPLE.ResourceValue": "Value",
|
||||
|
|
|
@ -429,8 +429,7 @@ export class EntitySheetHelper {
|
|||
group = v[attrKey]['group'];
|
||||
groupKeys.push(group);
|
||||
let attr = v[attrKey];
|
||||
let k = v[attrKey]["key"] ? v[attrKey]["key"].trim() : attrKey.trim();
|
||||
if ( /[\s\.]/.test(k) ) return ui.notifications.error("Attribute keys may not contain spaces or periods");
|
||||
const k = this.cleanKey(v[attrKey]["key"] ? v[attrKey]["key"].trim() : attrKey.trim());
|
||||
delete attr["key"];
|
||||
// Add the new attribute if it's grouped, but we need to build the nested structure first.
|
||||
if ( !obj[group] ) {
|
||||
|
@ -441,8 +440,7 @@ export class EntitySheetHelper {
|
|||
}
|
||||
// Handle attribute keys for ungrouped attributes.
|
||||
else {
|
||||
let k = v["key"].trim();
|
||||
if ( /[\s\.]/.test(k) ) return ui.notifications.error("Attribute keys may not contain spaces or periods");
|
||||
const k = this.cleanKey(v["key"].trim());
|
||||
delete v["key"];
|
||||
// Add the new attribute only if it's ungrouped.
|
||||
if ( !group ) {
|
||||
|
@ -588,4 +586,17 @@ export class EntitySheetHelper {
|
|||
foundry.utils.setProperty(attrs, attr, Math.clamped(value, current.min || 0, current.max || 0));
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Clean an attribute key, emitting an error if it contained invalid characters.
|
||||
* @param {string} key The key to clean.
|
||||
* @returns {string}
|
||||
*/
|
||||
static cleanKey(key) {
|
||||
const clean = key.replace(/[\s.]/g, "");
|
||||
if ( clean !== key ) ui.notifications.error("SIMPLE.NotifyAttrInvalid", { localize: true });
|
||||
return clean;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue