mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 10:02:18 +02:00
Solve #215 Better late init interest support
This commit is contained in:
@@ -193,6 +193,18 @@ local function process_input(self, action_id, action, components)
|
||||
end
|
||||
|
||||
|
||||
local function schedule_late_init(self)
|
||||
if self._late_init_timer_id then
|
||||
return
|
||||
end
|
||||
|
||||
self._late_init_timer_id = timer.delay(0, false, function()
|
||||
self._late_init_timer_id = nil
|
||||
self:late_init()
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
--- Druid class constructor
|
||||
-- @tparam DruidInstance self
|
||||
-- @tparam table context Druid context. Usually it is self of script
|
||||
@@ -215,10 +227,6 @@ function DruidInstance.initialize(self, context, style)
|
||||
for i = 1, #base_component.ALL_INTERESTS do
|
||||
self.components_interest[base_component.ALL_INTERESTS[i]] = {}
|
||||
end
|
||||
|
||||
timer.delay(0, false, function()
|
||||
self:late_init()
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -244,6 +252,9 @@ function DruidInstance.new(self, component, ...)
|
||||
if instance.init then
|
||||
instance:init(...)
|
||||
end
|
||||
if instance.on_late_init then
|
||||
schedule_late_init(self)
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
@@ -315,7 +326,7 @@ function DruidInstance.remove(self, component)
|
||||
end
|
||||
|
||||
|
||||
--- Druid late update function call after init and before udpate step
|
||||
--- Druid late update function call after init and before update step
|
||||
-- @tparam DruidInstance self
|
||||
function DruidInstance.late_init(self)
|
||||
local late_init_components = self.components_interest[base_component.ON_LATE_INIT]
|
||||
|
Reference in New Issue
Block a user