2022-04-29 23:14:24 -03:00
|
|
|
EventController = {
|
|
|
|
|
events = nil,
|
|
|
|
|
connected = false
|
|
|
|
|
}
|
2020-07-30 02:10:06 -03:00
|
|
|
|
|
|
|
|
function EventController:new(actor, events)
|
2024-07-04 15:15:46 -03:00
|
|
|
if actor == nil then
|
|
|
|
|
error('Actor is null.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if events == nil then
|
|
|
|
|
error('Events is null.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-29 23:14:24 -03:00
|
|
|
local obj = {
|
|
|
|
|
actor = actor,
|
|
|
|
|
events = events,
|
|
|
|
|
connected = false
|
|
|
|
|
}
|
2021-07-19 19:24:59 -03:00
|
|
|
setmetatable(obj, self)
|
|
|
|
|
self.__index = self
|
|
|
|
|
return obj
|
2020-07-30 02:10:06 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function EventController:connect()
|
2022-08-17 12:51:56 -03:00
|
|
|
if self.connected then
|
|
|
|
|
return
|
|
|
|
|
end
|
2021-07-19 19:24:59 -03:00
|
|
|
self.connected = true
|
2024-07-04 15:15:46 -03:00
|
|
|
|
2021-07-19 19:24:59 -03:00
|
|
|
connect(self.actor, self.events)
|
2020-07-30 02:10:06 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function EventController:disconnect()
|
2022-08-17 12:51:56 -03:00
|
|
|
if not self.connected then
|
|
|
|
|
return
|
|
|
|
|
end
|
2021-07-19 19:24:59 -03:00
|
|
|
self.connected = false
|
|
|
|
|
disconnect(self.actor, self.events)
|
2020-07-30 02:10:06 -03:00
|
|
|
end
|
|
|
|
|
|
2024-08-29 18:07:23 -03:00
|
|
|
function EventController:destroy()
|
|
|
|
|
self:disconnect()
|
|
|
|
|
self.actor = nil
|
|
|
|
|
self.events = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function EventController:isWidget()
|
2025-09-28 14:46:24 -03:00
|
|
|
return self.actor and self.actor.addChild ~= nil
|
2024-08-29 18:07:23 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function EventController:actorIsDestroyed()
|
|
|
|
|
return self:isWidget() and self.actor:isDestroyed()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function EventController:isDestroyed()
|
|
|
|
|
return self.actor == nil
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 18:50:59 -03:00
|
|
|
function EventController:getActor()
|
|
|
|
|
return self.actor
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-17 12:51:56 -03:00
|
|
|
function EventController:execute(name, ...)
|
2024-07-04 15:15:46 -03:00
|
|
|
if name == nil then
|
|
|
|
|
for name, act in pairs(self.events) do
|
|
|
|
|
act()
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-17 12:51:56 -03:00
|
|
|
self.events[name](...)
|
|
|
|
|
end
|