Move several component functions to private scope

This commit is contained in:
Insality 2020-09-23 01:51:10 +03:00
parent 3c32a5f75e
commit c8bf57ecd3
2 changed files with 63 additions and 62 deletions

View File

@ -24,14 +24,6 @@ function Component:set_style(druid_style)
end
--- Get current component template name
-- @function component:get_template
-- @treturn string Component template name
function Component:get_template()
return self._meta.template
end
--- Set current component template name
-- @function component:set_template
-- @tparam string template Component template name
@ -40,14 +32,6 @@ function Component:set_template(template)
end
--- Get current component nodes
-- @function component:get_nodes
-- @treturn table Component nodes table
function Component:get_nodes()
return self._meta.nodes
end
--- Set current component nodes
-- @function component:set_nodes
-- @tparam table nodes Component nodes table
@ -64,22 +48,6 @@ function Component:get_context(context)
end
--- Set current component context
-- @function component:set_context
-- @tparam table context Druid context. Usually it is self of script
function Component:set_context(context)
self._meta.context = context
end
--- Get current component interests
-- @function component:get_interests
-- @treturn table List of component interests
function Component:get_interests()
return self._component.interest
end
--- Increase input priority in current input stack
-- @function component:increase_input_priority
function Component:increase_input_priority()
@ -102,8 +70,8 @@ end
-- @tparam string|node node_or_name Node name or node itself
-- @treturn node Gui node
function Component:get_node(node_or_name)
local template_name = self:get_template() or const.EMPTY_STRING
local nodes = self:get_nodes()
local template_name = self:__get_template() or const.EMPTY_STRING
local nodes = self:__get_nodes()
if template_name ~= const.EMPTY_STRING then
template_name = template_name .. "/"
@ -134,14 +102,6 @@ function Component:get_druid()
end
--- Return true, if current component is child of another component
-- @function component:is_child_of
-- @treturn bool True, if current component is child of another
function Component:is_child_of(component)
return self:get_context() == component
end
--- Return component name
-- @function component:get_name
-- @treturn string The component name
@ -166,6 +126,9 @@ function Component:set_input_enabled(state)
end
--- Return the parent for current component
-- @function component:get_parent_component
-- @treturn Component|nil The druid component instance or nil
function Component:get_parent_component()
local context = self:get_context()
@ -177,26 +140,12 @@ function Component:get_parent_component()
end
function Component:add_children(children)
table.insert(self._meta.children, children)
end
function Component:remove_children(children)
for i = #self._meta.children, 1, -1 do
if self._meta.children[i] == children then
table.remove(self._meta.children, i)
end
end
end
--- Setup component context and his style table
-- @function component:setup_component
-- @tparam druid_instance table The parent druid instance
-- @tparam context table Druid context. Usually it is self of script
-- @tparam style table Druid style module
-- @treturn Component Component itself
-- @treturn component Component itself
function Component:setup_component(druid_instance, context, style)
self._meta = {
template = nil,
@ -209,12 +158,12 @@ function Component:setup_component(druid_instance, context, style)
children = {}
}
self:set_context(context)
self:__set_context(context)
self:set_style(style)
local parent = self:get_parent_component()
if parent then
parent:add_children(self)
parent:__add_children(self)
end
return self
@ -242,6 +191,58 @@ function Component:__tostring()
end
--- Set current component context
-- @function component:__set_context
-- @tparam table context Druid context. Usually it is self of script
function Component:__set_context(context)
self._meta.context = context
end
--- Get current component interests
-- @function component:__get_interests
-- @treturn table List of component interests
function Component:__get_interests()
return self._component.interest
end
--- Get current component template name
-- @function component:__get_template
-- @treturn string Component template name
function Component:__get_template()
return self._meta.template
end
--- Get current component nodes
-- @function component:__get_nodes
-- @treturn table Component nodes table
function Component:__get_nodes()
return self._meta.nodes
end
--- Add child to component children list
-- @function component:__add_children
-- @tparam component children The druid component instance
function Component:__add_children(children)
table.insert(self._meta.children, children)
end
--- Remove child from component children list
-- @function component:__remove_children
-- @tparam component children The druid component instance
function Component:__remove_children(children)
for i = #self._meta.children, 1, -1 do
if self._meta.children[i] == children then
table.remove(self._meta.children, i)
end
end
end
--- Create new component. It will inheritance from basic
-- druid component.
-- @function Component.create

View File

@ -78,7 +78,7 @@ local function create(self, instance_class)
table.insert(self.components[const.ALL], instance)
local register_to = instance:get_interests()
local register_to = instance:__get_interests()
for i = 1, #register_to do
local interest = register_to[i]
table.insert(self.components[interest], instance)
@ -199,7 +199,7 @@ function Druid.remove(self, component)
self:remove(children[i])
local parent = children[i]:get_parent_component()
if parent then
parent:remove_children(children[i])
parent:__remove_children(children[i])
end
end
component._meta.children = {}
@ -214,7 +214,7 @@ function Druid.remove(self, component)
end
end
local interests = component:get_interests()
local interests = component:__get_interests()
for i = 1, #interests do
local interest = interests[i]
local components = self.components[interest]