diff --git a/.vs/Tokenmagic/v16/.suo b/.vs/Tokenmagic/v16/.suo index 8102d4c..c4049f7 100644 Binary files a/.vs/Tokenmagic/v16/.suo and b/.vs/Tokenmagic/v16/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 1b8cd47..c720dcd 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -4,9 +4,9 @@ "\\tokenmagic", "\\tokenmagic\\fx", "\\tokenmagic\\fx\\filters", + "\\tokenmagic\\fx\\filters\\proto", "\\tokenmagic\\fx\\glsl", "\\tokenmagic\\fx\\glsl\\fragmentshaders", - "\\tokenmagic\\fx\\presets", "\\tokenmagic\\module", "\\tokenmagic\\module\\proto", "\\tokenmagic\\updates" diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 9e09ad5..60242f3 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/README.md b/README.md index 66b439d..902d857 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# Token Magic FX - Update v0.2.2b-alpha + +*Fixed issues :* +- Compatibility problem with furnace module drawings tools. + # Token Magic FX - Update v0.2.2-alpha *Added :* diff --git a/Tokenmagic.zip b/Tokenmagic.zip index 00aa98f..057ad40 100644 Binary files a/Tokenmagic.zip and b/Tokenmagic.zip differ diff --git a/tokenmagic/fx/Anime.js b/tokenmagic/fx/Anime.js index 3fb8c2d..2d9f85c 100644 --- a/tokenmagic/fx/Anime.js +++ b/tokenmagic/fx/Anime.js @@ -387,11 +387,14 @@ export class Anime { if (Anime._frameTime >= canvas.app.ticker.deltaMS) { // enough time passed : call animate for each animation Anime._animeMap.forEach((anime, id) => { - if (anime.puppet.hasOwnProperty("preComputation")) { - anime.puppet.preComputation(); - } - if (anime.puppet.hasOwnProperty("animated") && !(anime.puppet.animated == null)) { - anime.animate(Anime._frameTime); + if (anime.puppet.enabled) { + if (anime.puppet.hasOwnProperty("preComputation") + && anime.puppet.placeableImg != null) { + anime.puppet.preComputation(); + } + if (anime.puppet.hasOwnProperty("animated") && !(anime.puppet.animated == null)) { + anime.animate(Anime._frameTime); + } } }); Anime._prevTime = Anime._lastTime; diff --git a/tokenmagic/fx/filters/proto/FilterProto.js b/tokenmagic/fx/filters/proto/FilterProto.js index 266ae26..5f79985 100644 --- a/tokenmagic/fx/filters/proto/FilterProto.js +++ b/tokenmagic/fx/filters/proto/FilterProto.js @@ -1,4 +1,4 @@ -import { objectAssign, getPlaceableById, getMinPadding, PlaceableType } from "../../../module/tokenmagic.js"; +import { objectAssign, getPlaceableById, getMinPadding, PlaceableType, Magic } from "../../../module/tokenmagic.js"; import "../../../module/proto/PlaceableObjectProto.js"; PIXI.Filter.prototype.setTMParams = function (params) { @@ -52,6 +52,10 @@ PIXI.Filter.prototype.assignPlaceable = function () { : this.placeableImg = null; } +PIXI.Filter.prototype.assignPlaceable = function () { + this.placeableImg = this.getPlaceable(); +} + PIXI.Filter.prototype.activateTransform = function () { this.preComputation = this.filterTransform; this.filterTransform(); diff --git a/tokenmagic/fx/glsl/fragmentshaders/forcefield.js b/tokenmagic/fx/glsl/fragmentshaders/forcefield.js index 9d96e68..2c9c878 100644 --- a/tokenmagic/fx/glsl/fragmentshaders/forcefield.js +++ b/tokenmagic/fx/glsl/fragmentshaders/forcefield.js @@ -20,6 +20,7 @@ varying vec2 vFilterCoord; #define SQRT5B20 0.30901699 #define PI 3.14159265 +#define TWOPI 6.28318531 #define SPEED 0.01 #define MU_TWOPI 0.15915494309 #define MU_289 0.00346020761 @@ -394,33 +395,19 @@ vec4 surface4d(vec2 suv) { float s = suv.x + 0.61; float t = suv.y + 0.5; - - float multiplier = 1.0 * MU_TWOPI; - float nx = cos( s * 2.0 * PI ) * multiplier; - float ny = cos( t * 2.0 * PI ) * multiplier; - float nz = sin( s * 2.0 * PI ) * multiplier; - float nw = sin( t * 2.0 * PI ) * multiplier; + float nx = cos( s * TWOPI ) * MU_TWOPI; + float ny = cos( t * TWOPI ) * MU_TWOPI; + float nz = sin( s * TWOPI ) * MU_TWOPI; + float nw = sin( t * TWOPI ) * MU_TWOPI; - float surf = surface( vec4( nx, ny, nz, nw ) + time * SPEED * 3. ); + float surf = surface( vec4( nx, ny, nz, nw ) + time * 0.03 ); return vec4( color * vec3( surf ), 1.0 ); } -vec4 fbmy(vec2 suv) -{ - vec4 noiseColor; - noiseColor.r = (color.r * fbm(suv + time*0.5)); - noiseColor.g = (color.g * fbm(suv + time*0.5)); - noiseColor.b = (color.b * fbm(suv + time*0.5)); - noiseColor.a = 1.; - return clamp(noiseColor,0.,1.); -} - vec4 noisy(vec2 suv) { vec4 noiseColor; - noiseColor.r = (color.r * noise(suv + fbm(suv) + time*0.5)); - noiseColor.g = (color.g * noise(suv + fbm(suv) + time*0.5)); - noiseColor.b = (color.b * noise(suv + fbm(suv) + time*0.5)); + noiseColor.rgb = (color.rgb * noise(suv + fbm(suv) + time*0.5)); noiseColor.a = 1.; return clamp(noiseColor,0.,1.); } @@ -455,9 +442,7 @@ vec4 denseSmoke(vec2 suv) vec2 uv; uv.x = (fbm(suv*2.)-suv.x); uv.y = (suv.y+fbm(suv*2.)); - noiseColor.r = (color.r * min(fbm(uv - time*0.5),fbm(uv)*1.5)); - noiseColor.g = (color.g * min(fbm(uv - time*0.5),fbm(uv)*1.5)); - noiseColor.b = (color.b * min(fbm(uv - time*0.5),fbm(uv)*1.5)); + noiseColor.rgb = (color.rgb * min(fbm(uv - time*0.5),fbm(uv)*1.5)); noiseColor.a = 1.0; return clamp(noiseColor,0.,1.); } @@ -469,9 +454,7 @@ vec4 dancingFume(vec2 suv) uv.x += noise(suv)+fbm(suv); uv.y += noise(suv)+fbm(suv); uv *= 0.5; - noiseColor.r = (color.r * fbm((uv + suv*0.15) - time)); - noiseColor.g = (color.g * fbm((uv + suv*0.15) - time)); - noiseColor.b = (color.b * fbm((uv + suv*0.15) - time)); + noiseColor.rgb = (color.rgb * fbm((uv + suv*0.15) - time)); noiseColor.a = 1.0; return clamp(noiseColor,0.,1.); } diff --git a/tokenmagic/module.json b/tokenmagic/module.json index 529c5e1..9108c2f 100644 --- a/tokenmagic/module.json +++ b/tokenmagic/module.json @@ -2,7 +2,7 @@ "name": "tokenmagic", "title": "Token Magic FX", "description": "

Add graphic filters and animations on your tokens and tiles.

", - "version": "0.2.2", + "version": "0.2.2b", "compatibleCoreVersion": "0.6.5", "minimumCoreVersion": "0.6.0", "author": "SecretFire", diff --git a/tokenmagic/module/proto/PlaceableObjectProto.js b/tokenmagic/module/proto/PlaceableObjectProto.js index 7d80b27..401c064 100644 --- a/tokenmagic/module/proto/PlaceableObjectProto.js +++ b/tokenmagic/module/proto/PlaceableObjectProto.js @@ -47,7 +47,7 @@ PlaceableObject.prototype._TMFXgetSprite = function () { return this.template; break; case PlaceableType.DRAWING: - return this.drawing; + return this.drawing || this.img; break; default: return null; @@ -72,7 +72,9 @@ PlaceableObject.prototype._TMFXcheckSprite = function () { break; case PlaceableType.DRAWING: return (this.hasOwnProperty("drawing") - && !(this.drawing == null)); + && !(this.drawing == null)) + || (this.hasOwnProperty("img") + && !(this.img == null)); break; default: return null; diff --git a/tokenmagic/module/tokenmagic.js b/tokenmagic/module/tokenmagic.js index 4f15d69..671d510 100644 --- a/tokenmagic/module/tokenmagic.js +++ b/tokenmagic/module/tokenmagic.js @@ -97,7 +97,7 @@ export const PlaceableType = { TOKEN: Token.embeddedName, TILE: Tile.embeddedName, TEMPLATE: MeasuredTemplate.embeddedName, - DRAWING: Drawing.embeddedName, + DRAWING: Drawing.embeddedName, NOT_SUPPORTED: null }; @@ -107,7 +107,7 @@ function i18n(key) { async function exportObjectAsJson(exportObj, exportName) { let jsonStr = JSON.stringify(exportObj, null, 4); - + const a = document.createElement('a'); const file = new Blob([jsonStr], { type: 'plain/text' }); @@ -195,6 +195,15 @@ export function isAdditivePaddingConfig() { return game.settings.get("tokenmagic", "useAdditivePadding"); } +export var isFurnaceDrawingsActive = () => { + // module exeption for the Furnace by KaKaRoTo + if (isActiveModule("furnace") + && game.settings.get("furnace", "enableDrawingTools")) { + return true; + } + return false; +}; + export function isTheOne() { const theOne = game.users.find((user) => user.isGM && user.active); if (theOne && game.user !== theOne) { @@ -868,7 +877,7 @@ export function TokenMagic() { } catch (e) { error(e.message); } - } + } } async function importPresetLibraryFromURL(url) { @@ -1081,6 +1090,35 @@ function initSocketListener() { }); }; +function initFurnaceDrawingsException() { + if (isFurnaceDrawingsActive) { + DrawingConfig.prototype.refresh = (function () { + const cachedDCR = DrawingConfig.prototype.refresh; + return async function (html) { + + // Clear animations and filters + let tmfxUpdate = false; + if (this.object.data.hasOwnProperty("flags") + && this.object.data.flags.hasOwnProperty("tokenmagic") + && this.object.data.flags.tokenmagic.hasOwnProperty("filters")) { + tmfxUpdate = true; + Anime.removeAnimation(this.object.id); + Magic._clearImgFiltersByPlaceable(this.object); + } + + // Furnace function apply (updating data and full redraw : destruction/reconstruction) + cachedDCR.apply(this, arguments); + + // Reapply the filters if needed + if (tmfxUpdate) { + Magic._singleLoadFilters(this.object); + } + + }; + })(); + } +} + async function requestLoadFilters(placeable, startTimeout = 0) { var reqTimer; @@ -1113,6 +1151,7 @@ Hooks.once("init", () => { Hooks.on("ready", () => { log("Hook -> ready"); initSocketListener(); + initFurnaceDrawingsException(); window.TokenMagic = Magic; }); @@ -1242,10 +1281,9 @@ Hooks.on("updateDrawing", (scene, data, options, action) => { if (scene.id !== game.user.viewedScene) return; - // hum.. let's explain. Position change do not trigger a diff:true if ((action.hasOwnProperty("diff") && action.diff && !(options.hasOwnProperty("flags") && options.flags.hasOwnProperty("tokenmagic"))) - || (options.hasOwnProperty("x") || options.hasOwnProperty("y")) ) { + || (options.hasOwnProperty("x") || options.hasOwnProperty("y"))) { var placeable = getPlaceableById(data._id, PlaceableType.DRAWING); @@ -1256,7 +1294,7 @@ Hooks.on("updateDrawing", (scene, data, options, action) => { Magic._clearImgFiltersByPlaceable(placeable); // querying filters reload (when pixi containers are ready) - requestLoadFilters(placeable, 50); + requestLoadFilters(placeable, 250); } else { Magic._updateFilters(data, options, PlaceableType.DRAWING); diff --git a/tokenmagic/updates/UPDATE-0.2.2b.md b/tokenmagic/updates/UPDATE-0.2.2b.md new file mode 100644 index 0000000..38798b5 --- /dev/null +++ b/tokenmagic/updates/UPDATE-0.2.2b.md @@ -0,0 +1,4 @@ +# Token Magic FX - Update v0.2.2b-alpha + +*Fixed issues :* +- Compatibility problem with furnace module drawings tools. \ No newline at end of file