Skip to content

Commit

Permalink
multiple bars
Browse files Browse the repository at this point in the history
  • Loading branch information
theripper93 committed Jul 12, 2021
1 parent 12bf416 commit 3b0f218
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 3 additions & 1 deletion languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"bossbar.settings.backgroundPath.name":"Background Image",
"bossbar.settings.backgroundPath.hint":"Image to be placed as the healthbar background",
"bossbar.settings.foregroundPath.name":"Foreground Image",
"bossbar.settings.foregroundPath.hint":"Image to be palced as the healthbar foreground, this image will be resized depending on hp %"
"bossbar.settings.foregroundPath.hint":"Image to be palced as the healthbar foreground, this image will be resized depending on hp %",
"bossbar.settings.textSize.name":"Font Size",
"bossbar.settings.textSize.hint":"Font Size in pixels"
}
13 changes: 7 additions & 6 deletions scripts/BossBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class BossBar {
this.token;
this.bgPath = game.settings.get("bossbar", "backgroundPath");
this.fgPath = game.settings.get("bossbar", "foregroundPath");
this.textSize = game.settings.get("bossbar", "textSize")
}

static async create(token, render = true) {
Expand All @@ -13,7 +14,6 @@ class BossBar {
this.addBossBar(instance)
if (render) instance.draw(game.settings.get("bossbar", "barHeight"));
if (game.user.isGM){
debugger
let oldBars = canvas.scene.getFlag("bossbar", "bossBarActive")
if(Array.isArray(oldBars)){oldBars.push(token.id)}else{oldBars=[token.id]}
await canvas.scene.setFlag("bossbar", "bossBarActive", oldBars);
Expand All @@ -32,13 +32,14 @@ class BossBar {
draw(h) {
if($("body").find(`div[id="bossBar-${this.id}"]`).length > 0) return
$("#navigation").append(
`<div style="flex-basis: 100%;height: 0;"></div><div id ="bossBar-${this.id}" class="bossBar">
<a class="bossBarName">${this.name}</a>
`<div style="flex-basis: 100%;height: 0px;" id ="bossBarSpacer-${this.id}"></div><div id ="bossBar-${this.id}" class="bossBar">
<a class="bossBarName" style="font-size: ${this.textSize}px;">${this.name}</a>
<div id ="bossBarBar-${this.id}" style="z-index: 1000;">
<img id="bossBarMax-${this.id}" class="bossBarMax" src="${this.bgPath}" alt="test" width="100%" height="${h}">
<img id="bossBarCurrent-${this.id}" class="bossBarCurrent" src="${this.fgPath}" alt="test" width="100%" height="${h}">
</div>
</div>
<div style="flex-basis: 100%;height: ${this.textSize+3}px;" id ="bossBarSpacer-${this.id}"></div>
`
);
this.update();
Expand All @@ -55,17 +56,17 @@ class BossBar {
}

static clearAll(){
debugger
if(!canvas.scene._bossBars) return
for(let bar of Object.entries(canvas.scene._bossBars)){
$("body").find(`div[id="bossBar-${bar[1].id}"]`).remove();
$("body").find(`div[id="bossBarSpacer-${bar[1].id}"]`).remove();
}

}

remove() {
static remove() {
canvas.scene.unsetFlag("bossbar", "bossBarActive").then(() => {
this.clear();
this.clearAll();
});
}

Expand Down
22 changes: 18 additions & 4 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ Hooks.once("init", function () {
default: 20,
});

game.settings.register("bossbar", "textSize", {
name: game.i18n.localize("bossbar.settings.textSize.name"),
hint: game.i18n.localize("bossbar.settings.textSize.hint"),
scope: "world",
config: true,
type: Number,
default: 20,
});

game.settings.register("bossbar", "backgroundPath", {
name: game.i18n.localize("bossbar.settings.backgroundPath.name"),
hint: game.i18n.localize("bossbar.settings.backgroundPath.hint"),
Expand All @@ -51,7 +60,10 @@ Hooks.on("updateScene", async (scene, updates) => {
if (!game.user.isGM) {
if (updates.flags?.bossbar) {
const ids = canvas.scene.getFlag("bossbar", "bossBarActive");
if (!ids) return;
if (!ids){
if(canvas.scene._bossBars) delete canvas.scene._bossBars
return;
}
for (let id of ids) {
if (canvas.scene._bossBars && canvas.scene._bossBars[id]) {
canvas.scene._bossBars[id].draw(
Expand Down Expand Up @@ -91,16 +103,18 @@ Hooks.on("getSceneControlButtons", (controls, b, c) => {
controls
.find((c) => c.name == "token")
.tools.push({
name: "toggleCylinder",
name: "bossBar",
title: game.i18n.localize("bossbar.controls.bossUI.name"),
icon: "fas fa-pastafarianism",
toggle: true,
visible: game.user.isGM,
active: isBoss,
onClick: (toggle) => {
onClick: async (toggle) => {
if (toggle) {
if (canvas.tokens.controlled[0]) {
BossBar.create(canvas.tokens.controlled[0]);
for(let token of canvas.tokens.controlled){
await BossBar.create(token);
}
} else {
ui.notifications.warn(
game.i18n.localize("bossbar.controls.bossUI.warn")
Expand Down
7 changes: 4 additions & 3 deletions styles/module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.bossBarName {
text-align: left;
font-size: large;
background: rgba(0, 0, 0, 0.5);
font-size: 10px;
filter: drop-shadow(0 0 0.2rem black);
font-family:'Times New Roman', Times, serif;
padding: 3px;
border-radius: 3px;
}
Expand All @@ -13,7 +14,7 @@

.bossBarMax {
position: absolute;
transition: width 2s;
transition: width 4s;
}

.bossBar {
Expand Down

0 comments on commit 3b0f218

Please sign in to comment.