Skip to content

Commit

Permalink
Configure options for compatibility warning logs (#44)
Browse files Browse the repository at this point in the history
* feat: compatibility warnings

Signed-off-by: arcanist <[email protected]>

* feat: compatibility warnings

Signed-off-by: arcanist <[email protected]>

* feat: compatibility warnings

Signed-off-by: arcanist <[email protected]>

* feat: compatibility warnings

Signed-off-by: arcanist <[email protected]>

* feat: return v9 compatibility

Signed-off-by: arcanist <[email protected]>
  • Loading branch information
arcanistzed authored May 3, 2022
1 parent 5562d8f commit 334ab3e
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 3 deletions.
2 changes: 2 additions & 0 deletions foundryvtt-devMode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"version": "1.13.0",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"compatibleCoreVersion": "10",
"scripts": [],
"esmodules": ["foundryvtt-devMode.mjs"],
"styles": ["foundryvtt-devMode.css"],
Expand Down
22 changes: 22 additions & 0 deletions module/classes/DevMode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
}
28 changes: 26 additions & 2 deletions module/classes/DevModeConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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();
}

Expand All @@ -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, {
Expand All @@ -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();
}
Expand Down
13 changes: 13 additions & 0 deletions module/classes/DevModeSettings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
33 changes: 33 additions & 0 deletions templates/settings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<a class='item' data-tab='config'>{{localize 'DEV.configMenu.ConfigDebug'}}</a>
<a class='item' data-tab='packages'>{{localize 'DEV.configMenu.PackageSpecific'}}</a>
<a class='item' data-tab='performance'>{{localize 'DEV.configMenu.PerformanceTesting'}}</a>
{{#if compatibilityWarningsData.enabled}}
<a class='item' data-tab='compatibility'>{{localize 'DEV.configMenu.CompatibilityWarnings'}}</a>
{{/if}}
</nav>

<section class='tab' data-tab='config'>
Expand Down Expand Up @@ -102,6 +105,36 @@
</div>
<p class="notes">{{localize 'DEV.configMenu.performance.actorCRUD.hint'}}</p>
</section>

{{#if compatibilityWarningsData.enabled}}
<section class='tab' data-tab='compatibility'>
<div class="flexrow form-group">
<label class="flexrow flex3" style="gap: 1em">
{{localize 'DEV.configMenu.compatibility.mode'}}
<select name="compatibilityWarnings.mode" data-dtype="Number">
{{selectOptions compatibilityWarningsData.modes selected=compatibilityWarningsData.mode inverted=true}}
</select>
</label>
</div>
<div class="flexrow form-group">
<label class="flexrow flex3" style="gap: 1em">
{{localize 'DEV.configMenu.compatibility.includePatterns'}}
<input type="text" name="compatibilityWarnings.includePatterns" class="form-fields" value="{{compatibilityWarningsData.includePatterns}}">
</label>
</div>
<div class="flexrow form-group">
<label class="flexrow flex3" style="gap: 1em">
{{localize 'DEV.configMenu.compatibility.excludePatterns'}}
<input type="text" name="compatibilityWarnings.excludePatterns" class="form-fields" value="{{compatibilityWarningsData.excludePatterns}}">
</label>
</div>
<p class="notes">{{localize 'DEV.configMenu.compatibility.hint'}}</p>
<div class="flexrow">
<button type='submit'><i class="fas fa-save"></i> {{localize 'SETTINGS.Save'}}</button>
<button type='button' data-action="reset"><i class="fas fa-undo"></i> {{localize 'SETTINGS.Reset'}}</button>
</div>
</section>
{{/if}}
</div>

</form>

0 comments on commit 334ab3e

Please sign in to comment.