NETSCRIPT: Expose more enums for player use (#198)

* Add support for enums at other ns layers
* APIWrapper: simplified wrapping algorithm and modified to just use cloneDeep to copy enums instead of recursively wrapping enums as if they were new API layers
* Improve APIWrapper typing
* Changed some typings at RamCostGenerator to allow for enums at different levels without enums needing a ram cost
* Added enums to ns.corporation, removed getter functions that were being used instead.
* Add FactionWorkType for player use
* Add ClassType and CompanyWorkPos enums
* Change netscriptDefinitions to expect members of these new enums where appropriate.
This commit is contained in:
Snarling
2022-11-09 13:46:21 -05:00
committed by GitHub
parent 8e0e0eaa88
commit b275f88053
13 changed files with 355 additions and 285 deletions
+7 -4
View File
@@ -2,9 +2,12 @@ import { Player } from "@player";
import { NSFull } from "../NetscriptFunctions";
/** This type assumes any value that isn't an API layer or a function has been omitted (args and enum) */
type RamCostTree<API> = {
[Property in keyof API]: API[Property] extends () => unknown ? number | (() => number) : RamCostTree<API[Property]>;
};
type RamCostTree<API> = Omit<
{
[Property in keyof API]: API[Property] extends () => unknown ? number | (() => number) : RamCostTree<API[Property]>;
},
"enums" | "args"
>;
/** Constants for assigning costs to ns functions */
export const RamCostConstants: Record<string, number> = {
@@ -414,7 +417,7 @@ const corporation = {
* An error will be generated if there are missing OR additional ram costs defined.
* To avoid errors, define every function in NetscriptDefinition.d.ts and NetscriptFunctions,
* and have a ram cost associated here. */
export const RamCosts: RamCostTree<Omit<NSFull, "args" | "enums">> = {
export const RamCosts: RamCostTree<NSFull> = {
corporation,
hacknet,
stock,