From 45ed40e35eec2f1c895eb4ff4399f11195c465ab Mon Sep 17 00:00:00 2001 From: Arrvis the Lion Date: Sat, 6 Nov 2021 14:50:24 +0300 Subject: [PATCH] Added feature for event arguments analyze with delay --- DelayedEventHandler.lua | 51 +++++++++++++++++++++++++++++++++++++++++ RaidNotifier.txt | 1 + 2 files changed, 52 insertions(+) create mode 100644 DelayedEventHandler.lua 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