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 <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-12-09 22:07:18 -03:00
parent f446cf3784
commit 0e6a5c8d4a

View file

@ -122,8 +122,8 @@ const _generate = async (
// Images to select through // Images to select through
let at = 0; let at = 0;
/** @type {Image[]} */ /** @type {Array<string|null>} */
const images = []; const images = [null];
/** @type {HTMLDivElement} */ /** @type {HTMLDivElement} */
let imageSelectMenu = null; let imageSelectMenu = null;
@ -145,6 +145,8 @@ const _generate = async (
}; };
const redraw = (url = images[at]) => { const redraw = (url = images[at]) => {
if (url === null)
layer.ctx.clearRect(0, 0, layer.canvas.width, layer.canvas.height);
if (!url) return; if (!url) return;
const image = new Image(); const image = new Image();
@ -203,6 +205,7 @@ const _generate = async (
imageCollection.inputElement.appendChild(interruptButton); imageCollection.inputElement.appendChild(interruptButton);
images.push(...(await _dream(endpoint, requestCopy))); images.push(...(await _dream(endpoint, requestCopy)));
stopDrawingStatus = true; stopDrawingStatus = true;
at = 1;
} catch (e) { } catch (e) {
alert( alert(
`Error generating images. Please try again or see consolde for more details` `Error generating images. Please try again or see consolde for more details`
@ -219,7 +222,7 @@ const _generate = async (
at--; at--;
if (at < 0) at = images.length - 1; if (at < 0) at = images.length - 1;
imageindextxt.textContent = `${at + 1}/${images.length}`; imageindextxt.textContent = `${at}/${images.length}`;
redraw(); redraw();
}; };
@ -227,7 +230,7 @@ const _generate = async (
at++; at++;
if (at >= images.length) at = 0; if (at >= images.length) at = 0;
imageindextxt.textContent = `${at + 1}/${images.length}`; imageindextxt.textContent = `${at}/${images.length}`;
redraw(); redraw();
}; };
@ -253,7 +256,7 @@ const _generate = async (
interruptButton.disabled = false; interruptButton.disabled = false;
imageCollection.inputElement.appendChild(interruptButton); imageCollection.inputElement.appendChild(interruptButton);
images.push(...(await _dream(endpoint, requestCopy))); images.push(...(await _dream(endpoint, requestCopy)));
imageindextxt.textContent = `${at + 1}/${images.length}`; imageindextxt.textContent = `${at}/${images.length}`;
} catch (e) { } catch (e) {
alert( alert(
`Error generating images. Please try again or see consolde for more details` `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); imageSelectMenu = makeElement("div", bb.x, bb.y + bb.h);
const imageindextxt = document.createElement("button"); const imageindextxt = document.createElement("button");
imageindextxt.textContent = `${at + 1}/${images.length}`; imageindextxt.textContent = `${at}/${images.length}`;
imageindextxt.addEventListener("click", () => { imageindextxt.addEventListener("click", () => {
at = 0; at = 0;
imageindextxt.textContent = `${at + 1}/${images.length}`; imageindextxt.textContent = `${at}/${images.length}`;
redraw(); redraw();
}); });