From 8422388825e463b4d1821333704e8de92f757ad8 Mon Sep 17 00:00:00 2001 From: dev7355608 Date: Thu, 9 May 2024 18:27:07 +0200 Subject: [PATCH] Update for latest V12 --- module.json | 6 ++--- script.js | 77 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/module.json b/module.json index c72f24b..9581e8d 100644 --- a/module.json +++ b/module.json @@ -8,7 +8,7 @@ "email": "dev7355608@gmail.com" } ], - "version": "1.1.1", + "version": "1.1.2", "compatibility": { "minimum": "10", "verified": "12" @@ -18,8 +18,8 @@ ], "url": "https://github.com/dev7355608/gm-vision", "manifest": "https://github.com/dev7355608/gm-vision/releases/latest/download/module.json", - "download": "https://github.com/dev7355608/gm-vision/releases/download/v1.1.1/module.zip", - "changelog": "https://github.com/dev7355608/gm-vision/releases/tag/v1.1.1", + "download": "https://github.com/dev7355608/gm-vision/releases/download/v1.1.2/module.zip", + "changelog": "https://github.com/dev7355608/gm-vision/releases/tag/v1.1.2", "bugs": "https://github.com/dev7355608/gm-vision/issues", "readme": "https://raw.githubusercontent.com/dev7355608/gm-vision/main/README.md", "license": "https://raw.githubusercontent.com/dev7355608/gm-vision/main/LICENSE" diff --git a/script.js b/script.js index c6d1c77..8a6dc7e 100644 --- a/script.js +++ b/script.js @@ -167,29 +167,70 @@ Hooks.once("init", () => { const hatchFilter = HatchFilter.create(); - VisualEffectsMaskingFilter.defaultUniforms.gmVision = false; - VisualEffectsMaskingFilter.POST_PROCESS_TECHNIQUES.GM_VISION = { - id: "GM_VISION", - glsl: `if (gmVision) finalColor.rgb = sqrt(finalColor.rgb) * 0.5 + 0.5;` - }; + if (foundry.utils.isNewerVersion(game.version, 12)) { + Hooks.on("drawCanvasDarknessEffects", (layer) => { + const index = layer.filters?.indexOf(layer.filter); - VisualEffectsMaskingFilter.fragmentHeader = (wrapped => function (filterMode) { - let header = wrapped.call(this, filterMode); + layer.filter = new PIXI.AlphaFilter(); - if (filterMode === VisualEffectsMaskingFilter.FILTER_MODES.ILLUMINATION) { - header += "\nuniform bool gmVision;\n"; - } + if (index >= 0) { + layer.filters[index] = layer.filter; + } + }); - return header; - })(VisualEffectsMaskingFilter.fragmentHeader); + Hooks.on("sightRefresh", () => { + canvas.effects.darkness.filter.alpha = active ? 0.5 : 1; + }); - VisualEffectsMaskingFilter.fragmentShader = (wrapped => function (filterMode, postProcessModes = []) { - if (filterMode === VisualEffectsMaskingFilter.FILTER_MODES.ILLUMINATION) { - postProcessModes = [...postProcessModes, "GM_VISION"]; - } + CONFIG.Canvas.visualEffectsMaskingFilter = class extends CONFIG.Canvas.visualEffectsMaskingFilter { + /** @override */ + static defaultUniforms = { + ...super.defaultUniforms, + gmVision: false + }; + + /** @override */ + static fragmentHeader = ` + ${super.fragmentHeader} + uniform bool gmVision; + `; + + /** @override */ + static fragmentPostProcess(postProcessModes) { + return ` + ${super.fragmentPostProcess(postProcessModes)} + + if (mode == ${this.FILTER_MODES.ILLUMINATION} && gmVision) { + finalColor.rgb = sqrt(finalColor.rgb) * 0.5 + 0.5; + } + `; + } + }; + } else { + VisualEffectsMaskingFilter.defaultUniforms.gmVision = false; + VisualEffectsMaskingFilter.POST_PROCESS_TECHNIQUES.GM_VISION = { + id: "GM_VISION", + glsl: `if (gmVision) finalColor.rgb = sqrt(finalColor.rgb) * 0.5 + 0.5;` + }; + + VisualEffectsMaskingFilter.fragmentHeader = (wrapped => function (filterMode) { + let header = wrapped.call(this, filterMode); + + if (filterMode === VisualEffectsMaskingFilter.FILTER_MODES.ILLUMINATION) { + header += "\nuniform bool gmVision;\n"; + } - return wrapped.call(this, filterMode, postProcessModes); - })(VisualEffectsMaskingFilter.fragmentShader); + return header; + })(VisualEffectsMaskingFilter.fragmentHeader); + + VisualEffectsMaskingFilter.fragmentShader = (wrapped => function (filterMode, postProcessModes = []) { + if (filterMode === VisualEffectsMaskingFilter.FILTER_MODES.ILLUMINATION) { + postProcessModes = [...postProcessModes, "GM_VISION"]; + } + + return wrapped.call(this, filterMode, postProcessModes); + })(VisualEffectsMaskingFilter.fragmentShader); + } }; if (foundry.utils.isNewerVersion(game.version, 11)) {