-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrate.js
More file actions
42 lines (38 loc) · 1.2 KB
/
integrate.js
File metadata and controls
42 lines (38 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//Basics
import { registries, types } from "./modules/environment.js";
import { addModdableRegistry, Content } from "./modules/modcontent.js";
import { add, load, setInfoOutput, setPrefix } from "./modules/modloader.js";
import { Registry } from "./modules/registry.js";
export {
add,
addModdableRegistry,
Content,
load,
registries,
Registry,
setInfoOutput,
setPrefix,
types
};
/**
* Constructs an object using types from the `Integrate.types` registry.
* @param {object | string} object Object to construct, or its registry name. Registry names will be searched for through any moddable registry, searching the first registry added first.
* @param {function} defaultType Type to use if no other can be found.
*/
function construct(object, defaultType = Object) {
if (typeof object === "string") {
return constructObject(getFromAnyRegistry(object), defaultType);
} else {
return constructObject(object, defaultType);
}
}
function getFromAnyRegistry(name) {
for (let reg of registries) {
if (reg.has(name)) return reg.get(name);
}
reg.get(null);
}
function constructObject(object, defaultType = Object) {
return types.construct(object, defaultType);
}
export { construct };