mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 11:27:04 +02:00
SCRIPTS: Script modules are reused when they are imported (#461)
Also corrects some compile race conditions.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
/** Function for getting a list of keys to use for saving an object
|
||||
* @param ctor the class constructor
|
||||
*
|
||||
* @param removedKeys Keys that exist on a default constructed member, but should not be saved.
|
||||
* These keys will just revert to default values on load.
|
||||
*
|
||||
* @param addedKeys Optional keys that do not exist on a default constructed member, but should be saved when present.
|
||||
*/
|
||||
export function getKeyList<T extends object>(
|
||||
ctor: new () => T,
|
||||
modifications?: { removedKeys?: readonly (keyof T)[]; addedKeys?: readonly (keyof T)[] },
|
||||
): readonly (keyof T)[] {
|
||||
const newObj = new ctor();
|
||||
const keySet = new Set(Object.getOwnPropertyNames(newObj)) as Set<keyof T>;
|
||||
modifications?.removedKeys?.forEach((key) => keySet.delete(key));
|
||||
modifications?.addedKeys?.forEach((key) => keySet.add(key));
|
||||
return [...keySet];
|
||||
}
|
||||
Reference in New Issue
Block a user