From b5564edcaa0a48584792d63051e9d8d8854de4c5 Mon Sep 17 00:00:00 2001 From: "Joe A. Spandrusyszyn" Date: Sun, 23 Aug 2020 16:25:44 -0400 Subject: [PATCH] Initial release --- README.md | 17 ++++++++++++++++- init.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ module.json | 17 +++++++++++++++++ styles.css | 24 ++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 init.js create mode 100644 module.json create mode 100644 styles.css diff --git a/README.md b/README.md index a2621c7..b9bdce4 100644 --- a/README.md +++ b/README.md @@ -1 +1,16 @@ -# FoundryVTT-token-hud-scale \ No newline at end of file +# Illandril's Token HUD Scaler +This is a module for Foundry Virtual Tabletop that adjusts the scale of the Token HUD and status effect icons. + +The Token HUD scale is increased by 50%. The Status Effect icons are scaled so that they can fit 3 across for the token. It also increases the opacity of the background behind the Token HUD and Status Effect icons. + +# Installation +1. Open the Configuration and Setup for your FoundryVTT server +1. Open the Add-on Modules Tab +1. Click the Install Module button +1. In the Manifest URL input, specify https://github.com/illandril/FoundryVTT-token-hud-scale/releases/latest/download/module.json +1. Click Install +1. Launch your world +1. Log in as the GM +1. Open the Settings tab +1. Click Manage Modules +1. Check the checkbox for Illandril's Token HUD scaler diff --git a/init.js b/init.js new file mode 100644 index 0000000..abc9f7b --- /dev/null +++ b/init.js @@ -0,0 +1,53 @@ +Hooks.on("canvasReady", canvas => { + canvas.tokens.placeables.forEach(token => { + token.effects.addListener("childAdded", child => { + fixEffectScale(token, child); + }); + updateEffectScales(token); + }); +}); + +Hooks.on("createToken", (parent, tokenData, options, userId) => { + setTimeout(() => { + const token = canvas.tokens.get(tokenData._id); + token.effects.addListener("childAdded", child => { + fixEffectScale(token, child); + }); + updateEffectScales(token); + }, 1000); +}); + +let pendingUpdates = {}; + +function fixEffectScale(token, child) { + clearTimeout(pendingUpdates[token.id]); + pendingUpdates[token.id] = setTimeout(() => { + updateEffectScales(token); + }, 10); +} + +function updateEffectScales(token) { + const numEffects = token.data.effects.length; + if (numEffects > 0) { + const w = Math.floor(token.width / 3)-1; + const bg = token.effects.children[0]; + bg.clear(); + bg.beginFill(0x000000, 0.60).lineStyle(1.0, 0x000000); + token.effects.children.forEach((effectIcon, i) => { + if ( i === 0 ) { + // BG + } else if ( i <= numEffects ) { + // Effect icon + const ei = i-1; + const x = (ei % 3) * w; + const y = Math.floor(ei / 3) * w; + effectIcon.width = effectIcon.height = w; + effectIcon.position.x = x; + effectIcon.position.y = y; + bg.drawRoundedRect(effectIcon.position.x, effectIcon.position.y, effectIcon.width, effectIcon.width, 2); + } else { + // Overlay icon + } + }); + } +} diff --git a/module.json b/module.json new file mode 100644 index 0000000..f7aad00 --- /dev/null +++ b/module.json @@ -0,0 +1,17 @@ +{ + "type": "module", + "name": "illandril-token-hud-scale", + "version": "1.0.0", + "title": "Illandril's Token HUD scaler", + "description": "Adjusts the scale of the Token HUD and status effects for improved usability when zoomed out.", + "author": "Joe Spandrusyszyn", + "minimumCoreVersion": "0.6.5", + "compatibleCoreVersion": "0.6.5", + "styles": ["./styles.css"], + "esmodules": ["./init.js"], + "license": "./LICENSE", + "url": "https://github.com/illandril/FoundryVTT-token-hud-scale", + "bugs": "https://github.com/illandril/FoundryVTT-token-hud-scale/issues", + "manifest": "https://github.com/illandril/FoundryVTT-token-hud-scale/releases/latest/download/module.json", + "download": "https://github.com/illandril/FoundryVTT-token-hud-scale/releases/download/v1.0.0/illandril-sheet5e-lockdown.zip" +} diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..dca99d4 --- /dev/null +++ b/styles.css @@ -0,0 +1,24 @@ +#token-hud .control-icon { + background: rgba(0,0,0,0.8); +} + +#token-hud .status-effects { + width: 152px; + grid-template-columns: 38px 38px 38px 38px; + background: rgba(0,0,0,0.8); +} + +#token-hud .status-effects .effect-control { + width: 36px; + height: 36px; +} + +#token-hud .col.right { + transform: scale(1.5); + right: -80px; +} + +#token-hud .col.left { + transform: scale(1.5); + left: -80px; +}