Pluginmanager stuff

This commit is contained in:
Jiiks 2018-01-11 08:24:29 +02:00
parent 881b33f4b6
commit 5ec53510be
4 changed files with 521 additions and 416 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,13 +10,14 @@
'use strict';
const { Logger } = require('./modules');
const { Logger, PluginManager } = require('./modules');
class BetterDiscord {
constructor() {
Logger.log('main', 'Init');
window.pm = PluginManager;
}
}

View File

@ -16,9 +16,10 @@ class Module {
constructor(args) {
this.__ = {
state: args,
state: args || {},
args
}
this.setState = this.setState.bind(this);
this.init();
}

View File

@ -14,7 +14,7 @@ class PluginManager extends Module {
setInitialState() {
this.setState({
plugins: {}
plugins: []
});
}
@ -22,6 +22,24 @@ class PluginManager extends Module {
return this.state.plugins;
}
loadPlugin(plugin) {
const { plugins } = this;
plugins.push(plugin);
this.setState({
plugins
});
}
getPluginByName(name) {
return this.plugins.find(plugin => plugin.name === name);
}
getPluginById(id) {
return this.plugins.find(plugin => plugin.id === id);
}
}
module.exports = { PluginManager }
const _instance = new PluginManager();
module.exports = { PluginManager: _instance }