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.

630 lines
24 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import { injectConfig } from "./lib/injectConfig.js";
  2. import { TileHandler } from "./handlers/tileHandler.js";
  3. import { RefreshHandler } from "./handlers/refreshHandler.js";
  4. import { DrawingHandler } from "./handlers/drawingHandler.js";
  5. import { UIHandler } from "./handlers/uiHandler.js";
  6. import { SightHandler } from "./handlers/sightHandler.js";
  7. import { LightHandler } from "./handlers/lightHandler.js";
  8. import { SoundHandler } from "./handlers/soundHandler.js";
  9. import { NoteHandler } from "./handlers/noteHandler.js";
  10. import { TokenHandler } from "./handlers/tokenHandler.js";
  11. import { TemplateHandler } from "./handlers/templateHandler.js";
  12. import { FoWHandler } from "./handlers/fowHandler.js";
  13. import { BackgroundHandler } from "./handlers/backgroundHandler.js";
  14. import { SettingsHandler } from "./handlers/settingsHandler.js";
  15. import { LevelsAPI } from "./API.js";
  16. import { registerWrappers } from "./wrappers.js";
  17. import { inRange, getRangeForDocument, cloneTileMesh, inDistance } from "./helpers.js";
  18. import { setupWarnings } from "./warnings.js";
  19. //warnings
  20. Hooks.on("ready", () => {
  21. if (!game.user.isGM) return;
  22. setupWarnings();
  23. const recommendedVersion = "10.291";
  24. if (isNewerVersion(recommendedVersion, game.version)) {
  25. ui.notifications.error(`Levels recommends Foundry VTT version ${recommendedVersion} or newer. Levels might not work as expected in the currently installed version (${game.version}).`, { permanent: true });
  26. return;
  27. }
  28. });
  29. Object.defineProperty(globalThis, "_levels", {
  30. get: () => {
  31. console.warn("Levels: _levels is deprecated. Use CONFIG.Levels.API instead.");
  32. return CONFIG.Levels.API;
  33. },
  34. });
  35. Object.defineProperty(TileDocument.prototype, "elevation", {
  36. get: function () {
  37. if (CONFIG.Levels?.UI?.rangeEnabled && !this.id) {
  38. return parseFloat(CONFIG.Levels.UI.range[0] || 0);
  39. }
  40. return this.overhead ? this.flags?.levels?.rangeBottom ?? canvas.scene.foregroundElevation : canvas.primary.background.elevation;
  41. },
  42. });
  43. Tile.prototype.inTriggeringRange = function (token) {
  44. const bottom = this.document.elevation;
  45. let top = this.document.flags?.levels?.rangeTop ?? Infinity;
  46. if (game.Levels3DPreview?._active) {
  47. const depth = this.document.flags?.["levels-3d-preview"]?.depth;
  48. if (depth) top = bottom + (depth / canvas.scene.dimensions.size) * canvas.scene.dimensions.distance;
  49. }
  50. if (token) {
  51. return token.document.elevation >= bottom && token.document.elevation <= top;
  52. } else {
  53. return { bottom, top };
  54. }
  55. };
  56. Object.defineProperty(DrawingDocument.prototype, "elevation", {
  57. get: function () {
  58. if (CONFIG.Levels?.UI?.rangeEnabled && !this.id) {
  59. return parseFloat(CONFIG.Levels.UI.range[0] || 0);
  60. }
  61. return this.flags?.levels?.rangeBottom ?? canvas.primary.background.elevation;
  62. },
  63. });
  64. Object.defineProperty(NoteDocument.prototype, "elevation", {
  65. get: function () {
  66. return this.flags?.levels?.rangeBottom ?? canvas.primary.background.elevation;
  67. },
  68. });
  69. Object.defineProperty(AmbientLightDocument.prototype, "elevation", {
  70. get: function () {
  71. if (CONFIG.Levels.UI.rangeEnabled && !this.id) {
  72. return parseFloat(CONFIG.Levels.UI.range[0] || 0);
  73. }
  74. return this.flags?.levels?.rangeBottom ?? canvas.primary.background.elevation;
  75. },
  76. });
  77. Object.defineProperty(AmbientSoundDocument.prototype, "elevation", {
  78. get: function () {
  79. if (CONFIG.Levels.UI.rangeEnabled && !this.id) {
  80. return parseFloat(CONFIG.Levels.UI.range[0] || 0);
  81. }
  82. if (isNaN(this.flags?.levels?.rangeBottom)) return canvas.primary.background.elevation;
  83. return (this.flags?.levels?.rangeBottom + (this.flags?.levels?.rangeTop ?? this.flags?.levels?.rangeBottom)) / 2;
  84. },
  85. });
  86. Object.defineProperty(MeasuredTemplateDocument.prototype, "elevation", {
  87. get: function () {
  88. return this.flags?.levels?.elevation ?? canvas.primary.background.elevation;
  89. },
  90. });
  91. Object.defineProperty(WeatherEffects.prototype, "elevation", {
  92. get: function () {
  93. return canvas?.scene?.flags?.levels?.weatherElevation ?? Infinity;
  94. },
  95. set: function (value) {
  96. console.error("Cannot set elevation on WeatherEffects. Levels overrides WeatherEffects.prototype.elevation core behaviour. If you wish to set the WeatherEffects elevation, use SceneDocument.flags.levels.weatherElevation");
  97. },
  98. });
  99. Hooks.on("init", () => {
  100. const canvas3d = game.modules.get("levels-3d-preview")?.active;
  101. CONFIG.Levels = {
  102. MODULE_ID: "levels",
  103. };
  104. Object.defineProperty(CONFIG.Levels, "useCollision3D", {
  105. get: function () {
  106. return canvas3d && canvas.scene.flags["levels-3d-preview"]?.object3dSight;
  107. },
  108. });
  109. Object.defineProperty(CONFIG.Levels, "currentToken", {
  110. get: function () {
  111. return this._currentToken;
  112. },
  113. set: function (value) {
  114. this._currentToken = value;
  115. Hooks.callAll("levelsPerspectiveChanged", this._currentToken);
  116. },
  117. });
  118. CONFIG.Levels.handlers = {
  119. TileHandler,
  120. RefreshHandler,
  121. DrawingHandler,
  122. UIHandler,
  123. SightHandler,
  124. LightHandler,
  125. SoundHandler,
  126. NoteHandler,
  127. TokenHandler,
  128. TemplateHandler,
  129. FoWHandler,
  130. BackgroundHandler,
  131. SettingsHandler,
  132. };
  133. CONFIG.Levels.helpers = {
  134. inRange,
  135. getRangeForDocument,
  136. cloneTileMesh,
  137. inDistance,
  138. };
  139. CONFIG.Levels.API = LevelsAPI;
  140. CONFIG.Levels.UI = new LevelsUI();
  141. CONFIG.Levels.settings = new SettingsHandler();
  142. Hooks.callAll("levelsInit", CONFIG.Levels);
  143. registerWrappers();
  144. CONFIG.Levels.FoWHandler = new FoWHandler();
  145. CONFIG.Levels.handlers.BackgroundHandler.setupElevation();
  146. Hooks.callAll("levelsReady", CONFIG.Levels);
  147. });
  148. Hooks.once("ready", () => {
  149. if (game.modules.get("levels-3d-preview")?.active) return;
  150. // Module title
  151. const MODULE_ID = CONFIG.Levels.MODULE_ID;
  152. const MODULE_TITLE = game.modules.get(MODULE_ID).title;
  153. const FALLBACK_MESSAGE_TITLE = MODULE_TITLE;
  154. const FALLBACK_MESSAGE = `<large>
  155. <p><strong>This module may be very complicated for a first timer, be sure to stop by my <a href="https://theripper93.com/">Discord</a> for help and support from the wonderful community as well as many resources</strong></p>
  156. <p>Thanks to all the patreons supporting the development of this module making continued updates possible!</p>
  157. <p>If you want to support the development of the module or get customized support in setting up your maps you can do so here : <a href="https://www.patreon.com/theripper93">Patreon</a> </p></large>
  158. <p><strong>Patreons</strong> get also access to <strong>15+ premium modules</strong></p>
  159. <p>Is Levels not enough? Go Full 3D</p>
  160. <h1>3D Canvas</h1>
  161. <iframe width="385" height="225" src="https://www.youtube.com/embed/hC1QGZFUhcU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
  162. <p>Check 3D Canvas and all my other <strong>15+ premium modules <a href="https://theripper93.com/">Here</a></strong></p>
  163. <p>Special thanks to Baileywiki for the support and feedback and Blair for the amazing UI elements</p>`;
  164. // Settings key used for the "Don't remind me again" setting
  165. const DONT_REMIND_AGAIN_KEY = "popup-dont-remind-again-2";
  166. // Dialog code
  167. game.settings.register(MODULE_ID, DONT_REMIND_AGAIN_KEY, {
  168. name: "",
  169. default: false,
  170. type: Boolean,
  171. scope: "world",
  172. config: false,
  173. });
  174. if (game.user.isGM && !game.settings.get(MODULE_ID, DONT_REMIND_AGAIN_KEY)) {
  175. new Dialog({
  176. title: FALLBACK_MESSAGE_TITLE,
  177. content: FALLBACK_MESSAGE,
  178. buttons: {
  179. ok: { icon: '<i class="fas fa-check"></i>', label: "Understood" },
  180. dont_remind: {
  181. icon: '<i class="fas fa-times"></i>',
  182. label: "Don't remind me again",
  183. callback: () => game.settings.set(MODULE_ID, DONT_REMIND_AGAIN_KEY, true),
  184. },
  185. },
  186. }).render(true);
  187. }
  188. });
  189. Hooks.on("init", () => {
  190. game.settings.register(CONFIG.Levels.MODULE_ID, "tokenElevScale", {
  191. name: game.i18n.localize("levels.settings.tokenElevScale.name"),
  192. hint: game.i18n.localize("levels.settings.tokenElevScale.hint"),
  193. scope: "world",
  194. config: true,
  195. type: Boolean,
  196. default: false,
  197. onChange: () => {
  198. CONFIG.Levels.settings.cacheSettings();
  199. },
  200. });
  201. game.settings.register(CONFIG.Levels.MODULE_ID, "tokenElevScaleMultiSett", {
  202. name: game.i18n.localize("levels.settings.tokenElevScaleMultiSett.name"),
  203. hint: game.i18n.localize("levels.settings.tokenElevScaleMultiSett.hint"),
  204. scope: "world",
  205. config: true,
  206. type: Number,
  207. range: {
  208. min: 0.1,
  209. max: 2,
  210. step: 0.1,
  211. },
  212. default: 1,
  213. onChange: () => {
  214. CONFIG.Levels.settings.cacheSettings();
  215. },
  216. });
  217. game.settings.register(CONFIG.Levels.MODULE_ID, "fogHiding", {
  218. name: game.i18n.localize("levels.settings.fogHiding.name"),
  219. hint: game.i18n.localize("levels.settings.fogHiding.hint"),
  220. scope: "world",
  221. config: true,
  222. type: Boolean,
  223. default: true,
  224. onChange: () => {
  225. CONFIG.Levels.settings.cacheSettings();
  226. },
  227. });
  228. game.settings.register(CONFIG.Levels.MODULE_ID, "revealTokenInFog", {
  229. name: game.i18n.localize("levels.settings.revealTokenInFog.name"),
  230. hint: game.i18n.localize("levels.settings.revealTokenInFog.hint"),
  231. scope: "world",
  232. config: true,
  233. type: Boolean,
  234. default: false,
  235. onChange: () => {
  236. CONFIG.Levels.settings.cacheSettings();
  237. },
  238. });
  239. game.settings.register(CONFIG.Levels.MODULE_ID, "lockElevation", {
  240. name: game.i18n.localize("levels.settings.lockElevation.name"),
  241. hint: game.i18n.localize("levels.settings.lockElevation.hint"),
  242. scope: "world",
  243. config: true,
  244. type: Boolean,
  245. default: false,
  246. onChange: () => {
  247. CONFIG.Levels.settings.cacheSettings();
  248. },
  249. });
  250. game.settings.register(CONFIG.Levels.MODULE_ID, "hideElevation", {
  251. name: game.i18n.localize("levels.settings.hideElevation.name"),
  252. hint: game.i18n.localize("levels.settings.hideElevation.hint"),
  253. scope: "world",
  254. config: true,
  255. type: Number,
  256. choices: {
  257. 0: game.i18n.localize("levels.settings.hideElevation.opt0"),
  258. 1: game.i18n.localize("levels.settings.hideElevation.opt1"),
  259. 2: game.i18n.localize("levels.settings.hideElevation.opt2"),
  260. },
  261. default: 0,
  262. onChange: () => {
  263. CONFIG.Levels.settings.cacheSettings();
  264. },
  265. });
  266. game.settings.register(CONFIG.Levels.MODULE_ID, "enableTooltips", {
  267. name: game.i18n.localize("levels.settings.enableTooltips.name"),
  268. hint: game.i18n.localize("levels.settings.enableTooltips.hint"),
  269. scope: "world",
  270. config: true,
  271. type: Boolean,
  272. default: false,
  273. onChange: () => {
  274. CONFIG.Levels.settings.cacheSettings();
  275. },
  276. });
  277. game.settings.register(CONFIG.Levels.MODULE_ID, "preciseTokenVisibility", {
  278. name: game.i18n.localize("levels.settings.preciseTokenVisibility.name"),
  279. hint: game.i18n.localize("levels.settings.preciseTokenVisibility.hint"),
  280. scope: "world",
  281. config: true,
  282. type: Boolean,
  283. default: true,
  284. onChange: () => {
  285. CONFIG.Levels.settings.cacheSettings();
  286. },
  287. });
  288. game.settings.register(CONFIG.Levels.MODULE_ID, "exactTokenVisibility", {
  289. name: game.i18n.localize("levels.settings.exactTokenVisibility.name"),
  290. hint: game.i18n.localize("levels.settings.exactTokenVisibility.hint"),
  291. scope: "world",
  292. config: true,
  293. type: Boolean,
  294. default: false,
  295. onChange: () => {
  296. CONFIG.Levels.settings.cacheSettings();
  297. },
  298. });
  299. });
  300. Hooks.on("updateTile", (tile, updates) => {
  301. if (updates?.flags?.levels?.allWallBlockSight !== undefined) {
  302. canvas.walls.placeables.forEach((w) => w.identifyInteriorState());
  303. WallHeight.schedulePerceptionUpdate();
  304. }
  305. });
  306. Hooks.on("renderTileConfig", (app, html, data) => {
  307. const isInjected = html.find(`input[name="flags.${CONFIG.Levels.MODULE_ID}.rangeTop"]`).length > 0;
  308. if (isInjected) return;
  309. const injHtml = injectConfig.inject(app, html, {
  310. moduleId: "levels",
  311. tab: {
  312. name: "levels",
  313. label: "Levels",
  314. icon: "fas fa-layer-group",
  315. },
  316. rangeTop: {
  317. type: "number",
  318. label: game.i18n.localize("levels.tileconfig.rangeTop.name"),
  319. units: game.i18n.localize("levels.tileconfig.range.unit"),
  320. default: "",
  321. placeholder: "Infinity",
  322. step: "any",
  323. },
  324. rangeBottom: {
  325. type: "number",
  326. label: game.i18n.localize("levels.tileconfig.rangeBottom.name"),
  327. units: game.i18n.localize("levels.tileconfig.range.unit"),
  328. default: "",
  329. placeholder: "-Infinity",
  330. step: "any",
  331. },
  332. showIfAbove: {
  333. type: "checkbox",
  334. label: game.i18n.localize("levels.tileconfig.showIfAbove.name"),
  335. notes: game.i18n.localize("levels.tileconfig.showIfAbove.hint"),
  336. },
  337. showAboveRange: {
  338. type: "number",
  339. label: game.i18n.localize("levels.tileconfig.showAboveRange.name"),
  340. notes: game.i18n.localize("levels.tileconfig.showAboveRange.hint"),
  341. units: game.i18n.localize("levels.tileconfig.range.unit"),
  342. default: "",
  343. placeholder: "Infinity",
  344. },
  345. noCollision: {
  346. type: "checkbox",
  347. label: game.i18n.localize("levels.tileconfig.noCollision.name"),
  348. notes: game.i18n.localize("levels.tileconfig.noCollision.hint"),
  349. },
  350. noFogHide: {
  351. type: "checkbox",
  352. label: game.i18n.localize("levels.tileconfig.noFogHide.name"),
  353. notes: game.i18n.localize("levels.tileconfig.noFogHide.hint"),
  354. },
  355. isBasement: {
  356. type: "checkbox",
  357. label: game.i18n.localize("levels.tileconfig.isBasement.name"),
  358. notes: game.i18n.localize("levels.tileconfig.isBasement.hint"),
  359. },
  360. allWallBlockSight: {
  361. type: "checkbox",
  362. label: game.i18n.localize("levels.tileconfig.allWallBlockSight.name"),
  363. notes: game.i18n.localize("levels.tileconfig.allWallBlockSight.hint"),
  364. default: true,
  365. },
  366. });
  367. injHtml.find(`input[name="flags.${CONFIG.Levels.MODULE_ID}.rangeTop"]`).closest(".form-group").before(`
  368. <p class="notes" style="color: red" id="no-overhead-warning">${game.i18n.localize("levels.tileconfig.noOverhead")}</>
  369. <p class="notes" style="color: red" id="occlusion-none-warning">${game.i18n.localize("levels.tileconfig.occlusionNone")}</>
  370. `);
  371. html.on("change", "input", (e) => {
  372. const isOverhead = html.find(`input[name="overhead"]`).is(":checked");
  373. const occlusionMode = html.find(`select[name="occlusion.mode"]`).val();
  374. const isShowIfAbove = injHtml.find(`input[name="flags.levels.showIfAbove"]`).is(":checked");
  375. injHtml.find("input").prop("disabled", !isOverhead);
  376. injHtml.find("input[name='flags.levels.showAboveRange']").closest(".form-group").toggle(isShowIfAbove);
  377. html.find("#no-overhead-warning").toggle(!isOverhead);
  378. html.find("#occlusion-none-warning").toggle(occlusionMode == 0);
  379. app.setPosition({ height: "auto" });
  380. });
  381. html.find(`input[name="overhead"]`).trigger("change");
  382. app.setPosition({ height: "auto" });
  383. });
  384. Hooks.on("renderAmbientLightConfig", (app, html, data) => {
  385. const injHtml = injectConfig.inject(app, html, {
  386. moduleId: "levels",
  387. inject: 'input[name="config.dim"]',
  388. rangeTop: {
  389. type: "number",
  390. label: game.i18n.localize("levels.tileconfig.rangeTop.name"),
  391. units: game.i18n.localize("levels.tileconfig.range.unit"),
  392. default: "",
  393. placeholder: "Infinity",
  394. step: "any",
  395. },
  396. rangeBottom: {
  397. type: "number",
  398. label: game.i18n.localize("levels.tileconfig.rangeBottom.name"),
  399. units: game.i18n.localize("levels.tileconfig.range.unit"),
  400. default: "",
  401. placeholder: "-Infinity",
  402. step: "any",
  403. },
  404. });
  405. });
  406. Hooks.on("renderNoteConfig", (app, html, data) => {
  407. const injHtml = injectConfig.inject(app, html, {
  408. moduleId: "levels",
  409. inject: 'select[name="textAnchor"]',
  410. rangeTop: {
  411. type: "number",
  412. label: game.i18n.localize("levels.tileconfig.rangeTop.name"),
  413. units: game.i18n.localize("levels.tileconfig.range.unit"),
  414. default: "",
  415. placeholder: "Infinity",
  416. step: "any",
  417. },
  418. rangeBottom: {
  419. type: "number",
  420. label: game.i18n.localize("levels.tileconfig.rangeBottom.name"),
  421. units: game.i18n.localize("levels.tileconfig.range.unit"),
  422. default: "",
  423. placeholder: "-Infinity",
  424. step: "any",
  425. },
  426. });
  427. });
  428. Hooks.on("renderAmbientSoundConfig", (app, html, data) => {
  429. const injHtml = injectConfig.inject(app, html, {
  430. moduleId: "levels",
  431. inject: 'input[name="radius"]',
  432. rangeTop: {
  433. type: "number",
  434. label: game.i18n.localize("levels.tileconfig.rangeTop.name"),
  435. units: game.i18n.localize("levels.tileconfig.range.unit"),
  436. default: "",
  437. placeholder: "Infinity",
  438. step: "any",
  439. },
  440. rangeBottom: {
  441. type: "number",
  442. label: game.i18n.localize("levels.tileconfig.rangeBottom.name"),
  443. units: game.i18n.localize("levels.tileconfig.range.unit"),
  444. default: "",
  445. placeholder: "-Infinity",
  446. step: "any",
  447. },
  448. });
  449. });
  450. Hooks.on("renderDrawingConfig", (app, html, data) => {
  451. const injHtml = injectConfig.inject(app, html, {
  452. moduleId: "levels",
  453. inject: 'input[name="z"]',
  454. drawingMode: {
  455. type: "select",
  456. label: game.i18n.localize("levels.drawingconfig.isHole.name"),
  457. default: 0,
  458. dType: "Number",
  459. options: {
  460. 0: game.i18n.localize("levels.drawingconfig.isHole.opt0"),
  461. 2: game.i18n.localize("levels.drawingconfig.isHole.opt2"),
  462. 21: game.i18n.localize("levels.drawingconfig.isHole.opt21"),
  463. 22: game.i18n.localize("levels.drawingconfig.isHole.opt22"),
  464. 3: game.i18n.localize("levels.drawingconfig.isHole.opt3"),
  465. },
  466. },
  467. elevatorFloors: {
  468. type: "text",
  469. label: game.i18n.localize("levels.drawingconfig.elevatorFloors.name"),
  470. notes: game.i18n.localize("levels.drawingconfig.elevatorFloors.hint"),
  471. },
  472. rangeTop: {
  473. type: "number",
  474. label: game.i18n.localize("levels.tileconfig.rangeTop.name"),
  475. units: game.i18n.localize("levels.tileconfig.range.unit"),
  476. default: "",
  477. placeholder: "Infinity",
  478. step: "any",
  479. },
  480. rangeBottom: {
  481. type: "number",
  482. label: game.i18n.localize("levels.tileconfig.rangeBottom.name"),
  483. units: game.i18n.localize("levels.tileconfig.range.unit"),
  484. default: "",
  485. placeholder: "-Infinity",
  486. step: "any",
  487. },
  488. });
  489. });
  490. Hooks.on("renderMeasuredTemplateConfig", (app, html, data) => {
  491. const injHtml = injectConfig.inject(app, html, {
  492. moduleId: "levels",
  493. inject: 'input[name="width"]',
  494. elevation: {
  495. type: "text",
  496. dType: "Number",
  497. label: game.i18n.localize("levels.template.elevation.name"),
  498. units: game.i18n.localize("levels.tileconfig.range.unit"),
  499. default: Infinity,
  500. step: "any",
  501. },
  502. special: {
  503. type: "number",
  504. label: game.i18n.localize("levels.template.depth.name"),
  505. default: 0,
  506. dType: "Number",
  507. },
  508. });
  509. });
  510. Hooks.on("renderDrawingHUD", (data, hud, drawData) => {
  511. let drawing = data.object.document;
  512. if (drawing.getFlag(CONFIG.Levels.MODULE_ID, "drawingMode")) {
  513. let active = drawing.getFlag(CONFIG.Levels.MODULE_ID, "stairLocked") || false;
  514. let toggleStairbtn = `<div class="control-icon${active ? " active" : ""}" id="toggleStair">
  515. <i class="fas fa-lock" width="36" height="36" title='${game.i18n.localize("levels.drawingHud.title")}'></i>
  516. </div>`;
  517. const controlIcons = hud.find("div.control-icon");
  518. controlIcons.last().after(toggleStairbtn);
  519. $(hud.find(`div[id="toggleStair"]`)).on("click", test);
  520. function test() {
  521. console.log("test");
  522. active = !active;
  523. drawing.setFlag(CONFIG.Levels.MODULE_ID, "stairLocked", !(drawing.getFlag(CONFIG.Levels.MODULE_ID, "stairLocked") || false));
  524. let hudbtn = hud.find(`div[id="toggleStair"]`);
  525. if (active) hudbtn.addClass("active");
  526. else hudbtn.removeClass("active");
  527. }
  528. }
  529. });
  530. Hooks.on("renderTokenHUD", (data, hud, drawData) => {
  531. if (CONFIG.Levels.settings.get("lockElevation") && !game.user.isGM) {
  532. const controlIcons = hud.find(`div[class="attribute elevation"]`);
  533. $(controlIcons[0]).remove();
  534. }
  535. });
  536. Hooks.on("preCreateMeasuredTemplate", (template) => {
  537. const templateData = CONFIG.Levels.handlers.TemplateHandler.getTemplateData();
  538. if (template.flags?.levels?.elevation) return;
  539. template.updateSource({
  540. flags: { levels: { elevation: templateData.elevation, special: templateData.special } },
  541. });
  542. });
  543. Hooks.on("renderSceneConfig", (app, html, data) => {
  544. injectConfig.inject(app, html, {
  545. moduleId: "levels",
  546. inject: 'input[name="foregroundElevation"]',
  547. backgroundElevation: {
  548. type: "number",
  549. label: game.i18n.localize("levels.sceneconfig.backgroundElevation.name"),
  550. notes: game.i18n.localize("levels.sceneconfig.backgroundElevation.notes"),
  551. default: 0,
  552. },
  553. });
  554. injectConfig.inject(app, html, {
  555. moduleId: "levels",
  556. inject: 'select[name="weather"]',
  557. weatherElevation: {
  558. type: "number",
  559. label: game.i18n.localize("levels.sceneconfig.weatherElevation.name"),
  560. notes: game.i18n.localize("levels.sceneconfig.weatherElevation.notes"),
  561. default: "",
  562. placeholder: "Infinity",
  563. },
  564. });
  565. injectConfig.inject(app, html, {
  566. moduleId: "levels",
  567. inject: 'input[name="fogExploration"]',
  568. lightMasking: {
  569. type: "checkbox",
  570. label: game.i18n.localize("levels.sceneconfig.lightMasking.name"),
  571. notes: game.i18n.localize("levels.sceneconfig.lightMasking.notes"),
  572. default: true,
  573. },
  574. });
  575. });