From 6a8d25f140491f43cc6fcc23f377e1b273bd430a Mon Sep 17 00:00:00 2001 From: Litasa <5760383-litasa@users.noreply.gitlab.com> Date: Fri, 25 Jul 2025 15:48:21 +0000 Subject: [PATCH] Moved the popup manager into its own file. Made it more robust so there should... --- system/scripts/gm/gm-monitor.js | 55 +++++---- system/scripts/helpers.js | 63 ++-------- system/scripts/misc/l5r5e-popup-manager.js | 133 +++++++++++++++++++++ 3 files changed, 173 insertions(+), 78 deletions(-) create mode 100644 system/scripts/misc/l5r5e-popup-manager.js diff --git a/system/scripts/gm/gm-monitor.js b/system/scripts/gm/gm-monitor.js index cfdc73d..80b653d 100644 --- a/system/scripts/gm/gm-monitor.js +++ b/system/scripts/gm/gm-monitor.js @@ -1,6 +1,8 @@ +import { L5r5ePopupManager } from '../misc/l5r5e-popup-manager.js'; const HandlebarsApplicationMixin = foundry.applications.api.HandlebarsApplicationMixin; const ApplicationV2 = foundry.applications.api.ApplicationV2; + export class GmMonitor extends HandlebarsApplicationMixin(ApplicationV2) { /** @override ApplicationV2 */ static get DEFAULT_OPTIONS() { @@ -136,33 +138,34 @@ export class GmMonitor extends HandlebarsApplicationMixin(ApplicationV2) { }).bind(this.element); // Tooltips - game.l5r5e.HelpersL5r5e.popupManager($(this.element).find(".actor-infos-control"), async (event) => { - const type = $(event.currentTarget).data("type"); - if (!type) { - return; + new L5r5ePopupManager( + $(this.element).find(".actor-infos-control"), + async (event) => { + const type = $(event.currentTarget).data("type"); + if (!type) return; + + if (type === "text") { + return $(event.currentTarget).data("text"); + } + + const uuid = $(event.currentTarget).data("actor-uuid"); + if (!uuid) return; + + const actor = this.context.actors.find(actor => actor.uuid === uuid); + if (!actor) return; + + switch (type) { + case "armors": + return this.#getTooltipArmors(actor); + case "weapons": + return this.#getTooltipWeapons(actor); + case "global": + return actor.isArmy + ? this.#getTooltipArmiesGlobal(actor) + : this.#getTooltipGlobal(actor); + } } - if (type === "text") { - return $(event.currentTarget).data("text"); - } - - const uuid = $(event.currentTarget).data("actor-uuid"); - if (!uuid) { - return; - } - const actor = this.context.actors.find((actor) => actor.uuid === uuid); - if (!actor) { - return; - } - - switch (type) { - case "armors": - return this.#getTooltipArmors(actor); - case "weapons": - return this.#getTooltipWeapons(actor); - case "global": - return actor.isArmy ? this.#getTooltipArmiesGlobal(actor) : this.#getTooltipGlobal(actor); - } - }); + ); } /** @override ApplicationV2 */ diff --git a/system/scripts/helpers.js b/system/scripts/helpers.js index e94fe81..f48d0a3 100644 --- a/system/scripts/helpers.js +++ b/system/scripts/helpers.js @@ -1,3 +1,5 @@ +import { L5r5ePopupManager } from './misc/l5r5e-popup-manager.js'; + /** * Extends the actor to process special things from L5R. */ @@ -509,13 +511,16 @@ export class HelpersL5r5e { }); // Item detail tooltips - this.popupManager(html.find(".l5r5e-tooltip"), async (event) => { - const item = await HelpersL5r5e.getEmbedItemByEvent(event, actor); - if (!item) { - return; + new L5r5ePopupManager( + html.find(".l5r5e-tooltip"), + async (event) => { + const item = await HelpersL5r5e.getEmbedItemByEvent(event, actor); + if (!item) { + return; + } + return await item.renderTextTemplate(); } - return await item.renderTextTemplate(); - }); + ); // Open actor sheet html.find(".open-sheet-from-uuid").on("click", async (event) => { @@ -534,52 +539,6 @@ export class HelpersL5r5e { }); } - /** - * Do the Popup for the selected element - * @param {Selector} selector HTML Selector - * @param {function} callback Callback function(event), must return the html to display - */ - static popupManager(selector, callback) { - const popupPosition = (event, popup) => { - let left = +event.clientX + 60, - top = +event.clientY; - - let maxY = window.innerHeight - popup.outerHeight(); - if (top > maxY) { - top = maxY - 10; - } - - let maxX = window.innerWidth - popup.outerWidth(); - if (left > maxX) { - left -= popup.outerWidth() + 100; - } - return { left: left + "px", top: top + "px", visibility: "visible" }; - }; - - selector - .on("mouseenter", async (event) => { - $(document.body).find("#l5r5e-tooltip-ct").remove(); - - const tpl = await callback(event); - if (!tpl) { - return; - } - - $(document.body).append( - `