SCRIPTS: Script modules are reused when they are imported (#461)

Also corrects some compile race conditions.
This commit is contained in:
Snarling
2023-04-07 00:33:51 -04:00
committed by GitHub
parent f5cddb6984
commit 04d49e3a6d
67 changed files with 428 additions and 561 deletions
+18
View File
@@ -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];
}