From 4d138cbdfe6e722e1e079d0ba91f3b35b5122e73 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 1 Feb 2026 17:12:30 -0700 Subject: [PATCH] Update the token app render hook to also do the combat turn marker source --- module/hooks/renderTokenApplication.mjs | 47 +++++++++++++++++-------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/module/hooks/renderTokenApplication.mjs b/module/hooks/renderTokenApplication.mjs index 556a800..40edeca 100644 --- a/module/hooks/renderTokenApplication.mjs +++ b/module/hooks/renderTokenApplication.mjs @@ -2,24 +2,43 @@ import { ArtBrowser } from "../apps/ArtBrowser.mjs"; /* This hook handles adding the button for selecting an image using this module -into the prototype token config and the token-specific config. Handling both -apps with a single hook. +into the prototype token config and the token-specific config. Handling all of +the relevant locations in both apps with a single hook. */ Hooks.on(`renderTokenApplication`, (app, form) => { - // Locate where we want to inject the button - /** @type {HTMLElement | undefined} */ - const picker = form.querySelector(`file-picker[name="texture.src"]`); - if (!picker) { return }; - - // Create the button and listener const button = document.createElement(`button`); button.type = `button`; button.classList = `icon fa-solid fa-paintbrush`; - button.addEventListener(`click`, async () => { - const src = await ArtBrowser.select(1); - picker.value = src; - }); - // Inject the element into the DOM - picker.insertAdjacentElement(`afterend`, button); + /** @type {HTMLElement | undefined} */ + const textureSource = form.querySelector(`file-picker[name="texture.src"]`); + if (textureSource) { + const cloned = button.cloneNode(true); + cloned.addEventListener(`click`, async () => { + const src = await ArtBrowser.select(1); + if (!src) return + textureSource.value = src; + }); + textureSource.insertAdjacentElement(`afterend`, cloned); + }; + + /** @type {HTMLElement | undefined} */ + const turnMarkerSource = form.querySelector(`file-picker[name="turnMarker.src"]`); + if (turnMarkerSource) { + const cloned = button.cloneNode(true); + cloned.disabled = turnMarkerSource.disabled; + cloned.addEventListener(`click`, async () => { + const src = await ArtBrowser.select(1); + if (!src) return + turnMarkerSource.value = src; + }); + + // Ensure that the disabled state stays in sync + const observer = new MutationObserver(() => { + cloned.disabled = turnMarkerSource.disabled; + }); + observer.observe(turnMarkerSource, { attributeFilter: [`disabled`] }); + + turnMarkerSource.insertAdjacentElement(`afterend`, cloned); + }; });