Add fixed scale for ComfyUI zoom
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ class ComfyGameBoyPlayer:
|
|||||||
RETURN_TYPES = ()
|
RETURN_TYPES = ()
|
||||||
OUTPUT_NODE = True
|
OUTPUT_NODE = True
|
||||||
FUNCTION = "run"
|
FUNCTION = "run"
|
||||||
CATEGORY = "fun"
|
CATEGORY = "WAS/Play"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
return ()
|
return ()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const STATE = {
|
|||||||
nodeIdToIframe: new Map(),
|
nodeIdToIframe: new Map(),
|
||||||
cleanupIntervalId: null,
|
cleanupIntervalId: null,
|
||||||
cleanupListenersAttached: false,
|
cleanupListenersAttached: false,
|
||||||
|
lastScaleByNode: new Map(),
|
||||||
};
|
};
|
||||||
|
|
||||||
function readCssVar(style, name) {
|
function readCssVar(style, name) {
|
||||||
@@ -65,12 +66,26 @@ function postThemeToIframe(iframe) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachThemeSync(iframe) {
|
function postScaleToIframe(iframe, scale) {
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
type: "was-gba-scale",
|
||||||
|
scale: scale,
|
||||||
|
};
|
||||||
|
iframe.contentWindow?.postMessage(payload, "*");
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachThemeSync(iframe, nodeId) {
|
||||||
if (iframe.__wasThemeSyncAttached) return;
|
if (iframe.__wasThemeSyncAttached) return;
|
||||||
iframe.__wasThemeSyncAttached = true;
|
iframe.__wasThemeSyncAttached = true;
|
||||||
|
|
||||||
const onLoad = () => {
|
const onLoad = () => {
|
||||||
postThemeToIframe(iframe);
|
postThemeToIframe(iframe);
|
||||||
|
const scale = app.canvas?.ds?.scale ?? 1;
|
||||||
|
postScaleToIframe(iframe, scale);
|
||||||
|
STATE.lastScaleByNode.set(String(nodeId), scale);
|
||||||
};
|
};
|
||||||
iframe.addEventListener("load", onLoad);
|
iframe.addEventListener("load", onLoad);
|
||||||
|
|
||||||
@@ -80,6 +95,8 @@ function attachThemeSync(iframe) {
|
|||||||
if (!ev?.data || typeof ev.data !== "object") return;
|
if (!ev?.data || typeof ev.data !== "object") return;
|
||||||
if (ev.data.type !== "was-gba-request-theme") return;
|
if (ev.data.type !== "was-gba-request-theme") return;
|
||||||
postThemeToIframe(iframe);
|
postThemeToIframe(iframe);
|
||||||
|
const scale = app.canvas?.ds?.scale ?? 1;
|
||||||
|
postScaleToIframe(iframe, scale);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -186,7 +203,7 @@ function getContainer() {
|
|||||||
el.style.width = "0";
|
el.style.width = "0";
|
||||||
el.style.height = "0";
|
el.style.height = "0";
|
||||||
el.style.pointerEvents = "none";
|
el.style.pointerEvents = "none";
|
||||||
el.style.zIndex = "1000";
|
el.style.zIndex = "100";
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
STATE.container = el;
|
STATE.container = el;
|
||||||
return el;
|
return el;
|
||||||
@@ -216,7 +233,7 @@ function ensureIframeForNode(node) {
|
|||||||
const src = "extensions/ComfyUI_GB_Player/gba/player/index.html";
|
const src = "extensions/ComfyUI_GB_Player/gba/player/index.html";
|
||||||
iframe.src = src;
|
iframe.src = src;
|
||||||
|
|
||||||
attachThemeSync(iframe);
|
attachThemeSync(iframe, node.id);
|
||||||
|
|
||||||
getContainer().appendChild(iframe);
|
getContainer().appendChild(iframe);
|
||||||
STATE.nodeIdToIframe.set(key, iframe);
|
STATE.nodeIdToIframe.set(key, iframe);
|
||||||
@@ -310,6 +327,12 @@ app.registerExtension({
|
|||||||
try {
|
try {
|
||||||
const iframe = ensureIframeForNode(this);
|
const iframe = ensureIframeForNode(this);
|
||||||
updateIframeRect(this, iframe);
|
updateIframeRect(this, iframe);
|
||||||
|
const scale = app.canvas?.ds?.scale ?? 1;
|
||||||
|
const nodeKey = String(this.id);
|
||||||
|
if (STATE.lastScaleByNode.get(nodeKey) !== scale) {
|
||||||
|
STATE.lastScaleByNode.set(nodeKey, scale);
|
||||||
|
postScaleToIframe(iframe, scale);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@@ -219,15 +219,23 @@ Licensed under the MIT License (view LICENSE.md for more information)
|
|||||||
document.documentElement.style.setProperty(name, value);
|
document.documentElement.style.setProperty(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyScale(scale) {
|
||||||
|
if (typeof scale !== 'number' || !isFinite(scale) || scale <= 0) return;
|
||||||
|
document.documentElement.style.zoom = scale;
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('message', function(ev) {
|
window.addEventListener('message', function(ev) {
|
||||||
try {
|
try {
|
||||||
if (!ev || !ev.data || typeof ev.data !== 'object') return;
|
if (!ev || !ev.data || typeof ev.data !== 'object') return;
|
||||||
if (ev.data.type !== 'was-gba-theme') return;
|
if (ev.data.type === 'was-gba-theme') {
|
||||||
var t = ev.data.tokens || {};
|
var t = ev.data.tokens || {};
|
||||||
setVar('--was-gba-menu-bg', t.bg);
|
setVar('--was-gba-menu-bg', t.bg);
|
||||||
setVar('--was-gba-menu-fg', t.fg);
|
setVar('--was-gba-menu-fg', t.fg);
|
||||||
setVar('--was-gba-menu-border', t.border);
|
setVar('--was-gba-menu-border', t.border);
|
||||||
setVar('--was-gba-accent', t.accent);
|
setVar('--was-gba-accent', t.accent);
|
||||||
|
} else if (ev.data.type === 'was-gba-scale') {
|
||||||
|
applyScale(ev.data.scale);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user