diff --git a/DelayedEventHandler.lua b/DelayedEventHandler.lua new file mode 100644 index 0000000..ca44436 --- /dev/null +++ b/DelayedEventHandler.lua @@ -0,0 +1,51 @@ +local EventArgumentBag = ZO_Object:Subclass() + +function EventArgumentBag:New() + local object = ZO_Object.New(self) + + object.allEventArgs = {} + + return object +end + +function EventArgumentBag:Push(args) + table.insert(self.allEventArgs, args) +end + +function EventArgumentBag:ContainsArgumentWithValue(name, value) + for _, arguments in ipairs(self.allEventArgs) do + if arguments[name] == value then + return true + end + end + + return false +end + +local Handler = {} + +local eventStorage = {} + +function Handler.Add(name, arguments, releaseFunction, delayInMs) + if eventStorage[name] == nil then + eventStorage[name] = { + callId = nil, + argsBag = EventArgumentBag:New(), + } + end + + eventStorage[name].argsBag:Push(arguments) + + if eventStorage[name].callId == nil then + eventStorage[name].callId = zo_callLater( + function() + releaseFunction(eventStorage[name].argsBag) + eventStorage[name] = nil + end, + delayInMs + ) + end +end + +RaidNotifier = RaidNotifier or {} +RaidNotifier.DelayedEventHandler = Handler diff --git a/RaidNotifier.txt b/RaidNotifier.txt index c737ddf..4dd6e38 100644 --- a/RaidNotifier.txt +++ b/RaidNotifier.txt @@ -37,6 +37,7 @@ Util.lua BuffsDebuffs.lua Settings.lua UI.lua +DelayedEventHandler.lua RaidNotifier.xml Bindings.xml