From 334ab3e2fed97bae28678c6641d6881275b49f2b Mon Sep 17 00:00:00 2001 From: arcanist Date: Tue, 3 May 2022 15:11:55 -0400 Subject: [PATCH] Configure options for compatibility warning logs (#44) * feat: compatibility warnings Signed-off-by: arcanist * feat: compatibility warnings Signed-off-by: arcanist * feat: compatibility warnings Signed-off-by: arcanist * feat: compatibility warnings Signed-off-by: arcanist * feat: return v9 compatibility Signed-off-by: arcanist --- foundryvtt-devMode.mjs | 2 ++ lang/en.json | 7 +++++++ module.json | 2 +- module/classes/DevMode.mjs | 22 ++++++++++++++++++++ module/classes/DevModeConfig.mjs | 28 +++++++++++++++++++++++-- module/classes/DevModeSettings.mjs | 13 ++++++++++++ templates/settings.hbs | 33 ++++++++++++++++++++++++++++++ 7 files changed, 104 insertions(+), 3 deletions(-) diff --git a/foundryvtt-devMode.mjs b/foundryvtt-devMode.mjs index 364da3c..fffaed5 100644 --- a/foundryvtt-devMode.mjs +++ b/foundryvtt-devMode.mjs @@ -30,6 +30,8 @@ Hooks.once('init', function () { DevMode.setDebugOverrides(); + DevMode.setCompatibilityWarnings(); + game.modules.get(DevMode.MODULE_ID).api = DevMode.API; // register any modules as they init diff --git a/lang/en.json b/lang/en.json index c86bfbf..fbdafe4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -11,6 +11,7 @@ "ConfigDebug": "CONFIG.debug Overrides", "PackageSpecific": "Package Specific Debugging", "PerformanceTesting": "Performance", + "CompatibilityWarnings": "Compatibility Warnings", "LogLevel": "Select Log Level", "DebugMode": "Enable Debug Mode", "Hint": "Packages can register a debug mode setting which will appear below. Checking it or setting a log level will enable more detailed output in the console.", @@ -22,6 +23,12 @@ "label": "Actor CRUD Test", "hint": "Runs Actor.create, update, and delete repeatedly, outputs how long the total operation takes, as well as average per operation." } + }, + "compatibility": { + "mode": "Compatibility Mode", + "includePatterns": "Includes", + "excludePatterns": "Excludes", + "hint": "Enter a comma-separated list of regular expressions to match against the stack trace of the compatibility warning logs. Any log that matches the included patterns will be included, and any log that matches the exclude patterns will be excluded." } }, "settings": { diff --git a/module.json b/module.json index c51c677..2a7bec0 100755 --- a/module.json +++ b/module.json @@ -20,7 +20,7 @@ }, "version": "1.13.0", "minimumCoreVersion": "9", - "compatibleCoreVersion": "9", + "compatibleCoreVersion": "10", "scripts": [], "esmodules": ["foundryvtt-devMode.mjs"], "styles": ["foundryvtt-devMode.css"], diff --git a/module/classes/DevMode.mjs b/module/classes/DevMode.mjs index cc61aa6..44b47bb 100644 --- a/module/classes/DevMode.mjs +++ b/module/classes/DevMode.mjs @@ -24,6 +24,7 @@ export class DevMode { debugOverrides: 'debug-overrides', overrideConfigDebug: 'override-config-debug', packageSpecificDebug: 'package-specific-debug', + compatibilityWarnings: 'compatibility-warnings', suppressTooSmall: 'suppress-too-small', showDirectoryIds: 'show-directory-ids', showCompendiumIds: 'show-compendium-ids', @@ -192,4 +193,25 @@ export class DevMode { this.log(false, 'setDebugOverride', debugKey, 'to', relevantSetting); }); } + + /** + * Sets CONFIG.compatibility value to match the value stored in settings + */ + static setCompatibilityWarnings() { + const compatibilityWarnings = game.settings.get(this.MODULE_ID, this.SETTINGS.compatibilityWarnings); + if (isObjectEmpty(compatibilityWarnings) || !CONFIG.compatibility) return; + + // set all compatibility values to match settings + CONFIG.compatibility.mode = compatibilityWarnings.mode; + CONFIG.compatibility.includePatterns = compatibilityWarnings.includePatterns + ?.split(',') + .filter(s => String(s)) + .map(s => new RegExp(s.trim())); + CONFIG.compatibility.excludePatterns = compatibilityWarnings.excludePatterns + ?.split(',') + .filter(s => String(s)) + .map(s => new RegExp(s.trim())); + + this.log(false, 'setCompatibilityWarnings', compatibilityWarnings); + } } diff --git a/module/classes/DevModeConfig.mjs b/module/classes/DevModeConfig.mjs index 3d1a2df..f15f930 100644 --- a/module/classes/DevModeConfig.mjs +++ b/module/classes/DevModeConfig.mjs @@ -34,6 +34,11 @@ export class DevModeConfig extends FormApplication { return game.settings.get(DevMode.MODULE_ID, DevMode.SETTINGS.debugOverrides); } + get compatibilityWarnings() { + const settings = game.settings.get(DevMode.MODULE_ID, DevMode.SETTINGS.compatibilityWarnings) + return isObjectEmpty(settings) ? CONFIG.compatibility : settings; + } + /** * A helper to generate the names and hints of any debug key which has those defined * @@ -162,6 +167,12 @@ export class DevModeConfig extends FormApplication { isCheckbox: true, }); + const compatibilityWarningsData = { + enabled: game.release.generation >= 10, + modes: CONST.COMPATIBILITY_MODES, + ...this.compatibilityWarnings, + }; + const data = { ...super.getData(), packageSpecificDebugFormData, @@ -171,11 +182,13 @@ export class DevModeConfig extends FormApplication { types[type] = `ACTOR.Type${type.capitalize()}`; return types; }, {}), + compatibilityWarningsData, }; DevMode.log(false, data, { debugOverrides: this.debugOverrides, packageSpecificDebug: this.packageSpecificDebug, + compatibilityWarnings: this.compatibilityWarnings, }); return data; } @@ -187,6 +200,7 @@ export class DevModeConfig extends FormApplication { if (event.currentTarget?.dataset?.action === 'reset') { await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.packageSpecificDebug, {}); await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.debugOverrides, CONFIG.debug); + await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.compatibilityWarnings, {}); window.location.reload(); } @@ -206,11 +220,11 @@ export class DevModeConfig extends FormApplication { } async _updateObject(ev, formData) { - const { packageSpecificDebugFormData, debugOverrideFormData, overrideConfigDebug } = expandObject(formData); + const { packageSpecificDebugFormData, debugOverrideFormData, overrideConfigDebug, compatibilityWarnings } = expandObject(formData); DevMode.log(false, { formData, - data: { packageSpecificDebugFormData, debugOverrideFormData, overrideConfigDebug }, + data: { packageSpecificDebugFormData, debugOverrideFormData, overrideConfigDebug, compatibilityWarnings }, }); const newPackageSpecificDebug = mergeObject(this.packageSpecificDebug, packageSpecificDebugFormData, { @@ -229,14 +243,24 @@ export class DevModeConfig extends FormApplication { recursive: true, }); + const newCompatibilityWarnings = mergeObject(this.compatibilityWarnings, compatibilityWarnings, { + inplace: false, + insertKeys: true, + insertValues: true, + overwrite: true, + recursive: true, + }); + DevMode.log(true, 'setting settings', { newPackageSpecificDebug, newDebugOverrides, + newCompatibilityWarnings, }); await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.overrideConfigDebug, overrideConfigDebug); await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.packageSpecificDebug, newPackageSpecificDebug); await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.debugOverrides, newDebugOverrides); + await game.settings.set(DevMode.MODULE_ID, DevMode.SETTINGS.compatibilityWarnings, newCompatibilityWarnings); this.close(); } diff --git a/module/classes/DevModeSettings.mjs b/module/classes/DevModeSettings.mjs index a5c80d9..b749a3a 100644 --- a/module/classes/DevModeSettings.mjs +++ b/module/classes/DevModeSettings.mjs @@ -109,6 +109,19 @@ export class DevModeSettings { onChange: () => DevMode.setDebugOverrides(), }); + // register the setting where we'll store all compatibility warning Flags + game.settings.register(DevMode.MODULE_ID, DevMode.SETTINGS.compatibilityWarnings, { + default: { + mode: CONST.COMPATIBILITY_MODES?.WARNING ?? 1, + includePatterns: "", + excludePatterns: "", + }, + type: Object, + scope: 'client', + config: false, + onChange: () => DevMode.setCompatibilityWarnings(), + }); + this.booleanSettings.forEach(({ key, ...rest }) => { game.settings.register(DevMode.MODULE_ID, key, { name: `${DevMode.MODULE_ABBREV}.settings.${key}.Name`, diff --git a/templates/settings.hbs b/templates/settings.hbs index f76ac85..1f5391d 100644 --- a/templates/settings.hbs +++ b/templates/settings.hbs @@ -30,6 +30,9 @@ {{localize 'DEV.configMenu.ConfigDebug'}} {{localize 'DEV.configMenu.PackageSpecific'}} {{localize 'DEV.configMenu.PerformanceTesting'}} + {{#if compatibilityWarningsData.enabled}} + {{localize 'DEV.configMenu.CompatibilityWarnings'}} + {{/if}}
@@ -102,6 +105,36 @@

{{localize 'DEV.configMenu.performance.actorCRUD.hint'}}

+ + {{#if compatibilityWarningsData.enabled}} +
+
+ +
+
+ +
+
+ +
+

{{localize 'DEV.configMenu.compatibility.hint'}}

+
+ + +
+
+ {{/if}}