allbuild commit 252b0a30

This commit is contained in:
Olivier Gagnon 2022-05-25 11:10:25 -04:00
parent 252b0a3018
commit 4dd7afac9d
4 changed files with 39 additions and 42 deletions

4
dist/main.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -947,7 +947,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(fn: any, hostname: any = workerScript.hostname, ...scriptArgs: any[]): void => { (fn: any, hostname: any = workerScript.hostname, ...scriptArgs: any[]): void => {
let runningScriptObj; let runningScriptObj;
if (arguments.length === 0) { if (fn === undefined) {
runningScriptObj = workerScript.scriptRef; runningScriptObj = workerScript.scriptRef;
} else if (typeof fn === "number") { } else if (typeof fn === "number") {
runningScriptObj = getRunningScriptByPid(fn); runningScriptObj = getRunningScriptByPid(fn);
@ -1245,12 +1245,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
async (scriptname: any, _hostname1: unknown, hostname2?: any): Promise<boolean> => { async (scriptname: any, _hostname1: unknown, hostname2?: any): Promise<boolean> => {
const hostname1 = ctx.helper.string("hostname1", _hostname1); const hostname1 = ctx.helper.string("hostname1", _hostname1);
if (arguments.length !== 2 && arguments.length !== 3) {
throw ctx.makeRuntimeErrorMsg("Takes 2 or 3 arguments");
}
if (scriptname && scriptname.constructor === Array) { if (scriptname && scriptname.constructor === Array) {
// Recursively call scp on all elements of array // Recursively call scp on all elements of array
const scripts: Array<string> = scriptname; const scripts: string[] = scriptname;
if (scripts.length === 0) { if (scripts.length === 0) {
throw ctx.makeRuntimeErrorMsg("No scripts to copy"); throw ctx.makeRuntimeErrorMsg("No scripts to copy");
} }
@ -1409,7 +1406,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
// Get the grep filter, if one exists // Get the grep filter, if one exists
let filter = ""; let filter = "";
if (arguments.length >= 2) { if (_grep !== undefined) {
filter = grep.toString(); filter = grep.toString();
} }
@ -1784,7 +1781,6 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
(_name: unknown, _ram: unknown): string => { (_name: unknown, _ram: unknown): string => {
const name = ctx.helper.string("name", _name); const name = ctx.helper.string("name", _name);
const ram = ctx.helper.number("ram", _ram); const ram = ctx.helper.number("ram", _ram);
if (arguments.length !== 2) throw ctx.makeRuntimeErrorMsg("Takes 2 arguments");
let hostnameStr = String(name); let hostnameStr = String(name);
hostnameStr = hostnameStr.replace(/\s+/g, ""); hostnameStr = hostnameStr.replace(/\s+/g, "");
if (hostnameStr == "") { if (hostnameStr == "") {
@ -2211,7 +2207,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
getScriptIncome: getScriptIncome:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(scriptname?: any, hostname?: any, ...args: any[]): any => { (scriptname?: any, hostname?: any, ...args: any[]): any => {
if (arguments.length === 0) { if (scriptname === undefined) {
const res = []; const res = [];
// First element is total income of all currently running scripts // First element is total income of all currently running scripts
@ -2238,7 +2234,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
getScriptExpGain: getScriptExpGain:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(scriptname?: any, hostname?: any, ...args: any[]): number => { (scriptname?: any, hostname?: any, ...args: any[]): number => {
if (arguments.length === 0) { if (scriptname === undefined) {
let total = 0; let total = 0;
for (const ws of workerScripts.values()) { for (const ws of workerScripts.values()) {
total += ws.scriptRef.onlineExpGained / ws.scriptRef.onlineRunningTime; total += ws.scriptRef.onlineExpGained / ws.scriptRef.onlineRunningTime;

@ -2,36 +2,37 @@ import { toNative } from "./toNative";
import * as libarg from "arg"; import * as libarg from "arg";
export function Flags(vargs: string[]): any { export function Flags(vargs: string[]): any {
return function (data: any): any { return () =>
data = toNative(data); (data: any): any => {
// We always want the help flag. data = toNative(data);
const args: { // We always want the help flag.
[key: string]: any; const args: {
} = {}; [key: string]: any;
} = {};
for (const d of data) { for (const d of data) {
let t: any = String; let t: any = String;
if (typeof d[1] === "number") { if (typeof d[1] === "number") {
t = Number; t = Number;
} else if (typeof d[1] === "boolean") { } else if (typeof d[1] === "boolean") {
t = Boolean; t = Boolean;
} else if (Array.isArray(d[1])) { } else if (Array.isArray(d[1])) {
t = [String]; t = [String];
}
const numDashes = d[0].length > 1 ? 2 : 1;
args["-".repeat(numDashes) + d[0]] = t;
} }
const numDashes = d[0].length > 1 ? 2 : 1; const ret = libarg(args, { argv: vargs });
args["-".repeat(numDashes) + d[0]] = t; for (const d of data) {
} if (!ret.hasOwnProperty("--" + d[0]) || !ret.hasOwnProperty("-" + d[0])) ret[d[0]] = d[1];
const ret = libarg(args, { argv: vargs }); }
for (const d of data) { for (const key of Object.keys(ret)) {
if (!ret.hasOwnProperty("--" + d[0]) || !ret.hasOwnProperty("-" + d[0])) ret[d[0]] = d[1]; if (!key.startsWith("-")) continue;
} const value = ret[key];
for (const key of Object.keys(ret)) { delete ret[key];
if (!key.startsWith("-")) continue; const numDashes = key.length === 2 ? 1 : 2;
const value = ret[key]; ret[key.slice(numDashes)] = value;
delete ret[key]; }
const numDashes = key.length === 2 ? 1 : 2; return ret;
ret[key.slice(numDashes)] = value; };
}
return ret;
};
} }