added highlight thickness option
This commit is contained in:
@@ -11,6 +11,10 @@
|
|||||||
"name": "Refresh During Movement",
|
"name": "Refresh During Movement",
|
||||||
"hint": "If disabled, aura highlights will only refresh when a token stops moving or its settings are updated. This can improve performance."
|
"hint": "If disabled, aura highlights will only refresh when a token stops moving or its settings are updated. This can improve performance."
|
||||||
},
|
},
|
||||||
|
"thickness": {
|
||||||
|
"name": "Highlight Thickness",
|
||||||
|
"hint": "The thickness of the aura highlights in pixels (1-100)."
|
||||||
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"name": "Aura Name"
|
"name": "Aura Name"
|
||||||
},
|
},
|
||||||
|
|||||||
+26
-7
@@ -5,11 +5,11 @@ const MODULE_ID = "basic_aura_highlighting";
|
|||||||
const AURAS_TAB = "basic-aura-highlighting-auras";
|
const AURAS_TAB = "basic-aura-highlighting-auras";
|
||||||
const AURAS_FLAG_PATH = `flags.${MODULE_ID}.auras`;
|
const AURAS_FLAG_PATH = `flags.${MODULE_ID}.auras`;
|
||||||
const HIGHLIGHT_CONTAINER_NAME = `${MODULE_ID}.highlights`;
|
const HIGHLIGHT_CONTAINER_NAME = `${MODULE_ID}.highlights`;
|
||||||
const HIGHLIGHT_LINE_WIDTH = 4;
|
|
||||||
const HIGHLIGHT_RING_SPACING = 5;
|
const HIGHLIGHT_RING_SPACING = 5;
|
||||||
const HIGHLIGHT_ALPHA_THRESHOLD = 0.2;
|
const HIGHLIGHT_ALPHA_THRESHOLD = 0.2;
|
||||||
const ALPHA_SAMPLE_SIZE = 48;
|
const ALPHA_SAMPLE_SIZE = 48;
|
||||||
const HIGHLIGHT_FILTER_MARKER = Symbol(MODULE_ID);
|
const HIGHLIGHT_FILTER_MARKER = Symbol(MODULE_ID);
|
||||||
|
const THICKNESS_SETTING = "thickness";
|
||||||
|
|
||||||
// Shader for drawing an outline around the token's non-transparent pixels
|
// Shader for drawing an outline around the token's non-transparent pixels
|
||||||
const ALPHA_OUTLINE_FRAGMENT_SHADER = `
|
const ALPHA_OUTLINE_FRAGMENT_SHADER = `
|
||||||
@@ -64,6 +64,21 @@ Hooks.once("init", () => {
|
|||||||
default: true,
|
default: true,
|
||||||
onChange: scheduleAuraHighlightRefresh,
|
onChange: scheduleAuraHighlightRefresh,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
game.settings.register(MODULE_ID, THICKNESS_SETTING, {
|
||||||
|
name: localize("settings.thickness.name"),
|
||||||
|
hint: localize("settings.thickness.hint"),
|
||||||
|
scope: "client",
|
||||||
|
config: true,
|
||||||
|
type: Number,
|
||||||
|
range: {
|
||||||
|
min: 1,
|
||||||
|
max: 100,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
|
default: 4,
|
||||||
|
onChange: scheduleAuraHighlightRefresh,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.on("renderTokenConfig", injectAurasTab);
|
Hooks.on("renderTokenConfig", injectAurasTab);
|
||||||
@@ -888,7 +903,7 @@ function createOutlineFilter(color) {
|
|||||||
const colorNumber = colorToNumber(color);
|
const colorNumber = colorToNumber(color);
|
||||||
const pixiOutlineFilter = globalThis.PIXI?.filters?.OutlineFilter;
|
const pixiOutlineFilter = globalThis.PIXI?.filters?.OutlineFilter;
|
||||||
if (pixiOutlineFilter)
|
if (pixiOutlineFilter)
|
||||||
return new pixiOutlineFilter(HIGHLIGHT_LINE_WIDTH, colorNumber, 0.2);
|
return new pixiOutlineFilter(getHighlightThickness(), colorNumber, 0.2);
|
||||||
|
|
||||||
const outlineOverlayFilter =
|
const outlineOverlayFilter =
|
||||||
globalThis.OutlineOverlayFilter ??
|
globalThis.OutlineOverlayFilter ??
|
||||||
@@ -896,7 +911,7 @@ function createOutlineFilter(color) {
|
|||||||
if (outlineOverlayFilter?.create) {
|
if (outlineOverlayFilter?.create) {
|
||||||
const filter = outlineOverlayFilter.create({
|
const filter = outlineOverlayFilter.create({
|
||||||
outlineColor: colorToRgbArray(colorNumber),
|
outlineColor: colorToRgbArray(colorNumber),
|
||||||
thickness: [HIGHLIGHT_LINE_WIDTH, HIGHLIGHT_LINE_WIDTH],
|
thickness: [getHighlightThickness(), getHighlightThickness()],
|
||||||
alphaThreshold: HIGHLIGHT_ALPHA_THRESHOLD,
|
alphaThreshold: HIGHLIGHT_ALPHA_THRESHOLD,
|
||||||
knockout: false,
|
knockout: false,
|
||||||
wave: false,
|
wave: false,
|
||||||
@@ -915,7 +930,7 @@ function createOutlineFilter(color) {
|
|||||||
if (glowOverlayFilter?.create) {
|
if (glowOverlayFilter?.create) {
|
||||||
const filter = glowOverlayFilter.create({
|
const filter = glowOverlayFilter.create({
|
||||||
glowColor: colorToRgbArray(colorNumber),
|
glowColor: colorToRgbArray(colorNumber),
|
||||||
distance: HIGHLIGHT_LINE_WIDTH,
|
distance: getHighlightThickness(),
|
||||||
outerStrength: 3,
|
outerStrength: 3,
|
||||||
innerStrength: 0,
|
innerStrength: 0,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
@@ -931,7 +946,7 @@ function createOutlineFilter(color) {
|
|||||||
function createAlphaOutlineFilter(color) {
|
function createAlphaOutlineFilter(color) {
|
||||||
const uniforms = {
|
const uniforms = {
|
||||||
outlineColor: colorToRgbArray(color),
|
outlineColor: colorToRgbArray(color),
|
||||||
thickness: HIGHLIGHT_LINE_WIDTH,
|
thickness: getHighlightThickness(),
|
||||||
alphaThreshold: HIGHLIGHT_ALPHA_THRESHOLD,
|
alphaThreshold: HIGHLIGHT_ALPHA_THRESHOLD,
|
||||||
};
|
};
|
||||||
const baseFilter =
|
const baseFilter =
|
||||||
@@ -945,7 +960,7 @@ function createAlphaOutlineFilter(color) {
|
|||||||
ALPHA_OUTLINE_FRAGMENT_SHADER,
|
ALPHA_OUTLINE_FRAGMENT_SHADER,
|
||||||
uniforms,
|
uniforms,
|
||||||
);
|
);
|
||||||
filter.padding = HIGHLIGHT_LINE_WIDTH;
|
filter.padding = getHighlightThickness();
|
||||||
return filter;
|
return filter;
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
return null;
|
return null;
|
||||||
@@ -958,7 +973,7 @@ function drawFallbackTokenHighlights(container, token, highlights) {
|
|||||||
const bounds = token.bounds.clone().pad(index * HIGHLIGHT_RING_SPACING);
|
const bounds = token.bounds.clone().pad(index * HIGHLIGHT_RING_SPACING);
|
||||||
const graphic = new PIXI.Graphics();
|
const graphic = new PIXI.Graphics();
|
||||||
|
|
||||||
graphic.lineStyle(HIGHLIGHT_LINE_WIDTH, colorToNumber(aura.color), 0.9);
|
graphic.lineStyle(getHighlightThickness(), colorToNumber(aura.color), 0.9);
|
||||||
graphic.drawRoundedRect(
|
graphic.drawRoundedRect(
|
||||||
bounds.x,
|
bounds.x,
|
||||||
bounds.y,
|
bounds.y,
|
||||||
@@ -1014,6 +1029,10 @@ function activateAurasTab(root, group) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHighlightThickness() {
|
||||||
|
return game.settings.get(MODULE_ID, THICKNESS_SETTING) ?? 4;
|
||||||
|
}
|
||||||
|
|
||||||
function localize(path) {
|
function localize(path) {
|
||||||
return game.i18n.localize(`BASIC_AURA_HIGHLIGHTING.${path}`);
|
return game.i18n.localize(`BASIC_AURA_HIGHLIGHTING.${path}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user