Changed buttons that used <span> elements to use <button> elements. Allowed processing for modules that are dynamically imported from URL

This commit is contained in:
danielyxie 2018-10-03 12:50:39 -05:00
parent 59f525f08b
commit 781f2f09b4
5 changed files with 167185 additions and 203 deletions

56239
dist/engine.bundle.js vendored

File diff suppressed because one or more lines are too long

111029
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Bitburner</title> <title>Bitburner - development</title>
<link rel="apple-touch-icon" sizes="180x180" href="dist/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="dist/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="dist/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="32x32" href="dist/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="dist/favicon-16x16.png"> <link rel="icon" type="image/png" sizes="16x16" href="dist/favicon-16x16.png">
@ -471,7 +471,8 @@
<!-- Tutorial content --> <!-- Tutorial content -->
<div id="tutorial-container" class="generic-menupage-container"> <div id="tutorial-container" class="generic-menupage-container">
<a id="tutorial-getting-started-link" class="a-link-button" href="http://bitburner.wikia.com/wiki/Chapt3rs_Guide_to_Getting_Started_with_Bitburner" target="_blank"> Getting Started </a> <a id="tutorial-getting-started-link" class="a-link-button"
href="http://bitburner.wikia.com/wiki/Chapt3rs_Guide_to_Getting_Started_with_Bitburner" target="_blank"> Getting Started </a>
<a id="tutorial-networking-link" class="a-link-button"> Servers & Networking </a> <a id="tutorial-networking-link" class="a-link-button"> Servers & Networking </a>
<a id="tutorial-hacking-link" class="a-link-button"> Hacking </a> <a id="tutorial-hacking-link" class="a-link-button"> Hacking </a>
<a id="tutorial-scripts-link" class="a-link-button"> Scripts </a> <a id="tutorial-scripts-link" class="a-link-button"> Scripts </a>
@ -480,7 +481,8 @@
<a id="tutorial-jobs-link" class="a-link-button"> Companies and Infiltration </a> <a id="tutorial-jobs-link" class="a-link-button"> Companies and Infiltration </a>
<a id="tutorial-factions-link" class="a-link-button"> Factions </a> <a id="tutorial-factions-link" class="a-link-button"> Factions </a>
<a id="tutorial-augmentations-link" class="a-link-button"> Augmentations </a> <a id="tutorial-augmentations-link" class="a-link-button"> Augmentations </a>
<a id="tutorial-shortcuts-link" class="a-link-button" href="https://bitburner.wikia.com/wiki/Shortcuts" target="_blank"> Keyboard Shortcuts </a> <a id="tutorial-shortcuts-link" class="a-link-button"
href="https://bitburner.wikia.com/wiki/Shortcuts" target="_blank"> Keyboard Shortcuts </a>
<a id="tutorial-back-button" class="a-link-button"> Back </a> <a id="tutorial-back-button" class="a-link-button"> Back </a>
<p id="tutorial-text"> </p> <p id="tutorial-text"> </p>

@ -54,14 +54,13 @@ export async function executeJSScript(scripts = [], workerScript) {
// //
// - script -- the script for whom we are getting a URL. // - script -- the script for whom we are getting a URL.
// - scripts -- all the scripts available on this server // - scripts -- all the scripts available on this server
// - envHeader -- the preamble that goes at the start of every NSJS script.
// - seen -- The modules above this one -- to prevent mutual dependency. // - seen -- The modules above this one -- to prevent mutual dependency.
// //
// TODO We don't make any effort to cache a given module when it is imported at // TODO We don't make any effort to cache a given module when it is imported at
// different parts of the tree. That hasn't presented any problem with during // different parts of the tree. That hasn't presented any problem with during
// testing, but it might be an idea for the future. Would require a topo-sort // testing, but it might be an idea for the future. Would require a topo-sort
// then url-izing from leaf-most to root-most. // then url-izing from leaf-most to root-most.
function _getScriptUrls(script, scripts, seen) { export function _getScriptUrls(script, scripts, seen) {
// Inspired by: https://stackoverflow.com/a/43834063/91401 // Inspired by: https://stackoverflow.com/a/43834063/91401
const urlStack = []; const urlStack = [];
seen.push(script); seen.push(script);
@ -90,7 +89,8 @@ function _getScriptUrls(script, scripts, seen) {
// The top url in the stack is the replacement import file for this script. // The top url in the stack is the replacement import file for this script.
urlStack.push(...urls); urlStack.push(...urls);
return [prefix, urls[urls.length - 1], suffix].join(''); return [prefix, urls[urls.length - 1], suffix].join('');
}); }
);
// If we successfully transformed the code, create a blob url for it and // If we successfully transformed the code, create a blob url for it and

@ -24,8 +24,7 @@ import {iTutorialSteps, iTutorialNextStep,
ITutorial} from "./InteractiveTutorial"; ITutorial} from "./InteractiveTutorial";
import {evaluateImport} from "./NetscriptEvaluator"; import {evaluateImport} from "./NetscriptEvaluator";
import {NetscriptFunctions} from "./NetscriptFunctions"; import {NetscriptFunctions} from "./NetscriptFunctions";
import {addWorkerScript, import {addWorkerScript, WorkerScript} from "./NetscriptWorker";
WorkerScript} from "./NetscriptWorker";
import {Player} from "./Player"; import {Player} from "./Player";
import {AllServers, processSingleServerGrowth} from "./Server"; import {AllServers, processSingleServerGrowth} from "./Server";
import {Settings} from "./Settings"; import {Settings} from "./Settings";
@ -240,7 +239,7 @@ function scriptEditorInit() {
} }
//Updates RAM usage in script //Updates RAM usage in script
function updateScriptEditorContent() { async function updateScriptEditorContent() {
var filename = document.getElementById("script-editor-filename").value; var filename = document.getElementById("script-editor-filename").value;
if (scriptEditorRamCheck == null || !scriptEditorRamCheck.checked || !isScriptFilename(filename)) { if (scriptEditorRamCheck == null || !scriptEditorRamCheck.checked || !isScriptFilename(filename)) {
scriptEditorRamText.innerText = "N/A"; scriptEditorRamText.innerText = "N/A";
@ -249,7 +248,7 @@ function updateScriptEditorContent() {
var editor = ace.edit('javascript-editor'); var editor = ace.edit('javascript-editor');
var code = editor.getValue(); var code = editor.getValue();
var codeCopy = code.repeat(1); var codeCopy = code.repeat(1);
var ramUsage = calculateRamUsage(codeCopy); var ramUsage = await calculateRamUsage(codeCopy);
if (ramUsage !== -1) { if (ramUsage !== -1) {
scriptEditorRamText.innerText = "RAM: " + numeralWrapper.format(ramUsage, '0.00') + " GB"; scriptEditorRamText.innerText = "RAM: " + numeralWrapper.format(ramUsage, '0.00') + " GB";
} else { } else {
@ -402,9 +401,9 @@ Script.prototype.saveScript = function() {
} }
//Updates how much RAM the script uses when it is running. //Updates how much RAM the script uses when it is running.
Script.prototype.updateRamUsage = function() { Script.prototype.updateRamUsage = async function() {
var codeCopy = this.code.repeat(1); var codeCopy = this.code.repeat(1);
var res = calculateRamUsage(codeCopy); var res = await calculateRamUsage(codeCopy);
if (res !== -1) { if (res !== -1) {
this.ramUsage = roundToTwo(res); this.ramUsage = roundToTwo(res);
} }
@ -422,7 +421,7 @@ const memCheckGlobalKey = ".__GLOBAL__";
// Calcluates the amount of RAM a script uses. Uses parsing and AST walking only, // Calcluates the amount of RAM a script uses. Uses parsing and AST walking only,
// rather than NetscriptEvaluator. This is useful because NetscriptJS code does // rather than NetscriptEvaluator. This is useful because NetscriptJS code does
// not work under NetscriptEvaluator. // not work under NetscriptEvaluator.
function parseOnlyRamCalculate(server, code, workerScript) { async function parseOnlyRamCalculate(server, code, workerScript) {
try { try {
// Maps dependent identifiers to their dependencies. // Maps dependent identifiers to their dependencies.
// //
@ -465,11 +464,27 @@ function parseOnlyRamCalculate(server, code, workerScript) {
// Get the code from the server. // Get the code from the server.
const nextModule = parseQueue.shift(); const nextModule = parseQueue.shift();
let code;
if (nextModule.startsWith("https://")) {
try {
const module = await eval('import(nextModule)');
code = "";
for (const prop in module) {
if (typeof module[prop] === 'function') {
code += module[prop].toString();
}
}
} catch(e) {
console.error(`Error dynamically importing module from ${nextModule} for RAM calculations: ${e}`);
return -1;
}
} else {
const script = server.getScript(nextModule); const script = server.getScript(nextModule);
if (!script) return -1; // No such script on the server. if (!script) return -1; // No such script on the server.
code = script.code;
}
// Not sure why we always take copies, but let's do that here too. parseCode(code, nextModule);
parseCode(script.code.repeat(1), nextModule);
} }
// Finally, walk the reference map and generate a ram cost. The initial set of keys to scan // Finally, walk the reference map and generate a ram cost. The initial set of keys to scan
@ -551,7 +566,7 @@ function parseOnlyRamCalculate(server, code, workerScript) {
return ram; return ram;
} catch (error) { } catch (error) {
//console.info("parse or eval error: ", error); console.info("parse or eval error: ", error);
// This is not unexpected. The user may be editing a script, and it may be in // This is not unexpected. The user may be editing a script, and it may be in
// a transitory invalid state. // a transitory invalid state.
return -1; return -1;
@ -688,7 +703,7 @@ function parseOnlyCalculateDeps(code, currentModule) {
return {dependencyMap: dependencyMap, additionalModules: additionalModules}; return {dependencyMap: dependencyMap, additionalModules: additionalModules};
} }
function calculateRamUsage(codeCopy) { async function calculateRamUsage(codeCopy) {
//Create a temporary/mock WorkerScript and an AST from the code //Create a temporary/mock WorkerScript and an AST from the code
var currServ = Player.getCurrentServer(); var currServ = Player.getCurrentServer();
var workerScript = new WorkerScript({ var workerScript = new WorkerScript({
@ -700,7 +715,7 @@ function calculateRamUsage(codeCopy) {
workerScript.serverIp = currServ.ip; workerScript.serverIp = currServ.ip;
try { try {
return parseOnlyRamCalculate(currServ, codeCopy, workerScript); return await parseOnlyRamCalculate(currServ, codeCopy, workerScript);
} catch (e) { } catch (e) {
console.log("Failed to parse ram using new method. Falling back.", e); console.log("Failed to parse ram using new method. Falling back.", e);
} }
@ -862,7 +877,6 @@ function scriptCalculateOfflineProduction(runningScriptObj) {
var thisUpdate = new Date().getTime(); var thisUpdate = new Date().getTime();
var lastUpdate = Player.lastUpdate; var lastUpdate = Player.lastUpdate;
var timePassed = (thisUpdate - lastUpdate) / 1000; //Seconds var timePassed = (thisUpdate - lastUpdate) / 1000; //Seconds
console.log("Offline for " + timePassed + " seconds");
//Calculate the "confidence" rating of the script's true production. This is based //Calculate the "confidence" rating of the script's true production. This is based
//entirely off of time. We will arbitrarily say that if a script has been running for //entirely off of time. We will arbitrarily say that if a script has been running for