Files

130 lines
3.8 KiB
Lua
Raw Permalink Normal View History

local ____lualib = require("lualib_bundle")
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__New = ____lualib.__TS__New
local ____exports = __module.env
local M__share_base_scoped_object = __MODULE__.Import("share.base.scoped_object", __module)
local ScopedObject = M__share_base_scoped_object.ScopedObject
____exports.MgrDataBase = __TS__DefineClass("MgrDataBase", __module)
local MgrDataBase = ____exports.MgrDataBase
MgrDataBase.name = "MgrDataBase"
function MgrDataBase.prototype.____constructor(self)
end
function MgrDataBase.prototype.OnEnterGame(self)
end
function MgrDataBase.prototype.OnExitGame(self)
end
____exports.ControllerBase = __TS__DefineClass("ControllerBase", __module)
local ControllerBase = ____exports.ControllerBase
ControllerBase.name = "ControllerBase"
__TS__ClassExtends(ControllerBase, ScopedObject)
function ControllerBase.prototype.____constructor(self, mgr)
ScopedObject.prototype.____constructor(self)
self.mgr = mgr
end
function ControllerBase.prototype.OnEnter(self)
end
function ControllerBase.prototype.OnBindEvents(self)
end
function ControllerBase.prototype.OnActive(self)
end
function ControllerBase.prototype.OnExit(self)
end
____exports.MgrBase = __TS__DefineClass("MgrBase", __module)
local MgrBase = ____exports.MgrBase
MgrBase.name = "MgrBase"
__TS__ClassExtends(MgrBase, ScopedObject)
function MgrBase.prototype.____constructor(self, ...)
ScopedObject.prototype.____constructor(self, ...)
self.controllers = {}
self.isActive = true
end
function MgrBase.prototype.Initialization(self)
self:OnCreate()
self:OnBindControllers()
self:OnBindEvents()
end
function MgrBase.prototype.OnBindControllers(self)
end
function MgrBase.prototype.OnBindEvents(self)
end
function MgrBase.prototype.OnEnterGame(self)
end
function MgrBase.prototype.OnExitGame(self)
end
function MgrBase.prototype.OnClean(self)
end
function MgrBase.prototype.SetActive(self, active)
self.isActive = active
if active then
self:EnableControllers()
self:EnableAllEventListeners()
else
self:DisableControllers()
self:DisableAllEventListeners()
end
end
function MgrBase.prototype.AddController(self, ctor)
local existing = self.controllers[ctor]
assert(existing == nil, "MgrBase.AddController: controller already added")
local ctrl = __TS__New(ctor, self)
self.controllers[ctor] = ctrl
ctrl:OnEnter()
ctrl:OnBindEvents()
ctrl:OnActive()
return ctrl
end
function MgrBase.prototype.GetController(self, ctor)
return self.controllers[ctor]
end
function MgrBase.prototype.DelController(self, ctor)
local ctrl = self.controllers[ctor]
if ctrl == nil then
return
end
self.controllers[ctor] = nil
ctrl:OnExit()
ctrl:Dispose()
end
function MgrBase.prototype.DelAllControllers(self)
local list = {}
for ctorKey, ctrl in pairs(self.controllers) do
if ctrl ~= nil then
self.controllers[ctorKey] = nil
list[#list + 1] = ctrl
end
end
do
local i = 0
while i < #list do
list[i + 1]:OnExit()
list[i + 1]:Dispose()
i = i + 1
end
end
end
function MgrBase.prototype.EnableControllers(self)
for _, ctrl in pairs(self.controllers) do
if ctrl ~= nil then
ctrl:EnableAllEventListeners()
ctrl:OnActive()
end
end
end
function MgrBase.prototype.DisableControllers(self)
for _, ctrl in pairs(self.controllers) do
if ctrl ~= nil then
ctrl:DisableAllEventListeners()
end
end
end
function MgrBase.prototype.Dispose(self)
if self:IsDisposed() then
return
end
self:DelAllControllers()
self:OnClean()
ScopedObject.prototype.Dispose(self)
end
function __module.UpdateImports()
ScopedObject = M__share_base_scoped_object.ScopedObject
end