Allow token fatigue bar reversing

This commit is contained in:
Jzrzmy
2021-02-05 19:55:12 +00:00
committed by Mandar
parent 6a9e84f126
commit b54f58c9ce
5 changed files with 43 additions and 0 deletions

View File

@@ -113,6 +113,34 @@ Hooks.once("init", async () => {
// Journal
Items.unregisterSheet("core", JournalSheet);
Items.registerSheet("l5r5e", BaseJournalSheetL5r5e, { makeDefault: true });
// Override the default Token _drawBar function to allow fatigue bar reversing.
Token.prototype._drawBar = function (number, bar, data) {
let val = Number(data.value);
const reverseFatigue = game.settings.get("l5r5e", "token.reversefatiguebar");
// Bar value reversing.
if (data.attribute === "fatigue" && reverseFatigue) {
val = Number(data.max - data.value);
}
const pct = Math.clamped(val, 0, data.max) / data.max;
let h = Math.max(canvas.dimensions.size / 12, 8);
if (this.data.height >= 2) h *= 1.6; // Enlarge the bar for large tokens
// Draw the bar
let color = number === 0 ? [1 - pct / 2, pct, 0] : [0.5 * pct, 0.7 * pct, 0.5 + pct / 2];
bar
.clear()
.beginFill(0x000000, 0.5)
.lineStyle(2, 0x000000, 0.9)
.drawRoundedRect(0, 0, this.w, h, 3)
.beginFill(PIXI.utils.rgb2hex(color), 0.8)
.lineStyle(1, 0x000000, 0.8)
.drawRoundedRect(1, 1, pct * (this.w - 2), h - 2, 2);
// Set position
let posY = number === 0 ? this.h - h : 0;
bar.position.set(0, posY);
};
});
/* ------------------------------------ */

View File

@@ -70,4 +70,15 @@ export const RegisterSettings = function () {
type: String,
default: "null",
});
/* ------------------------------------ */
/* Token bars */
/* ------------------------------------ */
game.settings.register("l5r5e", "token.reversefatiguebar", {
name: game.i18n.localize("SETTINGS.ReverseFatigueBar"),
scope: "world",
config: true,
type: Boolean,
default: false,
});
};