mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Move several component functions to private scope
This commit is contained in:
parent
3c32a5f75e
commit
c8bf57ecd3
@ -24,14 +24,6 @@ function Component:set_style(druid_style)
|
|||||||
end
|
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
|
--- Set current component template name
|
||||||
-- @function component:set_template
|
-- @function component:set_template
|
||||||
-- @tparam string template Component template name
|
-- @tparam string template Component template name
|
||||||
@ -40,14 +32,6 @@ function Component:set_template(template)
|
|||||||
end
|
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
|
--- Set current component nodes
|
||||||
-- @function component:set_nodes
|
-- @function component:set_nodes
|
||||||
-- @tparam table nodes Component nodes table
|
-- @tparam table nodes Component nodes table
|
||||||
@ -64,22 +48,6 @@ function Component:get_context(context)
|
|||||||
end
|
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
|
--- Increase input priority in current input stack
|
||||||
-- @function component:increase_input_priority
|
-- @function component:increase_input_priority
|
||||||
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
|
-- @tparam string|node node_or_name Node name or node itself
|
||||||
-- @treturn node Gui node
|
-- @treturn node Gui node
|
||||||
function Component:get_node(node_or_name)
|
function Component:get_node(node_or_name)
|
||||||
local template_name = self:get_template() or const.EMPTY_STRING
|
local template_name = self:__get_template() or const.EMPTY_STRING
|
||||||
local nodes = self:get_nodes()
|
local nodes = self:__get_nodes()
|
||||||
|
|
||||||
if template_name ~= const.EMPTY_STRING then
|
if template_name ~= const.EMPTY_STRING then
|
||||||
template_name = template_name .. "/"
|
template_name = template_name .. "/"
|
||||||
@ -134,14 +102,6 @@ function Component:get_druid()
|
|||||||
end
|
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
|
--- Return component name
|
||||||
-- @function component:get_name
|
-- @function component:get_name
|
||||||
-- @treturn string The component name
|
-- @treturn string The component name
|
||||||
@ -166,6 +126,9 @@ function Component:set_input_enabled(state)
|
|||||||
end
|
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()
|
function Component:get_parent_component()
|
||||||
local context = self:get_context()
|
local context = self:get_context()
|
||||||
|
|
||||||
@ -177,26 +140,12 @@ function Component:get_parent_component()
|
|||||||
end
|
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
|
--- Setup component context and his style table
|
||||||
-- @function component:setup_component
|
-- @function component:setup_component
|
||||||
-- @tparam druid_instance table The parent druid instance
|
-- @tparam druid_instance table The parent druid instance
|
||||||
-- @tparam context table Druid context. Usually it is self of script
|
-- @tparam context table Druid context. Usually it is self of script
|
||||||
-- @tparam style table Druid style module
|
-- @tparam style table Druid style module
|
||||||
-- @treturn Component Component itself
|
-- @treturn component Component itself
|
||||||
function Component:setup_component(druid_instance, context, style)
|
function Component:setup_component(druid_instance, context, style)
|
||||||
self._meta = {
|
self._meta = {
|
||||||
template = nil,
|
template = nil,
|
||||||
@ -209,12 +158,12 @@ function Component:setup_component(druid_instance, context, style)
|
|||||||
children = {}
|
children = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
self:set_context(context)
|
self:__set_context(context)
|
||||||
self:set_style(style)
|
self:set_style(style)
|
||||||
|
|
||||||
local parent = self:get_parent_component()
|
local parent = self:get_parent_component()
|
||||||
if parent then
|
if parent then
|
||||||
parent:add_children(self)
|
parent:__add_children(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@ -242,6 +191,58 @@ function Component:__tostring()
|
|||||||
end
|
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
|
--- Create new component. It will inheritance from basic
|
||||||
-- druid component.
|
-- druid component.
|
||||||
-- @function Component.create
|
-- @function Component.create
|
||||||
|
@ -78,7 +78,7 @@ local function create(self, instance_class)
|
|||||||
|
|
||||||
table.insert(self.components[const.ALL], instance)
|
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
|
for i = 1, #register_to do
|
||||||
local interest = register_to[i]
|
local interest = register_to[i]
|
||||||
table.insert(self.components[interest], instance)
|
table.insert(self.components[interest], instance)
|
||||||
@ -199,7 +199,7 @@ function Druid.remove(self, component)
|
|||||||
self:remove(children[i])
|
self:remove(children[i])
|
||||||
local parent = children[i]:get_parent_component()
|
local parent = children[i]:get_parent_component()
|
||||||
if parent then
|
if parent then
|
||||||
parent:remove_children(children[i])
|
parent:__remove_children(children[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
component._meta.children = {}
|
component._meta.children = {}
|
||||||
@ -214,7 +214,7 @@ function Druid.remove(self, component)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local interests = component:get_interests()
|
local interests = component:__get_interests()
|
||||||
for i = 1, #interests do
|
for i = 1, #interests do
|
||||||
local interest = interests[i]
|
local interest = interests[i]
|
||||||
local components = self.components[interest]
|
local components = self.components[interest]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user