From e32f6526f67431036163d284cc52fc4aac223335 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 7 May 2026 11:04:19 +0200 Subject: [PATCH] Refactor map item loading logic into a dedicated function --- src/main.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.js b/src/main.js index 7618d3a..8d4b875 100644 --- a/src/main.js +++ b/src/main.js @@ -358,6 +358,17 @@ async function pathToObjectUrl(path) { return convertFileSrc(path); } +function applyPromptFromMap(item) { + promptInput.value = typeof item?.prompt === 'string' ? item.prompt : ''; +} + +function loadMapItem(item, fileUrl, statusPrefix = 'Loaded') { + currentMapPath = item.path; + applyPromptFromMap(item); + setSkyFromUrl(fileUrl); + setStatus(`${statusPrefix} ${item.filename}`); +} + function resetProgressState() { progressState = { upscale: null, @@ -468,23 +479,17 @@ async function refreshThumbnails(selectedPath, shouldLoadSelection = true) { el.title = item.filename; el.addEventListener('click', () => { if (fileUrl) { - currentMapPath = item.path; - setSkyFromUrl(fileUrl); - setStatus(`Loaded ${item.filename}`); + loadMapItem(item, fileUrl); } }); thumbList.appendChild(el); if (fileUrl) { if (shouldLoadSelection && idx === 0 && !selectedPath) { - currentMapPath = item.path; - setSkyFromUrl(fileUrl); - setStatus(`Showing ${item.filename}`); + loadMapItem(item, fileUrl, 'Showing'); } if (shouldLoadSelection && selectedPath && selectedPath === item.path) { - currentMapPath = item.path; - setSkyFromUrl(fileUrl); - setStatus(`Showing ${item.filename}`); + loadMapItem(item, fileUrl, 'Showing'); } } }