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