Prettified Code!

This commit is contained in:
zero01101 2023-03-12 15:27:32 +00:00 committed by GitHub Action
parent f8ca9800c9
commit d8ec2c0d0a

View file

@ -363,7 +363,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
/** @type {Array<string|null>} */ /** @type {Array<string|null>} */
const images = [null]; const images = [null];
const seeds = [-1]; const seeds = [-1];
const markedImages=[null]; //A sparse array of booleans indicating which images have been marked, by index const markedImages = [null]; //A sparse array of booleans indicating which images have been marked, by index
/** @type {HTMLDivElement} */ /** @type {HTMLDivElement} */
let imageSelectMenu = null; let imageSelectMenu = null;
// Layer for the images // Layer for the images
@ -501,7 +501,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
} else { } else {
prevImg(); prevImg();
} }
} };
const nextImg = () => { const nextImg = () => {
at++; at++;
@ -510,7 +510,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
highestNavigatedImageIndex = Math.max(at, highestNavigatedImageIndex); highestNavigatedImageIndex = Math.max(at, highestNavigatedImageIndex);
activateImgAt(at); activateImgAt(at);
if (needMoreGenerations() && !isGenerationPending()) { if (needMoreGenerations() && !isGenerationPending()) {
makeMore(); makeMore();
} }
@ -522,16 +522,14 @@ const _generate = async (endpoint, request, bb, options = {}) => {
} else { } else {
nextImg(); nextImg();
} }
} };
const activateImgAt = (at) => { const activateImgAt = (at) => {
updateImageIndexText(); updateImageIndexText();
var seed = seeds[at]; var seed = seeds[at];
seedbtn.title = "Use seed " + seed; seedbtn.title = "Use seed " + seed;
redraw(); redraw();
} };
const applyImg = async () => { const applyImg = async () => {
if (!images[at]) return; if (!images[at]) return;
@ -619,7 +617,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
if (!images[at]) return; if (!images[at]) return;
images.splice(at, 1); images.splice(at, 1);
seeds.splice(at, 1); seeds.splice(at, 1);
markedImages.splice(at,1); markedImages.splice(at, 1);
if (at > images.length - 1) prevImg(); if (at > images.length - 1) prevImg();
if (images.length - 1 === 0) discardImg(); if (images.length - 1 === 0) discardImg();
updateImageIndexText(); updateImageIndexText();
@ -648,7 +646,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
} }
at = nextIndex; at = nextIndex;
activateImgAt(at); activateImgAt(at);
} };
const prevMarkedImg = () => { const prevMarkedImg = () => {
var nextIndex = getPrevMarkedImage(at); var nextIndex = getPrevMarkedImage(at);
@ -665,32 +663,32 @@ const _generate = async (endpoint, request, bb, options = {}) => {
} }
at = nextIndex; at = nextIndex;
activateImgAt(at); activateImgAt(at);
} };
const getNextMarkedImage = (at) => { const getNextMarkedImage = (at) => {
for (let i = at+1; i < markedImages.length; i++) { for (let i = at + 1; i < markedImages.length; i++) {
if (markedImages[i] != null) { if (markedImages[i] != null) {
return i; return i;
} }
} }
return null; return null;
}; };
const getPrevMarkedImage = (at) => { const getPrevMarkedImage = (at) => {
for (let i = at-1; i >= 0; --i) { for (let i = at - 1; i >= 0; --i) {
if (markedImages[i] != null) { if (markedImages[i] != null) {
return i; return i;
} }
} }
return null; return null;
}; };
const updateImageIndexText = () => { const updateImageIndexText = () => {
var markedImageIndicator = markedImages[at] == true ? "*" : ""; var markedImageIndicator = markedImages[at] == true ? "*" : "";
imageindextxt.textContent = `${markedImageIndicator}${at}/${images.length - 1}`; imageindextxt.textContent = `${markedImageIndicator}${at}/${
} images.length - 1
}`;
};
const makeMore = async () => { const makeMore = async () => {
const moreQ = await waitQueue(); const moreQ = await waitQueue();
@ -869,7 +867,6 @@ const _generate = async (endpoint, request, bb, options = {}) => {
const onwheelhandler = mouse.listen.world.onwheel.on( const onwheelhandler = mouse.listen.world.onwheel.on(
(evn, state) => { (evn, state) => {
if (!state.dream_processed && bb.contains(evn.x, evn.y)) { if (!state.dream_processed && bb.contains(evn.x, evn.y)) {
if (evn.delta < 0) { if (evn.delta < 0) {
nextImgEvent(evn.evn); nextImgEvent(evn.evn);
} else prevImgEvent(evn.evn); } else prevImgEvent(evn.evn);
@ -908,7 +905,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
const imageindextxt = document.createElement("button"); const imageindextxt = document.createElement("button");
updateImageIndexText(); updateImageIndexText();
imageindextxt.addEventListener("click", () => { imageindextxt.addEventListener("click", () => {
at = 0; at = 0;
updateImageIndexText(); updateImageIndexText();