mirror of
https://github.com/edubart/otclient.git
synced 2025-12-01 07:36:49 +01:00
a lot of changes in modules
This commit is contained in:
@@ -1,34 +1,20 @@
|
||||
local eventId = 0
|
||||
local eventList = {}
|
||||
|
||||
function scheduleEvent(func, delay)
|
||||
if not func then return end
|
||||
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
|
||||
local event = g_dispatcher.scheduleEvent(callback, delay)
|
||||
|
||||
-- must hold a reference to the callback, otherwise it would be collected
|
||||
event._callback = callback
|
||||
return event
|
||||
end
|
||||
|
||||
function addEvent(func)
|
||||
return scheduleEvent(func, 0)
|
||||
function addEvent(callback, front)
|
||||
local event = g_dispatcher.addEvent(callback, front)
|
||||
-- must hold a reference to the callback, otherwise it would be collected
|
||||
event._callback = callback
|
||||
return event
|
||||
end
|
||||
|
||||
function removeEvent(id)
|
||||
if id and eventList[id] then
|
||||
eventList[id].active = false
|
||||
return true
|
||||
function removeEvent(event)
|
||||
if event then
|
||||
event:cancel()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user