From 6a45da2ee02ce6a7c9a51ba2adfe9c3956d21809 Mon Sep 17 00:00:00 2001 From: theripper93 Date: Sun, 10 Jul 2022 15:50:45 +0200 Subject: [PATCH] Cleanup of v10 update --- module.json | 5 --- scripts/BloodSplatter.js | 11 ++++- scripts/config.js | 90 +++++++++++++--------------------------- 3 files changed, 39 insertions(+), 67 deletions(-) diff --git a/module.json b/module.json index 84e0d22..8b7c0e5 100644 --- a/module.json +++ b/module.json @@ -56,11 +56,6 @@ "id": "colorsettings", "type": "module", "compatibility": {} - }, - { - "id": "lib-wrapper", - "type": "module", - "compatibility": {} } ] }, diff --git a/scripts/BloodSplatter.js b/scripts/BloodSplatter.js index b0049db..83642e9 100644 --- a/scripts/BloodSplatter.js +++ b/scripts/BloodSplatter.js @@ -120,6 +120,7 @@ class BloodSplatter { this.wallsBlock = game.settings.get("splatter", "wallsBlockBlood"); this.inCombat = game.settings.get("splatter", "onlyInCombat"); this.cleanup = game.settings.get("splatter", "cleanup"); + this.bloodTrail = game.settings.get("splatter", "enableBloodTrail"); this.scaleMulti = (canvas.dimensions.size / 100) * game.settings.get("splatter", "bloodsplatterScale"); @@ -185,6 +186,14 @@ class BloodSplatter { return g; } + static bloodTrailTicker(){ + if(!canvas.primary?.BloodSplatter?.bloodTrail) return; + for ( const [animationName, animation] of Object.entries(CanvasAnimation.animations) ) { + if ( !( animation.context instanceof Token) ) continue; + BloodSplatter.bloodTrail.bind(animation.context)(); + } + } + static bloodTrailOnTickWrapper(wrapped, ...args){ args[1] = args[1] ?? {}; const _this = this; @@ -199,7 +208,7 @@ class BloodSplatter { return wrapped(...args); } - static bloodTrail(wrapped, ...args) { + static bloodTrail() { if ( this.actor && !this.bleeding && diff --git a/scripts/config.js b/scripts/config.js index 167d36a..f70c112 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -21,23 +21,8 @@ Hooks.once("init", function () { type: Boolean, default: true, onChange: function (sett) { - if (!sett && canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Destroy(); - } - if (!sett) { - libWrapper.unregister( - "splatter", - "Token.prototype.animate", - false - ); - } else { - if(game.settings.get("splatter", "enableBloodTrail")){ - libWrapper.register( - "splatter", - "Token.prototype.animate", - BloodSplatter.bloodTrailOnTickWrapper - ); - } + if (!sett && canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Destroy(); } }, }); @@ -55,8 +40,8 @@ Hooks.once("init", function () { }, default: 1, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -74,8 +59,8 @@ Hooks.once("init", function () { }, default: 0, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -88,8 +73,8 @@ Hooks.once("init", function () { type: Boolean, default: true, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -102,30 +87,12 @@ Hooks.once("init", function () { type: Boolean, default: false, onChange: function (sett) { - if (sett && game.settings.get("splatter", "enableBloodsplatter")) { - libWrapper.register( - "splatter", - "Token.prototype.animate", - BloodSplatter.bloodTrailOnTickWrapper - ); - } else { - libWrapper.unregister( - "splatter", - "Token.prototype.animate", - false - ); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); - if (game.settings.get("splatter", "enableBloodTrail") === true && game.settings.get("splatter", "enableBloodsplatter")===true) { - libWrapper.register( - "splatter", - "Token.prototype.animate", - BloodSplatter.bloodTrailOnTickWrapper - ); - } - game.settings.register("splatter", "useBloodsheet", { name: game.i18n.localize("splatter.settings.useBloodsheet.text"), hint: game.i18n.localize("splatter.settings.useBloodsheet.hint"), @@ -134,8 +101,8 @@ Hooks.once("init", function () { type: Boolean, default: true, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -153,8 +120,8 @@ Hooks.once("init", function () { }, default: 50, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -172,8 +139,8 @@ Hooks.once("init", function () { }, default: 0.5, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -186,8 +153,8 @@ Hooks.once("init", function () { type: Number, default: 500, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -200,8 +167,8 @@ Hooks.once("init", function () { type: Boolean, default: false, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -214,8 +181,8 @@ Hooks.once("init", function () { type: Boolean, default: false, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -261,8 +228,8 @@ Hooks.once("init", function () { undead: "#440707d8", }, onChange: function () { - if (canvas.background.BloodSplatter) { - canvas.background.BloodSplatter.Update(); + if (canvas.primary.BloodSplatter) { + canvas.primary.BloodSplatter.Update(); } }, }); @@ -296,6 +263,7 @@ Hooks.once("init", function () { }); Hooks.once("ready", function () { + canvas.app.ticker.add(BloodSplatter.bloodTrailTicker) new window.Ardittristan.ColorSetting("splatter", "bloodColor", { name: game.i18n.localize("splatter.settings.bloodColor.text"), hint: game.i18n.localize("splatter.settings.bloodColor.hint"), @@ -304,8 +272,8 @@ Hooks.once("ready", function () { defaultColor: "#a51414d8", scope: "world", onChange: function () { - if (canvas.background.Bloodsplatter) { - canvas.background.Bloodsplatter.Update(); + if (canvas.primary.Bloodsplatter) { + canvas.primary.Bloodsplatter.Update(); } }, }); @@ -353,8 +321,8 @@ Hooks.on("getSceneControlButtons", (controls, b, c) => { button: true, visible: game.settings.get("splatter", "enableBloodsplatter"), onClick: () => { - if (canvas.background.BloodSplatter) - canvas.background.BloodSplatter.Destroy(); + if (canvas.primary.BloodSplatter) + canvas.primary.BloodSplatter.Destroy(); }, } );