From c72a95c15608891b4c78dd987917e993e98a4778 Mon Sep 17 00:00:00 2001 From: Russell Larkin Date: Fri, 15 Nov 2024 22:08:41 +0000 Subject: [PATCH] #137 - #137: Fix error when no config data. --- scripts/activation-costs.js | 14 +++++++------- scripts/actor-sizes.js | 14 +++++++------- scripts/armor-calculations.js | 14 +++++++------- scripts/armor-ids.js | 14 +++++++------- scripts/armor-types.js | 14 +++++++------- scripts/consumable-types.js | 14 +++++++------- scripts/currency.js | 14 +++++++------- scripts/damage-types.js | 14 +++++++------- scripts/feature-types.js | 14 +++++++------- scripts/item-action-types.js | 14 +++++++------- scripts/item-activation-cost-types.js | 14 +++++++------- scripts/item-properties.js | 14 +++++++------- scripts/item-rarity.js | 14 +++++++------- scripts/languages.js | 14 +++++++------- scripts/rolls.js | 16 +++++++++------- scripts/senses.js | 14 +++++++------- scripts/skills.js | 14 +++++++------- scripts/spell-schools.js | 14 +++++++------- scripts/tool-ids.js | 14 +++++++------- scripts/weapon-ids.js | 14 +++++++------- 20 files changed, 142 insertions(+), 140 deletions(-) diff --git a/scripts/activation-costs.js b/scripts/activation-costs.js index b6555e8..e26a4da 100644 --- a/scripts/activation-costs.js +++ b/scripts/activation-costs.js @@ -54,6 +54,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -66,13 +73,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/actor-sizes.js b/scripts/actor-sizes.js index 2d426fd..8f5a003 100644 --- a/scripts/actor-sizes.js +++ b/scripts/actor-sizes.js @@ -52,6 +52,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -67,13 +74,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/armor-calculations.js b/scripts/armor-calculations.js index c8b3afc..535a319 100644 --- a/scripts/armor-calculations.js +++ b/scripts/armor-calculations.js @@ -53,6 +53,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -64,13 +71,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/armor-ids.js b/scripts/armor-ids.js index abb6b4d..10169dc 100644 --- a/scripts/armor-ids.js +++ b/scripts/armor-ids.js @@ -45,6 +45,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -53,13 +60,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/armor-types.js b/scripts/armor-types.js index 34ea43a..ae95205 100644 --- a/scripts/armor-types.js +++ b/scripts/armor-types.js @@ -45,6 +45,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -53,13 +60,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/consumable-types.js b/scripts/consumable-types.js index adcc4f0..7798700 100644 --- a/scripts/consumable-types.js +++ b/scripts/consumable-types.js @@ -45,6 +45,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -55,13 +62,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/currency.js b/scripts/currency.js index 0d8f016..fd7ec83 100644 --- a/scripts/currency.js +++ b/scripts/currency.js @@ -84,6 +84,13 @@ function registerHooks () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -97,13 +104,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/damage-types.js b/scripts/damage-types.js index aca9278..bd94530 100644 --- a/scripts/damage-types.js +++ b/scripts/damage-types.js @@ -52,6 +52,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -66,13 +73,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/feature-types.js b/scripts/feature-types.js index a427b92..859501d 100644 --- a/scripts/feature-types.js +++ b/scripts/feature-types.js @@ -45,6 +45,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -55,13 +62,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/item-action-types.js b/scripts/item-action-types.js index 26c4531..616c44a 100644 --- a/scripts/item-action-types.js +++ b/scripts/item-action-types.js @@ -46,6 +46,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -54,13 +61,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/item-activation-cost-types.js b/scripts/item-activation-cost-types.js index 3c42e7e..006a609 100644 --- a/scripts/item-activation-cost-types.js +++ b/scripts/item-activation-cost-types.js @@ -46,6 +46,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -54,13 +61,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/item-properties.js b/scripts/item-properties.js index 4551cde..ef73a87 100644 --- a/scripts/item-properties.js +++ b/scripts/item-properties.js @@ -87,6 +87,13 @@ function getSettingDefault () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E.itemProperties)) { + resetDnd5eConfig('itemProperties') + } + return + } + const buildConfig = (data) => Object.fromEntries( Object.entries(data) .filter(([_, value]) => value.visible || value.visible === undefined) @@ -125,13 +132,6 @@ export function setConfig (data = null) { ? foundry.utils.deepClone(CONFIG.CUSTOM_DND5E.validProperties) : validProperties - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E.itemProperties)) { - resetDnd5eConfig('itemProperties') - } - return - } - const config = buildConfig(data) config && (CONFIG.DND5E.itemProperties = config) } diff --git a/scripts/item-rarity.js b/scripts/item-rarity.js index 0a6b15a..2732dbe 100644 --- a/scripts/item-rarity.js +++ b/scripts/item-rarity.js @@ -51,6 +51,13 @@ function registerHooks () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -59,13 +66,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/languages.js b/scripts/languages.js index 61aec60..43bb339 100644 --- a/scripts/languages.js +++ b/scripts/languages.js @@ -44,6 +44,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -54,13 +61,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/rolls.js b/scripts/rolls.js index 5611695..702a244 100644 --- a/scripts/rolls.js +++ b/scripts/rolls.js @@ -96,11 +96,13 @@ function registerHooks () { export function isCustomRoll () { const rolls = getSetting(constants.SETTING.ROLLS.KEY) - return (rolls.ability.die && rolls.ability.die !== '1d20') || - (rolls.attack.die && rolls.attack.die !== '1d20') || - (rolls.concentration.die && rolls.concentration.die !== '1d20') || - (rolls.initiative.die && rolls.initiative.die !== '1d20') || - (rolls.savingThrow.die && rolls.savingThrow.die !== '1d20') || - (rolls.skill.die && rolls.skill.die !== '1d20') || - (rolls.tool.die && rolls.tool.die !== '1d20') + if (!rolls) return false + + return (rolls.ability?.die && rolls.ability?.die !== '1d20') || + (rolls.attack?.die && rolls.attack?.die !== '1d20') || + (rolls.concentration?.die && rolls.concentration?.die !== '1d20') || + (rolls.initiative?.die && rolls.initiative?.die !== '1d20') || + (rolls.savingThrow?.die && rolls.savingThrow?.die !== '1d20') || + (rolls.skill?.die && rolls.skill?.die !== '1d20') || + (rolls.tool?.die && rolls.tool?.die !== '1d20') } diff --git a/scripts/senses.js b/scripts/senses.js index 2136af8..4246897 100644 --- a/scripts/senses.js +++ b/scripts/senses.js @@ -89,6 +89,13 @@ function registerHooks () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -97,13 +104,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/skills.js b/scripts/skills.js index dcd55c9..e8d9a37 100644 --- a/scripts/skills.js +++ b/scripts/skills.js @@ -52,6 +52,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -66,13 +73,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/spell-schools.js b/scripts/spell-schools.js index bc87a65..ca0412c 100644 --- a/scripts/spell-schools.js +++ b/scripts/spell-schools.js @@ -52,6 +52,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -65,13 +72,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/tool-ids.js b/scripts/tool-ids.js index 1cdb1ac..db90c67 100644 --- a/scripts/tool-ids.js +++ b/scripts/tool-ids.js @@ -44,6 +44,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -52,13 +59,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config) diff --git a/scripts/weapon-ids.js b/scripts/weapon-ids.js index 050b8ad..6966a0c 100644 --- a/scripts/weapon-ids.js +++ b/scripts/weapon-ids.js @@ -44,6 +44,13 @@ function registerSettings () { * @param {object} data */ export function setConfig (data = null) { + if (checkEmpty(data)) { + if (checkEmpty(CONFIG.DND5E[property])) { + resetDnd5eConfig(property) + } + return + } + const buildConfig = (keys, data) => Object.fromEntries( keys.filter((key) => data[key].visible || data[key].visible === undefined) .map((key) => [ @@ -52,13 +59,6 @@ export function setConfig (data = null) { ]) ) - if (checkEmpty(data)) { - if (checkEmpty(CONFIG.DND5E[property])) { - resetDnd5eConfig(property) - } - return - } - const defaultConfig = foundry.utils.deepClone(CONFIG.CUSTOM_DND5E[property]) const config = buildConfig(Object.keys(data), foundry.utils.mergeObject(defaultConfig, data)) config && (CONFIG.DND5E[property] = config)