UNPKG

@ayanaware/bento

Version:

Modular runtime framework designed to solve complex tasks

279 lines 8.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Bento = void 0; const Globals_1 = require("./Globals"); const EntityManager_1 = require("./entities/EntityManager"); const PropertyManager_1 = require("./properties/PropertyManager"); const LiteEmitter_1 = require("./util/LiteEmitter"); const VariableManager_1 = require("./variables/VariableManager"); class Bento { constructor(options) { this.properties = new PropertyManager_1.PropertyManager(); this.variables = new VariableManager_1.VariableManager(); this.entities = new EntityManager_1.EntityManager(this); try { // ESLint Hates him, check out this one weird trick // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, import/extensions const { version } = require('../package.json'); this.version = version || 'Error'; } catch { this.version = 'Error'; } this.options = { ...{ eventEmitter: () => new LiteEmitter_1.LiteEmitter(), }, ...options, }; try { (0, Globals_1.useBento)(this); } catch { // We ignore this as somebody, somewhere, might want to run multiple Bento instances. } } // ENTITY Aliases /** * Alias for Bento.entities.getEntity() * @param reference EntityReference * * @see EntityManager#getEntity * @returns See Bento.entities.getEntity() */ getEntity(reference) { return this.entities.getEntity(reference); } /** * Alias for Bento.entities.addEntity() * @param entity Entity * * @see EntityManager#addEntity * @returns See Bento.entities.addEntity() */ async addEntity(entity) { return this.entities.addEntity(entity); } /** * Alias for Bento.entities.replaceEntity() * @param reference EntityReference * @param entity Entity * * @see EntityManager#replaceEntity * @returns See Bento.entities.replaceEntity() */ async replaceEntity(reference, entity) { return this.entities.replaceEntity(reference, entity); } /** * Alias for Bento.entities.removeEntity() * @param reference EntityReference * * @see EntityManager#removeEntity * @returns See Bento.entities.removeEntity() */ async removeEntity(reference) { return this.entities.removeEntity(reference); } // PLUGINS Aliases /** * Alias for Bento.entities.getPlugin() * @param reference PluginReference * * @see EntityManager#getPlugin * @returns {Plugin} */ getPlugin(reference) { return this.entities.getPlugin(reference); } /** * Alias for Bento.entities.addPlugins() * @param plugins Array of Plugins * * @see EntityManager#addPlugins * @returns See Bento.entities.addPlugins() */ async addPlugins(plugins) { return this.entities.addPlugins(plugins); } /** * Alias for Bento.entities.addPlugin() * @param plugin Plugin * * @see EntityManager#addPlugin * @returns See Bento.entities.addPlugin() */ async addPlugin(plugin) { return this.entities.addPlugin(plugin); } /** * * @param reference PluginReference * @param plugin Plugin * * @see EntityManager#replacePlugin * @returns See Bento.entities.replacePlugin() */ async replacePlugin(reference, plugin) { return this.entities.replacePlugin(reference, plugin); } /** * Alias for Bento.entities.removePlugin() * @param reference PluginReference * * @see EntityManager#removePlugin * @returns See Bento.entities.removePlugin() */ async removePlugin(reference) { return this.entities.removePlugin(reference); } // COMPONENTS Aliases /** * Alias for Bento.entities.getComponent() * @param reference ComponentReference * * @see EntityManager#getComponent * @returns See Bento.entities.getComponent() */ getComponent(reference) { return this.entities.getComponent(reference); } /** * Alias for Bento.entities.addComponent() * @param component Component * * @see EntityManager#addComponent * @returns See Bento.entities.addComponent() */ async addComponent(component) { return this.entities.addComponent(component); } /** * * @param reference ComponentReference * @param component Plugin * * @see EntityManager#replaceComponent * @returns See Bento.entities.replaceComponent() */ async replaceComponent(reference, component) { return this.entities.replaceComponent(reference, component); } /** * Alias for Bento.entities.removeComponent() * @param reference ComponentReference * * @see EntityManager#removeComponent */ async removeComponent(reference) { return this.entities.removeComponent(reference); } // PROPERTIES Aliases /** * Alias for Bento.properties.hasProperty() * @param name Property name * * @see PropertyManager#hasProperty * @returns See Bento.properties.hasProperty() */ hasProperty(name) { return this.properties.hasProperty(name); } /** * Alias for Bento.properties.getProperty() * @param name Property name * * @see PropertyManager#getProperty * @returns See Bento.properties.getProperty() */ getProperty(name) { return this.properties.getProperty(name); } /** * Alias for Bento.properties.setProperties() * @param properties Object with property key: value pairs * * @see PropertyManager#setProperties * @returns See Bento.properties.setProperties() */ setProperties(properties) { this.properties.setProperties(properties); } /** * Alias for Bento.properties.setProperty() * @param name Property name * @param value Property value * * @see PropertyManager#setProperty * @returns See Bento.properties.setProperty() */ setProperty(name, value) { this.properties.setProperty(name, value); } // VARIABLES Aliases /** * Alias for Bento.variables.hasVariable() * @param name Variable name * * @see VariableManager#hasVariable * @returns See Bento.variables.hasVariable() */ hasVariable(name) { return this.variables.hasVariable(name); } /** * Alias for Bento.variables.getVariable() * @param name Variable name * * @see VariableManager#getVariable * @returns See Bento.variables.getVariable() */ getVariable(name) { return this.variables.getVariable(name); } /** * Alias for Bento.variables.setVariable() * @param name Variable name * @param value Variable value * * @see VariableManager#setVariable * @returns See Bento.variables.setVariable() */ setVariable(name, value) { this.variables.setVariable(name, value); } /** * Alias for Bento.variables.deleteVariable() * @param name Variable name * * @see VariableManager#deleteVariable * @returns See Bento.variables.deleteVariable() */ deleteVariable(name) { this.variables.deleteVariable(name); } /** * Verifies the state of your Application, Will throw an error at anything * "weird" looking. For example if any entities are pending. * * Also indirectly calls .onVerify() lifecycle event. Bento expects this to be called * and may introduce a auto-kill in the future if it is not. * * @returns Application state Object */ async verify() { const state = { entities: [], variables: [] }; // verify entities const entities = await this.entities.verify(); for (const entity of entities.values()) { state.entities.push({ type: entity.type, name: entity.name }); } // add variable names const variables = this.variables.getVariables(); state.variables = Object.keys(variables); // freze object Object.freeze(state); return state; } } exports.Bento = Bento; //# sourceMappingURL=Bento.js.map