Fix stepping.

Move stepping logic into App.
Change toggleBakeButtonFunction to use a str instead of booleans.
Tidy up handleLoaderMessage in InputWaiter.
This commit is contained in:
j433866 2019-07-02 12:23:46 +01:00
parent 3dc57c4a4a
commit a9f8dac656
5 changed files with 77 additions and 55 deletions

View File

@ -166,6 +166,34 @@ class App {
}
/**
* Executes the next step of the recipe.
*/
step() {
if (this.baking) return;
// Reset status using cancelBake
this.manager.worker.cancelBake(true, false);
const activeTab = this.manager.tabs.getActiveInputTab();
if (activeTab === -1) return;
let progress = 0;
if (this.manager.output.outputs[activeTab].progress !== false) {
log.error(this.manager.output.outputs[activeTab]);
progress = this.manager.output.outputs[activeTab].progress;
}
this.manager.input.inputWorker.postMessage({
action: "step",
data: {
activeTab: activeTab,
progress: progress + 1
}
});
}
/**
* Runs a silent bake, forcing the browser to load and cache all the relevant JavaScript code needed
* to do a real bake.

View File

@ -68,23 +68,8 @@ class ControlsWaiter {
/**
* Handler for the 'Step through' command. Executes the next step of the recipe.
*/
async stepClick() {
if (this.app.baking) return;
// Reset status using cancelBake
this.manager.worker.cancelBake(true, false);
const activeTab = this.manager.tabs.getActiveInputTab();
let progress = 0;
if (this.manager.output.outputs[activeTab].progress !== false) {
progress = this.manager.output.outputs[activeTab].progress;
}
this.manager.input.inputWorker.postMessage({
action: "step",
data: {
activeTab: activeTab,
progress: progress + 1
}
});
stepClick() {
this.app.step();
}
@ -394,30 +379,32 @@ ${navigator.userAgent}
/**
* Switches the Bake button between 'Bake', 'Cancel' and 'Loading' functions.
*
* @param {boolean} cancel - Whether to change to cancel or not
* @param {boolean} loading - Whether to change to loading or not
* @param {string} func - The function to change to. Either "cancel", "loading" or "bake"
*/
toggleBakeButtonFunction(cancel, loading) {
toggleBakeButtonFunction(func) {
const bakeButton = document.getElementById("bake"),
btnText = bakeButton.querySelector("span");
if (cancel) {
btnText.innerText = "Cancel";
bakeButton.classList.remove("btn-success");
bakeButton.classList.remove("btn-warning");
bakeButton.classList.add("btn-danger");
} else if (loading) {
bakeButton.style.background = "";
btnText.innerText = "Loading...";
bakeButton.classList.remove("btn-success");
bakeButton.classList.remove("btn-danger");
bakeButton.classList.add("btn-warning");
} else {
bakeButton.style.background = "";
btnText.innerText = "Bake!";
bakeButton.classList.remove("btn-danger");
bakeButton.classList.remove("btn-warning");
bakeButton.classList.add("btn-success");
switch (func) {
case "cancel":
btnText.innerText = "Cancel";
bakeButton.classList.remove("btn-success");
bakeButton.classList.remove("btn-warning");
bakeButton.classList.add("btn-danger");
break;
case "loading":
bakeButton.style.background = "";
btnText.innerText = "Loading...";
bakeButton.classList.remove("btn-success");
bakeButton.classList.remove("btn-danger");
bakeButton.classList.add("btn-warning");
break;
default:
bakeButton.style.background = "";
btnText.innerText = "Bake!";
bakeButton.classList.remove("btn-danger");
bakeButton.classList.remove("btn-warning");
bakeButton.classList.add("btn-success");
}
}

View File

@ -55,6 +55,8 @@ class InputWaiter {
this.maxWorkers = 1;
if (navigator.hardwareConcurrency !== undefined &&
navigator.hardwareConcurrency > 1) {
// Subtract 1 from hardwareConcurrency value to avoid using
// the entire available resources
this.maxWorkers = navigator.hardwareConcurrency - 1;
}
}
@ -223,17 +225,11 @@ class InputWaiter {
this.manager.tabs.updateInputTabProgress(r.inputNum, 100, 100);
}
if (r.hasOwnProperty("fileBuffer")) {
this.inputWorker.postMessage({
action: "loaderWorkerMessage",
data: r
}, [r.fileBuffer]);
} else {
this.inputWorker.postMessage({
action: "loaderWorkerMessage",
data: r
});
}
const transferable = r.hasOwnProperty("fileBuffer") ? [r.fileBuffer] : undefined;
this.inputWorker.postMessage({
action: "loaderWorkerMessage",
data: r
}, transferable);
}
@ -318,7 +314,7 @@ class InputWaiter {
*/
bakeAll() {
this.app.progress = 0;
this.manager.controls.toggleBakeButtonFunction(false, true);
this.manager.controls.toggleBakeButtonFunction("loading");
this.inputWorker.postMessage({
action: "bakeAll"
});

View File

@ -233,7 +233,9 @@ class OutputWaiter {
if (!this.outputExists(inputNum)) return;
this.outputs[inputNum].progress = progress;
this.manager.tabs.updateOutputTabProgress(inputNum, progress, total);
if (progress !== false) {
this.manager.tabs.updateOutputTabProgress(inputNum, progress, total);
}
}

View File

@ -194,6 +194,7 @@ class WorkerWaiter {
} else {
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
}
this.app.progress = r.data.progress;
if (r.data.progress === this.recipeConfig.length) {
@ -258,11 +259,16 @@ class WorkerWaiter {
if (progress === this.recipeConfig.length) {
progress = false;
}
this.manager.output.updateOutputProgress(progress, inputNum);
this.manager.output.updateOutputProgress(progress, this.recipeConfig.length, inputNum);
this.manager.output.updateOutputValue(data, inputNum, false);
if (progress !== false) {
this.manager.output.updateOutputStatus("error", inputNum);
if (inputNum === this.manager.tabs.getActiveInputTab()) {
this.manager.recipe.updateBreakpointIndicator(progress);
}
} else {
this.manager.output.updateOutputStatus("baked", inputNum);
}
@ -275,7 +281,7 @@ class WorkerWaiter {
*/
setBakingStatus(bakingStatus) {
this.app.baking = bakingStatus;
this.manager.controls.toggleBakeButtonFunction(bakingStatus);
this.manager.controls.toggleBakeButtonFunction(bakingStatus ? "cancel" : "bake");
if (bakingStatus) this.manager.output.hideMagicButton();
}
@ -403,6 +409,7 @@ class WorkerWaiter {
} else {
document.getElementById("bake-info").style.display = "none";
}
document.getElementById("bake").style.background = "";
this.totalOutputs = 0; // Reset for next time
log.debug("--- Bake complete ---");
@ -431,9 +438,11 @@ class WorkerWaiter {
if (this.step) {
// Remove all breakpoints from the recipe up to progress
for (let i = 0; i < this.app.progress; i++) {
if (recipeConfig[i].hasOwnProperty("breakpoint")) {
delete recipeConfig[i].breakpoint;
if (nextInput.progress !== false) {
for (let i = 0; i < nextInput.progress; i++) {
if (recipeConfig[i].hasOwnProperty("breakpoint")) {
delete recipeConfig[i].breakpoint;
}
}
}