Skip to content

Commit

Permalink
Cleanup of v10 update
Browse files Browse the repository at this point in the history
  • Loading branch information
theripper93 committed Jul 10, 2022
1 parent 826728a commit 6a45da2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 67 deletions.
5 changes: 0 additions & 5 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@
"id": "colorsettings",
"type": "module",
"compatibility": {}
},
{
"id": "lib-wrapper",
"type": "module",
"compatibility": {}
}
]
},
Expand Down
11 changes: 10 additions & 1 deletion scripts/BloodSplatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -199,7 +208,7 @@ class BloodSplatter {
return wrapped(...args);
}

static bloodTrail(wrapped, ...args) {
static bloodTrail() {
if (
this.actor &&
!this.bleeding &&
Expand Down
90 changes: 29 additions & 61 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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"),
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand All @@ -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();
}
},
});
Expand Down Expand Up @@ -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();
}
},
});
Expand Down Expand Up @@ -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"),
Expand All @@ -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();
}
},
});
Expand Down Expand Up @@ -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();
},
}
);
Expand Down

0 comments on commit 6a45da2

Please sign in to comment.