Skip to content

Commit

Permalink
3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorako committed Dec 3, 2023
1 parent 3c31283 commit 25ff8de
Show file tree
Hide file tree
Showing 26 changed files with 885 additions and 829 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 3.2.0

- (New) Excluded PFS premium module journals from styling.
- (New) Invalid settings from now on should be migrated to default values.
- (Refinement) Refactored the settings to hopefully increase clarity.
- (New) The old color-scheme-based-on-speaker setting has been replaced by two settings, one standard, and one for opposition.
- (New) Added BG3 blue variant chat message theme.
- (Refinement) Various fixes to various themes.

# 3.1.15

- (Fix) Excluded Party Overview module from theming.
Expand Down
2 changes: 1 addition & 1 deletion esmodules/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const baseThemeApplications = [...baseThemeCoreFoundryApplications,...bas
/* ----------------------------------------- */
/* Premium module */
/* ----------------------------------------- */
export const premiumModuleSelector = ".pf2e-yom, .pf2e-ii, .pf2e-woii, .seasonofghosts, .seasonofghosts-wrapper, .skykingstomb-wrapper, .skykingstomb, .stolenfate-wrapper, .stolenfate, .harrow-reading, .harrow, .pf2e-km, .kingdom-app, .swpf-sheet, .swpf-wrapper, .pf2e-av, .pf2e-bb, .gatewalkers-wrapper, .gatewalkers, .outlaws-wrapper, .outlaws, .bloodlords-wrapper, .bloodlords, .kingmaker-wrapper, .kingmaker"; //
export const premiumModuleSelector = ".pfs05Pt1, .pfs05Pt1-wrapper, .pf2e-yom, .pf2e-ii, .pf2e-woii, .seasonofghosts, .seasonofghosts-wrapper, .skykingstomb-wrapper, .skykingstomb, .stolenfate-wrapper, .stolenfate, .harrow-reading, .harrow, .pf2e-km, .kingdom-app, .swpf-sheet, .swpf-wrapper, .pf2e-av, .pf2e-bb, .gatewalkers-wrapper, .gatewalkers, .outlaws-wrapper, .outlaws, .bloodlords-wrapper, .bloodlords, .kingmaker-wrapper, .kingmaker"; //

/* ----------------------------------------- */
/* Apps */
Expand Down
97 changes: 22 additions & 75 deletions esmodules/message-hooks.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
import { getChatTheme, getDefaultColorScheme } from "./ui-theme.js";

const rgb2hex = (rgb) =>
`#${rgb
.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)
.slice(1)
.map((n) => parseInt(n, 10).toString(16).padStart(2, "0"))
.join("")}`;
import { getChatTheme, getDefaultColorScheme, lookupThemeAndSchemeForKey } from "./ui-theme.js";

Hooks.on("renderChatMessage", (chatMessage, html, messageData) => {
html[0].dataset.colorScheme = getMessageColorScheme(chatMessage, html, messageData);
if (html[0].hasAttribute("style")) {
html.css("border-color", "");
}
});

function getMessageColorScheme(chatMessage, html, messageData) {
const chatColorSchemeSetting = game.settings.get("pf2e-dorako-ui", "theme.chat-message-color-scheme");
const chatTheme = game.settings.get("pf2e-dorako-ui", "theme.chat-message-theme");
const defaultColorScheme = getDefaultColorScheme(chatTheme);
let colorScheme = null;
switch (chatColorSchemeSetting) {
case "default":
colorScheme = defaultColorScheme;
break;
case "prefer-dark":
colorScheme = "dark";
break;
case "prefer-light":
colorScheme = "light";
break;
case "alliance":
colorScheme = defaultColorScheme; // Fallback for GM speaking from non-actors
if (!chatMessage?.actor?.alliance) {
colorScheme = defaultColorScheme;
} else {
colorScheme = chatMessage.actor.alliance === "opposition" ? "dark" : "light";
}
break;
case "gm-vs-players":
colorScheme = chatMessage.user.isGM ? "dark" : "light";
break;
}
return colorScheme;
}

// Chat cards
Hooks.on("renderChatMessage", (chatMessage, html, messageData) => {
const isNarratorToolsMessage = chatMessage.flags["narrator-tools"];
Expand All @@ -56,30 +18,31 @@ Hooks.on("renderChatMessage", (chatMessage, html, messageData) => {

let html0 = html[0];
html0.style.setProperty("--player-color", chatMessage?.user?.color ?? "#DAC0FB");
html0.dataset.headerTextColorScheme = calcHeaderTextColor(html, chatMessage);

const uiTheme = getChatTheme();
const { dorakoUiTheme, colorScheme } = uiTheme;
if (uiTheme) {
html0.dataset.dorakoUiTheme = dorakoUiTheme;
html0.dataset.dorakoUiScope = "unlimited";
}
const isSecretDisposition =
game?.scenes?.get(chatMessage?.speaker?.scene)?.tokens?.get(chatMessage?.speaker?.token)?.disposition == -2;
const { dorakoUiTheme, colorScheme } =
chatMessage?.actor?.alliance === "opposition" && !isSecretDisposition
? lookupThemeAndSchemeForKey(game.settings.get("pf2e-dorako-ui", "theme.chat-message-opposition-theme"))
: lookupThemeAndSchemeForKey(game.settings.get("pf2e-dorako-ui", "theme.chat-message-standard-theme"));
html0.dataset.dorakoUiTheme = dorakoUiTheme;
html0.dataset.colorScheme = colorScheme;
html0.dataset.dorakoUiScope = "unlimited";

const headerStyle = game.settings.get("pf2e-dorako-ui", "theme.chat-message-header-style");
if (dorakoUiTheme === "crb" && headerStyle !== "none") {
html0.dataset.hasHeader = "";
}
themeHeader(html, chatMessage);
});

function themeHeader(html, message) {
let messageHeader = html.find(".message-header")[0];
const headerColor = getHeaderColor(html, message);
messageHeader.style.setProperty("--header-color", headerColor);

const headerStyle = game.settings.get("pf2e-dorako-ui", "theme.chat-message-header-style");
if (headerStyle != "none") {
let bgCol = getHeaderColor(html, message);
messageHeader.style.setProperty("--header-color", bgCol);
messageHeader.classList.add("dorako-header");
}

let textColTheme = calcHeaderTextColor(html, message);
messageHeader.classList.add(textColTheme);
let textColTheme = calcHeaderTextColor(headerColor);
html[0].dataset.headerTextColorScheme = textColTheme;

// some modules add different timestamps and hide the original, like dfce-simple-timestamp
let time = html.find("time")[0];
Expand Down Expand Up @@ -108,26 +71,10 @@ function invertColor(color) {
return color === "dark" ? "light" : "dark";
}

function calcHeaderTextColor(html, message) {
const headerStyle = game.settings.get("pf2e-dorako-ui", "theme.chat-message-header-style");
const chatTheme = game.settings.get("pf2e-dorako-ui", "theme.chat-message-theme");
// const defaultColorScheme = getDefaultColorScheme(chatTheme);
const inverseColorScheme = invertColor(getMessageColorScheme(message, html, null));
// const inverse = invertColor(defaultColorScheme);
const messageHeader = html.find(".message-header")[0];
if (headerStyle === "none" && chatTheme == "crb") {
return inverseColorScheme;
} else if (headerStyle === "none") {
return "light";
}

// let bgCol = messageHeader.style.backgroundColor;

let bgCol = getHeaderColor(html, message);
// bgCol = rgb2hex(bgCol);
var r = parseInt(bgCol.substr(1, 2), 16);
var g = parseInt(bgCol.substr(3, 2), 16);
var b = parseInt(bgCol.substr(5, 2), 16);
function calcHeaderTextColor(headerColor) {
var r = parseInt(headerColor.substr(1, 2), 16);
var g = parseInt(headerColor.substr(3, 2), 16);
var b = parseInt(headerColor.substr(5, 2), 16);
var yiq = (r * 299 + g * 587 + b * 114) / 1000;

if (yiq >= 180) {
Expand Down
2 changes: 1 addition & 1 deletion esmodules/misc-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Hooks.on("renderSettingsConfig", (app, html, data) => {
.html(
i18n("pf2e-dorako-ui.settings.theme.name") + `<p class="notes">${i18n("pf2e-dorako-ui.settings.theme.hint")}</p>`
)
.insertBefore($('[name="pf2e-dorako-ui.theme.window-app-theme"]').parents("div.form-group:first"));
.insertBefore($('[name="pf2e-dorako-ui.theme.app-theme"]').parents("div.form-group:first"));
$("<div>")
.addClass("form-group dorako settings-header")
.html(
Expand Down
4 changes: 2 additions & 2 deletions esmodules/premium-module-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export function isPremiumApplication(app, html, data, appName) {
}
for (var key in app.document?.flags) {
//prettier-ignore
const fvttPremium = new RegExp(/^pf2e-(beginner-box|abomination-vaults|kingmaker|km|mercenary-marketplace-vol1)/);
const fvttPremium = new RegExp(/^pf2e-(beginner-box|abomination-vaults|kingmaker|km|mercenary-marketplace-vol1|pfs)/);
if (fvttPremium.test(key)) {
console.debug(
`${MODULE_NAME} | ${appName} contains key matching '^pf2e-(beginner-box|abomination-vaults|kingmaker)' => add .premium`
`${MODULE_NAME} | ${appName} contains key matching '^pf2e-(beginner-box|abomination-vaults|kingmaker|km|mercenary-marketplace-vol1|pfs)' => add .premium`
);
html[0].classList.add("premium");
html.closest(".app").find(".journal-entry-content").addClass("premium");
Expand Down
42 changes: 19 additions & 23 deletions esmodules/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MiscSettings } from "./misc-settings.js";
import { CustomizationSettings } from "./customization-settings.js";
import { ExternalModuleSettings } from "./external-module-settings.js";
import { getAppThemeAndScheme, getUiTheme } from "../ui-theme.js";
import { MODULE_NAME } from "../consts.js";

export function refreshChat() {
if (game.messages.size > 100) {
Expand All @@ -16,7 +17,7 @@ export function refreshChat() {
}

Hooks.once("init", async () => {
util.debug("init");
util.debug("Init...");

game.settings.register("pf2e-dorako-ui", "mld-nag", {
scope: "world",
Expand All @@ -25,26 +26,27 @@ Hooks.once("init", async () => {
type: Boolean,
});

// game.settings.register("pf2e-dorako-ui", "tah-nag", {
// scope: "client",
// config: false,
// default: true,
// type: Boolean,
// });

game.settings.register("pf2e-dorako-ui", "migration-version", {
scope: "world",
config: false,
default: "0.0.0",
type: String,
});

ThemeSettings.registerSettings();
MiscSettings.registerSettings();
CustomizationSettings.registerSettings();
ExternalModuleSettings.registerSettings();

util.debug("registered settings");
util.debug("Registered settings...");

util.debug("Migrating invalid settings to default...");
const allSettings = [...game.settings.settings].filter(([k, _]) => k.includes(MODULE_NAME));
for (const [_, setting] of allSettings) {
const key = setting.key;
const currentValue = game.settings.get(MODULE_NAME, key);
const choices = setting.choices;
if (choices) {
if (!(currentValue in choices)) {
const defaultValue = setting.default;
await game.settings.set(MODULE_NAME, key, defaultValue);
console.warn(`Set ${key} to '${defaultValue}' since '${currentValue}' is invalid`);
}
}
}

const applicationTheme = game.settings.get("pf2e-dorako-ui", "theme.app-theme");
if (applicationTheme !== "no-theme") {
Expand All @@ -57,17 +59,11 @@ Hooks.once("init", async () => {
}
}

const chatMessageTheme = game.settings.get("pf2e-dorako-ui", "theme.chat-message-theme");
const chatMessageHeaderStyle = game.settings.get("pf2e-dorako-ui", "theme.chat-message-header-style");
if (chatMessageTheme === "bg3" && chatMessageHeaderStyle !== "none") {
game.settings.set("pf2e-dorako-ui", "theme.chat-message-header-style", "none");
}

const root = document.querySelector(":root").style;

root.setProperty("--border-radius", game.settings.get("pf2e-dorako-ui", "theme.border-radius").toString() + "px");

util.debug("initialized properties");
util.debug("initialized properties...");
});

Hooks.once("ready", () => {
Expand Down
Loading

0 comments on commit 25ff8de

Please sign in to comment.