mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 17:43:48 +01:00
107 lines
3.1 KiB
TypeScript
107 lines
3.1 KiB
TypeScript
import { killWorkerScript } from "../src/Netscript/killWorkerScript";
|
|
import { RunningScript } from "../src/Script/RunningScript";
|
|
|
|
import { clearEventListeners } from "./uiHelpers/clearEventListeners";
|
|
import { arrayToString } from "./helpers/arrayToString";
|
|
|
|
import { KEY } from "./helpers/keyCodes";
|
|
|
|
document.addEventListener("keydown", function(event: KeyboardEvent) {
|
|
if (logBoxOpened && event.keyCode == KEY.ESC) {
|
|
logBoxClose();
|
|
}
|
|
});
|
|
|
|
let logBoxContainer: HTMLElement | null;
|
|
let textHeader: HTMLElement | null;
|
|
let logText: HTMLElement | null;
|
|
|
|
function logBoxInit(): void {
|
|
// Initialize Close button click listener
|
|
const closeButton = document.getElementById("log-box-close");
|
|
if (closeButton == null) {
|
|
console.error(`Could not find LogBox's close button`);
|
|
return;
|
|
}
|
|
|
|
closeButton.addEventListener("click", function() {
|
|
logBoxClose();
|
|
return false;
|
|
});
|
|
|
|
// Initialize text header
|
|
textHeader = document.getElementById("log-box-text-header");
|
|
if (textHeader instanceof HTMLElement) {
|
|
textHeader.style.display = "inline-block";
|
|
}
|
|
|
|
// Initialize references to other DOM elements
|
|
logBoxContainer = document.getElementById("log-box-container");
|
|
logText = document.getElementById("log-box-text");
|
|
|
|
logBoxClose();
|
|
|
|
document.removeEventListener("DOMContentLoaded", logBoxInit);
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", logBoxInit);
|
|
|
|
function logBoxClose(): void {
|
|
logBoxOpened = false;
|
|
if (logBoxContainer instanceof HTMLElement) {
|
|
logBoxContainer.style.display = "none";
|
|
}
|
|
}
|
|
|
|
function logBoxOpen(): void {
|
|
logBoxOpened = true;
|
|
|
|
if (logBoxContainer instanceof HTMLElement) {
|
|
logBoxContainer.style.display = "block";
|
|
}
|
|
}
|
|
|
|
|
|
export let logBoxOpened = false;
|
|
let logBoxCurrentScript: RunningScript | null = null;
|
|
export function logBoxCreate(script: RunningScript): void {
|
|
logBoxCurrentScript = script;
|
|
|
|
const killScriptBtn = clearEventListeners("log-box-kill-script");
|
|
if (killScriptBtn == null) {
|
|
console.error(`Could not find LogBox's 'Kill Script' button`);
|
|
return;
|
|
}
|
|
|
|
killScriptBtn.addEventListener("click", () => {
|
|
killWorkerScript(script, script.server, true);
|
|
return false;
|
|
});
|
|
|
|
killScriptBtn.style.display = "inline-block";
|
|
|
|
logBoxOpen();
|
|
|
|
if (textHeader instanceof HTMLElement) {
|
|
textHeader.innerHTML = `${logBoxCurrentScript.filename} ${arrayToString(logBoxCurrentScript.args)}:<br><br>`;
|
|
} else {
|
|
console.warn(`LogBox's Text Header DOM element is null`);
|
|
}
|
|
|
|
logBoxCurrentScript.logUpd = true;
|
|
logBoxUpdateText();
|
|
}
|
|
|
|
export function logBoxUpdateText(): void {
|
|
if (!(logText instanceof HTMLElement)) { return; }
|
|
|
|
if (logBoxCurrentScript && logBoxOpened && logBoxCurrentScript.logUpd) {
|
|
logText.innerHTML = "";
|
|
for (let i = 0; i < logBoxCurrentScript.logs.length; ++i) {
|
|
logText.innerHTML += logBoxCurrentScript.logs[i];
|
|
logText.innerHTML += "<br>";
|
|
}
|
|
logBoxCurrentScript.logUpd = false;
|
|
}
|
|
}
|