From 0e6a5c8d4a6ca233b1051c820c87256b6648450c Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Fri, 9 Dec 2022 22:07:18 -0300 Subject: [PATCH] adds index 0 to image gen image gen has now index 0 to show what was before the image generation. this is especially useful for img2img Signed-off-by: Victor Seiji Hariki --- js/ui/tool/dream.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index e8b57aa..fdd5733 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -122,8 +122,8 @@ const _generate = async ( // Images to select through let at = 0; - /** @type {Image[]} */ - const images = []; + /** @type {Array} */ + const images = [null]; /** @type {HTMLDivElement} */ let imageSelectMenu = null; @@ -145,6 +145,8 @@ const _generate = async ( }; const redraw = (url = images[at]) => { + if (url === null) + layer.ctx.clearRect(0, 0, layer.canvas.width, layer.canvas.height); if (!url) return; const image = new Image(); @@ -203,6 +205,7 @@ const _generate = async ( imageCollection.inputElement.appendChild(interruptButton); images.push(...(await _dream(endpoint, requestCopy))); stopDrawingStatus = true; + at = 1; } catch (e) { alert( `Error generating images. Please try again or see consolde for more details` @@ -219,7 +222,7 @@ const _generate = async ( at--; if (at < 0) at = images.length - 1; - imageindextxt.textContent = `${at + 1}/${images.length}`; + imageindextxt.textContent = `${at}/${images.length}`; redraw(); }; @@ -227,7 +230,7 @@ const _generate = async ( at++; if (at >= images.length) at = 0; - imageindextxt.textContent = `${at + 1}/${images.length}`; + imageindextxt.textContent = `${at}/${images.length}`; redraw(); }; @@ -253,7 +256,7 @@ const _generate = async ( interruptButton.disabled = false; imageCollection.inputElement.appendChild(interruptButton); images.push(...(await _dream(endpoint, requestCopy))); - imageindextxt.textContent = `${at + 1}/${images.length}`; + imageindextxt.textContent = `${at}/${images.length}`; } catch (e) { alert( `Error generating images. Please try again or see consolde for more details` @@ -327,11 +330,11 @@ const _generate = async ( imageSelectMenu = makeElement("div", bb.x, bb.y + bb.h); const imageindextxt = document.createElement("button"); - imageindextxt.textContent = `${at + 1}/${images.length}`; + imageindextxt.textContent = `${at}/${images.length}`; imageindextxt.addEventListener("click", () => { at = 0; - imageindextxt.textContent = `${at + 1}/${images.length}`; + imageindextxt.textContent = `${at}/${images.length}`; redraw(); });