mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-30 02:31:41 -04:00
28: Fix issue with reserved groups
This commit is contained in:
parent
7d8eb74ee7
commit
6eee073a24
3 changed files with 22 additions and 7 deletions
|
@ -14,6 +14,7 @@
|
|||
"SIMPLE.NotifyGroupDuplicate": "Attribute group already exists.",
|
||||
"SIMPLE.NotifyGroupAttrDuplicate": "Attribute group already exists as an attribute.",
|
||||
"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.ResourceMin": "Min",
|
||||
|
|
|
@ -49,7 +49,6 @@ export class SimpleActor extends Actor {
|
|||
if ( !!shorthand ) {
|
||||
delete data.attributes;
|
||||
delete data.attr;
|
||||
delete data.abil;
|
||||
delete data.groups;
|
||||
}
|
||||
return data;
|
||||
|
@ -211,11 +210,11 @@ export class SimpleActor extends Actor {
|
|||
}
|
||||
// Non-grouped attributes.
|
||||
if ( data.attributes[k]?.value ) {
|
||||
data.attributes[k].value = Roll.replaceFormulaData(data.attributes[k].value, data);
|
||||
data.attributes[k].value = Roll.replaceFormulaData(String(data.attributes[k].value), data);
|
||||
}
|
||||
// Grouped attributes.
|
||||
else if ( attr ) {
|
||||
data.attributes[k][attr].value = Roll.replaceFormulaData(data.attributes[k][attr].value, data);
|
||||
data.attributes[k][attr].value = Roll.replaceFormulaData(String(data.attributes[k][attr].value), data);
|
||||
}
|
||||
|
||||
// Duplicate values to shorthand.
|
||||
|
|
|
@ -244,6 +244,12 @@ export class EntitySheetHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Check for reserved group names.
|
||||
if ( ["attr", "attributes"].includes(groupName) ) {
|
||||
ui.notifications.error(game.i18n.format("SIMPLE.NotifyGroupReserved", {key: groupName}));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for whitespace or periods.
|
||||
if ( groupName.match(/[\s|\.]/i) ) {
|
||||
ui.notifications.error(game.i18n.localize("SIMPLE.NotifyGroupAlphanumeric"));
|
||||
|
@ -481,6 +487,7 @@ export class EntitySheetHelper {
|
|||
static updateGroups(formData, document) {
|
||||
// Handle the free-form groups list
|
||||
const formGroups = expandObject(formData).data.groups || {};
|
||||
const documentGroups = Object.keys(document.data.data.groups || {});
|
||||
const groups = Object.values(formGroups).reduce((obj, v) => {
|
||||
// If there are duplicate groups, collapse them.
|
||||
if ( Array.isArray(v["key"]) ) {
|
||||
|
@ -488,16 +495,24 @@ export class EntitySheetHelper {
|
|||
}
|
||||
// Trim and clean up.
|
||||
let k = v["key"].trim();
|
||||
if ( /[\s\.]/.test(k) ) return ui.notifications.error("Group keys may not contain spaces or periods");
|
||||
// Validate groups.
|
||||
let isValidGroup = true;
|
||||
// Skip validation for existing/duplicate groups since they're collapsed above.
|
||||
if ( !documentGroups.includes(k) ) {
|
||||
isValidGroup = this.validateGroup(k, document);
|
||||
}
|
||||
// Delete the key and add the group to the reducer if valid.
|
||||
delete v["key"];
|
||||
obj[k] = v;
|
||||
if (isValidGroup) obj[k] = v;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
// Remove groups which are no longer used
|
||||
if (groups) {
|
||||
for ( let k of Object.keys(document.data.data.groups)) {
|
||||
if ( !groups.hasOwnProperty(k) ) groups[`-=${k}`] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-combine formData
|
||||
formData = Object.entries(formData).filter(e => !e[0].startsWith("data.groups")).reduce((obj, e) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue