mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 08:42:53 +02:00
All 0.28.0 Changes - Bitnodes 4 and 11 and webpack migration
This commit is contained in:
+44
-34
@@ -1,5 +1,14 @@
|
||||
/* Active Scripts UI*/
|
||||
import {workerScripts,
|
||||
addWorkerScript,
|
||||
killWorkerScript} from "./NetscriptWorker.js";
|
||||
import {getServer} from "./Server.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox.js";
|
||||
import {printArray} from "../utils/HelperFunctions.js";
|
||||
import {logBoxCreate} from "../utils/LogBox.js";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions.js";
|
||||
|
||||
|
||||
/* Active Scripts UI*/
|
||||
function setActiveScriptsClickHandlers() {
|
||||
//Server panel click handlers
|
||||
var serverPanels = document.getElementsByClassName("active-scripts-server-header");
|
||||
@@ -10,7 +19,7 @@ function setActiveScriptsClickHandlers() {
|
||||
for (i = 0; i < serverPanels.length; ++i) {
|
||||
serverPanels[i].onclick = function() {
|
||||
this.classList.toggle("active");
|
||||
|
||||
|
||||
var panel = this.nextElementSibling;
|
||||
if (panel.style.display === "block") {
|
||||
panel.style.display = "none";
|
||||
@@ -19,7 +28,7 @@ function setActiveScriptsClickHandlers() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Script Panel click handlers
|
||||
var scriptPanels = document.getElementsByClassName("active-scripts-script-header");
|
||||
if (scriptPanels == null) {
|
||||
@@ -29,13 +38,13 @@ function setActiveScriptsClickHandlers() {
|
||||
for (var i = 0; i < scriptPanels.length; ++i) {
|
||||
scriptPanels[i].onclick = function() {
|
||||
this.classList.toggle("active");
|
||||
|
||||
|
||||
var panel = this.nextElementSibling;
|
||||
if (panel.style.display === "block") {
|
||||
panel.style.display = "none";
|
||||
} else {
|
||||
panel.style.display = "block";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,35 +63,34 @@ function getActiveScriptsServerList(server) {
|
||||
function createActiveScriptsServerPanel(server) {
|
||||
var panelname = "active-scripts-server-panel-" + server.hostname;
|
||||
var activeScriptsList = document.getElementById("active-scripts-list");
|
||||
|
||||
|
||||
//Div of entire Panel
|
||||
var panelDiv = document.createElement("div");
|
||||
panelDiv.setAttribute("id", panelname);
|
||||
|
||||
|
||||
//Panel Header
|
||||
var panelHdr = document.createElement("button");
|
||||
panelHdr.setAttribute("class", "active-scripts-server-header")
|
||||
panelHdr.setAttribute("id", panelname + "-hdr");
|
||||
panelHdr.innerHTML = server.hostname;
|
||||
|
||||
|
||||
//Panel content
|
||||
var panelContentDiv = document.createElement("div");
|
||||
panelContentDiv.setAttribute("class", "active-scripts-server-panel");
|
||||
panelContentDiv.setAttribute("id", panelname + "-content");
|
||||
|
||||
|
||||
//List of scripts
|
||||
var panelScriptList = document.createElement("ul");
|
||||
panelScriptList.setAttribute("id", panelname + "-script-list");
|
||||
|
||||
|
||||
panelContentDiv.appendChild(panelScriptList);
|
||||
panelDiv.appendChild(panelHdr);
|
||||
panelDiv.appendChild(panelContentDiv);
|
||||
activeScriptsList.appendChild(panelDiv);
|
||||
|
||||
|
||||
setActiveScriptsClickHandlers() //Reset click handlers
|
||||
|
||||
|
||||
return panelDiv;
|
||||
//TODO Alphabetize Active Scripts list?
|
||||
}
|
||||
|
||||
//Deletes the info for a particular server (Dropdown header + Panel with all info)
|
||||
@@ -94,7 +102,7 @@ function deleteActiveScriptsServerPanel(server) {
|
||||
console.log("No such panel exists: " + panelname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//Remove the panel if it has no elements
|
||||
var scriptList = document.getElementById(panelname + "-script-list");
|
||||
if (scriptList.childNodes.length == 0) {
|
||||
@@ -110,12 +118,12 @@ function addActiveScriptsItem(workerscript) {
|
||||
return;
|
||||
}
|
||||
var panelname = "active-scripts-server-panel-" + server.hostname;
|
||||
|
||||
|
||||
var panel = document.getElementById(panelname);
|
||||
if (panel == null) {
|
||||
panel = createActiveScriptsServerPanel(server);
|
||||
}
|
||||
|
||||
|
||||
//Create the element itself. Each element is an accordion collapsible
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
@@ -125,24 +133,24 @@ function addActiveScriptsItem(workerscript) {
|
||||
//var itemName = "active-scripts-" + server.hostname + "-" + workerscript.name;
|
||||
var item = document.createElement("li");
|
||||
item.setAttribute("id", itemName);
|
||||
|
||||
|
||||
var btn = document.createElement("button");
|
||||
btn.setAttribute("class", "active-scripts-script-header");
|
||||
btn.innerHTML = workerscript.name;
|
||||
|
||||
|
||||
var itemContentDiv = document.createElement("div");
|
||||
itemContentDiv.setAttribute("class", "active-scripts-script-panel");
|
||||
itemContentDiv.setAttribute("id", itemName + "-content");
|
||||
|
||||
|
||||
item.appendChild(btn);
|
||||
item.appendChild(itemContentDiv);
|
||||
|
||||
|
||||
createActiveScriptsText(workerscript, itemContentDiv);
|
||||
|
||||
|
||||
//Append element to list
|
||||
var list = getActiveScriptsServerList(server);
|
||||
list.appendChild(item);
|
||||
|
||||
|
||||
setActiveScriptsClickHandlers() //Reset click handlers
|
||||
}
|
||||
|
||||
@@ -191,47 +199,47 @@ function updateActiveScriptsItemContent(workerscript) {
|
||||
var itemName = itemNameArray.join("-");
|
||||
//var itemName = "active-scripts-" + server.hostname + "-" + workerscript.name;
|
||||
var itemContent = document.getElementById(itemName + "-content")
|
||||
|
||||
|
||||
//Clear the item
|
||||
while (itemContent.firstChild) {
|
||||
itemContent.removeChild(itemContent.firstChild);
|
||||
}
|
||||
|
||||
|
||||
//Add the updated text back. Returns the total online production rate
|
||||
return createActiveScriptsText(workerscript, itemContent);
|
||||
}
|
||||
|
||||
function createActiveScriptsText(workerscript, item) {
|
||||
var itemText = document.createElement("p");
|
||||
|
||||
|
||||
//Server ip/hostname
|
||||
var threads = "Threads: " + workerscript.scriptRef.threads;
|
||||
var args = "Args: " + printArray(workerscript.args);
|
||||
|
||||
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + formatNumber(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + formatNumber(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineMpsText = "Online production rate: $" + formatNumber(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + formatNumber(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + formatNumber(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + formatNumber(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + formatNumber(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + formatNumber(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
|
||||
itemText.innerHTML = threads + "<br>" + args + "<br>" + onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
|
||||
|
||||
item.appendChild(itemText);
|
||||
|
||||
|
||||
var logButton = document.createElement("span");
|
||||
logButton.innerHTML = "Log";
|
||||
var killButton = document.createElement("span");
|
||||
@@ -249,7 +257,9 @@ function createActiveScriptsText(workerscript, item) {
|
||||
});
|
||||
item.appendChild(logButton);
|
||||
item.appendChild(killButton);
|
||||
|
||||
|
||||
//Return total online production rate
|
||||
return onlineMps;
|
||||
}
|
||||
}
|
||||
|
||||
export {setActiveScriptsClickHandlers, addActiveScriptsItem, deleteActiveScriptsItem, updateActiveScriptsItems};
|
||||
|
||||
Reference in New Issue
Block a user