1
0
mirror of synced 2024-11-17 03:27:13 +01:00

Add comments to inputWorker.

Slightly improve logic for getNearbyNums
This commit is contained in:
j433866 2019-05-14 16:13:36 +01:00
parent 04587a8a47
commit 0855dc617f
5 changed files with 220 additions and 57 deletions

View File

@ -186,11 +186,9 @@ class App {
/** /**
* Gets the user's input data for all tabs. * Gets the user's input data for all tabs.
*
* @returns {Array}
*/ */
getAllInput() { getAllInput() {
this.manager.input.getAll(); this.manager.input.bakeAll();
} }
/** /**

View File

@ -58,7 +58,7 @@ class ControlsWaiter {
bakeClick() { bakeClick() {
const btnBake = document.getElementById("bake"); const btnBake = document.getElementById("bake");
if (btnBake.textContent.indexOf("Bake") > 0) { if (btnBake.textContent.indexOf("Bake") > 0) {
this.app.manager.input.getAll(); this.app.manager.input.bakeAll();
} else if (btnBake.textContent.indexOf("Cancel") > 0) { } else if (btnBake.textContent.indexOf("Cancel") > 0) {
this.manager.worker.cancelBake(); this.manager.worker.cancelBake();
} }
@ -90,7 +90,7 @@ class ControlsWaiter {
/** /**
* Populates the save disalog box with a URL incorporating the recipe and input. * Populates the save dialog box with a URL incorporating the recipe and input.
* *
* @param {Object[]} [recipeConfig] - The recipe configuration object array. * @param {Object[]} [recipeConfig] - The recipe configuration object array.
*/ */

View File

@ -284,12 +284,12 @@ class InputWaiter {
} }
/** /**
* Sends a message to the inputWorker to get all inputs * Sends a message to the inputWorker to bake all inputs
*/ */
getAll() { bakeAll() {
this.manager.controls.toggleBakeButtonFunction(false, true); this.manager.controls.toggleBakeButtonFunction(false, true);
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "getAll" action: "bakeAll"
}); });
} }
@ -684,7 +684,6 @@ class InputWaiter {
* @param {FileList} files - The list of files to be loaded * @param {FileList} files - The list of files to be loaded
*/ */
loadUIFiles(files) { loadUIFiles(files) {
log.error(files);
const numFiles = files.length; const numFiles = files.length;
const activeTab = this.getActiveTab(); const activeTab = this.getActiveTab();
log.debug(`Loading ${numFiles} files.`); log.debug(`Loading ${numFiles} files.`);

View File

@ -20,6 +20,8 @@ self.loadingInputs = 0;
/** /**
* Respond to message from parent thread. * Respond to message from parent thread.
*
* @param {MessageEvent} e
*/ */
self.addEventListener("message", function(e) { self.addEventListener("message", function(e) {
const r = e.data; const r = e.data;
@ -49,14 +51,11 @@ self.addEventListener("message", function(e) {
case "updateInputObj": case "updateInputObj":
self.updateInputObj(r.data); self.updateInputObj(r.data);
break; break;
case "getInputProgress":
self.getLoadProgress(r.data);
break;
case "updateInputProgress": case "updateInputProgress":
self.updateInputProgress(r.data); self.updateInputProgress(r.data);
break; break;
case "getAll": case "bakeAll":
self.getAllInputs(); self.bakeAllInputs();
break; break;
case "getLoadProgress": case "getLoadProgress":
self.getLoadProgress(r.data); self.getLoadProgress(r.data);
@ -102,6 +101,12 @@ self.addEventListener("message", function(e) {
} }
}); });
/**
* Gets the load progress of the input files, and the
* load progress for the input given in inputNum
*
* @param {number} inputNum - The input to get the file loading progress for
*/
self.getLoadProgress = function(inputNum) { self.getLoadProgress = function(inputNum) {
const total = self.numInputs; const total = self.numInputs;
const pending = self.pendingFiles.length; const pending = self.pendingFiles.length;
@ -123,6 +128,12 @@ self.getLoadProgress = function(inputNum) {
}); });
}; };
/**
* Fired when an autobake is initiated.
* Queues the active input and sends a bake command.
*
* @param {number} inputNum - The input to be baked
*/
self.autoBake = function(inputNum) { self.autoBake = function(inputNum) {
const input = self.getInputObj(inputNum); const input = self.getInputObj(inputNum);
if (input) { if (input) {
@ -144,7 +155,11 @@ self.autoBake = function(inputNum) {
} }
}; };
self.getAllInputs = function() { /**
* Fired when we want to bake all inputs (bake button clicked)
* Queues all of the loaded inputs and sends a bake command
*/
self.bakeAllInputs = function() {
const inputNums = Object.keys(self.inputs); const inputNums = Object.keys(self.inputs);
for (let i = 0; i < inputNums.length; i++) { for (let i = 0; i < inputNums.length; i++) {
@ -169,10 +184,22 @@ self.getAllInputs = function() {
}; };
/**
* Gets the stored object for a specific inputNum
*
* @param {number} inputNum - The input we want to get the object for
* @returns {object}
*/
self.getInputObj = function(inputNum) { self.getInputObj = function(inputNum) {
return self.inputs[inputNum]; return self.inputs[inputNum];
}; };
/**
* Gets the stored value for a specific inputNum.
*
* @param {number} inputNum - The input we want to get the value of
* @returns {string | ArrayBuffer}
*/
self.getInputValue = function(inputNum) { self.getInputValue = function(inputNum) {
if (self.inputs[inputNum]) { if (self.inputs[inputNum]) {
if (typeof self.inputs[inputNum].data === "string") { if (typeof self.inputs[inputNum].data === "string") {
@ -184,6 +211,12 @@ self.getInputValue = function(inputNum) {
return ""; return "";
}; };
/**
* Gets the load progress for a specific inputNum
*
* @param {number} inputNum - The input we want to get the progress of
* @returns {number | string} - Returns "error" if there was a load error
*/
self.getInputProgress = function(inputNum) { self.getInputProgress = function(inputNum) {
const inputObj = self.getInputObj(inputNum); const inputObj = self.getInputObj(inputNum);
if (inputObj === undefined || inputObj === null) return; if (inputObj === undefined || inputObj === null) return;
@ -193,8 +226,8 @@ self.getInputProgress = function(inputNum) {
return inputObj.progress; return inputObj.progress;
}; };
/** /**
* Gets the largest inputNum * Gets the largest inputNum of all the inputs
* *
* @returns {number} * @returns {number}
*/ */
@ -210,8 +243,8 @@ self.getLargestInputNum = function() {
return largest; return largest;
}; };
/** /**
* Gets the smallest inputNum * Gets the smallest inputNum of all the inputs
* *
* @returns {number} * @returns {number}
*/ */
@ -228,7 +261,7 @@ self.getSmallestInputNum = function() {
}; };
/** /**
* Gets the previous inputNum * Gets the next smallest inputNum
* *
* @param {number} inputNum - The current input number * @param {number} inputNum - The current input number
* @returns {number} * @returns {number}
@ -248,7 +281,7 @@ self.getPreviousInputNum = function(inputNum) {
}; };
/** /**
* Gets the next inputNum * Gets the next largest inputNum
* *
* @param {number} inputNum - The current input number * @param {number} inputNum - The current input number
* @returns {number} * @returns {number}
@ -267,6 +300,14 @@ self.getNextInputNum = function(inputNum) {
return num; return num;
}; };
/**
* Gets a list of inputNums starting from the provided inputNum.
* If direction is "left", gets the inputNums higher than the provided number.
* If direction is "right", gets the inputNums lower than the provided number.
* @param {number} inputNum - The inputNum we want to get the neighbours of
* @param {string} direction - Either "left" or "right". Determines which direction we search for nearby numbers in
* @returns {number[]}
*/
self.getNearbyNums = function(inputNum, direction) { self.getNearbyNums = function(inputNum, direction) {
const nums = []; const nums = [];
for (let i = 0; i < self.maxTabs; i++) { for (let i = 0; i < self.maxTabs; i++) {
@ -279,14 +320,14 @@ self.getNearbyNums = function(inputNum, direction) {
newNum = self.getNextInputNum(nums[i - 1]); newNum = self.getNextInputNum(nums[i - 1]);
if (newNum === nums[i - 1]) { if (newNum === nums[i - 1]) {
direction = "right"; direction = "right";
newNum = self.getPreviousInputNum(nums[i - 1]); newNum = self.getPreviousInputNum(nums[0]);
} }
break; break;
case "right": case "right":
newNum = self.getPreviousInputNum(nums[i - 1]); newNum = self.getPreviousInputNum(nums[i - 1]);
if (newNum === nums[i - 1]) { if (newNum === nums[i - 1]) {
direction = "left"; direction = "left";
newNum = self.getNextInputNum(nums[i - 1]); newNum = self.getNextInputNum(nums[0]);
} }
} }
} }
@ -300,6 +341,12 @@ self.getNearbyNums = function(inputNum, direction) {
return nums; return nums;
}; };
/**
* Gets the data to display in the tab header for an input, and
* posts it back to the inputWaiter
*
* @param {number} inputNum - The inputNum of the tab header
*/
self.updateTabHeader = function(inputNum) { self.updateTabHeader = function(inputNum) {
const input = self.getInputObj(inputNum); const input = self.getInputObj(inputNum);
if (input === null || input === undefined) return; if (input === null || input === undefined) return;
@ -316,6 +363,14 @@ self.updateTabHeader = function(inputNum) {
}); });
}; };
/**
* Gets the input for a specific inputNum, and posts it to the inputWaiter
* so that it can be displayed in the input area
*
* @param {object} inputData
* @param {number} inputData.inputNum - The input to get the data for
* @param {boolean} inputData.silent - If false, the manager statechange event won't be fired
*/
self.setInput = function(inputData) { self.setInput = function(inputData) {
const inputNum = inputData.inputNum; const inputNum = inputData.inputNum;
const silent = inputData.silent; const silent = inputData.silent;
@ -356,6 +411,13 @@ self.setInput = function(inputData) {
self.updateTabHeader(inputNum); self.updateTabHeader(inputNum);
}; };
/**
* Gets the nearby inputNums to the provided number, and posts them
* to the inputWaiter to be displayed on the page.
*
* @param {number} inputNum - The inputNum to find the nearby numbers for
* @param {string} direction - The direction to search for inputNums in. Either "left" or "right"
*/
self.refreshTabs = function(inputNum, direction) { self.refreshTabs = function(inputNum, direction) {
const nums = self.getNearbyNums(inputNum, direction); const nums = self.getNearbyNums(inputNum, direction);
self.postMessage({ self.postMessage({
@ -366,17 +428,31 @@ self.refreshTabs = function(inputNum, direction) {
} }
}); });
// Update the tab headers for the new tabs
for (let i = 0; i < nums.length; i++) { for (let i = 0; i < nums.length; i++) {
self.updateTabHeader(nums[i]); self.updateTabHeader(nums[i]);
} }
}; };
/**
* Update the stored status for an input
*
* @param {number} inputNum - The input that's having its status changed
* @param {string} status - The status of the input
*/
self.updateInputStatus = function(inputNum, status) { self.updateInputStatus = function(inputNum, status) {
if (self.inputs[inputNum] !== undefined) { if (self.inputs[inputNum] !== undefined) {
self.inputs[inputNum].status = status; self.inputs[inputNum].status = status;
} }
}; };
/**
* Update the stored load progress of an input
*
* @param {object} inputData
* @param {number} inputData.inputNum - The input that's having its progress updated
* @param {number} inputData.progress - The load progress of the input
*/
self.updateInputProgress = function(inputData) { self.updateInputProgress = function(inputData) {
const inputNum = inputData.inputNum; const inputNum = inputData.inputNum;
const progress = inputData.progress; const progress = inputData.progress;
@ -386,6 +462,13 @@ self.updateInputProgress = function(inputData) {
} }
}; };
/**
* Update the stored value of an input.
*
* @param {object} inputData
* @param {number} inputData.inputNum - The input that's having its value updated
* @param {string | ArrayBuffer} inputData.value - The new value of the input
*/
self.updateInputValue = function(inputData) { self.updateInputValue = function(inputData) {
const inputNum = inputData.inputNum; const inputNum = inputData.inputNum;
if (inputNum < 1) return; if (inputNum < 1) return;
@ -401,9 +484,9 @@ self.updateInputValue = function(inputData) {
return; return;
} }
// If we get to here, an input for inputNum could not be found // If we get to here, an input for inputNum could not be found,
// Only do this if the value is a string, as loadFiles will create // so create a new one. Only do this if the value is a string, as
// the input object for files // loadFiles will create the input object for files
if (typeof value === "string") { if (typeof value === "string") {
self.inputs.push({ self.inputs.push({
inputNum: inputNum, inputNum: inputNum,
@ -414,6 +497,14 @@ self.updateInputValue = function(inputData) {
} }
}; };
/**
* Update the stored data object for an input.
* Used if we need to change a string to an ArrayBuffer
*
* @param {object} inputData
* @param {number} inputData.inputNum - The number of the input we're updating
* @param {object} inputData.data - The new data object for the input
*/
self.updateInputObj = function(inputData) { self.updateInputObj = function(inputData) {
const inputNum = inputData.inputNum; const inputNum = inputData.inputNum;
const data = inputData.data; const data = inputData.data;
@ -423,6 +514,13 @@ self.updateInputObj = function(inputData) {
self.inputs[inputNum].data = data; self.inputs[inputNum].data = data;
}; };
/**
* Get the index of a loader worker object.
* Returns -1 if the worker could not be found
*
* @param {number} workerId - The ID of the worker we're searching for
* @returns {number}
*/
self.getLoaderWorkerIdx = function(workerId) { self.getLoaderWorkerIdx = function(workerId) {
for (let i = 0; i < self.loaderWorkers.length; i++) { for (let i = 0; i < self.loaderWorkers.length; i++) {
if (self.loaderWorkers[i].id === workerId) { if (self.loaderWorkers[i].id === workerId) {
@ -432,6 +530,14 @@ self.getLoaderWorkerIdx = function(workerId) {
return -1; return -1;
}; };
/**
* Fires when a loaderWorker is ready to load files.
* Stores data about the new loaderWorker in the loaderWorkers array,
* and sends the next file to the loaderWorker to be loaded.
*
* @param {object} workerData
* @param {number} workerData.id - The ID of the new loaderWorker
*/
self.loaderWorkerReady = function(workerData) { self.loaderWorkerReady = function(workerData) {
const newWorkerObj = { const newWorkerObj = {
id: workerData.id, id: workerData.id,
@ -442,6 +548,16 @@ self.loaderWorkerReady = function(workerData) {
self.loadNextFile(self.loaderWorkers.indexOf(newWorkerObj)); self.loadNextFile(self.loaderWorkers.indexOf(newWorkerObj));
}; };
/**
* Handler for messages sent by loaderWorkers.
* (Messages are sent between the inputWorker and
* loaderWorkers via the main thread)
*
* @param {object} r - The data sent by the loaderWorker
* @param {number} r.inputNum - The inputNum which the message corresponds to
* @param {string} r.error - Present if an error is fired by the loaderWorker. Contains the error message string.
* @param {ArrayBuffer} r.fileBuffer - Present if a file has finished loading. Contains the loaded file buffer.
*/
self.handleLoaderMessage = function(r) { self.handleLoaderMessage = function(r) {
let inputNum = 0; let inputNum = 0;
@ -471,8 +587,6 @@ self.handleLoaderMessage = function(r) {
value: r.fileBuffer value: r.fileBuffer
}); });
// self.setInput({inputNum: inputNum, silent: false});
const idx = self.getLoaderWorkerIdx(r.id); const idx = self.getLoaderWorkerIdx(r.id);
self.loadNextFile(idx); self.loadNextFile(idx);
} else if (r.hasOwnProperty("progress")) { } else if (r.hasOwnProperty("progress")) {
@ -480,6 +594,11 @@ self.handleLoaderMessage = function(r) {
} }
}; };
/**
* Loads the next file using a loaderWorker
*
* @param {number} - The loaderWorker which will load the file
*/
self.loadNextFile = function(workerIdx) { self.loadNextFile = function(workerIdx) {
if (workerIdx === -1) return; if (workerIdx === -1) return;
const id = self.loaderWorkers[workerIdx].id; const id = self.loaderWorkers[workerIdx].id;
@ -502,6 +621,10 @@ self.loadNextFile = function(workerIdx) {
}); });
}; };
/**
* Sends a message to the inputWaiter to create a new loaderWorker.
* If there's an inactive loaderWorker that already exists, use that instead.
*/
self.activateLoaderWorker = function() { self.activateLoaderWorker = function() {
for (let i = 0; i < self.loaderWorkers.length; i++) { for (let i = 0; i < self.loaderWorkers.length; i++) {
if (!self.loaderWorkers[i].active) { if (!self.loaderWorkers[i].active) {
@ -515,11 +638,17 @@ self.activateLoaderWorker = function() {
}); });
}; };
/**
* Sends a message to the inputWaiter to terminate a loaderWorker.
*
* @param {number} id - The ID of the worker to be terminated
*/
self.terminateLoaderWorker = function(id) { self.terminateLoaderWorker = function(id) {
self.postMessage({ self.postMessage({
action: "terminateLoaderWorker", action: "terminateLoaderWorker",
data: id data: id
}); });
// If we still have pending files, spawn a worker
if (self.pendingFiles.length > 0) { if (self.pendingFiles.length > 0) {
self.activateLoaderWorker(); self.activateLoaderWorker();
} }
@ -529,8 +658,8 @@ self.terminateLoaderWorker = function(id) {
* Loads files using LoaderWorkers * Loads files using LoaderWorkers
* *
* @param {object} filesData * @param {object} filesData
* @param filesData.files * @param {FileList} filesData.files - The list of files to be loaded
* @param {number} filesData.activeTab * @param {number} filesData.activeTab - The active tab in the UI
*/ */
self.loadFiles = function(filesData) { self.loadFiles = function(filesData) {
const files = filesData.files; const files = filesData.files;
@ -562,6 +691,7 @@ self.loadFiles = function(filesData) {
let max = self.maxWorkers; let max = self.maxWorkers;
if (self.pendingFiles.length < self.maxWorkers) max = self.pendingFiles.length; if (self.pendingFiles.length < self.maxWorkers) max = self.pendingFiles.length;
// Create loaderWorkers to load the new files
for (let i = 0; i < max; i++) { for (let i = 0; i < max; i++) {
self.activateLoaderWorker(); self.activateLoaderWorker();
} }
@ -571,14 +701,14 @@ self.loadFiles = function(filesData) {
}; };
/** /**
* Adds an input to the input array * Adds an input to the input dictionary
* *
* @param {boolean} [changetab=false] - Whether or not to change to the new input * @param {boolean} [changetab=false] - Whether or not to change to the new input
* @param {string} type - Either "string" or "file" * @param {string} type - Either "string" or "file"
* @param {Object} fileData - Contains information about the file to be added to the input * @param {Object} fileData - Contains information about the file to be added to the input (only used when type is "file")
* @param {string} fileData.name * @param {string} fileData.name - The filename of the input being added
* @param {string} fileData.size * @param {number} fileData.size - The file size (in bytes) of the input being added
* @param {string} fileData.type * @param {string} fileData.type - The MIME type of the input being added
* @param {number} inputNum - Defaults to auto-incrementing self.currentInputNum * @param {number} inputNum - Defaults to auto-incrementing self.currentInputNum
*/ */
self.addInput = function(changeTab=false, type, fileData={name: "unknown", size: "unknown", type: "unknown"}, inputNum = self.currentInputNum++) { self.addInput = function(changeTab=false, type, fileData={name: "unknown", size: "unknown", type: "unknown"}, inputNum = self.currentInputNum++) {
@ -609,7 +739,7 @@ self.addInput = function(changeTab=false, type, fileData={name: "unknown", size:
} }
self.inputs[inputNum] = newInputObj; self.inputs[inputNum] = newInputObj;
// Tell the inputWaiter we've added an input, so it can create a tab to display it
self.postMessage({ self.postMessage({
action: "inputAdded", action: "inputAdded",
data: { data: {
@ -621,32 +751,48 @@ self.addInput = function(changeTab=false, type, fileData={name: "unknown", size:
return inputNum; return inputNum;
}; };
/**
* Remove an input from the inputs dictionary
*
* @param {object} removeInputData
* @param {number} removeInputData.inputNum - The number of the input to be removed
* @param {boolean} removeInputData.refreshTabs - If true, refresh the tabs after removing the input
*/
self.removeInput = function(removeInputData) { self.removeInput = function(removeInputData) {
const inputNum = removeInputData.inputNum; const inputNum = removeInputData.inputNum;
const refreshTabs = removeInputData.refreshTabs; const refreshTabs = removeInputData.refreshTabs;
self.numInputs--; self.numInputs--;
delete self.inputs[inputNum];
for (let i = 0; i < self.loaderWorkers.length; i++) { for (let i = 0; i < self.loaderWorkers.length; i++) {
if (self.loaderWorkers[i].inputNum === inputNum) { if (self.loaderWorkers[i].inputNum === inputNum) {
// Terminate any loaderWorker that's loading the removed input
self.loadingInputs--; self.loadingInputs--;
self.terminateLoaderWorker(self.loaderWorkers[i].id); self.terminateLoaderWorker(self.loaderWorkers[i].id);
break;
} }
} }
for (let i = 0; i < self.pendingFiles.length; i++) { for (let i = 0; i < self.pendingFiles.length; i++) {
// Remove the input from the pending files list
if (self.pendingFiles[i].inputNum === inputNum) { if (self.pendingFiles[i].inputNum === inputNum) {
self.pendingFiles.splice(i, 1); self.pendingFiles.splice(i, 1);
break; break;
} }
} }
delete self.inputs[inputNum];
if (refreshTabs) { if (refreshTabs) {
self.refreshTabs(inputNum, "left"); self.refreshTabs(inputNum, "left");
} }
}; };
/**
* Change to the next tab.
*
* @param {number} inputNum - The inputNum of the tab to change to
* @param {number[]} tabNums - List of the currently displayed tabs
*/
self.changeTabRight = function(inputNum, tabNums) { self.changeTabRight = function(inputNum, tabNums) {
const newInput = self.getNextInputNum(inputNum); const newInput = self.getNextInputNum(inputNum);
if (tabNums.includes(newInput)) { if (tabNums.includes(newInput)) {
@ -655,10 +801,17 @@ self.changeTabRight = function(inputNum, tabNums) {
data: newInput data: newInput
}); });
} else { } else {
// If the tab is not displayed, refresh the tabs to display it
self.refreshTabs(newInput, "right"); self.refreshTabs(newInput, "right");
} }
}; };
/**
* Change to the previous tab.
*
* @param {number} inputNum - The inputNum of the tab to change to
* @param {number[]} tabNums - List of the currently displayed tabs
*/
self.changeTabLeft = function(inputNum, tabNums) { self.changeTabLeft = function(inputNum, tabNums) {
const newInput = self.getPreviousInputNum(inputNum); const newInput = self.getPreviousInputNum(inputNum);
if (tabNums.includes(newInput)) { if (tabNums.includes(newInput)) {
@ -667,10 +820,23 @@ self.changeTabLeft = function(inputNum, tabNums) {
data: newInput data: newInput
}); });
} else { } else {
// If the tab is not displayed, refresh the tabs to display it
self.refreshTabs(newInput, "left"); self.refreshTabs(newInput, "left");
} }
}; };
/**
* Search the inputs for any that match the filters provided,
* posting the results back to the inputWaiter
*
* @param {object} searchData - Object containing the search filters
* @param {boolean} searchData.showPending - If true, include pending inputs in the results
* @param {boolean} searchData.showLoading - If true, include loading inputs in the results
* @param {boolean} searchData.showLoaded - If true, include loaded inputs in the results
* @param {string} searchData.fileNameFilter - A string that must be present in the filename of an input
* @param {string} searchData.contentFilter - A string that must be present in the input contents
* @param {number} searchData.numResults - The maximum number of results to be returned
*/
self.filterTabs = function(searchData) { self.filterTabs = function(searchData) {
const showPending = searchData.showPending; const showPending = searchData.showPending;
const showLoading = searchData.showLoading; const showLoading = searchData.showLoading;
@ -718,6 +884,7 @@ self.filterTabs = function(searchData) {
} }
} }
// Send the results back to the inputWaiter
self.postMessage({ self.postMessage({
action: "displayTabSearchResults", action: "displayTabSearchResults",
data: inputs data: inputs
@ -728,8 +895,8 @@ self.filterTabs = function(searchData) {
* Swaps the input and outputs, and sends the old input back to the main thread. * Swaps the input and outputs, and sends the old input back to the main thread.
* *
* @param {object} switchData * @param {object} switchData
* @param {number} switchData.inputNum * @param {number} switchData.inputNum - The inputNum of the input to be switched to
* @param {string | ArrayBuffer} switchData.outputData * @param {string | ArrayBuffer} switchData.outputData - The data to switch to
*/ */
self.inputSwitch = function(switchData) { self.inputSwitch = function(switchData) {
const currentInput = self.getInputObj(switchData.inputNum); const currentInput = self.getInputObj(switchData.inputNum);

View File

@ -43,8 +43,8 @@ class OutputWaiter {
/** /**
* Gets the output for the specified input number * Gets the output for the specified input number
* *
* @param {number} inputNum * @param {number} inputNum - The input to get the output for
* @param {boolean} raw * @param {boolean} [raw=true] - If true, returns the raw data instead of the presented result.
* @returns {string | ArrayBuffer} * @returns {string | ArrayBuffer}
*/ */
getOutput(inputNum, raw=true) { getOutput(inputNum, raw=true) {
@ -76,7 +76,7 @@ class OutputWaiter {
/** /**
* Checks if an output exists in the output dictionary * Checks if an output exists in the output dictionary
* *
* @param {number} inputNum * @param {number} inputNum - The number of the output we're looking for
* @returns {boolean} * @returns {boolean}
*/ */
outputExists(inputNum) { outputExists(inputNum) {
@ -90,7 +90,7 @@ class OutputWaiter {
/** /**
* Gets the output string or FileBuffer for the active input * Gets the output string or FileBuffer for the active input
* *
* @param {boolean} [raw=true] * @param {boolean} [raw=true] - If true, returns the raw data instead of the presented result.
* @returns {string | ArrayBuffer} * @returns {string | ArrayBuffer}
*/ */
getActive(raw=true) { getActive(raw=true) {
@ -101,8 +101,8 @@ class OutputWaiter {
* Adds a new output to the output array. * Adds a new output to the output array.
* Creates a new tab if we have less than maxtabs tabs open * Creates a new tab if we have less than maxtabs tabs open
* *
* @param {number} inputNum * @param {number} inputNum - The inputNum of the new output
* @param {boolean} [changeTab=true] * @param {boolean} [changeTab=true] - If true, change to the new output
*/ */
addOutput(inputNum, changeTab = true) { addOutput(inputNum, changeTab = true) {
// Remove the output (will only get removed if it already exists) // Remove the output (will only get removed if it already exists)
@ -119,7 +119,6 @@ class OutputWaiter {
this.outputs[inputNum] = newOutput; this.outputs[inputNum] = newOutput;
// add new tab
this.addTab(inputNum, changeTab); this.addTab(inputNum, changeTab);
} }
@ -127,7 +126,7 @@ class OutputWaiter {
* Updates the value for the output in the output array. * Updates the value for the output in the output array.
* If this is the active output tab, updates the output textarea * If this is the active output tab, updates the output textarea
* *
* @param {Object} data * @param {ArrayBuffer | String} data - The
* @param {number} inputNum * @param {number} inputNum
* @param {boolean} set * @param {boolean} set
*/ */
@ -741,14 +740,14 @@ class OutputWaiter {
newNum = this.getNextInputNum(nums[i - 1]); newNum = this.getNextInputNum(nums[i - 1]);
if (newNum === nums[i - 1]) { if (newNum === nums[i - 1]) {
direction = "right"; direction = "right";
newNum = this.getPreviousInputNum(nums[i - 1]); newNum = this.getPreviousInputNum(nums[0]);
} }
break; break;
case "right": case "right":
newNum = this.getPreviousInputNum(nums[i - 1]); newNum = this.getPreviousInputNum(nums[i - 1]);
if (newNum === nums[i - 1]) { if (newNum === nums[i - 1]) {
direction = "left"; direction = "left";
newNum = this.getNextInputNum(nums[i - 1]); newNum = this.getNextInputNum(nums[0]);
} }
} }
} }