From 48653ec89538f1650106a5e77463412cad4684c2 Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Sun, 31 Oct 2021 09:49:42 +0800 Subject: first commit --- class.js | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 class.js (limited to 'class.js') diff --git a/class.js b/class.js new file mode 100644 index 0000000..1cfdd8b --- /dev/null +++ b/class.js @@ -0,0 +1,139 @@ +/// + +import logger from "../logger" + +/// + +class Feature { + constructor(){ + this.FeatureManager = undefined + this.events = {} + this.customEvents = {} + this.forgeEvents = {} + this.soopyEvents = {} + + this.id = undefined + + this.enabled = false + } + + setId(id){ + this.id = id + } + getId(){ + return this.id + } + + _onDisable(){ + Object.values(this.events).forEach(e=>this.FeatureManager.unregisterEvent(e)) //calling parent unregister to avoid the set in unregister event + Object.values(this.customEvents).forEach(e=>this.FeatureManager.unregisterCustom(e)) //calling parent unregister to avoid the set in unregister event + + this.onDisable() + + this.events = {} + this.customEvents = {} + this.enabled = false + } + + _onEnable(parent){ + this.FeatureManager = parent + + this.enabled = true + + this.onEnable() + } + + onDisable(){} + onEnable(){} + + registerEvent(event, func){ + let theEvent = this.FeatureManager.registerEvent(event, func, this) + + this.events[theEvent.id] = theEvent + + return theEvent + } + + unregisterEvent(event){ + this.FeatureManager.unregisterEvent(event) + + delete this.events[event.id] + } + registerSoopy(event, func){ + let theEvent = this.FeatureManager.registerSoopy(event, func, this) + + this.soopyEvents[theEvent.id] = theEvent + + return theEvent + } + + unregisterSoopy(event){ + this.FeatureManager.unregisterSoopy(event) + + delete this.soopyEvents[event.id] + } + + registerForge(event, func){ + let theEvent = this.FeatureManager.registerForge(event, func, this) + + this.forgeEvents[theEvent.id] = theEvent + + return theEvent + } + + unregisterForge(event){ + this.FeatureManager.unregisterForge(event) + + delete this.forgeEvents[event.id] + } + + registerChat(criteria, func){ + let theEvent = this.FeatureManager.registerChat(criteria, func, this) + + this.customEvents[theEvent.id] = theEvent + + return theEvent + } + registerStep(isFps, interval, func){ + let theEvent = this.FeatureManager.registerStep(isFps, interval, func, this) + + this.customEvents[theEvent.id] = theEvent + + return theEvent + } + + registerCustom(event, func){ + let theEvent = this.FeatureManager.registerCustom(event, func, this) + + this.customEvents[theEvent.id] = theEvent + + return theEvent + } + + registerCommand(name, func){ + this.FeatureManager.commandFuncs[name] = func + + this.FeatureManager.registerCommand(name, (...args)=>{ + if(this.FeatureManager.commandFuncs[name]){ + this.FeatureManager.commandFuncs[name].call(this, ...(args || [])) + }else{ + ChatLib.chat("&cThis command is not available atm") + } + }, this) + } + unregisterCommand(name){ + delete this.FeatureManager.commandFuncs[name] + } + + unregisterCustom(event){ + this.FeatureManager.unregisterCustom(event) + + delete this.customEvents[event.id] + } + + createCustomEvent(eventId){ + return this.FeatureManager.createCustomEvent(eventId) + } +} + +export default Feature \ No newline at end of file -- cgit