diff --git a/src/core/ChefWorker.js b/src/core/ChefWorker.js index d29a3cae..b095cbc8 100644 --- a/src/core/ChefWorker.js +++ b/src/core/ChefWorker.js @@ -92,7 +92,7 @@ async function bake(data) { } catch (err) { self.postMessage({ action: "bakeError", - data: err.message + data: err.message.split(":").slice(1).join(":").slice(1) // Cut off worker blurb }); } } @@ -182,13 +182,15 @@ self.setOption = function(option, value) { * Send register values back to the app. * * @param {number} opIndex + * @param {number} numPrevRegisters * @param {string[]} registers */ -self.setRegisters = function(opIndex, registers) { +self.setRegisters = function(opIndex, numPrevRegisters, registers) { self.postMessage({ action: "setRegisters", data: { opIndex: opIndex, + numPrevRegisters: numPrevRegisters, registers: registers } }); diff --git a/src/core/FlowControl.js b/src/core/FlowControl.js index 6cc2b5d4..aa4082e5 100755 --- a/src/core/FlowControl.js +++ b/src/core/FlowControl.js @@ -116,7 +116,7 @@ const FlowControl = { if (!registers) return state; if (ENVIRONMENT_IS_WORKER()) { - self.setRegisters(state.progress, registers.slice(1)); + self.setRegisters(state.progress, state.numRegisters, registers.slice(1)); } /** @@ -127,31 +127,34 @@ const FlowControl = { */ function replaceRegister(str) { // Replace references to registers ($Rn) with contents of registers - str = str.replace(/((?:^|[^\\])(?:\\.|[^\\])*?)\$R(\d{1,2})/g, (match, pre, regNum) => { + str = str ? str.replace(/((?:^|[^\\])(?:\\.|[^\\])*?)\$R(\d{1,2})/g, (match, pre, regNum) => { const index = parseInt(regNum, 10) + 1; - return (index >= registers.length) ? match : pre + registers[index]; - }); + return (index <= state.numRegisters || index >= state.numRegisters + registers.length) ? + match : pre + registers[index - state.numRegisters]; + }) : str; // Unescape remaining register references - return str.replace(/\\\$R(\d{1,2})/, "$R$1"); + return str ? str.replace(/\\\$R(\d{1,2})/, "$R$1") : str; } // Step through all subsequent ops and replace registers in args with extracted content for (let i = state.progress + 1; i < state.opList.length; i++) { + if (state.opList[i].isDisabled()) continue; + let args = state.opList[i].getIngValues(); args = args.map(arg => { if (typeof arg !== "string" && typeof arg !== "object") return arg; - if (typeof arg === "object" && arg.string) { + if (typeof arg === "object" && arg.hasOwnProperty("string")) { arg.string = replaceRegister(arg.string); return arg; } - return replaceRegister(arg); }); state.opList[i].setIngValues(args); } + state.numRegisters += registers.length - 1; return state; }, diff --git a/src/core/Recipe.js b/src/core/Recipe.js index d703ac1e..fdd06943 100755 --- a/src/core/Recipe.js +++ b/src/core/Recipe.js @@ -145,7 +145,7 @@ Recipe.prototype.lastOpIndex = function(startIndex) { */ Recipe.prototype.execute = async function(dish, startFrom) { startFrom = startFrom || 0; - let op, input, output, numJumps = 0; + let op, input, output, numJumps = 0, numRegisters = 0; for (let i = startFrom; i < this.opList.length; i++) { op = this.opList[i]; @@ -162,15 +162,17 @@ Recipe.prototype.execute = async function(dish, startFrom) { if (op.isFlowControl()) { // Package up the current state let state = { - "progress": i, - "dish": dish, - "opList": this.opList, - "numJumps": numJumps + "progress": i, + "dish": dish, + "opList": this.opList, + "numJumps": numJumps, + "numRegisters": numRegisters }; state = await op.run(state); i = state.progress; numJumps = state.numJumps; + numRegisters = state.numRegisters; } else { output = await op.run(input, op.getIngValues()); dish.set(output, op.outputType); diff --git a/src/web/RecipeWaiter.js b/src/web/RecipeWaiter.js index ac6bdfd9..8e64eb4b 100755 --- a/src/web/RecipeWaiter.js +++ b/src/web/RecipeWaiter.js @@ -441,18 +441,19 @@ RecipeWaiter.prototype.opRemove = function(e) { * Sets register values. * * @param {number} opIndex + * @param {number} numPrevRegisters * @param {string[]} registers */ -RecipeWaiter.prototype.setRegisters = function(opIndex, registers) { +RecipeWaiter.prototype.setRegisters = function(opIndex, numPrevRegisters, registers) { const op = document.querySelector(`#rec-list .operation:nth-child(${opIndex + 1})`), prevRegList = op.querySelector(".register-list"); // Remove previous div if (prevRegList) prevRegList.remove(); - +window.Utils = Utils; let registerList = []; for (let i = 0; i < registers.length; i++) { - registerList.push(`$R${i} = ${Utils.truncate(Utils.printable(registers[i]), 100)}`); + registerList.push(`$R${numPrevRegisters + i} = ${Utils.escapeHtml(Utils.truncate(Utils.printable(registers[i]), 100))}`); } const registerListEl = `
${registerList.join("
")} diff --git a/src/web/WorkerWaiter.js b/src/web/WorkerWaiter.js index e8c0f1ce..6fc69e40 100644 --- a/src/web/WorkerWaiter.js +++ b/src/web/WorkerWaiter.js @@ -62,7 +62,7 @@ WorkerWaiter.prototype.handleChefMessage = function(e) { this.app.options[r.data.option] = r.data.value; break; case "setRegisters": - this.manager.recipe.setRegisters(r.data.opIndex, r.data.registers); + this.manager.recipe.setRegisters(r.data.opIndex, r.data.numPrevRegisters, r.data.registers); break; case "highlightsCalculated": this.manager.highlighter.displayHighlights(r.data.pos, r.data.direction); diff --git a/src/web/stylesheets/components/_operation.css b/src/web/stylesheets/components/_operation.css index c3a80a59..d596ed05 100644 --- a/src/web/stylesheets/components/_operation.css +++ b/src/web/stylesheets/components/_operation.css @@ -201,3 +201,13 @@ button.dropdown-toggle { background-color: var(--disabled-bg-colour) !important; border-color: var(--disabled-border-colour) !important; } + +.break .register-list { + color: var(--fc-breakpoint-operation-font-colour) !important; + background-color: var(--fc-breakpoint-operation-border-colour) !important; +} + +.disabled .register-list { + color: var(--disabled-font-colour) !important; + background-color: var(--disabled-border-colour) !important; +}