From 4c30f107e3642876eaadc2445c76623b75e43ed8 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Tue, 16 Mar 2021 06:01:15 -0400 Subject: [PATCH] convert more netscript functions to use common error message --- src/NetscriptFunctions.js | 32 ++++++++++++++++---------------- src/engine.jsx | 9 +++++---- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 257eb4fcf..5de0d085e 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -329,10 +329,10 @@ function NetscriptFunctions(workerScript) { */ const checkTixApiAccess = function(callingFn="") { if (!Player.hasWseAccount) { - throw makeRuntimeRejectMsg(workerScript, `You don't have WSE Access! Cannot use ${callingFn}()`); + throw makeRuntimeErrorMsg(callingFn, `You don't have WSE Access! Cannot use ${callingFn}()`); } if (!Player.hasTixApiAccess) { - throw makeRuntimeRejectMsg(workerScript, `You don't have TIX API Access! Cannot use ${callingFn}()`); + throw makeRuntimeErrorMsg(callingFn, `You don't have TIX API Access! Cannot use ${callingFn}()`); } } @@ -344,7 +344,7 @@ function NetscriptFunctions(workerScript) { const getStockFromSymbol = function(symbol, callingFn="") { const stock = SymbolToStockMap[symbol]; if (stock == null) { - throw makeRuntimeRejectMsg(workerScript, `Invalid stock symbol passed into ${callingFn}()`); + throw makeRuntimeErrorMsg(callingFn, `Invalid stock symbol: '${symbol}'`); } return stock; @@ -367,18 +367,18 @@ function NetscriptFunctions(workerScript) { } // Utility function to get Hacknet Node object - const getHacknetNode = function(i) { + const getHacknetNode = function(i, callingFn="") { if (isNaN(i)) { - throw makeRuntimeRejectMsg(workerScript, "Invalid index specified for Hacknet Node: " + i); + throw makeRuntimeErrorMsg(callingFn, "Invalid index specified for Hacknet Node: " + i); } if (i < 0 || i >= Player.hacknetNodes.length) { - throw makeRuntimeRejectMsg(workerScript, "Index specified for Hacknet Node is out-of-bounds: " + i); + throw makeRuntimeErrorMsg(callingFn, "Index specified for Hacknet Node is out-of-bounds: " + i); } if (hasHacknetServers()) { const hserver = AllServers[Player.hacknetNodes[i]]; if (hserver == null) { - throw makeRuntimeRejectMsg(workerScript, `Could not get Hacknet Server for index ${i}. This is probably a bug, please report to game dev`); + throw makeRuntimeErrorMsg(callingFn, `Could not get Hacknet Server for index ${i}. This is probably a bug, please report to game dev`); } return hserver; @@ -579,7 +579,7 @@ function NetscriptFunctions(workerScript) { } }, getNodeStats : function(i) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "getNodeStats"); const hasUpgraded = hasHacknetServers(); const res = { name: hasUpgraded ? node.hostname : node.name, @@ -599,20 +599,20 @@ function NetscriptFunctions(workerScript) { return res; }, upgradeLevel : function(i, n) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeLevel"); return purchaseLevelUpgrade(node, n); }, upgradeRam : function(i, n) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeRam"); return purchaseRamUpgrade(node, n); }, upgradeCore : function(i, n) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeCore"); return purchaseCoreUpgrade(node, n); }, upgradeCache : function(i, n) { if (!hasHacknetServers()) { return false; } - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeCache"); const res = purchaseCacheUpgrade(node, n); if (res) { updateHashManagerCapacity(); @@ -620,20 +620,20 @@ function NetscriptFunctions(workerScript) { return res; }, getLevelUpgradeCost : function(i, n) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeLevel"); return node.calculateLevelUpgradeCost(n, Player.hacknet_node_level_cost_mult); }, getRamUpgradeCost : function(i, n) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeRam"); return node.calculateRamUpgradeCost(n, Player.hacknet_node_ram_cost_mult); }, getCoreUpgradeCost : function(i, n) { - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeCore"); return node.calculateCoreUpgradeCost(n, Player.hacknet_node_core_cost_mult); }, getCacheUpgradeCost : function(i, n) { if (!hasHacknetServers()) { return Infinity; } - const node = getHacknetNode(i); + const node = getHacknetNode(i, "upgradeCache"); return node.calculateCacheUpgradeCost(n); }, numHashes : function() { diff --git a/src/engine.jsx b/src/engine.jsx index a544ca202..23f89bdfc 100644 --- a/src/engine.jsx +++ b/src/engine.jsx @@ -1149,10 +1149,11 @@ const Engine = { Engine.start(); // Run main game loop and Scripts loop removeLoadingScreen(); const timeOfflineString = convertTimeMsToTimeElapsedString(time); - dialogBoxCreate(`Offline for ${timeOfflineString}. While you were offline, your scripts ` + - "generated " + - numeralWrapper.formatMoney(offlineProductionFromScripts) + " " + - "and your Hacknet Nodes generated " + hacknetProdInfo + ""); + dialogBoxCreate(<> + Offline for {timeOfflineString}. While you were offline, your scripts generated + {numeralWrapper.formatMoney(offlineProductionFromScripts)} + and your Hacknet Nodes generated {hacknetProdInfo}. + ); // Close main menu accordions for loaded game var visibleMenuTabs = [terminal, createScript, activeScripts, stats, hacknetnodes, city, tutorial, options, dev];