Update BaseComponent annotations

This commit is contained in:
Insality 2020-10-11 23:18:53 +03:00
parent fbef0cbe54
commit 62cca31b28
3 changed files with 81 additions and 75 deletions

View File

@ -1,7 +1,7 @@
--- Component to handle basic GUI button --- Component to handle basic GUI button
-- @module Button -- @module Button
-- @within BaseComponent
-- @alias druid.button -- @alias druid.button
-- @within component
--- On release button callback(self, params, button_instance) --- On release button callback(self, params, button_instance)
-- @tfield druid_event on_click -- @tfield druid_event on_click
@ -181,7 +181,7 @@ end
--- Component init function --- Component init function
-- @tparam druid.button self -- @tparam Button self
-- @tparam node node Gui node -- @tparam node node Gui node
-- @tparam function callback Button callback -- @tparam function callback Button callback
-- @tparam[opt] table params Button callback params -- @tparam[opt] table params Button callback params
@ -288,9 +288,9 @@ end
--- Set enabled button component state --- Set enabled button component state
-- @tparam druid.button self -- @tparam Button self
-- @tparam bool state Enabled state -- @tparam bool state Enabled state
-- @treturn druid.button Current button instance -- @treturn Button Current button instance
function Button.set_enabled(self, state) function Button.set_enabled(self, state)
self.disabled = not state self.disabled = not state
self.hover:set_enabled(state) self.hover:set_enabled(state)
@ -301,7 +301,7 @@ end
--- Return button enabled state --- Return button enabled state
-- @tparam druid.button self -- @tparam Button self
-- @treturn bool True, if button is enabled -- @treturn bool True, if button is enabled
function Button.is_enabled(self) function Button.is_enabled(self)
return not self.disabled return not self.disabled
@ -310,9 +310,9 @@ end
--- Strict button click area. Useful for --- Strict button click area. Useful for
-- no click events outside stencil node -- no click events outside stencil node
-- @tparam druid.button self -- @tparam Button self
-- @tparam node zone Gui node -- @tparam node zone Gui node
-- @treturn druid.button Current button instance -- @treturn Button Current button instance
function Button.set_click_zone(self, zone) function Button.set_click_zone(self, zone)
self.click_zone = self:get_node(zone) self.click_zone = self:get_node(zone)
self.hover:set_click_zone(zone) self.hover:set_click_zone(zone)
@ -322,9 +322,9 @@ end
--- Set key-code to trigger this button --- Set key-code to trigger this button
-- @tparam druid.button self -- @tparam Button self
-- @tparam hash key The action_id of the key -- @tparam hash key The action_id of the key
-- @treturn druid.button Current button instance -- @treturn Button Current button instance
function Button.set_key_trigger(self, key) function Button.set_key_trigger(self, key)
self.key_trigger = hash(key) self.key_trigger = hash(key)
@ -333,7 +333,7 @@ end
--- Get key-code to trigger this button --- Get key-code to trigger this button
-- @tparam druid.button self -- @tparam Button self
-- @treturn hash The action_id of the key -- @treturn hash The action_id of the key
function Button.get_key_trigger(self) function Button.get_key_trigger(self)
return self.key_trigger return self.key_trigger

View File

@ -1,20 +1,20 @@
--- Basic class for all Druid components. --- Basic class for all Druid components.
-- To create you component, use `component.create` -- To create you component, use `component.create`
-- @module component -- @module BaseComponent
-- @alias druid.base_component
local const = require("druid.const") local const = require("druid.const")
local class = require("druid.system.middleclass") local class = require("druid.system.middleclass")
-- @classmod Component local BaseComponent = class("druid.component")
local Component = class("druid.component")
--- Set current component style table. --- Set current component style table.
-- Invoke `on_style_change` on component, if exist. Component should handle -- Invoke `on_style_change` on component, if exist. BaseComponent should handle
-- their style changing and store all style params -- their style changing and store all style params
-- @function component:set_style -- @tparam BaseComponent self
-- @tparam table style Druid style module -- @tparam table druid_style Druid style module
function Component:set_style(druid_style) function BaseComponent.set_style(self, druid_style)
self._meta.style = druid_style or const.EMPTY_TABLE self._meta.style = druid_style or const.EMPTY_TABLE
local component_style = self._meta.style[self._component.name] or const.EMPTY_TABLE local component_style = self._meta.style[self._component.name] or const.EMPTY_TABLE
@ -25,39 +25,39 @@ end
--- Set current component template name --- Set current component template name
-- @function component:set_template -- @tparam BaseComponent self
-- @tparam string template Component template name -- @tparam string template BaseComponent template name
function Component:set_template(template) function BaseComponent.set_template(self, template)
self._meta.template = template self._meta.template = template
end end
--- Set current component nodes --- Set current component nodes
-- @function component:set_nodes -- @tparam BaseComponent self
-- @tparam table nodes Component nodes table -- @tparam table nodes BaseComponent nodes table
function Component:set_nodes(nodes) function BaseComponent.set_nodes(self, nodes)
self._meta.nodes = nodes self._meta.nodes = nodes
end end
--- Get current component context --- Get current component context
-- @function component:get_context -- @tparam BaseComponent self
-- @treturn table Component context -- @treturn table BaseComponent context
function Component:get_context(context) function BaseComponent.get_context(self)
return self._meta.context return self._meta.context
end end
--- Increase input priority in current input stack --- Increase input priority in current input stack
-- @function component:increase_input_priority -- @tparam BaseComponent self
function Component:increase_input_priority() function BaseComponent.increase_input_priority(self)
self._meta.increased_input_priority = true self._meta.increased_input_priority = true
end end
--- Reset input priority in current input stack --- Reset input priority in current input stack
-- @function component:reset_input_priority -- @tparam BaseComponent self
function Component:reset_input_priority() function BaseComponent.reset_input_priority(self)
self._meta.increased_input_priority = false self._meta.increased_input_priority = false
end end
@ -66,10 +66,10 @@ end
-- If component has nodes, node_or_name should be string -- If component has nodes, node_or_name should be string
-- It auto pick node by template name or from nodes by clone_tree -- It auto pick node by template name or from nodes by clone_tree
-- if they was setup via component:set_nodes, component:set_template -- if they was setup via component:set_nodes, component:set_template
-- @function component:get_node -- @tparam BaseComponent self
-- @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 BaseComponent.get_node(self, 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()
@ -94,28 +94,28 @@ end
--- Return druid with context of calling component. --- Return druid with context of calling component.
-- Use it to create component inside of other components. -- Use it to create component inside of other components.
-- @function component:get_druid -- @tparam BaseComponent self
-- @treturn Druid Druid instance with component context -- @treturn Druid Druid instance with component context
function Component:get_druid() function BaseComponent.get_druid(self)
local context = { _context = self } local context = { _context = self }
return setmetatable(context, { __index = self._meta.druid }) return setmetatable(context, { __index = self._meta.druid })
end end
--- Return component name --- Return component name
-- @function component:get_name -- @tparam BaseComponent self
-- @treturn string The component name -- @treturn string The component name
function Component:get_name() function BaseComponent.get_name(self)
return self._component.name return self._component.name
end end
--- Set component input state. By default it enabled --- Set component input state. By default it enabled
-- You can disable any input of component by this function -- You can disable any input of component by this function
-- @function component:set_input_enabled -- @tparam BaseComponent self
-- @tparam bool state The component input state -- @tparam bool state The component input state
-- @treturn Component Component itself -- @treturn BaseComponent BaseComponent itself
function Component:set_input_enabled(state) function BaseComponent.set_input_enabled(self, state)
self._meta.input_enabled = state self._meta.input_enabled = state
for index = 1, #self._meta.children do for index = 1, #self._meta.children do
@ -127,12 +127,12 @@ end
--- Return the parent for current component --- Return the parent for current component
-- @function component:get_parent_component -- @tparam BaseComponent self
-- @treturn Component|nil The druid component instance or nil -- @treturn druid.base_component|nil The druid component instance or nil
function Component:get_parent_component() function BaseComponent.get_parent_component(self)
local context = self:get_context() local context = self:get_context()
if context.isInstanceOf and context:isInstanceOf(Component) then if context.isInstanceOf and context:isInstanceOf(BaseComponent) then
return context return context
end end
@ -141,12 +141,12 @@ end
--- Setup component context and his style table --- Setup component context and his style table
-- @function component:setup_component -- @tparam BaseComponent self
-- @tparam druid_instance table The parent druid instance -- @tparam table druid_instance The parent druid instance
-- @tparam context table Druid context. Usually it is self of script -- @tparam table context Druid context. Usually it is self of script
-- @tparam style table Druid style module -- @tparam table style Druid style module
-- @treturn component Component itself -- @treturn component BaseComponent itself
function Component:setup_component(druid_instance, context, style) function BaseComponent.setup_component(self, druid_instance, context, style)
self._meta = { self._meta = {
template = nil, template = nil,
context = nil, context = nil,
@ -171,12 +171,12 @@ end
--- Basic constructor of component. It will call automaticaly --- Basic constructor of component. It will call automaticaly
-- by `Component.static.create` -- by `BaseComponent.static.create`
-- @function component:initialize -- @tparam BaseComponent self
-- @tparam string name Component name -- @tparam string name BaseComponent name
-- @tparam[opt={}] table interest List of component's interest -- @tparam[opt={}] table interest List of component's interest
-- @local -- @local
function Component:initialize(name, interest) function BaseComponent.initialize(self, name, interest)
interest = interest or {} interest = interest or {}
self._component = { self._component = {
@ -186,55 +186,61 @@ function Component:initialize(name, interest)
end end
function Component:__tostring() function BaseComponent.__tostring(self)
return self._component.name return self._component.name
end end
--- Set current component context --- Set current component context
-- @function component:__set_context -- @tparam BaseComponent self
-- @tparam table context Druid context. Usually it is self of script -- @tparam table context Druid context. Usually it is self of script
function Component:__set_context(context) -- @local
function BaseComponent.__set_context(self, context)
self._meta.context = context self._meta.context = context
end end
--- Get current component interests --- Get current component interests
-- @function component:__get_interests -- @tparam BaseComponent self
-- @treturn table List of component interests -- @treturn table List of component interests
function Component:__get_interests() -- @local
function BaseComponent.__get_interests(self)
return self._component.interest return self._component.interest
end end
--- Get current component template name --- Get current component template name
-- @function component:__get_template -- @tparam BaseComponent self
-- @treturn string Component template name -- @treturn string BaseComponent template name
function Component:__get_template() -- @local
function BaseComponent.__get_template(self)
return self._meta.template return self._meta.template
end end
--- Get current component nodes --- Get current component nodes
-- @function component:__get_nodes -- @tparam BaseComponent self
-- @treturn table Component nodes table -- @treturn table BaseComponent nodes table
function Component:__get_nodes() -- @local
function BaseComponent.__get_nodes(self)
return self._meta.nodes return self._meta.nodes
end end
--- Add child to component children list --- Add child to component children list
-- @function component:__add_children -- @tparam BaseComponent self
-- @tparam component children The druid component instance -- @tparam component children The druid component instance
function Component:__add_children(children) -- @local
function BaseComponent.__add_children(self, children)
table.insert(self._meta.children, children) table.insert(self._meta.children, children)
end end
--- Remove child from component children list --- Remove child from component children list
-- @function component:__remove_children -- @tparam BaseComponent self
-- @tparam component children The druid component instance -- @tparam component children The druid component instance
function Component:__remove_children(children) -- @local
function BaseComponent.__remove_children(self, children)
for i = #self._meta.children, 1, -1 do for i = #self._meta.children, 1, -1 do
if self._meta.children[i] == children then if self._meta.children[i] == children then
table.remove(self._meta.children, i) table.remove(self._meta.children, i)
@ -245,19 +251,19 @@ end
--- Create new component. It will inheritance from basic --- Create new component. It will inheritance from basic
-- druid component. -- druid component.
-- @function Component.create -- @tparam string name BaseComponent name
-- @tparam string name Component name
-- @tparam[opt={}] table interest List of component's interest -- @tparam[opt={}] table interest List of component's interest
function Component.static.create(name, interest) -- @local
function BaseComponent.static.create(name, interest)
-- Yea, inheritance here -- Yea, inheritance here
local new_class = class(name, Component) local new_class = class(name, BaseComponent)
new_class.initialize = function(self) new_class.initialize = function(self)
Component.initialize(self, name, interest) BaseComponent.initialize(self, name, interest)
end end
return new_class return new_class
end end
return Component return BaseComponent

View File

@ -8,7 +8,7 @@
-- --
-- Learn Druid instance function here -- Learn Druid instance function here
-- @module druid_instance -- @module druid_instance
-- @see druid.button -- @see Button
-- @see druid.blocker -- @see druid.blocker
-- @see druid.back_handler -- @see druid.back_handler
-- @see druid.input -- @see druid.input