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.

177 lines
5.1 KiB

1 year ago
  1. Hooks.once("ready", function () {
  2. game.settings.register("bossbar", "currentHpPath", {
  3. name: game.i18n.localize("bossbar.settings.currentHpPath.name"),
  4. hint: game.i18n.localize("bossbar.settings.currentHpPath.hint"),
  5. scope: "world",
  6. config: true,
  7. type: String,
  8. default: "attributes.hp.value",
  9. });
  10. game.settings.register("bossbar", "maxHpPath", {
  11. name: game.i18n.localize("bossbar.settings.maxHpPath.name"),
  12. hint: game.i18n.localize("bossbar.settings.maxHpPath.hint"),
  13. scope: "world",
  14. config: true,
  15. type: String,
  16. default: "attributes.hp.max",
  17. });
  18. game.settings.register("bossbar", "barHeight", {
  19. name: game.i18n.localize("bossbar.settings.barHeight.name"),
  20. hint: game.i18n.localize("bossbar.settings.barHeight.hint"),
  21. scope: "world",
  22. config: true,
  23. type: Number,
  24. default: 20,
  25. });
  26. game.settings.register("bossbar", "textSize", {
  27. name: game.i18n.localize("bossbar.settings.textSize.name"),
  28. hint: game.i18n.localize("bossbar.settings.textSize.hint"),
  29. scope: "world",
  30. config: true,
  31. type: Number,
  32. default: 20,
  33. });
  34. game.settings.register("bossbar", "cameraPan", {
  35. name: game.i18n.localize("bossbar.settings.cameraPan.name"),
  36. hint: game.i18n.localize("bossbar.settings.cameraPan.hint"),
  37. scope: "world",
  38. config: true,
  39. type: Boolean,
  40. default: false,
  41. });
  42. game.settings.register("bossbar", "position", {
  43. name: game.i18n.localize("bossbar.settings.position.name"),
  44. hint: game.i18n.localize("bossbar.settings.position.hint"),
  45. scope: "world",
  46. config: true,
  47. type: Number,
  48. choices: {
  49. 0: game.i18n.localize("bossbar.settings.position.opt0"),
  50. 1: game.i18n.localize("bossbar.settings.position.opt1"),
  51. },
  52. default: 0,
  53. });
  54. game.settings.register("bossbar", "backgroundPath", {
  55. name: game.i18n.localize("bossbar.settings.backgroundPath.name"),
  56. hint: game.i18n.localize("bossbar.settings.backgroundPath.hint"),
  57. scope: "world",
  58. config: true,
  59. type: String,
  60. default: "modules/bossbar/resources/Dark.webp",
  61. filePicker: true,
  62. });
  63. game.settings.register("bossbar", "foregroundPath", {
  64. name: game.i18n.localize("bossbar.settings.foregroundPath.name"),
  65. hint: game.i18n.localize("bossbar.settings.foregroundPath.hint"),
  66. scope: "world",
  67. config: true,
  68. type: String,
  69. default: "modules/bossbar/resources/Blood.webp",
  70. filePicker: true,
  71. });
  72. new window.Ardittristan.ColorSetting("bossbar", "tempBarColor", {
  73. name: game.i18n.localize("bossbar.settings.tempBarColor.name"),
  74. hint: game.i18n.localize("bossbar.settings.tempBarColor.hint"),
  75. label: game.i18n.localize("bossbar.settings.tempBarColor.label"),
  76. restricted: true,
  77. defaultColor: "#7e7e7e",
  78. scope: "world",
  79. });
  80. Hooks.on("renderApplication", (app) => {
  81. if (app.id == "controls" || app.id =="navigation" || app.id == "camera-views") {
  82. BossBar.renderBossBar();
  83. }
  84. });
  85. BossBar.renderBossBar();
  86. });
  87. Hooks.once("ready", function () {});
  88. Hooks.on("updateScene", async (scene, updates) => {
  89. if (!game.user.isGM) {
  90. if (updates.flags?.bossbar) {
  91. const ids = canvas.scene.getFlag("bossbar", "bossBarActive");
  92. if (!ids) {
  93. if (canvas.scene._bossBars) {
  94. for (let bar of Object.entries(canvas.scene._bossBars)) {
  95. bar[1].unHook();
  96. }
  97. delete canvas.scene._bossBars;
  98. }
  99. return;
  100. }
  101. for (let id of ids) {
  102. if (canvas.scene._bossBars && canvas.scene._bossBars[id]) {
  103. canvas.scene._bossBars[id].draw(
  104. game.settings.get("bossbar", "barHeight")
  105. );
  106. return;
  107. } else {
  108. await BossBar.create(canvas.tokens.get(id));
  109. }
  110. }
  111. } else {
  112. //BossBar.clearAll();
  113. }
  114. }
  115. });
  116. Hooks.on("getSceneControlButtons", (controls, b, c) => {
  117. if (!canvas.scene) return;
  118. let isBoss = canvas.scene.getFlag("bossbar", "bossBarActive") ? true : false;
  119. controls
  120. .find((c) => c.name == "token")
  121. .tools.push({
  122. name: "bossBar",
  123. title: game.i18n.localize("bossbar.controls.bossUI.name"),
  124. icon: "fas fa-pastafarianism",
  125. toggle: true,
  126. visible: game.user.isGM,
  127. active: isBoss,
  128. onClick: async (toggle) => {
  129. if (toggle) {
  130. if (canvas.tokens.controlled[0]) {
  131. for (let token of canvas.tokens.controlled) {
  132. await BossBar.create(token);
  133. if (game.settings.get("bossbar", "cameraPan"))
  134. BossBar.panCamera(token);
  135. }
  136. } else {
  137. ui.notifications.warn(
  138. game.i18n.localize("bossbar.controls.bossUI.warn")
  139. );
  140. }
  141. } else {
  142. await canvas.scene.unsetFlag("bossbar", "bossBarActive");
  143. BossBar.remove();
  144. }
  145. },
  146. });
  147. });
  148. Object.byString = function (o, s) {
  149. s = s.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties
  150. s = s.replace(/^\./, ""); // strip a leading dot
  151. var a = s.split(".");
  152. for (var i = 0, n = a.length; i < n; ++i) {
  153. var k = a[i];
  154. if (k in o) {
  155. o = o[k];
  156. } else {
  157. return;
  158. }
  159. }
  160. return o;
  161. };