From 2c729c8a759ca96eb9610cb3ba5622cc8d8a458f Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 22 Mar 2020 14:08:51 +0100 Subject: [PATCH] api: new api call to delay functions to ooc A new function that allows to register functions to a queue, that is processed as soon as the combat lockdown fades. --- api/api.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/api/api.lua b/api/api.lua index 7f7d1e92..6f22ef97 100644 --- a/api/api.lua +++ b/api/api.lua @@ -58,6 +58,27 @@ function pfUI.api.UnitInRange(unit) end end +-- [ RunOOC ] +-- Runs a function once, as soon as the combat lockdown fades. +-- func [function] The function that shall run ooc. +-- return: [bool] true if the function was added, +-- nil if the function already exists in queue +local queue, frame = {} +function pfUI.api.RunOOC(func) + if not frame then + frame = CreateFrame("Frame") + frame:SetScript("OnUpdate", function() + if InCombatLockdown and InCombatLockdown() then return end + for key, func in pairs(queue) do func(); queue[key] = nil end + end) + end + + if not queue[tostring(func)] then + queue[tostring(func)] = func + return true + end +end + -- [ UnitHasBuff ] -- Returns whether a unit has the given buff or not. -- unit [string] A unit to query (string, unitID)