Skip to content

Commit

Permalink
Migrate global settings from the scene specific config to game settings
Browse files Browse the repository at this point in the history
  • Loading branch information
UranusBytes committed Sep 11, 2022
1 parent 08cb5ff commit 7911603
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 67 deletions.
19 changes: 15 additions & 4 deletions classes/MaskLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class MaskLayer extends InteractionLayer {
};
this.DEFAULTS = {
visible: false,
blurEnable: true,
blurQuality: 2,
blurRadius: 5,
};
Expand All @@ -34,8 +35,9 @@ export default class MaskLayer extends InteractionLayer {
static get layerOptions() {
//@ts-ignore
return mergeObject(super.layerOptions, {
// ToDo: is ugly hack still needed?
// Ugly hack - render at very high zindex and then re-render at layer init with layerZindex value
zIndex: 2147483647,
zIndex: game.settings.get('simplefog', 'zIndex')
});
}

Expand Down Expand Up @@ -67,13 +69,19 @@ export default class MaskLayer extends InteractionLayer {
this.setTint(this.getTint());
this.setAlpha(this.getAlpha(), true);

// Filters
this.blur = new PIXI.filters.BlurFilter();
this.blur.padding = 0;
this.blur.repeatEdgePixels = true;
this.blur.blur = this.getSetting("blurRadius");
this.blur.quality = this.getSetting("blurQuality");

// Filters
if (this.getSetting("blurEnable")) {
this.baseLayer.filters = [this.blur];
} else {
this.baseLayer.filters = [];
}

//So you can hit escape on the keyboard and it will bring up the menu
this._controlled = {};

Expand All @@ -83,7 +91,6 @@ export default class MaskLayer extends InteractionLayer {
this.baseLayer.mask = this.maskSprite;
this.setFill();

this.baseLayer.filters = [this.blur];

// Allow zIndex prop to function for items on this layer
this.sortableChildren = true;
Expand Down Expand Up @@ -162,7 +169,7 @@ export default class MaskLayer extends InteractionLayer {
simplefogLogDebug('MaskLayer.renderStack')
// If history is blank, do nothing
if (history === undefined) {
this.visible = this.getSetting("autoFog");
this.visible = game.settings.get('simplefog', 'autoEnableSceneFog');
return;
}
// If history is zero, reset scene fog
Expand Down Expand Up @@ -435,4 +442,8 @@ export default class MaskLayer extends InteractionLayer {

this.addChild(this.fogSprite);
}

refreshZIndex() {
canvas.simplefog.zIndex = game.settings.get('simplefog', 'zIndex');
}
}
16 changes: 1 addition & 15 deletions classes/SimplefogConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,13 @@ export default class SimplefogConfig extends FormApplication {
playerTint: hexToWeb(canvas.simplefog.getSetting('playerTint')),
transition: canvas.simplefog.getSetting('transition'),
transitionSpeed: canvas.simplefog.getSetting('transitionSpeed'),
blurEnable: canvas.simplefog.getSetting('blurEnable'),
blurRadius: canvas.simplefog.getSetting('blurRadius'),
blurQuality: canvas.simplefog.getSetting('blurQuality'),
autoVisibility: canvas.simplefog.getSetting('autoVisibility'),
autoFog: canvas.simplefog.getSetting('autoFog'),
autoVisGM: canvas.simplefog.getSetting('autoVisGM'),
vThreshold: Math.round(canvas.simplefog.getSetting('vThreshold') * 100),
layerZindex: canvas.simplefog.getSetting('layerZindex'),
fogTextureFilePath: canvas.simplefog.getSetting('fogTextureFilePath'),
confirmDisablingFog: canvas.simplefog.getSetting( 'confirmDisablingFog'),
enableHotkeys: canvas.simplefog.getSetting('enableHotkeys'),
hotKeyTool: canvas.simplefog.getSetting('hotKeyTool'),
hotKeyToolOptions: {
brush: "Brush",
grid: "Grid",
polygon: "Polygon",
box: "Box",
ellipse: "Ellipse"
},
versionNotification: canvas.simplefog.getSetting('versionNotification')
};
}
Expand Down Expand Up @@ -77,9 +66,6 @@ export default class SimplefogConfig extends FormApplication {
}
});

// If zIndex was changed
canvas.simplefog.zIndex = canvas.simplefog.getSetting('layerZindex');

// If save button was clicked, close app
if (event.submitter?.name === 'submit') {
Object.values(ui.windows).forEach((val) => {
Expand Down
5 changes: 1 addition & 4 deletions classes/SimplefogHUDControlLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export default class SimplefogHUDControlLayer extends InteractionLayer {

static get layerOptions() {
//@ts-ignore
return mergeObject(super.layerOptions, {
// Ugly hack - render at very high zindex (but one below simplefog) and then re-render at zindex below simplefog
zIndex: 2147483646,
});
return super.layerOptions
}
}
11 changes: 11 additions & 0 deletions classes/SimplefogLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ export default class SimplefogLayer extends MaskLayer {
canvas[this.layername].visible = data.flags[this.layername].visible;
}
// React to composite history change
if (hasProperty(data, `flags.${this.layername}.blurEnable`)) {

if (this.baseLayer !== undefined) {
if (this.getSetting("blurEnable")) {
this.baseLayer.filters = [this.blur];
} else {
this.baseLayer.filters = [];
}
}
}
if (hasProperty(data, `flags.${this.layername}.blurRadius`)) {
canvas[this.layername].blur.blur = this.getSetting('blurRadius');
}
Expand Down Expand Up @@ -730,6 +740,7 @@ export default class SimplefogLayer extends MaskLayer {
async draw() {
simplefogLogDebug('SimplefogLayer.draw')
super.draw();
simplefogLogDebug('SimplefogLayer.draw - this', this)
this.addChild(this.boxPreview);
this.addChild(this.ellipsePreview);
this.addChild(this.polygonPreview);
Expand Down
3 changes: 1 addition & 2 deletions js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function setBrushControlPos() {
*/
function toggleSimpleFog() {
simplefogLogDebug('controls.toggleSimpleFog')
if (canvas.simplefog.getSetting("confirmDisablingFog") && canvas.simplefog.getSetting("visible")) {
if (game.settings.get('simplefog', 'confirmFogDisable') && canvas.simplefog.getSetting("visible")) {
let dg = Dialog.confirm({
title: game.i18n.localize('SIMPLEFOG.disableFog'),
content: game.i18n.localize('SIMPLEFOG.confirmDisableFog'),
Expand All @@ -175,7 +175,6 @@ function cancelToggleSimpleFog(result = undefined) {
ui.controls.render();
}


// Reset position when brush controls are rendered or sceneNavigation changes
Hooks.on('renderBrushControls', setBrushControlPos);
Hooks.on('renderSceneNavigation', setBrushControlPos);
Expand Down
4 changes: 2 additions & 2 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function addSimplefogControlToggleListener() {
}

let controlName = getNewControlName();
let toolName = canvas.simplefog.getSetting('hotKeyTool');
let toolName = game.settings.get('simplefog', 'toolHotKeys');

$('li.scene-control[data-control=' + controlName + ']')?.click();
setTimeout(function(){$('ol.sub-controls.active li.control-tool[data-tool=' + toolName + ']')?.click();}, 500);
Expand All @@ -143,7 +143,7 @@ export function addSimplefogControlToggleListener() {
* @returns bool
*/
function areHotkeysEnabled() {
return canvas.simplefog.getSetting('enableHotkeys');
return game.settings.get('simplefog', 'enableHotKeys');
}

/**
Expand Down
56 changes: 54 additions & 2 deletions js/simplefog.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,56 @@ Hooks.once('init', () => {
game.settings.register('simplefog', cfg.name, cfg.data);
});

// Register global config settings
game.settings.register('simplefog', 'confirmFogDisable', {
name: 'Confirm Disabling of Scene Simplefog',
hint: 'When enabled, a confirmation dialog will be displayed before Simplefog can be toggled off for a scene',
scope: 'world',
config: true,
default: true,
type: Boolean
});
game.settings.register('simplefog', 'autoEnableSceneFog', {
name: 'Auto Enable Scene Fog',
hint: 'When enabled, Simplefog will automatically be enabled for a scene when it is first created.',
scope: 'world',
config: true,
default: true,
type: Boolean
});
game.settings.register('simplefog', 'enableHotKeys', {
name: 'Enable Simplefog Hotkeys',
hint: 'When enabled, you will be able to quickly swap to the Simplefog control by using Ctrl+S and toggle the opacity using the hotkey \'T\'',
scope: 'world',
config: true,
default: false,
type: Boolean
});
game.settings.register('simplefog', 'toolHotKeys', {
name: 'Hotkey Tool',
hint: 'When Hotkeys is enabled, define which tool will be selected by using Ctrl+S',
scope: 'world',
config: true,
default: 'brush',
type: String,
choices: {
'brush': 'Brush',
'grid': 'Grid',
'polygon': 'Polygon',
'box': 'Box',
'ellipse': 'Ellipse',
}
});
game.settings.register('simplefog', 'zIndex', {
name: 'Simplefog Z-Index',
hint: 'The z-index determines the order in which various layers are rendered within the Foundry canvas. A higher number will be rendered on top of lower numbered layers (and the objects on that layer). This allows for the adjustment of the z-index to allow for Simple Fog to be rendered above/below other layers; particularly ones added by other modules. Going below 200 will intermingle with Foundry layers such as the foreground image (200), tokens (100), etc... (Default: 220)',
scope: 'world',
config: true,
default: 220,
type: Number,
onChange: SimplefogLayer.refreshZIndex
});

if (isNewerVersion(game.version, "10")) {
CONFIG.Canvas.layers.simplefog = {group: "interface", layerClass: SimplefogLayer};
CONFIG.Canvas.layers.simplefogHUDControls = {group: "interface", layerClass: SimplefogHUDControlLayer};
Expand Down Expand Up @@ -85,8 +135,10 @@ Hooks.once('ready', () => {
SimplefogMigrations.check();

// Fix simplefog zIndex
canvas.simplefog.zIndex = canvas.simplefog.getSetting('layerZindex');
canvas.simplefogHUDControls.zIndex = canvas.simplefog.getSetting('layerZindex') - 1;

canvas.simplefog.refreshZIndex()
// ToDo: why is this set below???
//canvas.simplefogHUDControls.zIndex = canvas.simplefog.getSetting('layerZindex') - 1;

// Move object hud to tokens layer
game.canvas.controls.hud.setParent(game.canvas.simplefogHUDControls)
Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"SIMPLEFOG.opacity": "Opacity",
"SIMPLEFOG.playerFogSettings": "Player Fog Settings",
"SIMPLEFOG.filterSettings": "Filter Settings",
"SIMPLEFOG.blurEnable": "Enable Reveal Blur",
"SIMPLEFOG.blurRadius": "Blur Radius",
"SIMPLEFOG.blurQuality": "Blur Quality",
"SIMPLEFOG.blurQualityDesc": "Higher blur quality improves the appearance of the blur effect, but may cause slower performance.",
Expand Down
43 changes: 5 additions & 38 deletions templates/scene-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ <h3 class="form-header"><i class="fas fa-users"></i> {{localize 'SIMPLEFOG.playe

<h3 class="form-header"><i class="fas fa-filter"></i> {{localize 'SIMPLEFOG.filterSettings'}}</h3>
<div class="form-group">
<label for="blur">{{localize 'SIMPLEFOG.blurRadius'}}</label>
<label for="blurEnable">{{localize 'SIMPLEFOG.blurEnable'}}</label>
<input type='checkbox' {{#if blurEnable}}checked{{/if}} name='blurEnable' />
</div>
<div class="form-group">
<label for="blurRadius">{{localize 'SIMPLEFOG.blurRadius'}}</label>
<input type="range" name="blurRadius" value="{{ blurRadius }}" min="0" max="50" step="1" data-dtype="Number" />
<span class="range-value">{{ blurRadius }}</span>
</div>
Expand Down Expand Up @@ -77,43 +81,6 @@ <h3 class="form-header"><i class="fas fa-low-vision"></i> {{localize 'SIMPLEFOG.
<span class="range-value">{{ vThreshold }}</span>
</div>

<h3 class="form-header"><i class="fas fa-cloud-upload-alt"></i> {{localize 'SIMPLEFOG.autoFogSettings'}}</h3>
<div class="form-group">
<label for="autoFog">{{localize 'SIMPLEFOG.enableAutoFog'}}</label>
<input type='checkbox' {{#if autoFog}}checked{{/if}} name='autoFog' />
<p class="notes">{{ localize 'SIMPLEFOG.autoFogNotes' }}</p>
</div>

<h3 class="form-header"><i class="fas fa-external-link-square-alt"></i> {{localize 'SIMPLEFOG.hotkeySettings'}}</h3>
<div class="form-group">
<label for="enableHotkeys">{{localize 'SIMPLEFOG.enableHotkeys'}}</label>
<input type='checkbox' {{#if enableHotkeys}}checked{{/if}} name='enableHotkeys' />
<p class="notes">{{ localize 'SIMPLEFOG.hotkeyNotes' }}</p>
</div>
<div class="form-group">
<label for="hotKeyTool">{{localize 'SIMPLEFOG.hotKeyToolDesc'}}</label>
<select name="hotKeyTool">
{{selectOptions hotKeyToolOptions selected=hotKeyTool}}
</select>
<p class="notes">{{ localize 'SIMPLEFOG.hotKeyToolNotes' }}</p>
</div>

<h3 class="form-header"><i class="fas fas fa-exclamation-triangle"></i> {{localize 'SIMPLEFOG.confirmDisablingFogSettings'}}</h3>
<div class="form-group">
<label for="autoFog">{{localize 'SIMPLEFOG.confirmDisablingFog'}}</label>
<input type='checkbox' {{#if confirmDisablingFog}}checked{{/if}} name='confirmDisablingFog' />
<p class="notes">{{ localize 'SIMPLEFOG.confirmDisablingFogNotes' }}</p>
</div>

<h3 class="form-header"><i class="fas fa-atom"></i> {{localize 'SIMPLEFOG.advancedSettings'}}</h3>
<div class="form-group">
<label for="configurableZindex">{{localize 'SIMPLEFOG.configurableZindex'}}</label>
<input type="range" name="layerZindex" value="{{ layerZindex }}" min="0" max="500" step="10"
data-dtype="Number" />
<span class="range-value">{{ layerZindex }}</span>
<p class="notes">{{localize 'SIMPLEFOG.configurableZindexNotes'}}</p>
</div>

<hr>
<footer class="sheet-footer flexrow">
<button type="submit" name="saveDefaults">
Expand Down

0 comments on commit 7911603

Please sign in to comment.