Fixed bug with Terminal parsing changes. Stock's otlkMag is now capped at 50 to prevent forecast from going above 100% or below 0%

This commit is contained in:
danielyxie 2019-02-05 18:32:15 -08:00
parent 5ac10f17f8
commit dc63b14476
3 changed files with 35 additions and 57 deletions

@ -511,11 +511,17 @@ export let CONSTANTS: IMap<any> = {
LatestUpdate: LatestUpdate:
` `
v0.43.1 v0.43.1
* Terminal changes:
** Quoted arguments are now properly parsed. (e.g. run f.script "this is one argument" will be correctly parsed)
** Errors are now shown in red text
** 'unalias' command now has a different format and no longer needs the quotations
* Added two new Bladeburner skills for increasing money and experience gain * Added two new Bladeburner skills for increasing money and experience gain
* Made some minor adjustments to Bladeburner UI * Made some minor adjustments to Bladeburner UI
* Corporation "Smart Factories" and "Smart Storage" upgrades have slightly lower price multipliers * Corporation "Smart Factories" and "Smart Storage" upgrades have slightly lower price multipliers
* Added 6 new Coding Contract problems * Added 6 new Coding Contract problems
* Updated documentation with list of all Coding Contract problems * Updated documentation with list of all Coding Contract problems
* Bug Fix: A Stock Forecast should no longer go above 1 (i.e. 100%)
` `
} }

@ -640,6 +640,7 @@ function processStockPrices(numCycles=1) {
} else { } else {
stock.otlkMag -= otlkMagChange; stock.otlkMag -= otlkMagChange;
} }
if (stock.otlkMag > 50) { stock.otlkMag = 50; } // Cap so the "forecast" is between 0 and 100
if (stock.otlkMag < 0) { if (stock.otlkMag < 0) {
stock.otlkMag *= -1; stock.otlkMag *= -1;
stock.b = !stock.b; stock.b = !stock.b;

@ -60,6 +60,12 @@ function postNetburnerText() {
post("Bitburner v" + CONSTANTS.Version); post("Bitburner v" + CONSTANTS.Version);
} }
// Helper function that checks if an argument (which is a string) is a valid number
function isNumber(str) {
if (typeof str != "string") { return false; } // Only process strings
return !isNaN(str) && !isNaN(parseFloat(str));
}
//Defines key commands in terminal //Defines key commands in terminal
$(document).keydown(function(event) { $(document).keydown(function(event) {
//Terminal //Terminal
@ -803,12 +809,6 @@ let Terminal = {
}, },
parseCommandArguments : function(command) { parseCommandArguments : function(command) {
// Helper function that checks if an argument (which is a string) is a valid number
function isNumber(str) {
if (typeof str != "string") { return false; } // Only process strings
return !isNaN(str) && !isNaN(parseFloat(str));
}
// This will be used to keep track of whether we're in a quote. This is for situations // This will be used to keep track of whether we're in a quote. This is for situations
// like the alias command: // like the alias command:
// alias run="run NUKE.exe" // alias run="run NUKE.exe"
@ -1370,7 +1370,7 @@ let Terminal = {
break; break;
case "run": case "run":
//Run a program or a script //Run a program or a script
if (commandArray.length !== 2) { if (commandArray.length < 2) {
postError("Incorrect number of arguments. Usage: run [program/script] [-t] [num threads] [arg1] [arg2]..."); postError("Incorrect number of arguments. Usage: run [program/script] [-t] [num threads] [arg1] [arg2]...");
} else { } else {
var executableName = commandArray[1]; var executableName = commandArray[1];
@ -1382,9 +1382,8 @@ let Terminal = {
} }
//Check if its a script or just a program/executable //Check if its a script or just a program/executable
//Dont use isScriptFilename here because `executableName` includes the args too if (isScriptFilename(executableName)) {
if (executableName.includes(".script") || executableName.includes(".js") || executableName.includes(".ns")) { Terminal.runScript(commandArray);
Terminal.runScript(executableName);
} else if (executableName.endsWith(".cct")) { } else if (executableName.endsWith(".cct")) {
Terminal.runContract(executableName); Terminal.runContract(executableName);
} else { } else {
@ -2158,59 +2157,31 @@ let Terminal = {
programHandlers[programName](s, splitArgs); programHandlers[programName](s, splitArgs);
}, },
runScript: function(scriptName) { runScript: function(commandArray) {
var server = Player.getCurrentServer(); if (commandArray.length < 2) {
dialogBoxCreate(`Bug encountered with Terminal.runScript(). Command array has a length of less than 2: ${commandArray}`);
var numThreads = 1; return;
var args = [];
var results = scriptName.split(" ");
if (results.length <= 0) {
post("This is a bug. Please contact developer");
} }
scriptName = results[0];
if (results.length > 1) { const server = Player.getCurrentServer();
if (results.length >= 3 && results[1] == "-t") {
numThreads = Math.round(Number(results[2])); let numThreads = 1;
const args = [];
const scriptName = commandArray[1];
if (commandArray.length > 2) {
if (commandArray.length >= 4 && commandArray[2] == "-t") {
numThreads = Math.round(parseFloat(commandArray[3]));
if (isNaN(numThreads) || numThreads < 1) { if (isNaN(numThreads) || numThreads < 1) {
post("Invalid number of threads specified. Number of threads must be greater than 0"); postError("Invalid number of threads specified. Number of threads must be greater than 0");
return; return;
} }
for (var i = 3; i < results.length; ++i) { for (let i = 4; i < commandArray.length; ++i) {
var arg = results[i]; args.push(commandArray[i]);
//Forced string
if ((arg.startsWith("'") && arg.endsWith("'")) ||
(arg.startsWith('"') && arg.endsWith('"'))) {
args.push(arg.slice(1, -1));
continue;
}
//Number
var tempNum = Number(arg);
if (!isNaN(tempNum)) {
args.push(tempNum);
continue;
}
//Otherwise string
args.push(arg);
} }
} else { } else {
for (var i = 1; i < results.length; ++i) { for (let i = 2; i < commandArray.length; ++i) {
var arg = results[i]; args.push(commandArray[i])
//Forced string
if ((arg.startsWith("'") && arg.endsWith("'")) ||
(arg.startsWith('"') && arg.endsWith('"'))) {
args.push(arg.slice(1, -1));
continue;
}
//Number
var tempNum = Number(arg);
if (!isNaN(tempNum)) {
args.push(tempNum);
continue;
}
//Otherwise string
args.push(arg);
} }
} }
} }