Reduced extraneous auto bakes

This commit is contained in:
n1474335 2017-09-22 17:33:46 +00:00
parent e2a35ea844
commit db98e56e72
6 changed files with 18 additions and 14 deletions

View File

@ -280,7 +280,7 @@ const Hash = {
* @default
*/
WHIRLPOOL_VARIANT: ["Whirlpool", "Whirlpool-T", "Whirlpool-0"],
/**
* Whirlpool operation.
*

View File

@ -122,7 +122,12 @@ App.prototype.bake = function(step) {
* Runs Auto Bake if it is set.
*/
App.prototype.autoBake = function() {
if (this.autoBake_ && !this.autoBakePause && !this.baking) {
// If autoBakePause is set, we are loading a full recipe (and potentially input), so there is no
// need to set the staleness indicator. Just exit and wait until auto bake is called after loading
// has completed.
if (this.autoBakePause) return false;
if (this.autoBake_ && !this.baking) {
this.bake();
} else {
this.manager.controls.showStaleIndicator();
@ -369,10 +374,6 @@ App.prototype.loadURIParams = function() {
window.location.hash;
this.uriParams = Utils.parseURIParams(params);
// Pause auto-bake while loading but don't modify `this.autoBake_`
// otherwise `manualBake` cannot trigger.
this.autoBakePause = true;
// Read in recipe from URI params
if (this.uriParams.recipe) {
try {
@ -407,8 +408,6 @@ App.prototype.loadURIParams = function() {
} catch (err) {}
}
// Unpause auto-bake
this.autoBakePause = false;
this.autoBake();
};
@ -441,6 +440,10 @@ App.prototype.getRecipeConfig = function() {
App.prototype.setRecipeConfig = function(recipeConfig) {
document.getElementById("rec-list").innerHTML = null;
// Pause auto-bake while loading but don't modify `this.autoBake_`
// otherwise `manualBake` cannot trigger.
this.autoBakePause = true;
for (let i = 0; i < recipeConfig.length; i++) {
const item = this.manager.recipe.addOperation(recipeConfig[i].op);
@ -473,6 +476,9 @@ App.prototype.setRecipeConfig = function(recipeConfig) {
this.progress = 0;
}
// Unpause auto bake
this.autoBakePause = false;
};

View File

@ -361,6 +361,7 @@ ControlsWaiter.prototype.loadButtonClick = function() {
try {
const recipeConfig = Utils.parseRecipeConfig(document.getElementById("load-text").value);
this.app.setRecipeConfig(recipeConfig);
this.app.autoBake();
$("#rec-list [data-toggle=popover]").popover();
} catch (e) {

View File

@ -158,13 +158,11 @@ InputWaiter.prototype.inputDrop = function(e) {
const CHUNK_SIZE = 20480; // 20KB
const setInput = function() {
this.app.autoBakePause = true;
const recipeConfig = this.app.getRecipeConfig();
if (!recipeConfig[0] || recipeConfig[0].op !== "From Hex") {
recipeConfig.unshift({op: "From Hex", args: ["Space"]});
this.app.setRecipeConfig(recipeConfig);
}
this.app.autoBakePause = false;
this.set(inputCharcode);

View File

@ -119,9 +119,8 @@ Manager.prototype.initialiseEventListeners = function() {
this.addDynamicListener("li.operation", "operationadd", this.recipe.opAdd.bind(this.recipe));
// Recipe
this.addDynamicListener(".arg", "keyup", this.recipe.ingChange, this.recipe);
this.addDynamicListener(".arg", "change", this.recipe.ingChange, this.recipe);
this.addDynamicListener(".arg", "input", this.recipe.ingChange, this.recipe);
this.addDynamicListener(".arg:not(select)", "input", this.recipe.ingChange, this.recipe);
this.addDynamicListener(".arg[type=checkbox], .arg[type=radio], select.arg", "change", this.recipe.ingChange, this.recipe);
this.addDynamicListener(".disable-icon", "click", this.recipe.disableClick, this.recipe);
this.addDynamicListener(".breakpoint", "click", this.recipe.breakpointClick, this.recipe);
this.addDynamicListener("#rec-list li.operation", "dblclick", this.recipe.operationDblclick, this.recipe);

View File

@ -191,7 +191,7 @@ RecipeWaiter.prototype.favDrop = function(e) {
*
* @fires Manager#statechange
*/
RecipeWaiter.prototype.ingChange = function() {
RecipeWaiter.prototype.ingChange = function(e) {
window.dispatchEvent(this.manager.statechange);
};