From 47246881b9ecd8e3627ece0cf31ed64b04d1ae01 Mon Sep 17 00:00:00 2001 From: Dorako Date: Sat, 30 Jul 2022 20:12:22 +0200 Subject: [PATCH] 1.5.1 --- module.json | 4 +- scripts/dorako-ui.js | 120 +++++++++++++++++++++++++++++++++---------- styles/dorako-ui.css | 4 +- 3 files changed, 98 insertions(+), 30 deletions(-) diff --git a/module.json b/module.json index e6b0652..a812d01 100644 --- a/module.json +++ b/module.json @@ -4,12 +4,12 @@ "description": "Overhauls the Foundry UI and several modules.", "url": "https://github.com/Dorako/pf2e-dorako-ui", "author": "Dorako", - "version": "1.5.0", + "version": "1.5.1", "minimumCoreVersion": "9", "compatibleCoreVersion": "9", "system": ["pf2e"], "scripts": ["scripts/dorako-ui.js"], "templates": ["templates/*"], - "download": "https://github.com/Dorako/pf2e-dorako-ui/archive/refs/tags/v1.5.0.zip", + "download": "https://github.com/Dorako/pf2e-dorako-ui/archive/refs/tags/v1.5.1.zip", "manifest": "https://github.com/Dorako/pf2e-dorako-ui/raw/main/module.json" } diff --git a/scripts/dorako-ui.js b/scripts/dorako-ui.js index f91c953..f4edaad 100644 --- a/scripts/dorako-ui.js +++ b/scripts/dorako-ui.js @@ -42,11 +42,11 @@ class ActorAvatar extends Avatar { } class TokenAvatar extends Avatar { - constructor(name, image, actualScale, renderScale) { + constructor(name, image, scale, isSmall) { super(name, image); this.type = "token"; - this.scale = actualScale; - this.renderScale = renderScale; + this.scale = scale; + this.isSmall = isSmall; } } @@ -388,14 +388,15 @@ function addAvatarsToFlags(message) { ? new ActorAvatar(message.data.speaker.alias, actorImg) : null; - let tokenAvatar = tokenImg - ? new TokenAvatar( - message.data.speaker.alias, - tokenImg, - message.token.data.scale, - message.token.data.scale > 1 ? message.token.data.scale : 1 - ) - : null; + let tokenAvatar = null; + if (tokenImg) { + tokenAvatar = new TokenAvatar( + message.data.speaker.alias, + tokenImg, + message.token.data.scale, + message.actor.size == "sm" + ); + } message.data.update({ "flags.pf2eDorakoUi.userAvatar": userAvatar, @@ -412,9 +413,12 @@ function getAvatar(message) { : null; let tokenAvatar = message.data.flags?.pf2eDorakoUi?.tokenAvatar; let actorAvatar = message.data.flags?.pf2eDorakoUi?.actorAvatar; - let userAvatar = message.data.flags?.pf2eDorakoUi?.userAvatar; + let userAvatar = game.settings.get("pf2e-dorako-ui", "use-user-avatar") + ? message.data.flags?.pf2eDorakoUi?.userAvatar + : null; if (combatantAvatar) return combatantAvatar; + return main == "token" ? tokenAvatar || actorAvatar || userAvatar : actorAvatar || tokenAvatar || userAvatar; @@ -429,26 +433,39 @@ Hooks.on("renderChatMessage", (message, b) => { avatarElem.src = avatar.image; if (avatar.type == "token") { + const smallScale = game.settings.get( + "pf2e-dorako-ui", + "small-creature-token-portrait-size" + ); + let smallCorrection = avatar.isSmall ? 1.25 * smallScale : 1; + message.data.flags?.pf2eDorakoUi?.combatantAvatar?.image; avatarElem?.setAttribute( "style", - "transform: scale(" + avatar.renderScale + ")" + "transform: scale(" + avatar.scale * smallCorrection + ")" ); } - let degree = message?.roll?.data?.degreeOfSuccess; - if (degree == undefined) return; - if (degree == 0) { - let wrapper = html.getElementsByClassName("portrait-wrapper")[0]; - wrapper?.setAttribute( - "style", - "filter: saturate(0.2) drop-shadow(0px 0px 6px black)" - ); - } else if (degree == 3) { - let wrapper = html.getElementsByClassName("portrait-wrapper")[0]; - wrapper?.setAttribute( - "style", - "filter: drop-shadow(0px 0px 6px lightgreen)" - ); + const portraitDegreeSetting = game.settings.get( + "pf2e-dorako-ui", + "portrait-reacts-to-degree-of-success" + ); + + if (portraitDegreeSetting) { + let degree = message?.roll?.data?.degreeOfSuccess; + if (degree == undefined) return; + if (degree == 0) { + let wrapper = html.getElementsByClassName("portrait-wrapper")[0]; + wrapper?.setAttribute( + "style", + "filter: saturate(0.2) drop-shadow(0px 0px 6px black)" + ); + } else if (degree == 3) { + let wrapper = html.getElementsByClassName("portrait-wrapper")[0]; + wrapper?.setAttribute( + "style", + "filter: drop-shadow(0px 0px 6px lightgreen)" + ); + } } }); @@ -558,6 +575,55 @@ Hooks.once("init", async () => { }, }); + game.settings.register( + "pf2e-dorako-ui", + "portrait-reacts-to-degree-of-success", + { + name: "Should the portraits react to critical success/failure?", + hint: "A critical success will glow green, and a critical failure will become muted and dark.", + scope: "world", + type: Boolean, + default: true, + config: true, + onChange: () => { + debouncedReload(); + }, + } + ); + + game.settings.register( + "pf2e-dorako-ui", + "small-creature-token-portrait-size", + { + name: "Chat portrait small creature scale", + hint: "Default is 0.8", + scope: "world", + type: Number, + default: 0.8, + range: { + min: 0.7, + max: 1.0, + step: 0.1, + }, + config: true, + onChange: () => { + debouncedReload(); + }, + } + ); + + game.settings.register("pf2e-dorako-ui", "use-user-avatar", { + name: "Use user avatar as fallback for chat potraits?", + hint: "Configure user avatars by right-clicking users in the lower left area of Foundry.", + scope: "world", + type: Boolean, + default: true, + config: true, + onChange: () => { + debouncedReload(); + }, + }); + game.settings.register("pf2e-dorako-ui", "chat-portrait-border", { name: "... and add a border?", hint: "Disable if your token art is fancy.", diff --git a/styles/dorako-ui.css b/styles/dorako-ui.css index 2d97088..7322b2e 100644 --- a/styles/dorako-ui.css +++ b/styles/dorako-ui.css @@ -70,8 +70,9 @@ button:hover, button:focus, form button:hover, form button:focus { - box-shadow: 0px 0px 2px rgb(0 0 0 / 80%) inset, 0px 0px 4px rgb(0 0 0 / 50%) inset; + box-shadow: 0px 0px 4px rgb(0 0 0 / 50%) inset; background-color: rgba(214, 214, 191, 0.8); + transition: background-color 0.1s ease-in-out, box-shadow 0.2s ease-in-out; } body { @@ -107,6 +108,7 @@ form button { box-shadow: none; margin: 0px; cursor: pointer; + transition: background-color 0.1s ease-in-out, box-shadow 0.2s ease-in-out; } .sheet header.sheet-header {