mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
#53 Add init all interests arrays, fix final on empty druid instance
This commit is contained in:
@@ -63,21 +63,15 @@ local function create(self, instance_class)
|
||||
local instance = instance_class()
|
||||
instance:setup_component(self._context, self._style)
|
||||
|
||||
self.components[const.ALL] = self.components[const.ALL] or {}
|
||||
table.insert(self.components[const.ALL], instance)
|
||||
|
||||
local register_to = instance:get_interests()
|
||||
if register_to then
|
||||
for i = 1, #register_to do
|
||||
local interest = register_to[i]
|
||||
if not self.components[interest] then
|
||||
self.components[interest] = {}
|
||||
end
|
||||
table.insert(self.components[interest], instance)
|
||||
for i = 1, #register_to do
|
||||
local interest = register_to[i]
|
||||
table.insert(self.components[interest], instance)
|
||||
|
||||
if const.UI_INPUT[interest] then
|
||||
input_init(self)
|
||||
end
|
||||
if const.UI_INPUT[interest] then
|
||||
input_init(self)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,7 +80,7 @@ end
|
||||
|
||||
|
||||
local function process_input(action_id, action, components, is_input_consumed)
|
||||
if not components then
|
||||
if #components == 0 then
|
||||
return is_input_consumed
|
||||
end
|
||||
|
||||
@@ -130,7 +124,11 @@ function Druid.initialize(self, context, style)
|
||||
self._style = style or settings.default_style
|
||||
self._deleted = false
|
||||
self.url = msg.url()
|
||||
|
||||
self.components = {}
|
||||
for i = 1, #const.ALL_INTERESTS do
|
||||
self.components[const.ALL_INTERESTS[i]] = {}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -182,14 +180,12 @@ function Druid.remove(self, component)
|
||||
end
|
||||
|
||||
local interests = component:get_interests()
|
||||
if interests then
|
||||
for i = 1, #interests do
|
||||
local interest = interests[i]
|
||||
local components = self.components[interest]
|
||||
for j = #components, 1, -1 do
|
||||
if components[j] == component then
|
||||
table.remove(components, j)
|
||||
end
|
||||
for i = 1, #interests do
|
||||
local interest = interests[i]
|
||||
local components = self.components[interest]
|
||||
for j = #components, 1, -1 do
|
||||
if components[j] == component then
|
||||
table.remove(components, j)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -201,10 +197,8 @@ end
|
||||
-- @tparam number dt Delta time
|
||||
function Druid.update(self, dt)
|
||||
local components = self.components[const.ON_UPDATE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:update(dt)
|
||||
end
|
||||
for i = 1, #components do
|
||||
components[i]:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -233,6 +227,7 @@ end
|
||||
-- @tparam hash sender Sender from on_message
|
||||
function Druid.on_message(self, message_id, message, sender)
|
||||
local specific_ui_message = const.SPECIFIC_UI_MESSAGES[message_id]
|
||||
|
||||
if specific_ui_message then
|
||||
local components = self.components[message_id]
|
||||
if components then
|
||||
@@ -243,10 +238,8 @@ function Druid.on_message(self, message_id, message, sender)
|
||||
end
|
||||
else
|
||||
local components = self.components[const.ON_MESSAGE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_message(message_id, message, sender)
|
||||
end
|
||||
for i = 1, #components do
|
||||
components[i]:on_message(message_id, message, sender)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -257,10 +250,8 @@ end
|
||||
-- @function druid:on_focus_lost
|
||||
function Druid.on_focus_lost(self)
|
||||
local components = self.components[const.ON_FOCUS_LOST]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_lost()
|
||||
end
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_lost()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -270,10 +261,8 @@ end
|
||||
-- @function druid:on_focus_gained
|
||||
function Druid.on_focus_gained(self)
|
||||
local components = self.components[const.ON_FOCUS_GAINED]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_gained()
|
||||
end
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_gained()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -283,10 +272,8 @@ end
|
||||
-- @function druid:on_layout_change
|
||||
function Druid.on_layout_change(self)
|
||||
local components = self.components[const.ON_LAYOUT_CHANGE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_layout_change()
|
||||
end
|
||||
for i = 1, #components do
|
||||
components[i]:on_layout_change()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -297,10 +284,8 @@ end
|
||||
-- @function druid.on_language_change
|
||||
function Druid.on_language_change(self)
|
||||
local components = self.components[const.ON_LANGUAGE_CHANGE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_language_change()
|
||||
end
|
||||
for i = 1, #components do
|
||||
components[i]:on_language_change()
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user