Skip to content

Resolve "Allow mods to add components"

hazel requested to merge hazel_meow/isleward:569-mod-add-components into v0.1.11

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 required 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.

Merge request reports