Skip to content

Commit

Permalink
adding GM only view helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kandashi committed May 24, 2022
1 parent 9a01772 commit 68ee2cd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Available fonts are: Arial, Arial Black, Comic Sans MS, Courier New, Georgia, He
A border may be toggled off by using the Token HUD element here

![BorderHUD](https://github.com/kandashi/Border-Control/blob/master/Border_Control_HUD.PNG?raw=true)

HUD Bars can be set to show as semi-transparant when only visible to the
43 changes: 32 additions & 11 deletions scripts/BorderControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BCconfig {
tempMax: undefined,
temp: undefined
}

this.stepLevel = game.settings.get("Border-Control", "stepLevel")
this.endColor = hexToRGB(colorStringToHex(game.settings.get("Border-Control", "healthGradientA")))
this.startColor = hexToRGB(colorStringToHex(game.settings.get("Border-Control", "healthGradientB")))
Expand All @@ -62,6 +62,8 @@ Hooks.on('renderSettingsConfig', (app, el, data) => {
let gS = game.settings.get("Border-Control", "healthGradientA");
let gE = game.settings.get("Border-Control", "healthGradientB");
let gT = game.settings.get("Border-Control", "healthGradientC");
let nPC = game.settings.get("Border-Control", "nameplateColor");
let nPCGM = game.settings.get("Border-Control", "nameplateColorGM");
el.find('[name="Border-Control.neutralColor"]').parent().append(`<input type="color" value="${nC}" data-edit="Border-Control.neutralColor">`)
el.find('[name="Border-Control.friendlyColor"]').parent().append(`<input type="color" value="${fC}" data-edit="Border-Control.friendlyColor">`)
el.find('[name="Border-Control.hostileColor"]').parent().append(`<input type="color" value="${hC}" data-edit="Border-Control.hostileColor">`)
Expand All @@ -79,7 +81,8 @@ Hooks.on('renderSettingsConfig', (app, el, data) => {
el.find('[name="Border-Control.healthGradientA"]').parent().append(`<input type="color"value="${gS}" data-edit="Border-Control.healthGradientA">`)
el.find('[name="Border-Control.healthGradientB"]').parent().append(`<input type="color"value="${gE}" data-edit="Border-Control.healthGradientB">`)
el.find('[name="Border-Control.healthGradientC"]').parent().append(`<input type="color"value="${gT}" data-edit="Border-Control.healthGradientC">`)

el.find('[name="Border-Control.nameplateColor"]').parent().append(`<input type="color"value="${nPC}" data-edit="Border-Control.nameplateColor">`)
el.find('[name="Border-Control.nameplateColorGM"]').parent().append(`<input type="color"value="${nPCGM}" data-edit="Border-Control.nameplateColorGM">`)
});


Expand Down Expand Up @@ -126,7 +129,7 @@ export let BorderFrame = class BorderFrame {
}
if (this.data.flags["Border-Control"]?.noBorder) return;
let t = game.settings.get("Border-Control", "borderWidth") || CONFIG.Canvas.objectBorderThickness;
if(game.settings.get("Border-Control", "permanentBorder") && this._controlled) t = t*2
if (game.settings.get("Border-Control", "permanentBorder") && this._controlled) t = t * 2
const sB = game.settings.get("Border-Control", "scaleBorder")
const bS = game.settings.get("Border-Control", "borderGridScale")
const nBS = bS ? canvas.dimensions.size / 100 : 1
Expand Down Expand Up @@ -158,15 +161,15 @@ export let BorderFrame = class BorderFrame {
const p = game.settings.get("Border-Control", "borderOffset")
const h = Math.round(t / 2);
const o = Math.round(h / 2);
this.border.lineStyle(t*nBS, borderColor.EX, 0.8).drawCircle(this.w / 2, this.h / 2, (this.w / 2) * s + t + p);
this.border.lineStyle(h*nBS, borderColor.INT, 1.0).drawCircle(this.w / 2, this.h / 2, (this.w / 2) * s + h + t / 2 + p);
this.border.lineStyle(t * nBS, borderColor.EX, 0.8).drawCircle(this.w / 2, this.h / 2, (this.w / 2) * s + t + p);
this.border.lineStyle(h * nBS, borderColor.INT, 1.0).drawCircle(this.w / 2, this.h / 2, (this.w / 2) * s + h + t / 2 + p);
}
else if (hexTypes.includes(canvas.grid.type) && (this.data.width === 1) && (this.data.height === 1)) {
const p = game.settings.get("Border-Control", "borderOffset")
const q = Math.round(p / 2)
const polygon = canvas.grid.grid.getPolygon(-1.5 - q + sW, -1.5 - q + sH, (this.w + 2)*s + p, (this.h + 2)*s + p);
this.border.lineStyle(t*nBS, borderColor.EX, 0.8).drawPolygon(polygon);
this.border.lineStyle(t*nBS / 2, borderColor.INT, 1.0).drawPolygon(polygon);
const polygon = canvas.grid.grid.getPolygon(-1.5 - q + sW, -1.5 - q + sH, (this.w + 2) * s + p, (this.h + 2) * s + p);
this.border.lineStyle(t * nBS, borderColor.EX, 0.8).drawPolygon(polygon);
this.border.lineStyle(t * nBS / 2, borderColor.INT, 1.0).drawPolygon(polygon);
}

// Otherwise Draw Square border
Expand All @@ -176,8 +179,8 @@ export let BorderFrame = class BorderFrame {
const h = Math.round(t / 2);
const o = Math.round(h / 2);

this.border.lineStyle(t*nBS, borderColor.EX, 0.8).drawRoundedRect(-o - q + sW, -o - q + sH, (this.w + h) * s + p, (this.h + h) * s + p, 3);
this.border.lineStyle(h*nBS, borderColor.INT, 1.0).drawRoundedRect(-o - q + sW, -o - q + sH, (this.w + h) * s + p, (this.h + h) * s + p, 3);
this.border.lineStyle(t * nBS, borderColor.EX, 0.8).drawRoundedRect(-o - q + sW, -o - q + sH, (this.w + h) * s + p, (this.h + h) * s + p, 3);
this.border.lineStyle(h * nBS, borderColor.INT, 1.0).drawRoundedRect(-o - q + sW, -o - q + sH, (this.w + h) * s + p, (this.h + h) * s + p, 3);
}
return;
}
Expand Down Expand Up @@ -374,6 +377,7 @@ export let BorderFrame = class BorderFrame {
const yOff = game.settings.get("Border-Control", "nameplateOffset")
const bOff = game.settings.get("Border-Control", "borderWidth") / 2
const replaceFont = game.settings.get("Border-Control", "plateFont")
let color = game.user.isGM && [10, 40, 20].includes(this.data.displayName) ? game.settings.get("Border-Control", "nameplateColorGM") : game.settings.get("Border-Control", "nameplateColor")
const sizeMulti = game.settings.get("Border-Control", "sizeMultiplier")

if (game.settings.get("Border-Control", "circularNameplate")) {
Expand All @@ -382,8 +386,9 @@ export let BorderFrame = class BorderFrame {
if (!game.modules.get("custom-nameplates")?.active) {
style.fontFamily = replaceFont
style.fontSize *= sizeMulti
if (game.settings.get("Border-Control", "plateConsistency")) style.fontSize *= canvas.grid.size / 100
}
if (game.settings.get("Border-Control", "plateConsistency")) style.fontSize *= canvas.grid.size / 100
style.fill = color
var text = new PreciseText(this.name, style);
text.resolution = 4;
text.style.trim = true;
Expand Down Expand Up @@ -413,6 +418,9 @@ export let BorderFrame = class BorderFrame {
style.fontFamily = game.settings.get("Border-Control", "plateFont")
style.fontSize *= sizeMulti
}
if (game.settings.get("Border-Control", "plateConsistency")) style.fontSize *= canvas.grid.size / 100
style.fill = color

const name = new PreciseText(this.data.name, style);
name.anchor.set(0.5, 0);
name.position.set(this.w / 2, this.h + bOff + yOff + offSet);
Expand All @@ -424,4 +432,17 @@ export let BorderFrame = class BorderFrame {
static refreshAll() {
canvas.tokens.placeables.forEach(t => t.draw())
}

static drawBars(wrapped, ...args) {
if (!game.settings.get("Border-Control", "barAlpha") || !game.user.isGM) return wrapped(...args);
if (!this.actor || ([50, 0, 30].includes(this.data.displayBars))) return wrapped(...args);
else return ["bar1", "bar2"].forEach((b, i) => {
const bar = this.hud.bars[b];
const attr = this.document.getBarAttribute(b);
if (!attr || (attr.type !== "bar")) return bar.visible = false;
this._drawBar(i, bar, attr);
bar.visible = true;
bar.alpha = 0.5
});
}
}
26 changes: 26 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ Hooks.once('init', async function () {
default: 0,
config: true,
});
game.settings.register("Border-Control", "nameplateColor", {
name: 'Nameplate Color',
scope: 'client',
type: String,
default: "#FFFFFF",
config: true,
});
game.settings.register("Border-Control", "nameplateColorGM", {
name: 'Nameplate Color for GM only view',
hint: "Nameplate color used when only the GM can see the nameplate",
scope: 'client',
type: String,
default: "#FFFFFF",
config: true,
});
game.settings.register("Border-Control", "nameplateOffset", {
name: 'Nameplate Y Offset',
hint: "Y axis offset in pixels",
Expand Down Expand Up @@ -295,11 +310,22 @@ Hooks.once('init', async function () {
default: false,
config: true,
});
game.settings.register("Border-Control", "barAlpha", {
name: 'Transparent Bars',
hint: 'Display transparent HUD bars if these elements are not visible to players',
scope: 'world',
type: Boolean,
default: false,
config: true,
});

libWrapper.register('Border-Control', 'Token.prototype._refreshBorder', BorderFrame.newBorder, 'OVERRIDE')
libWrapper.register('Border-Control', 'Token.prototype._getBorderColor', BorderFrame.newBorderColor, 'OVERRIDE')
if (!game.settings.get("Border-Control", "disableRefreshTarget")) {
libWrapper.register('Border-Control', 'Token.prototype._refreshTarget', BorderFrame.newTarget, 'OVERRIDE')
}
libWrapper.register('Border-Control', 'Token.prototype._drawNameplate', BorderFrame.drawNameplate, 'OVERRIDE')
libWrapper.register('Border-Control', 'Token.prototype.drawBars', BorderFrame.drawBars, 'MIXED')


});

0 comments on commit 68ee2cd

Please sign in to comment.