ENUMS: Initial Enum Helper rework + Reorganization (#596)

This commit is contained in:
Snarling
2023-06-12 00:34:20 -04:00
committed by GitHub
parent 6ed8ea9796
commit 6732549196
224 changed files with 2126 additions and 2171 deletions
-21
View File
@@ -7,7 +7,6 @@ import { Player } from "@player";
import { ScriptDeath } from "./ScriptDeath";
import { formatExp, formatMoney, formatRam, formatThreads } from "../ui/formatNumber";
import { ScriptArg } from "./ScriptArg";
import { CityName } from "../Enums";
import { BasicHGWOptions, RunningScript as IRunningScript, Person as IPerson, Server as IServer } from "@nsdefs";
import { Server } from "../Server/Server";
import {
@@ -33,7 +32,6 @@ import { arrayToString } from "../utils/helpers/ArrayHelpers";
import { HacknetServer } from "../Hacknet/HacknetServer";
import { BaseServer } from "../Server/BaseServer";
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { checkEnum } from "../utils/helpers/enum";
import { RamCostConstants } from "./RamCostGenerator";
import { isPositiveInteger, PositiveInteger, Unknownify } from "../types";
import { Engine } from "../engine";
@@ -55,7 +53,6 @@ export const helpers = {
checkSingularityAccess,
netscriptDelay,
updateDynamicRam,
city,
getServer,
scriptIdentifier,
hack,
@@ -83,17 +80,6 @@ export interface CompleteRunOptions {
preventDuplicates: boolean;
}
export function assertMember<T extends string>(
ctx: NetscriptContext,
obj: Record<string, T> | T[],
typeName: string,
argName: string,
v: unknown,
): asserts v is T {
assertString(ctx, argName, v);
if (!checkEnum(obj, v)) throw makeRuntimeErrorMsg(ctx, `${argName}: ${v} is not a valid ${typeName}.`, "TYPE");
}
export function assertString(ctx: NetscriptContext, argName: string, v: unknown): asserts v is string {
if (typeof v !== "string")
throw makeRuntimeErrorMsg(ctx, `${argName} expected to be a string. ${debugType(v)}`, "TYPE");
@@ -412,13 +398,6 @@ function updateDynamicRam(ctx: NetscriptContext, ramCost: number): void {
}
}
/** Validates the input v as being a CityName. Throws an error if it is not. */
function city(ctx: NetscriptContext, argName: string, v: unknown): CityName {
if (typeof v !== "string" || !checkEnum(CityName, v))
throw makeRuntimeErrorMsg(ctx, `${argName} should be a city name.`);
return v;
}
function scriptIdentifier(
ctx: NetscriptContext,
scriptID: unknown,