mirror of
https://github.com/edubart/otclient.git
synced 2025-10-22 23:35:54 +02:00
reorganize some stuff
This commit is contained in:
33
modules/core_lib/dispatcher.lua
Normal file
33
modules/core_lib/dispatcher.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
local eventId = 0
|
||||
local eventList = {}
|
||||
|
||||
function scheduleEvent(func, delay)
|
||||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
if eventList[id] then
|
||||
if eventList[id].active then
|
||||
func()
|
||||
end
|
||||
eventList[id] = nil
|
||||
end
|
||||
end
|
||||
eventList[id] = { func = proxyFunc, active = true }
|
||||
if delay and delay > 0 then
|
||||
g_dispatcher.scheduleEvent(proxyFunc, delay)
|
||||
else
|
||||
g_dispatcher.addEvent(proxyFunc, false)
|
||||
end
|
||||
return id
|
||||
end
|
||||
|
||||
function addEvent(func)
|
||||
return scheduleEvent(func, 0)
|
||||
end
|
||||
|
||||
function removeEvent(id)
|
||||
if id and eventList[id] then
|
||||
eventList[id].active = false
|
||||
return true
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user