gibbon.js
Version:
Actor/Component system for use with pixi.js.
32 lines • 837 B
JavaScript
import { isConstructor, isClonable } from './utils/types';
export class Library {
_lib = new Map();
constructor() { }
/**
*
* @param {string} name
* @param {Object|function} item - function(position) to create an object,
* an Object with a clone() function, or a plain object to return.
*/
addItem(name, item) {
this._lib.set(name, item);
}
/**
*
* @param {string} name
* @returns {?Object} Object created, or null.
*/
instance(name, p) {
const item = this._lib.get(name);
if (!item)
return null;
if (isConstructor(item)) {
const type = new item();
}
else if (isClonable(item))
return item.clone();
else
return item;
}
}
//# sourceMappingURL=library.js.map