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.

235 lines
9.5 KiB

  1. import {
  2. limitedScopeApplications,
  3. MODULE_NAME,
  4. themedApps,
  5. systemSheets,
  6. excludedApplications,
  7. moduleWindowApps,
  8. } from "./consts.js";
  9. import { isPremiumApplication } from "./premium-module-hooks.js";
  10. export function lookupThemeAndSchemeForKey(key) {
  11. switch (key) {
  12. case "opaque":
  13. return { dorakoUiTheme: "opaque", colorScheme: null };
  14. case "crb":
  15. return { dorakoUiTheme: "crb", colorScheme: null };
  16. case "crb-light":
  17. return { dorakoUiTheme: "crb", colorScheme: "light" };
  18. case "crb-dark":
  19. return { dorakoUiTheme: "crb", colorScheme: "dark" };
  20. case "foundry2":
  21. return { dorakoUiTheme: "foundry2", colorScheme: "dark" };
  22. case "bg3":
  23. return { dorakoUiTheme: "bg3", colorScheme: "dark" };
  24. case "bg3-brown":
  25. return { dorakoUiTheme: "bg3-brown", colorScheme: "dark" };
  26. case "bg3-blue":
  27. return { dorakoUiTheme: "bg3-blue", colorScheme: "dark" };
  28. case "discord":
  29. return { dorakoUiTheme: "discord", colorScheme: "dark" };
  30. case "discord-light":
  31. return { dorakoUiTheme: "discord-light", colorScheme: "light" };
  32. case "discord-dark":
  33. return { dorakoUiTheme: "discord-dark", colorScheme: "dark" };
  34. case "custom-light":
  35. return { dorakoUiTheme: "custom-light", colorScheme: "light" };
  36. case "custom-dark":
  37. return { dorakoUiTheme: "custom-dark", colorScheme: "dark" };
  38. default:
  39. return "", "";
  40. }
  41. }
  42. Hooks.on("renderSvelteApplication", (app, html, data) => {
  43. const theme = game.settings.get("pf2e-dorako-ui", "theme.window-app-theme");
  44. if (theme === "no-theme") return;
  45. const uiTheme = lookupThemeAndSchemeForKey(theme);
  46. if (uiTheme === null) return;
  47. const excludeString = game.settings.get("pf2e-dorako-ui", "customization.excluded-applications");
  48. const excludeList = excludeString.split(/[\s,]+/);
  49. if (excludeList.includes(app.constructor.name) || excludedApplications.includes(app.constructor.name)) {
  50. console.debug(`${MODULE_NAME} | render${app.constructor.name} | is included in excluded applications`);
  51. return;
  52. }
  53. const { dorakoUiTheme, colorScheme } = uiTheme;
  54. app.element[0].dataset.theme = dorakoUiTheme;
  55. app.element[0].dataset.colorScheme = colorScheme;
  56. app.element[0].dataset.dorakoUiScope = "unlimited";
  57. });
  58. for (const appName of [...themedApps]) {
  59. Hooks.on("render" + appName, (app, html, data) => {
  60. const theme = game.settings.get("pf2e-dorako-ui", "theme.app-theme");
  61. if (theme === "no-theme") return;
  62. const uiTheme = lookupThemeAndSchemeForKey(theme);
  63. if (uiTheme === null) return;
  64. const { dorakoUiTheme, colorScheme } = uiTheme;
  65. const excludeString = game.settings.get("pf2e-dorako-ui", "customization.excluded-applications");
  66. const excludeList = excludeString.split(/[\s,]+/);
  67. if (excludeList.includes(app.constructor.name) || excludedApplications.includes(app.constructor.name)) {
  68. console.debug(
  69. `${MODULE_NAME} | render${app.constructor.name} | is included in excluded applications string ${excludeString} => do not set dorako-ui-theme to ${dorakoUiTheme}`
  70. );
  71. return;
  72. }
  73. app.element[0].dataset.theme = dorakoUiTheme;
  74. console.debug(`${MODULE_NAME} | render${app.constructor.name} | [data-theme='${dorakoUiTheme}']`);
  75. });
  76. }
  77. for (const appName of [...systemSheets, ...moduleWindowApps]) {
  78. Hooks.on("render" + appName, (app, html, data) => {
  79. const theme = game.settings.get("pf2e-dorako-ui", "theme.window-app-theme");
  80. if (theme === "no-theme") return;
  81. const uiTheme = lookupThemeAndSchemeForKey(theme);
  82. if (uiTheme === null) return;
  83. const { dorakoUiTheme, colorScheme } = uiTheme;
  84. const excludeString = game.settings.get("pf2e-dorako-ui", "customization.excluded-applications");
  85. const excludeList = excludeString.split(/[\s,]+/);
  86. if (excludeList.includes(app.constructor.name)) {
  87. console.debug(
  88. `${MODULE_NAME} | render${app.constructor.name} | is included in excluded applications string ${excludeString} => do not set dorako-ui-theme to ${dorakoUiTheme}`
  89. );
  90. return;
  91. }
  92. if (
  93. theme == "crb-light" &&
  94. (app.constructor.name === "PartySheetPF2e" || app.constructor.name === "FamiliarSheetPF2e")
  95. )
  96. return;
  97. if (theme == "discord-light" && app.constructor.name === "PartySheetPF2e") return;
  98. app.element[0].dataset.theme = dorakoUiTheme;
  99. app.element[0].dataset.colorScheme = colorScheme;
  100. app.element[0].dataset.dorakoUiScope = "unlimited";
  101. console.debug(
  102. `${MODULE_NAME} | render${app.constructor.name} | [data-theme='${dorakoUiTheme}'] [data-color-scheme='${colorScheme}'] [data-dorako-ui-scope='unlimited']`
  103. );
  104. });
  105. }
  106. Hooks.on("renderApplication", (app, html, data) => {
  107. let html0 = html[0];
  108. if (html0.classList.contains("editable")) return;
  109. if (!html0.classList.contains("window-app")) return;
  110. if (isPremiumApplication(app, html, data, app.constructor.name)) return;
  111. const theme = game.settings.get("pf2e-dorako-ui", "theme.window-app-theme");
  112. if (theme === "no-theme") return;
  113. const uiTheme = lookupThemeAndSchemeForKey(theme);
  114. if (uiTheme === null) return;
  115. const { dorakoUiTheme, colorScheme } = uiTheme;
  116. const excludeString =
  117. game.settings.get("pf2e-dorako-ui", "customization.excluded-applications") +
  118. ", EnhancedJournal" +
  119. ", SceneActorsLayer" +
  120. ", SmallTimeApp" +
  121. ", SceneDarknessAdjuster" +
  122. ", AutorecMenuApp" +
  123. ", ImagePopout";
  124. const excludeList = excludeString.split(/[\s,]+/);
  125. if (excludeList.includes(app.constructor.name) || excludedApplications.includes(app.constructor.name)) {
  126. console.debug(
  127. `${MODULE_NAME} | render${app.constructor.name} | is included in excluded applications string ${excludeString} => do not set dorako-ui-theme to ${dorakoUiTheme}`
  128. );
  129. return;
  130. }
  131. const fakeDialogPatterns = ["popup", "dialog"];
  132. for (const fakeDialogPattern of [...fakeDialogPatterns]) {
  133. if (app.constructor.name.toLowerCase().includes(fakeDialogPattern)) {
  134. console.debug(
  135. `${MODULE_NAME} | render${app.constructor.name} | constructor includes '${fakeDialogPattern}' => add .dialog`
  136. );
  137. html.addClass("dialog");
  138. }
  139. }
  140. app.element[0].dataset.theme = dorakoUiTheme;
  141. app.element[0].dataset.colorScheme = colorScheme;
  142. app.element[0].dataset.dorakoUiScope = "unlimited";
  143. });
  144. // Hooks.on("renderDialog", (app, html, data) => {
  145. // const theme = game.settings.get("pf2e-dorako-ui", "theme.window-app-theme");
  146. // if (theme === "no-theme") return;
  147. // const uiTheme = getUiTheme();
  148. // if (uiTheme === null) return;
  149. // const { dorakoUiTheme, colorScheme } = uiTheme;
  150. // console.debug(`${MODULE_NAME} | render${app.constructor.name} | set dorako-ui-theme to ${dorakoUiTheme}`);
  151. // app.element[0].dataset.theme = dorakoUiTheme;
  152. // app.element[0].dataset.colorScheme = colorScheme;
  153. // app.element[0].dataset.dorakoUiScope = "unlimited";
  154. // });
  155. for (const appName of [...limitedScopeApplications]) {
  156. Hooks.on("render" + appName, (app, html, data) => {
  157. const theme = game.settings.get("pf2e-dorako-ui", "theme.window-app-theme");
  158. if (theme === "no-theme") return;
  159. const uiTheme = lookupThemeAndSchemeForKey(theme);
  160. if (uiTheme === null) return;
  161. const excludeString = game.settings.get("pf2e-dorako-ui", "customization.excluded-applications");
  162. const excludeList = excludeString.split(/[\s,]+/);
  163. if (excludeList.includes(app.constructor.name)) {
  164. console.debug(
  165. `${MODULE_NAME} | render${app.constructor.name} | is included in excluded applications string ${excludeString} => do not set data-dorako-ui-scope to 'limited'`
  166. );
  167. return;
  168. }
  169. console.debug(
  170. `${MODULE_NAME} | render${app.constructor.name} | theme: ${theme} => set data-dorako-ui-scope to 'limited'`
  171. );
  172. app.element[0].dataset.dorakoUiScope = "limited";
  173. });
  174. }
  175. for (const appName of ["CharacterSheetPF2e", "VehicleSheetPF2e"]) {
  176. Hooks.on("render" + appName, (app, html, data) => {
  177. const theme = game.settings.get("pf2e-dorako-ui", "theme.sheet-theme-color");
  178. if (theme === "default") return;
  179. app.element[0].dataset.themeColor = theme;
  180. });
  181. }
  182. Hooks.on("render" + "ItemSheetPF2e", (app, html, data) => {
  183. const rarity = app?.object?.rarity;
  184. if (rarity) app.element[0].dataset.rarity = rarity;
  185. });
  186. Hooks.on("render" + "NPCSheetPF2e", (app, html, data) => {
  187. const rarity = app?.object?.rarity;
  188. if (rarity) app.element[0].dataset.rarity = rarity;
  189. });
  190. Hooks.on("render" + "ChatMessage", (app, html, data) => {
  191. const footer = html.find("footer")[0];
  192. if (footer) html[0].dataset.hasFooter = "";
  193. });
  194. Hooks.on("render" + "ChatLogPF2e", (app, html, data) => {
  195. const theme = game.settings.get("pf2e-dorako-ui", "theme.app-theme");
  196. if (theme === "no-theme") return;
  197. app.element[0].dataset.chatInterfaceTheme = theme;
  198. });
  199. Hooks.on("render" + "Sidebar", (app, html, data) => {
  200. const theme = game.settings.get("pf2e-dorako-ui", "theme.app-theme");
  201. if (theme === "no-theme") return;
  202. if (theme === "bg3") {
  203. app.element[0].dataset.chatInterfaceTheme = "bg3-translucent";
  204. } else {
  205. app.element[0].dataset.chatInterfaceTheme = theme;
  206. }
  207. });
  208. Hooks.on("render" + "Sidebar", (app, html, data) => {
  209. const excludeString = game.settings.get("pf2e-dorako-ui", "customization.excluded-applications");
  210. const excludeList = excludeString.split(/[\s,]+/);
  211. if (excludeList.includes(app.constructor.name)) {
  212. console.debug(`${MODULE_NAME} | render${app.constructor.name} | is included in excluded applications string`);
  213. return;
  214. }
  215. $("#sidebar-tabs").attr("data-theme", "");
  216. app.element[0].dataset.dorakoUiScope = "sidebar";
  217. });