2019-03-17 23:45:48 -05:00
|
|
|
const behaviorItemRegistry = new Map();
|
|
|
|
|
|
|
|
export function fromJSON({type, ...json}) {
|
|
|
|
const Class = behaviorItemRegistry.get(type);
|
|
|
|
if (!Class) {
|
|
|
|
throw new TypeError(`There is no class for the behavior item "${type}"`);
|
|
|
|
}
|
|
|
|
return (new Class()).fromJSON(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deregister(BehaviorItem) {
|
|
|
|
behaviorItemRegistry.delete(BehaviorItem.type());
|
|
|
|
}
|
|
|
|
|
|
|
|
export function register(BehaviorItem) {
|
2019-04-16 17:58:49 -05:00
|
|
|
if (!BehaviorItem.type) {
|
|
|
|
BehaviorItem.type = function() {
|
|
|
|
return BehaviorItem.name.toLowerCase();
|
|
|
|
}
|
|
|
|
}
|
2019-03-17 23:45:48 -05:00
|
|
|
behaviorItemRegistry.set(BehaviorItem.type(), BehaviorItem);
|
|
|
|
}
|