Refactor map item loading logic into a dedicated function

This commit is contained in:
2026-05-07 11:04:19 +02:00
parent 6fdbd9d94a
commit e32f6526f6

View File

@@ -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');
}
}
}