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); 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() { function resetProgressState() {
progressState = { progressState = {
upscale: null, upscale: null,
@@ -468,23 +479,17 @@ async function refreshThumbnails(selectedPath, shouldLoadSelection = true) {
el.title = item.filename; el.title = item.filename;
el.addEventListener('click', () => { el.addEventListener('click', () => {
if (fileUrl) { if (fileUrl) {
currentMapPath = item.path; loadMapItem(item, fileUrl);
setSkyFromUrl(fileUrl);
setStatus(`Loaded ${item.filename}`);
} }
}); });
thumbList.appendChild(el); thumbList.appendChild(el);
if (fileUrl) { if (fileUrl) {
if (shouldLoadSelection && idx === 0 && !selectedPath) { if (shouldLoadSelection && idx === 0 && !selectedPath) {
currentMapPath = item.path; loadMapItem(item, fileUrl, 'Showing');
setSkyFromUrl(fileUrl);
setStatus(`Showing ${item.filename}`);
} }
if (shouldLoadSelection && selectedPath && selectedPath === item.path) { if (shouldLoadSelection && selectedPath && selectedPath === item.path) {
currentMapPath = item.path; loadMapItem(item, fileUrl, 'Showing');
setSkyFromUrl(fileUrl);
setStatus(`Showing ${item.filename}`);
} }
} }
} }