Resolve "Allow mods to add components"
Closes #569 (closed)
Example usage:
define([
], function (
) {
return {
name: 'Clock Logger Component', //You'd never actually need this, just an example
extraScripts: [],
init: function () {
this.events.on('onBeforeGetComponents', this.beforeGetComponents.bind(this));
},
beforeGetComponents: function(components) {
components.clockLogger = {
type: 'clockLogger',
init: function(blueprint) {
var now = new Date().toISOString();
console.log('Current data/time: ' + now);
}
};
}
};
});
It first broadcasts an event with the components object so mods can add components.
Then, it loads the components from the usual src/server/components
folder.
After that, since the waiting
array isn't touched by mods (components are added directly into the object, not require
d from a file), when it is empty components/components.js
will call the onReady()
callback.
Also made some other small clarity changes to the file, but it shouldn't affect anything else.