All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.0 KiB

  1. import { lookupThemeAndSchemeForKey } from "./ui-theme.js";
  2. Hooks.on("renderChatMessage", (chatMessage, html, messageData) => {
  3. if (html[0].hasAttribute("style")) {
  4. html.css("border-color", "");
  5. }
  6. });
  7. // Chat cards
  8. Hooks.on("renderChatMessage", (chatMessage, html, messageData) => {
  9. const isNarratorToolsMessage = chatMessage.flags["narrator-tools"];
  10. const isMLDRoundMarker = chatMessage.flags["monks-little-details"]?.roundmarker;
  11. const isMCDRoundMarker = chatMessage.flags["monks-combat-details"]?.roundmarker;
  12. const isRoundMarker = isMLDRoundMarker || isMCDRoundMarker;
  13. if (isNarratorToolsMessage || isRoundMarker) {
  14. return;
  15. }
  16. let html0 = html[0];
  17. html0.style.setProperty("--player-color", chatMessage?.user?.color ?? "#DAC0FB");
  18. const isSecretDisposition =
  19. game?.scenes?.get(chatMessage?.speaker?.scene)?.tokens?.get(chatMessage?.speaker?.token)?.disposition == -2;
  20. const { dorakoUiTheme, colorScheme } =
  21. chatMessage?.actor?.alliance === "opposition" && !isSecretDisposition
  22. ? lookupThemeAndSchemeForKey(game.settings.get("pf2e-dorako-ui", "theme.chat-message-opposition-theme"))
  23. : lookupThemeAndSchemeForKey(game.settings.get("pf2e-dorako-ui", "theme.chat-message-standard-theme"));
  24. html0.dataset.theme = dorakoUiTheme;
  25. html0.dataset.colorScheme = colorScheme;
  26. html0.dataset.dorakoUiScope = "unlimited";
  27. const headerStyle = game.settings.get("pf2e-dorako-ui", "theme.chat-message-header-style");
  28. if (dorakoUiTheme === "crb" && headerStyle !== "none") {
  29. html0.dataset.hasHeader = "";
  30. }
  31. themeHeader(html, chatMessage);
  32. });
  33. function themeHeader(html, message) {
  34. let messageHeader = html.find(".message-header")[0];
  35. const headerColor = getHeaderColor(html, message);
  36. messageHeader.style.setProperty("--header-color", headerColor);
  37. let textColTheme = calcHeaderTextColor(headerColor);
  38. html[0].dataset.headerTextColorScheme = textColTheme;
  39. // some modules add different timestamps and hide the original, like dfce-simple-timestamp
  40. let time = html.find("time")[0];
  41. if (time) {
  42. time.classList.add("header-meta");
  43. }
  44. }
  45. const headerStyleColors = {
  46. none: "none",
  47. fallback: "#DAC0FB",
  48. blue: "#191F65",
  49. green: "#002A17",
  50. red: "#540C06",
  51. }
  52. function getHeaderColor(html, message) {
  53. const headerStyle = game.settings.get("pf2e-dorako-ui", "theme.chat-message-header-style");
  54. if (headerStyle === "tint") {
  55. return message?.user?.color ?? headerStyleColors.fallback;
  56. }
  57. return headerStyleColors[headerStyle] ?? headerStyleColors.fallback;
  58. }
  59. function invertColor(color) {
  60. return color === "dark" ? "light" : "dark";
  61. }
  62. function calcHeaderTextColor(headerColor) {
  63. if (headerColor === headerStyleColors.none) {
  64. return "dark"
  65. }
  66. var r = parseInt(headerColor.substr(1, 2), 16);
  67. var g = parseInt(headerColor.substr(3, 2), 16);
  68. var b = parseInt(headerColor.substr(5, 2), 16);
  69. var yiq = (r * 299 + g * 587 + b * 114) / 1000;
  70. if (yiq >= 180) {
  71. return "dark";
  72. } else {
  73. return "light";
  74. }
  75. }