-
Notifications
You must be signed in to change notification settings - Fork 2
Feature
This class handles event(s) depending on the area/subarea the user is currently in, it will register/unregister all of the events inside its list.
Note: You're the one that has to make the location listener and then pass it through to this feature so it knows when to register/unregister depending on the area/subarea
Make sure the path to the folder is correct.
import { Feature } from "../tska/event/Feature"Creating a feature is very simple because you only need to create a new instance with the area/subarea where your events may only register
const myFeature = new Feature("catacombs")Adding events to a feature is quite easy since it provides everything you need to not worry much about it
myFeature.register("stepFps", () => {
ChatLib.chat("hello")
}, /* FPS */2)Why a sub event? sub events in this context are meant to be events that only need to run whenever all the criteria of the feature is matched BUT also a "custom" criteria added by you (or more commonly known registerWhen)
myFeature.registersub("stepFps", () => {
ChatLib.chat("hello from sub")
}, () => {
// This is the registerWhen function
// This function should always return a boolean
return false // Will never register
})Why is update() important? This will basically tell the Feature to update the sub events to check whether their registerWhen function returned true or not so it can register these events.
myFeature.update() // Call whenever you think it should check for the sub events' `registerWhen` functionThis also provides some useful listeners
// Called whenever the events get registered
myFeature.onRegister(() => {})
// Called whenever the events get unregistered
myFeature.onUnregister(() => {})That's the thing, it doesn't you have to tell it.
For this you can use the Location class to add a listener and trigger the necessary functions
Location.onWorldChange((areaName) => {
myFeature.onAreaChange(areaName)
})
Location.onAreaChange((subareaName) => {
myFeature.onSubareaChange(subareaName)
})