mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
import * as Settings from './util/settings';
|
|
|
|
export class Plugin {
|
|
constructor() {
|
|
this.stylesheets = [];
|
|
}
|
|
|
|
loadStylesheet(css) {
|
|
const el = document.createElement('style');
|
|
|
|
el.appendChild(document.createTextNode(css)); // Load the stylesheet via style element w/ CSS text
|
|
|
|
document.head.appendChild(el);
|
|
|
|
this.stylesheets.push(el); // Push to internal array so we can remove the elements on unload
|
|
}
|
|
|
|
delayedConstructor() { // Run funcs which rely on after eval (GooseMod sets keys on this class with more info, mostly metadata)
|
|
if (this.delayedConstructed) return;
|
|
this.delayedConstructed = true;
|
|
|
|
Settings.makeStore(this.entityID);
|
|
}
|
|
|
|
get entityID() {
|
|
return this.name;
|
|
}
|
|
|
|
get settings() {
|
|
const store = Settings.settingStores[this.entityID];
|
|
|
|
return { // Basic wrapper with renamed functions
|
|
get: store.getSetting,
|
|
set: store.setSetting,
|
|
delete: store.deleteSetting,
|
|
|
|
getKeys: store.getKeys,
|
|
|
|
connectStore: () => {} // Unneeded util func, but here incase it is attempted to be called
|
|
};
|
|
}
|
|
|
|
get goosemodHandlers() {
|
|
return {
|
|
onImport: () => {
|
|
this.delayedConstructor();
|
|
|
|
this.startPlugin.bind(this)();
|
|
},
|
|
|
|
onRemove: () => {
|
|
this.stylesheets.forEach((x) => x.remove()); // Remove loaded stylesheets which were added with Plugin.loadStylesheet
|
|
|
|
this.pluginWillUnload.bind(this)();
|
|
}
|
|
};
|
|
}
|
|
}
|