mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-12 00:07:40 +01:00
fix an any
This commit is contained in:
parent
83c26903c0
commit
ce2ebf576e
@ -73,6 +73,9 @@ export async function executeJSScript(
|
|||||||
|
|
||||||
const ns = workerScript.env.vars;
|
const ns = workerScript.env.vars;
|
||||||
|
|
||||||
|
if (!loadedModule) {
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, `${script.filename} cannot be run because the script module won't load`);
|
||||||
|
}
|
||||||
// TODO: putting await in a non-async function yields unhelpful
|
// TODO: putting await in a non-async function yields unhelpful
|
||||||
// "SyntaxError: unexpected reserved word" with no line number information.
|
// "SyntaxError: unexpected reserved word" with no line number information.
|
||||||
if (!loadedModule.main) {
|
if (!loadedModule.main) {
|
||||||
@ -100,7 +103,7 @@ function isDependencyOutOfDate(filename: string, scripts: Script[], scriptModule
|
|||||||
* @param {Script[]} scripts
|
* @param {Script[]} scripts
|
||||||
*/
|
*/
|
||||||
function shouldCompile(script: Script, scripts: Script[]): boolean {
|
function shouldCompile(script: Script, scripts: Script[]): boolean {
|
||||||
if (script.module === "") return true;
|
if (!script.module) return true;
|
||||||
return script.dependencies.some((dep) => isDependencyOutOfDate(dep.filename, scripts, script.moduleSequenceNumber));
|
return script.dependencies.some((dep) => isDependencyOutOfDate(dep.filename, scripts, script.moduleSequenceNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import { ScriptUrl } from "./ScriptUrl";
|
|||||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver";
|
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver";
|
||||||
import { roundToTwo } from "../utils/helpers/roundToTwo";
|
import { roundToTwo } from "../utils/helpers/roundToTwo";
|
||||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||||
|
import { ScriptModule } from "./ScriptModule";
|
||||||
|
|
||||||
let globalModuleSequenceNumber = 0;
|
let globalModuleSequenceNumber = 0;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ export class Script {
|
|||||||
|
|
||||||
// The dynamic module generated for this script when it is run.
|
// The dynamic module generated for this script when it is run.
|
||||||
// This is only applicable for NetscriptJS
|
// This is only applicable for NetscriptJS
|
||||||
module: any = "";
|
module: Promise<ScriptModule> | null = null;
|
||||||
|
|
||||||
// The timestamp when when the script was last updated.
|
// The timestamp when when the script was last updated.
|
||||||
moduleSequenceNumber: number;
|
moduleSequenceNumber: number;
|
||||||
@ -53,7 +54,7 @@ export class Script {
|
|||||||
this.code = code;
|
this.code = code;
|
||||||
this.ramUsage = 0;
|
this.ramUsage = 0;
|
||||||
this.server = server; // hostname of server this script is on
|
this.server = server; // hostname of server this script is on
|
||||||
this.module = "";
|
this.module = null;
|
||||||
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
|
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
|
||||||
if (this.code !== "" && player !== null) {
|
if (this.code !== "" && player !== null) {
|
||||||
this.updateRamUsage(player, otherScripts);
|
this.updateRamUsage(player, otherScripts);
|
||||||
@ -90,7 +91,7 @@ export class Script {
|
|||||||
* to exec it.
|
* to exec it.
|
||||||
*/
|
*/
|
||||||
markUpdated(): void {
|
markUpdated(): void {
|
||||||
this.module = "";
|
this.module = null;
|
||||||
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
|
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
src/Script/ScriptModule.ts
Normal file
6
src/Script/ScriptModule.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { AutocompleteData, NS } from "../ScriptEditor/NetscriptDefinitions";
|
||||||
|
|
||||||
|
export interface ScriptModule {
|
||||||
|
main?: (ns: NS) => Promise<void>;
|
||||||
|
autocomplete?: (data: AutocompleteData, flags: string[]) => unknown;
|
||||||
|
}
|
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -2037,9 +2037,10 @@ export interface Singularity {
|
|||||||
* guarantee that your browser will follow that time limit.
|
* guarantee that your browser will follow that time limit.
|
||||||
*
|
*
|
||||||
* @param crime - Name of crime to attempt.
|
* @param crime - Name of crime to attempt.
|
||||||
|
* @param focus - Acquire player focus on this program creation. Optional. Defaults to true.
|
||||||
* @returns The number of milliseconds it takes to attempt the specified crime.
|
* @returns The number of milliseconds it takes to attempt the specified crime.
|
||||||
*/
|
*/
|
||||||
commitCrime(crime: string): number;
|
commitCrime(crime: string, focus?: boolean): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get chance to successfully commit a crime.
|
* Get chance to successfully commit a crime.
|
||||||
|
@ -289,7 +289,7 @@ export async function determineAllPossibilitiesForTabCompletion(
|
|||||||
await compile(p, script, currServ.scripts);
|
await compile(p, script, currServ.scripts);
|
||||||
}
|
}
|
||||||
const loadedModule = await script.module;
|
const loadedModule = await script.module;
|
||||||
if (!loadedModule.autocomplete) return; // Doesn't have an autocomplete function.
|
if (!loadedModule || !loadedModule.autocomplete) return; // Doesn't have an autocomplete function.
|
||||||
|
|
||||||
const runArgs = { "--tail": Boolean, "-t": Number };
|
const runArgs = { "--tail": Boolean, "-t": Number };
|
||||||
const flags = libarg(runArgs, {
|
const flags = libarg(runArgs, {
|
||||||
@ -317,7 +317,9 @@ export async function determineAllPossibilitiesForTabCompletion(
|
|||||||
};
|
};
|
||||||
let pos: string[] = [];
|
let pos: string[] = [];
|
||||||
let pos2: string[] = [];
|
let pos2: string[] = [];
|
||||||
pos = pos.concat(loadedModule.autocomplete(autocompleteData, flags._));
|
const options = loadedModule.autocomplete(autocompleteData, flags._);
|
||||||
|
if (!Array.isArray(options)) throw new Error("autocomplete did not return list of strings");
|
||||||
|
pos = pos.concat(options.map((x) => String(x)));
|
||||||
return pos.concat(pos2);
|
return pos.concat(pos2);
|
||||||
}
|
}
|
||||||
const pos = await scriptAutocomplete();
|
const pos = await scriptAutocomplete();
|
||||||
|
Loading…
Reference in New Issue
Block a user