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.

133 lines
4.6 KiB

  1. import { debug } from "../util.js";
  2. import { MODULE_NAME } from "../consts.js";
  3. import ChatMerge from "../dorako-ux/chat-merge.js";
  4. import ChatRollPrivacy from "../dorako-ux/chat-rolltype-buttons.js";
  5. function injectCSS(filename) {
  6. const head = document.getElementsByTagName("head")[0];
  7. const mainCss = document.createElement("link");
  8. mainCss.setAttribute("rel", "stylesheet");
  9. mainCss.setAttribute("type", "text/css");
  10. mainCss.setAttribute("href", "modules/pf2e-dorako-ux/styles/" + filename + ".css");
  11. mainCss.setAttribute("media", "all");
  12. head.insertBefore(mainCss, head.lastChild);
  13. }
  14. Hooks.once("ready", () => {
  15. if (!game.settings.get("pf2e-dorako-ux", "moving.center-hotbar")) return;
  16. document.getElementById("ui-bottom").classList.add("centered");
  17. });
  18. Hooks.once("ready", () => {
  19. if (game.settings.get("pf2e-dorako-ux", "hiding.no-logo")) {
  20. $("#logo")[0].style.setProperty("display", "none", "important");
  21. }
  22. });
  23. Hooks.once("ready", () => {
  24. if (game.settings.get("pf2e-dorako-ux", "hiding.no-compendium-banner-images")) {
  25. $("body").addClass("no-compendium-banner-images");
  26. }
  27. });
  28. Hooks.on("renderChatLogPF2e", (app, html, data) => {
  29. if (game.settings.get("pf2e-dorako-ux", "hiding.no-chat-control-icon")) {
  30. html.find("#chat-controls")[0].classList.add("no-chat-control-icon");
  31. }
  32. });
  33. Hooks.once("renderSidebar", () => {
  34. const noCards = game.settings.get("pf2e-dorako-ux", "hiding.no-cards");
  35. if (!noCards) return;
  36. $(".item[data-tab=cards]").addClass("dorako-display-none");
  37. });
  38. Hooks.once("init", async () => {
  39. debug(`INIT`);
  40. debug(`REGISTERING SETTINGS`);
  41. debug(`INITIALIZING APPLICATIONS`);
  42. if (game.settings.get("pf2e-dorako-ux", "moving.chat-merge")) {
  43. ChatMerge.init();
  44. }
  45. if (game.settings.get("pf2e-dorako-ux", "moving.adjust-chat-controls")) {
  46. ChatRollPrivacy.setup();
  47. ChatRollPrivacy.init();
  48. }
  49. debug(`INJECTING CSS VARIABLES`);
  50. injectCSS("fonts");
  51. const root = document.querySelector(":root").style;
  52. root.setProperty("--avatar-size", game.settings.get("pf2e-dorako-ux", "avatar.size").toString() + "px");
  53. root.setProperty("--control-size", game.settings.get("pf2e-dorako-ux", "other.control-size").toString() + "px");
  54. root.setProperty(
  55. "--sidebar-tab-size",
  56. game.settings.get("pf2e-dorako-ux", "other.sidebar-tab-size").toString() + "px"
  57. );
  58. root.setProperty("--controls-alignment", game.settings.get("pf2e-dorako-ux", "moving.controls-alignment").toString());
  59. debug(`INIT COMPLETE`);
  60. });
  61. Hooks.once("ready", (app, html, data) => {
  62. if (!game.settings.get(`${MODULE_NAME}`, "hiding.start-sidebar-collapsed")) return;
  63. ui.sidebar.collapse();
  64. });
  65. Hooks.once("ready", (app, html, data) => {
  66. if (!game.settings.get(`${MODULE_NAME}`, "hiding.start-navigation-collapsed")) return;
  67. ui.nav.collapse();
  68. });
  69. Hooks.on("getItemSheetPF2eHeaderButtons", (sheet, buttons) => {
  70. if (!game.settings.get(`${MODULE_NAME}`, "other.send-to-chat")) {
  71. return;
  72. }
  73. buttons.unshift({
  74. label: `${MODULE_NAME}.text.send-to-chat`,
  75. class: "send",
  76. icon: "fas fa-comment-alt",
  77. onclick: async () => {
  78. if (sheet.document.actor) {
  79. await sheet.document.toChat(); // Can post directly
  80. } else {
  81. const json = sheet.document.toJSON();
  82. const actor =
  83. canvas.tokens.controlled[0]?.actor ?? // Selected token's corresponding actor
  84. game.user?.character ?? // Assigned actor
  85. new Actor({ name: game.user.name, type: "character" }); // Dummy actor fallback
  86. await new sheet.document.constructor(json, { parent: actor }).toChat();
  87. }
  88. },
  89. });
  90. });
  91. Hooks.on("renderCombatTracker", addScalingToCombatTrackerAvatars);
  92. function addScalingToCombatTrackerAvatars(app, html, data) {
  93. const combatImagesActive = game.modules.get("combat-tracker-images")?.active;
  94. $(".combatant", html).each(function () {
  95. let id = this.dataset.combatantId;
  96. let combatant = game.combat.combatants.get(id);
  97. let scale = combatant.token.texture.scaleX;
  98. let tokenImageElem = this.getElementsByClassName("token-image")[0];
  99. if (scale < 1 || (combatImagesActive && combatant.actor.getFlag("combat-tracker-images", "trackerImage"))) {
  100. scale = 1;
  101. }
  102. tokenImageElem.setAttribute("style", "transform: scale(" + Math.abs(scale) + ")");
  103. });
  104. }
  105. for (const appName of ["JournalSheet", "JournalPageSheet"]) {
  106. Hooks.on("render" + appName, (app, html, data) => {
  107. const isDalvyn = game.settings.get("pf2e-dorako-ux", "other.skin-crb-journal");
  108. if (!isDalvyn) return;
  109. if (app.id.includes("Compendium-pf2e-criticaldeck")) return;
  110. html.closest(".app").find(".journal-entry-content").addClass("dalvyn-journal");
  111. });
  112. }