[Feature]: Custom Events
Describe the Problem
Addon/Library (addon from hereon) based events are easy to do within an addon, but unless a second addonis a hard requirement of the first, there's no simple way to safely trigger a macro in the second addonfrom the first, without some funky "does addon exist, if so, call it's macro" and that would require hardcoding checks for any intended-to-be-compatible addon.
The Solution you'd like
Functions for the following:
-
addEventCallback(eventName, macro) -
removeEventCallback(eventName, macro) -
triggerEvent(eventName, arguments)- any and all addons that have active callbacks as registered by the first function, will be called with the passed arguments.
The benefits are simple:
- unnecessary to check whether addons are present, if nothing is listening to the event, it goes unheeded
- More modularity possible between addons, as individuals working on similar or interchangeable addons can agree on how the passed arguments should be formatted, and then it's just up to the user to choose the addon they like.
- less dependance on a GM having to press a GM macro button to trigger something easily detectable
Alternatives that you've considered.
I'm sure it's possible to check which addons/libraries are present and then manually call their relevant functions should they exist, but that would require validation and recoding should things change in even trivial ways.
Additional Context
As an example, Addon A has a function it wants to be called every time a creature dies. Addon A runs addEventCallback("tokenDeath", "onTokenDeath@Lib:AddonA"). Addon B happily calls triggerEvent("tokenDeath",thisToken) whenever its relevent macros indicate the death of a token, not caring whether any other addons are listening to this call at all.