mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-03 22:37:06 +02:00
BUGFIX: Running scripts may be loaded before main UI (#1726)
This commit is contained in:
+42
-26
@@ -29,6 +29,8 @@ import { ScriptArg } from "@nsdefs";
|
||||
import { CompleteRunOptions, getRunningScriptsByArgs } from "./Netscript/NetscriptHelpers";
|
||||
import { handleUnknownError } from "./utils/ErrorHandler";
|
||||
import { isLegacyScript, resolveScriptFilePath, ScriptFilePath } from "./Paths/ScriptFilePath";
|
||||
import { Player } from "@player";
|
||||
import { UIEventEmitter, UIEventType } from "./ui/UIEventEmitter";
|
||||
import { getErrorMessageWithStackAndCause } from "./utils/ErrorHelper";
|
||||
import { exceptionAlert } from "./utils/helpers/exceptionAlert";
|
||||
import { Result } from "./types";
|
||||
@@ -215,36 +217,50 @@ function createAutoexec(server: BaseServer): RunningScript | null {
|
||||
*/
|
||||
export function loadAllRunningScripts(): void {
|
||||
/**
|
||||
* Accept all parameters containing "?noscript". The "standard" parameter is "?noScripts", but new players may not
|
||||
* notice the "s" character at the end of "noScripts".
|
||||
* While loading the save data, the game engine calls this function to load all running scripts. With each script, we
|
||||
* calculate the offline data, so we need the current "lastUpdate" and "playtimeSinceLastAug" from the save data.
|
||||
* After the main UI is loaded and the logic of this function starts executing, those info in the Player object might be
|
||||
* overwritten, so we need to save them here and use them later in "scriptCalculateOfflineProduction".
|
||||
*/
|
||||
const skipScriptLoad = window.location.href.toLowerCase().includes("?noscript");
|
||||
if (skipScriptLoad) {
|
||||
Terminal.warn("Skipped loading player scripts during startup");
|
||||
console.info("Skipping the load of any scripts during startup");
|
||||
}
|
||||
for (const server of GetAllServers()) {
|
||||
// Reset each server's RAM usage to 0
|
||||
server.ramUsed = 0;
|
||||
|
||||
const rsList = server.savedScripts;
|
||||
server.savedScripts = undefined;
|
||||
if (skipScriptLoad || !rsList) {
|
||||
// Start game with no scripts
|
||||
continue;
|
||||
const playerLastUpdate = Player.lastUpdate;
|
||||
const playerPlaytimeSinceLastAug = Player.playtimeSinceLastAug;
|
||||
const unsubscribe = UIEventEmitter.subscribe((event) => {
|
||||
if (event !== UIEventType.MainUILoaded) {
|
||||
return;
|
||||
}
|
||||
if (server.hostname === "home") {
|
||||
// Push autoexec script onto the front of the list
|
||||
const runningScript = createAutoexec(server);
|
||||
if (runningScript) {
|
||||
rsList.unshift(runningScript);
|
||||
unsubscribe();
|
||||
/**
|
||||
* Accept all parameters containing "?noscript". The "standard" parameter is "?noScripts", but new players may not
|
||||
* notice the "s" character at the end of "noScripts".
|
||||
*/
|
||||
const skipScriptLoad = window.location.href.toLowerCase().includes("?noscript");
|
||||
if (skipScriptLoad) {
|
||||
Terminal.warn("Skipped loading player scripts during startup");
|
||||
console.info("Skipping the load of any scripts during startup");
|
||||
}
|
||||
for (const server of GetAllServers()) {
|
||||
// Reset each server's RAM usage to 0
|
||||
server.ramUsed = 0;
|
||||
|
||||
const rsList = server.savedScripts;
|
||||
server.savedScripts = undefined;
|
||||
if (skipScriptLoad || !rsList) {
|
||||
// Start game with no scripts
|
||||
continue;
|
||||
}
|
||||
if (server.hostname === "home") {
|
||||
// Push autoexec script onto the front of the list
|
||||
const runningScript = createAutoexec(server);
|
||||
if (runningScript) {
|
||||
rsList.unshift(runningScript);
|
||||
}
|
||||
}
|
||||
for (const runningScript of rsList) {
|
||||
startWorkerScript(runningScript, server);
|
||||
scriptCalculateOfflineProduction(runningScript, playerLastUpdate, playerPlaytimeSinceLastAug);
|
||||
}
|
||||
}
|
||||
for (const runningScript of rsList) {
|
||||
startWorkerScript(runningScript, server);
|
||||
scriptCalculateOfflineProduction(runningScript);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function createRunningScriptInstance(
|
||||
|
||||
Reference in New Issue
Block a user