Ldoc compliant

This commit is contained in:
Cooldude2606
2019-05-29 22:24:04 +01:00
parent 53f9c51c0e
commit e187059ae0
94 changed files with 15315 additions and 479 deletions

View File

@@ -235,8 +235,7 @@ local Commands = {
}
--- Adds an authorization callback, function used to check if a player if allowed to use a command
-- @see Commands.authorize
-- @tparam callback function the callback you want to register as an authenticator
-- @tparam function callback the callback you want to register as an authenticator
-- callback param - player: LuaPlayer - the player who is trying to use the command
-- callback param - command: string - the name of the command which is being used
-- callback param - flags: table - any flags which have been set for the command
@@ -248,8 +247,7 @@ function Commands.add_authenticator(callback)
end
--- Removes an authorization callback
-- @see Commands.add_authenticator
-- @tparam callback function|number the callback to remove, an index returned by add_authenticator can be passed
-- @tparam function|number callback the callback to remove, an index returned by add_authenticator can be passed
-- @treturn boolean was the callback found and removed
function Commands.remove_authenticator(callback)
if type(callback) == 'number' then
@@ -277,8 +275,8 @@ function Commands.remove_authenticator(callback)
end
--- Mostly used internally, calls all authorization callbacks, returns if the player is authorized
-- @tparam player LuaPlayer the player that is using the command, passed to callbacks
-- @tparam command_name string the command that is being used, passed to callbacks
-- @tparam LuaPlayer player the player that is using the command, passed to callbacks
-- @tparam string command_name the command that is being used, passed to callbacks
-- @treturn[1] boolean true player is authorized
-- @treturn[1] string commands const for success
-- @treturn[2] boolean false player is unauthorized
@@ -322,7 +320,7 @@ function Commands.authorize(player,command_name)
end
--- Gets all commands that a player is allowed to use, game commands not included
-- @tparam[opt] player LuaPlayer the player that you want to get commands of, nil will return all commands
-- @tparam[opt] LuaPlayer player the player that you want to get commands of, nil will return all commands
-- @treturn table all commands that that player is allowed to use, or all commands
function Commands.get(player)
player = Game.get_player_from_any(player)
@@ -337,8 +335,8 @@ function Commands.get(player)
end
--- Searches command names and help messages to find possible commands, game commands included
-- @tparam keyword string the word which you are trying to find
-- @tparam[opt] allowed_player LuaPlayer the player to get allowed commands of, if nil all commands are searched
-- @tparam string keyword the word which you are trying to find
-- @tparam[opt] LuaPlayer allowed_player the player to get allowed commands of, if nil all commands are searched
-- @treturn table all commands that contain the key word, and allowed by player if player given
function Commands.search(keyword,allowed_player)
local custom_commands = Commands.get(allowed_player)
@@ -369,8 +367,8 @@ end
--- Adds a parse function which can be called by name rather than callback (used in add_param)
-- nb: this is not needed as you can use the callback directly this just allows it to be called by name
-- @tparam name string the name of the parse, should be the type like player or player_alive, must be unique
-- @tparam callback function the callback that is ran to parse the input
-- @tparam string name the name of the parse, should be the type like player or player_alive, must be unique
-- @tparam function callback the callback that is ran to parse the input
-- parse param - input: string - the input given by the user for this param
-- parse param - player: LuaPlayer - the player who is using the command
-- parse param - reject: function(error_message) - use this function to send a error to the user and fail running
@@ -386,14 +384,16 @@ function Commands.add_parse(name,callback)
end
--- Removes a parse function, see add_parse for adding them
-- @tparam name string the name of the parse to remove
-- @tparam string name the name of the parse to remove
function Commands.remove_parse(name)
Commands.parse_functions[name] = nil
end
--- Intended to be used within other parse functions, runs a parse and returns success and new value
-- @tparam name string the name of the parse to call, must be registered and cant be a function
-- @tparam input string the input to pass to the parse, will always be a string but might not be the orginal input
-- @tparam string name the name of the parse to call, must be registered and cant be a function
-- @tparam string input string the input to pass to the parse, will always be a but might not be the orginal input
-- @tparam LuaPlayer player the player that is calling using the command
-- @tparam function reject the reject function that was passed by the command hander
-- @treturn any the new value for the input, may be nil, if nil then either there was an error or input was nil
function Commands.parse(name,input,player,reject,...)
if not Commands.parse_functions[name] then return end
@@ -405,8 +405,8 @@ function Commands.parse(name,input,player,reject,...)
end
--- Creates a new command object to added details to, note this does not register the command to the game
-- @tparam name string the name of the command to be created
-- @tparam help string the help message for the command
-- @tparam string name the name of the command to be created
-- @tparam string help the help message for the command
-- @treturn Commands._prototype this will be used with other functions to generate the command functions
function Commands.new_command(name,help)
local command = setmetatable({
@@ -427,9 +427,9 @@ function Commands.new_command(name,help)
end
--- Adds a new param to the command this will be displayed in the help and used to parse the input
-- @tparam name string the name of the new param that is being added to the command
-- @tparam[opt=true] optional is this param required for this command, these must be after all required params
-- @tparam[opt=pass through] parse function this function will take the input and return a new (or same) value
-- @tparam string name the name of the new param that is being added to the command
-- @tparam[opt=true] boolean optional is this param required for this command, these must be after all required params
-- @tparam[opt=pass function through] ?string|function parse this function will take the input and return a new (or same) value
-- @param[opt] ... extra args you want to pass to the parse function; for example if the parse is general use
-- parse param - input: string - the input given by the user for this param
-- parse param - player: LuaPlayer - the player who is using the command
@@ -452,7 +452,7 @@ function Commands._prototype:add_param(name,optional,parse,...)
end
--- Adds default values to params only matters if the param is optional, if default value is a function it is called with param player
-- @tparam defaults table a table keyed by the name of the param with the value as the default value {paramName=defaultValue}
-- @tparam table defaults table a keyed by the name of the param with the value as the default value {paramName=defaultValue}
-- callback param - player: LuaPlayer - the player using the command, default value does not need to be a function callback
-- @treturn Commands._prototype pass through to allow more functions to be called
function Commands._prototype:set_defaults(defaults)
@@ -465,8 +465,8 @@ function Commands._prototype:set_defaults(defaults)
end
--- Adds a tag to the command which is passed via the flags param to the authenticators, can be used to assign command roles or type
-- @tparam name string the name of the tag to be added; used to keep flags separate
-- @tparam value any the tag that you want can be anything that the authenticators are expecting
-- @tparam string name the name of the tag to be added; used to keep flags separate
-- @tparam any value the tag that you want can be anything that the authenticators are expecting
-- nb: if value is nil then name will be assumed as the value and added at a numbered index
-- @treturn Commands._prototype pass through to allow more functions to be called
function Commands._prototype:set_flag(name,value)
@@ -482,7 +482,7 @@ end
--- Adds an alias or multiple that will also be registered with the same callback, eg /teleport can be /tp with both working
-- @usage command:add_alias('aliasOne','aliasTwo','etc')
-- @tparam ... string any amount of aliases that you want this command to be callable with
-- @tparam string any ... amount of aliases that you want this command to be callable with
-- @treturn Commands._prototype pass through to allow more functions to be called
function Commands._prototype:add_alias(...)
for _,alias in pairs({...}) do
@@ -503,7 +503,7 @@ end
--- Adds the callback to the command and registers all aliases, params and help message with the game
-- nb: this must be the last function ran on the command and must be done for the command to work
-- @tparam callback function the callback for the command, will receive the player running command, and params added with add_param
-- @tparam function callback the callback for the command, will receive the player running command, and params added with add_param
-- callback param - player: LuaPlayer - the player who used the command
-- callback param - ... - any params which were registered with add_param in the order they where registered
-- callback param - raw: string - the raw input from the user, comes after every param added with add_param
@@ -540,8 +540,8 @@ end
-- nb: this is for non fatal errors meaning there is no log of this event
-- nb: if reject is giving as a param to the callback use that instead
-- @usage return Commands.error()
-- @tparam[opt] error_message string an optional error message that can be sent to the user
-- @tparam[opt] play_sound string the sound to play for the error
-- @tparam[opt] string error_message an optional error message that can be sent to the user
-- @tparam[opt] string play_sound the sound to play for the error
-- @treturn Commands.defines.error return this to command handler to exit execution
function Commands.error(error_message,play_sound)
error_message = error_message or ''
@@ -555,9 +555,9 @@ end
--- Sends an error to the player and logs the error, used with pcall within command handler please avoid direct use
-- nb: use error(error_message) within your callback to trigger do not trigger directly as the handler may still continue
-- @tparam success boolean the success value returned from pcall, or just false to trigger error
-- @tparam command_name string the name of the command this is used within the log
-- @tparam error_message string the error returned by pcall or some other error, this is logged and not returned to player
-- @tparam boolean success the success value returned from pcall, or just false to trigger error
-- @tparam string command_name the name of the command this is used within the log
-- @tparam string error_message the error returned by pcall or some other error, this is logged and not returned to player
-- @treturn boolean the opposite of success so true means to cancel execution, used internally
function Commands.internal_error(success,command_name,error_message)
if not success then
@@ -569,7 +569,7 @@ end
--- Sends a value to the player, followed by a command complete message
-- nb: either return a value from your callback to trigger or return the return of this to prevent two messages
-- @tparam[opt] value any the value to return to the player, if nil then only success message returned
-- @tparam[opt] any value the value to return to the player, if nil then only success message returned
-- @treturn Commands.defines.success return this to the command handler to prevent two success messages
function Commands.success(value)
if value ~= nil then player_return(value) end
@@ -591,7 +591,7 @@ local function command_log(player,command,comment,params,raw,details)
end
--- Main event function that is ran for all commands, used internally please avoid direct use
-- @tparam command_event table passed directly from command event from the add_command function
-- @tparam table command_event passed directly from command event from the add_command function
function Commands.run_command(command_event)
local command_data = Commands.commands[command_event.name]
-- player can be nil when it is the server

View File

@@ -48,7 +48,7 @@ local Public = {}
--- Compare types faster for faster validation of params
-- @usage type_check('foo','string') -- return true
-- @usage type_check('foo') -- return false
-- @param v the value to be tested
-- @tparam any value the value to be tested
-- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil
-- @treturn boolean is v of type test_type
function Public.type_check(value,test_type)
@@ -57,10 +57,10 @@ end
--- Raises an error if the value is of the wrong type
-- @usage type_check_error('foo','number','Value must be a number') -- will raise error "Value must be a number"
-- @tparam value any the value that you want to test the type of
-- @tparam test_type string the type that the value should be
-- @tparam error_message string the error message that is returned
-- @tparam level number the level to call the error on (level = 1 means the caller)
-- @tparam any value the value that you want to test the type of
-- @tparam string test_type the type that the value should be
-- @tparam string error_message the error message that is returned
-- @tparam number level the level to call the error on (level = 1 means the caller)
-- @treturn boolean true if no error was called
function Public.type_check_error(value,test_type,error_message,level)
level = level and level+1 or 2
@@ -69,10 +69,10 @@ end
--- Raises an error when the value is the incorrect type, uses a consistent error message format
-- @usage param_check('foo','number','repeat_count',2) -- will raise error "Invalid param #02 given to <anon>; repeat_count is not of type number"
-- @tparam value any the value that you want to test the type of
-- @tparam test_type string the type that the value should be
-- @tparam param_name string the name of the param
-- @tparam param_number number the number param it is
-- @tparam any value the value that you want to test the type of
-- @tparam string test_type the type that the value should be
-- @tparam string param_name the name of the param
-- @tparam number param_number the number param it is
-- @treturn boolean true if no error was raised
function Public.param_check(value,test_type,param_name,param_number)
if not Public.test_type(value,test_type) then
@@ -125,15 +125,15 @@ function Public.player_return(value,colour,player)
end
--- Writes a table object to a file in json format
-- @tparam path string the path of the file to write include / to use dir
-- @tpatam tbl table the table that will be converted to a json string and wrote to file
-- @tparam string path the path of the file to write include / to use dir
-- @tparam table tbl the table that will be converted to a json string and wrote to file
function Public.write_json(path,tbl)
game.write_file(path,game.table_to_json(tbl)..'\n',true,0)
end
--- Calls a require that will not error if the file is not found
-- @usage local file = opt_require('file.not.present') -- will not cause any error
-- @tparam path string the path that you want to require
-- @tparam string path the path that you want to require
-- @return the returns from that file or nil, error if not loaded
function Public.opt_require(path)
local success, rtn = pcall(require,path)
@@ -142,9 +142,9 @@ function Public.opt_require(path)
end
--- Calls a require and returns only the keys given, file must return a table
-- @useage local extract, param_check = ext_require('expcore.common','extract','param_check')
-- @tparam path string the path that you want to require
-- @tparam ... string the name of the keys that you want returned
-- @usage local extract, param_check = ext_require('expcore.common','extract','param_check')
-- @tparam string path the path that you want to require
-- @tparam string ... the name of the keys that you want returned
-- @return the keys in the order given
function Public.ext_require(path,...)
local rtn = require(path)
@@ -159,8 +159,8 @@ end
-- time will use : separates
-- string will return a string not a locale string
-- when a denomination is false it will overflow into the next one
-- @tparam ticks number the number of ticks that represents a time
-- @tparam options table a table of options to use for the format
-- @tparam number ticks the number of ticks that represents a time
-- @tparam table options table a of options to use for the format
-- @treturn string a locale string that can be used
function Public.format_time(ticks,options)
-- Sets up the options
@@ -247,10 +247,11 @@ function Public.format_time(ticks,options)
end
--- Moves items to the position and stores them in the closest entity of the type given
-- @tparam items table items which are to be added to the chests, ['name']=count
-- @tparam[opt=navies] surface LuaSurface the surface that the items will be moved to
-- @tparam[opt={0,0}] position table the position that the items will be moved to {x=100,y=100}
-- @tparam[opt=32] radius number the radius in which the items are allowed to be placed
-- @tparam table items items which are to be added to the chests, ['name']=count
-- @tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
-- @tparam[opt={0,0}] table position the position that the items will be moved to {x=100,y=100}
-- @tparam[opt=32] number radius the radius in which the items are allowed to be placed
-- @tparam[opt=iron-chest] string chest_type the chest type that the items should be moved into
function Public.move_items(items,surface,position,radius,chest_type)
chest_type = chest_type or 'iron-chest'
surface = surface or game.surfaces[1]
@@ -438,7 +439,7 @@ function Public.print_colored_grid_value(value, surface, position, offset, immut
end
--- Clears all flying text entites on a surface
-- @tparam surface LuaSurface the surface to clear
-- @tparam LuaSurface surface the surface to clear
function Public.clear_flying_text(surface)
local entities = surface.find_entities_filtered{name ='flying-text'}
for _,entity in pairs(entities) do
@@ -458,8 +459,8 @@ end
--- Extracts certain keys from a table
-- @usage local key_three, key_one = extract({key_one='foo',key_two='bar',key_three=true},'key_three','key_one')
-- @tparam tbl table the table which contains the keys
-- @tparam ... string the names of the keys you want extracted
-- @tparam table tbl table the which contains the keys
-- @tparam string ... the names of the keys you want extracted
-- @return the keys in the order given
function Public.extract_keys(tbl,...)
local values = {}
@@ -470,7 +471,7 @@ function Public.extract_keys(tbl,...)
end
--- Converts a table to an enum
-- @tparam tbl table the table that will be converted
-- @tparam table tbl table the that will be converted
-- @treturn table the new table that acts like an enum
function Public.enum(tbl)
local rtn = {}
@@ -491,10 +492,10 @@ function Public.enum(tbl)
end
--- Returns the closest match to the input
-- @tparam options table a table of options for the auto complete
-- @tparam input string the input string that will be completed
-- @tparam[opt=false] use_key boolean when true the keys of options will be used as the options
-- @tparam[opt=false] rtn_key boolean when true the the key will be returned rather than the value
-- @tparam table options table a of options for the auto complete
-- @tparam string input string the input that will be completed
-- @tparam[opt=false] boolean use_key when true the keys of options will be used as the options
-- @tparam[opt=false] boolean rtn_key when true the the key will be returned rather than the value
-- @return the list item found that matches the input
function Public.auto_complete(options,input,use_key,rtn_key)
local rtn = {}
@@ -511,7 +512,7 @@ function Public.auto_complete(options,input,use_key,rtn_key)
end
--- Returns all the keys of a table
-- @tparam tbl table the table to get the keys of
-- @tparam table tbl table the to get the keys of
-- @treturn table an array of the table keys
function Public.table_keys(tbl)
local rtn = {}
@@ -522,7 +523,7 @@ function Public.table_keys(tbl)
end
--- Returns all the values of a table
-- @tparam tbl table the table to get the values of
-- @tparam table tbl table the to get the values of
-- @treturn table an array of the table values
function Public.table_values(tbl)
local rtn = {}
@@ -558,8 +559,8 @@ function Public.table_keysort(tbl)
end
--- Returns a message with valid chat tags to change its colour
-- @tparam message string the message that will be in the output
-- @tparam color table a color which contains r,g,b as its keys
-- @tparam string message the message that will be in the output
-- @tparam table color a color which contains r,g,b as its keys
-- @treturn string the message with the color tags included
function Public.format_chat_colour(message,color)
color = color or Colours.white
@@ -568,8 +569,8 @@ function Public.format_chat_colour(message,color)
end
--- Returns a message with valid chat tags to change its colour, using localization
-- @tparam message ?string|table the message that will be in the output
-- @tparam color table a color which contains r,g,b as its keys
-- @tparam ?string|table message the message that will be in the output
-- @tparam table color a color which contains r,g,b as its keys
-- @treturn table the message with the color tags included
function Public.format_chat_colour_localized(message,color)
color = color or Colours.white
@@ -578,8 +579,8 @@ function Public.format_chat_colour_localized(message,color)
end
--- Returns the players name in the players color
-- @tparam player LuaPlayer the player to use the name and color of
-- @tparam[opt=false] raw_string boolean when true a string is returned rather than a localized string
-- @tparam LuaPlayer player the player to use the name and color of
-- @tparam[opt=false] boolean raw_string when true a is returned rather than a localized string
-- @treturn table the players name with tags for the players color
function Public.format_chat_player_name(player,raw_string)
player = Game.get_player_from_any(player)

View File

@@ -25,7 +25,7 @@ local Button = {
}
--- Creates a new button element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new button element define
function Button.new_button(name)
@@ -68,9 +68,9 @@ function Button.new_button(name)
end
--- Adds sprites to a button making it a spirte button
-- @tparam sprite SpritePath the sprite path for the default sprite for the button
-- @tparam[opt] hovered_sprite SpritePath the sprite path for the sprite when the player hovers over the button
-- @tparam[opt] clicked_sprite SpritePath the sprite path for the sprite when the player clicks the button
-- @tparam SpritePath sprite the sprite path for the default sprite for the button
-- @tparam[opt] SpritePath hovered_sprite the sprite path for the sprite when the player hovers over the button
-- @tparam[opt] SpritePath clicked_sprite the sprite path for the sprite when the player clicks the button
-- @treturn self returns the button define to allow chaining
function Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite)
self.draw_data.type = 'sprite-button'
@@ -81,8 +81,8 @@ function Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite)
end
--- Adds a click / mouse button filter to the button
-- @tparam filter ?string|table either a table of mouse buttons or the first mouse button to filter, with a table true means allowed
-- @tparam[opt] ... when filter is not a table you can add the mouse buttons one after each other
-- @tparam table filter ?string|table either a of mouse buttons or the first mouse button to filter, with a table true means allowed
-- @tparam[opt] table ... when filter is not a you can add the mouse buttons one after each other
-- @treturn self returns the button define to allow chaining
function Button._prototype:set_click_filter(filter,...)
if type(filter) == 'string' then
@@ -103,8 +103,8 @@ function Button._prototype:set_click_filter(filter,...)
end
--- Adds a control key filter to the button
-- @tparam filter ?string|table either a table of control keys or the first control keys to filter, with a table true means allowed
-- @tparam[opt] ... when filter is not a table you can add the control keyss one after each other
-- @tparam table filter ?string|table either a of control keys or the first control keys to filter, with a table true means allowed
-- @tparam[opt] table ... when filter is not a you can add the control keyss one after each other
-- @treturn self returns the button define to allow chaining
function Button._prototype:set_key_filter(filter,...)
if type(filter) == 'string' then

View File

@@ -26,7 +26,7 @@ local CenterFrames = {
}
--- Gets the center flow for a player
-- @tparam player LuapPlayer the player to get the flow for
-- @tparam LuaPlayer player the player to get the flow for
-- @treturn LuaGuiElement the center flow
function CenterFrames.get_flow(player)
player = Game.get_player_from_any(player)
@@ -34,15 +34,15 @@ function CenterFrames.get_flow(player)
end
--- Clears the center flow for a player
-- @tparam player LuapPlayer the player to clear the flow for
-- @tparam LuaPlayer player the player to clear the flow for
function CenterFrames.clear_flow(player)
local flow = CenterFrames.get_flow(player)
flow.clear()
end
--- Draws the center frame for a player, if already open then will do nothing
-- @tparam player LuapPlayer the player that will have the frame drawn
-- @tparam name string the name of the hui that will drawn
-- @tparam LuaPlayer player the player that will have the frame drawn
-- @tparam string name the name of the hui that will drawn
-- @treturn LuaGuiElement the new frame that was made
function CenterFrames.draw_frame(player,name)
local define = Gui.get_define(name,true)
@@ -52,8 +52,8 @@ function CenterFrames.draw_frame(player,name)
end
--- Draws the center frame for a player, if already open then will destroy it and redraw
-- @tparam player LuapPlayer the player that will have the frame drawn
-- @tparam name string the name of the hui that will drawn
-- @tparam LuaPlayer player the player that will have the frame drawn
-- @tparam string name the name of the hui that will drawn
-- @treturn LuaGuiElement the new frame that was made
function CenterFrames.redraw_frame(player,name)
local define = Gui.get_define(name,true)
@@ -63,9 +63,9 @@ function CenterFrames.redraw_frame(player,name)
end
--- Toggles if the frame is currently open or not, will open if closed and close if open
-- @tparam player LuapPlayer the player that will have the frame toggled
-- @tparam name string the name of the hui that will be toggled
-- @tparam[opt] state boolean when set will force a state for the frame
-- @tparam LuaPlayer player the player that will have the frame toggled
-- @tparam string name the name of the hui that will be toggled
-- @tparam[opt] boolean state when set will force a state for the frame
-- @treturn boolean if the frame if no open or closed
function CenterFrames.toggle_frame(player,name,state)
local define = Gui.get_define(name,true)
@@ -86,7 +86,7 @@ function CenterFrames.toggle_frame(player,name,state)
end
--- Creates a new center frame define
-- @tparam permision_name string the name that can be used with the permision system
-- @tparam string permision_name the name that can be used with the permision system
-- @treturn table the new center frame define
function CenterFrames.new_frame(permision_name)
local self = Toolbar.new_button(permision_name)
@@ -108,7 +108,7 @@ function CenterFrames.new_frame(permision_name)
end
--- Sets the frame to be the current active gui when opened and closes all other frames
-- @tparam[opt=true] state boolean when true will auto close other frames and set this frame as player.opened
-- @tparam[opt=true] boolean state when true will auto close other frames and set this frame as player.opened
function CenterFrames._prototype:set_auto_focus(state)
if state == false then
self.auto_focus = false
@@ -118,7 +118,7 @@ function CenterFrames._prototype:set_auto_focus(state)
end
--- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
-- @tparam player LuaPlayer the player to draw the frame for
-- @tparam LuaPlayer player the player to draw the frame for
-- @treturn LuaGuiElement the new frame that was drawn
function CenterFrames._prototype:draw_frame(player)
player = Game.get_player_from_any(player)
@@ -149,7 +149,7 @@ function CenterFrames._prototype:draw_frame(player)
end
--- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)
-- @tparam player LuaPlayer the player to draw the frame for
-- @tparam LuaPlayer player the player to draw the frame for
-- @treturn LuaGuiElement the new frame that was drawn
function CenterFrames._prototype:redraw_frame(player)
player = Game.get_player_from_any(player)
@@ -163,7 +163,7 @@ function CenterFrames._prototype:redraw_frame(player)
end
--- Toggles if the frame is open, if open it will close it and if closed it will open it
-- @tparam player LuaPlayer the player to draw the frame for
-- @tparam LuaPlayer player the player to draw the frame for
-- @treturn boolean with the gui frame is now open
function CenterFrames._prototype:toggle_frame(player)
player = Game.get_player_from_any(player)
@@ -179,7 +179,7 @@ function CenterFrames._prototype:toggle_frame(player)
end
--- Creates an event handler that will trigger one of its functions, use with Event.add
-- @tparam[opt=update] action string the action to take on this event
-- @tparam[opt=update] string action the action to take on this event
function CenterFrames._prototype:event_handler(action)
action = action or 'update'
return function(event)

View File

@@ -50,9 +50,9 @@ local Store = require 'expcore.store'
local Game = require 'utils.game'
--- Event call for on_checked_state_changed and store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value boolean the new state of the checkbox
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam boolean value the new state of the checkbox
local function event_call(define,element,value)
if define.events.on_element_update then
local player = Game.get_player_by_index(element.player_index)
@@ -61,9 +61,9 @@ local function event_call(define,element,value)
end
--- Store call for store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value boolean the new state of the checkbox
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam boolean value the new state of the checkbox
local function store_call(define,element,value)
element.state = value
event_call(define,element,value)
@@ -87,7 +87,7 @@ local Checkbox = {
}
--- Creates a new checkbox element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new checkbox element define
function Checkbox.new_checkbox(name)
@@ -131,7 +131,7 @@ function Checkbox.new_checkbox(name)
end
--- Creates a new radiobutton element define, has all functions checkbox has
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new button element define
function Checkbox.new_radiobutton(name)
local self = Checkbox.new_checkbox(name)
@@ -144,9 +144,9 @@ function Checkbox.new_radiobutton(name)
end
--- Adds this radiobutton to be an option in the given option set (only one can be true at a time)
-- @tparam option_set string the name of the option set to add this element to
-- @tparam option_name string the name of this option that will be used to idenitife it
-- @tparam self the define to allow chaining
-- @tparam string option_set the name of the option set to add this element to
-- @tparam string option_name the name of this option that will be used to idenitife it
-- @treturn self the define to allow chaining
function Checkbox._prototype_radiobutton:add_as_option(option_set,option_name)
self.option_set = option_set
self.option_name = option_name or self.name
@@ -160,7 +160,8 @@ function Checkbox._prototype_radiobutton:add_as_option(option_set,option_name)
end
--- Gets the stored value of the radiobutton or the option set if present
-- @tparam category[opt] string the category to get such as player name or force name
-- @tparam string category[opt] the category to get such as player name or force name
-- @tparam boolean internal used to prevent stackover flow
-- @treturn any the value that is stored for this define
function Checkbox._prototype_radiobutton:get_store(category,internal)
if not self.store then return end
@@ -174,8 +175,9 @@ function Checkbox._prototype_radiobutton:get_store(category,internal)
end
--- Sets the stored value of the radiobutton or the option set if present
-- @tparam category[opt] string the category to get such as player name or force name
-- @tparam value any the value to set for this define, must be valid for its type ie boolean for checkbox etc
-- @tparam string category[opt] the category to get such as player name or force name
-- @tparam boolean value the value to set for this define, must be valid for its type ie for checkbox etc
-- @tparam boolean internal used to prevent stackover flow
-- @treturn boolean true if the value was set
function Checkbox._prototype_radiobutton:set_store(category,value,internal)
if not self.store then return end
@@ -189,11 +191,11 @@ function Checkbox._prototype_radiobutton:set_store(category,value,internal)
end
--- Registers a new option set that can be linked to radiobutotns (only one can be true at a time)
-- @tparam name string the name of the option set, must be unique
-- @tparam callback function the update callback when the value of the option set chagnes
-- @tparam string name the name of the option set, must be unique
-- @tparam function callback the update callback when the value of the option set chagnes
-- callback param - value string - the new selected option for this option set
-- callback param - category string - the category that updated if categorize was used
-- @tpram categorize function the function used to convert an element into a string
-- @tparam function categorize the function used to convert an element into a string
-- @treturn string the name of this option set to be passed to add_as_option
function Checkbox.new_option_set(name,callback,categorize)
@@ -216,8 +218,8 @@ function Checkbox.new_option_set(name,callback,categorize)
end
--- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)
-- @tparam name string the name of the option set to draw the radiobuttons of
-- @tparam element LuaGuiElement the parent element that the radiobuttons will be drawn to
-- @tparam string name the name of the option set to draw the radiobuttons of
-- @tparam LuaGuiElement element the parent element that the radiobuttons will be drawn to
function Checkbox.draw_option_set(name,element)
if not Checkbox.option_sets[name] then return end
local options = Checkbox.option_sets[name]
@@ -231,9 +233,9 @@ function Checkbox.draw_option_set(name,element)
end
--- Sets all radiobutotn in a element to false (unless excluded) and can act recursivly
-- @tparam element LuaGuiElement the root gui element to start setting radio buttons from
-- @tparam[opt] exclude ?string|table the name of the radiobutton to exclude or a table of radiobuttons where true will set the state true
-- @tparam[opt=false] recursive boolean if true will recur as much as possible, if a number will recur that number of times
-- @tparam LuaGuiElement element the root gui element to start setting radio buttons from
-- @tparam[opt] table exclude ?string|table the name of the radiobutton to exclude or a of radiobuttons where true will set the state true
-- @tparam[opt=false] ?number|boolean recursive if true will recur as much as possible, if a will recur that number of times
-- @treturn boolean true if successful
function Checkbox.reset_radiobuttons(element,exclude,recursive)
if not element or not element.valid then return end

View File

@@ -167,7 +167,7 @@ Gui.defines = {} -- Stores the indivdual element definations
Gui.names = {} -- Stores debug names to link to gui uids
--- Used internally to create new prototypes for element defines
-- @tparam tbl table a table that will have functions added to it
-- @tparam table tbl table a that will have functions added to it
-- @treturn table the new table with the keys added to it
function Gui._prototype_factory(tbl)
for k,v in pairs(Gui._prototype) do
@@ -177,12 +177,12 @@ function Gui._prototype_factory(tbl)
end
--- Used internally to create event handler adders for element defines
-- @tparam name string the key that the event will be stored under, should be the same as the event name
-- @tparam string name the key that the event will be stored under, should be the same as the event name
-- @treturn function the function that can be used to add an event handler
function Gui._event_factory(name)
--- Gui._prototype:on_event(callback)
--- Add a hander to run on this event, replace event with the event, different classes have different events
-- @tparam callback function the function that will be called on the event
-- @tparam function callback the function that will be called on the event
-- callback param - player LuaPlayer - the player who owns the gui element
-- callback param - element LuaGuiElement - the element that caused the event
-- callback param - value any - (not always present) the updated value for the element
@@ -204,7 +204,7 @@ end
function Gui._store_factory(callback)
--- Gui._prototype:add_store(categorize)
--- Adds a store location for the define that will save the state of the element, categorize is a function that returns a string
-- @tparam[opt] categorize function if present will be called to convert an element into a category string
-- @tparam[opt] function categorize if present will be called to convert an element into a category string
-- categorize param - element LuaGuiElement - the element that needs to be converted
-- categorize return - string - a determistic string that referses to a category such as player name or force name
-- @treturn self the element define to allow chaining
@@ -238,8 +238,8 @@ end
function Gui._sync_store_factory(callback)
--- Gui._prototype:add_sync_store(location,categorize)
--- Adds a store location for the define that will sync between games, categorize is a function that returns a string
-- @tparam location string a unique string location, unlike add_store a uid location should not be used to avoid migration problems
-- @tparam[opt] categorize function if present will be called to convert an element into a category string
-- @tparam string location string a unique location, unlike add_store a uid location should not be used to avoid migration problems
-- @tparam[opt] function categorize if present will be called to convert an element into a category string
-- categorize param - element LuaGuiElement - the element that needs to be converted
-- categorize return - string - a determistic string that referses to a category such as player name or force name
-- @treturn self the element define to allow chaining
@@ -272,7 +272,7 @@ function Gui._sync_store_factory(callback)
end
--- Used internally to create new element defines from a class prototype
-- @tparam prototype table the class prototype that will be used for the element define
-- @tparam table prototype the class prototype that will be used for the element define
-- @treturn table the new element define with all functions accessed via __index metamethod
function Gui._define_factory(prototype)
local uid = Gui.uid_name()
@@ -299,7 +299,7 @@ function Gui._prototype:uid()
end
--- Sets a debug alias for the define
-- @tparam name string the debug name for the element define that can be used to get this element define
-- @tparam string name the debug name for the element define that can be used to get this element define
-- @treturn self the element define to allow chaining
function Gui._prototype:debug_name(name)
self.debug_name = name
@@ -307,7 +307,7 @@ function Gui._prototype:debug_name(name)
end
--- Sets the caption for the element define
-- @tparam caption string the caption that will be drawn with the element
-- @tparam string caption the caption that will be drawn with the element
-- @treturn self the element define to allow chaining
function Gui._prototype:set_caption(caption)
self.draw_data.caption = caption
@@ -315,7 +315,7 @@ function Gui._prototype:set_caption(caption)
end
--- Sets the tooltip for the element define
-- @tparam tooltip string the tooltip that will be displayed for this element when drawn
-- @tparam string tooltip the tooltip that will be displayed for this element when drawn
-- @treturn self the element define to allow chaining
function Gui._prototype:set_tooltip(tooltip)
self.draw_data.tooltip = tooltip
@@ -323,8 +323,8 @@ function Gui._prototype:set_tooltip(tooltip)
end
--- Sets the style for the element define
-- @tparam style string the style that will be used for this element when drawn
-- @tapram[opt] callback function function is called when element is drawn to alter its style
-- @tparam string style the style that will be used for this element when drawn
-- @tparam[opt] callback function function is called when element is drawn to alter its style
-- @treturn self the element define to allow chaining
function Gui._prototype:set_style(style,callback)
self.draw_data.style = style
@@ -345,7 +345,7 @@ function Gui._prototype:set_embeded_flow(state)
end
--- Sets an authenticator that blocks the draw function if check fails
-- @tparam callback function the function that will be ran to test if the element should be drawn or not
-- @tparam function callback the function that will be ran to test if the element should be drawn or not
-- callback param - player LuaPlayer - the player that the element is being drawn to
-- callback param - define_name string - the name of the define that is being drawn
-- callback return - boolean - false will stop the element from being drawn
@@ -360,7 +360,7 @@ function Gui._prototype:set_pre_authenticator(callback)
end
--- Sets an authenticator that disables the element if check fails
-- @tparam callback function the function that will be ran to test if the element should be enabled or not
-- @tparam function callback the function that will be ran to test if the element should be enabled or not
-- callback param - player LuaPlayer - the player that the element is being drawn to
-- callback param - define_name string - the name of the define that is being drawn
-- callback return - boolean - false will disable the element
@@ -376,7 +376,7 @@ end
--- Draws the element using what is in the draw_data table, allows use of authenticator if present, registers new instances if store present
-- the data with in the draw_data is set up through the use of all the other functions
-- @tparam element LuaGuiElement the element that the define will draw a copy of its self onto
-- @tparam LuaGuiElement element the element that the define will draw a copy of its self onto
-- @treturn LuaGuiElement the new element that was drawn so styles can be applied
function Gui._prototype:draw_to(element,...)
if element[self.name] then return end
@@ -415,7 +415,7 @@ function Gui._prototype:draw_to(element,...)
end
--- Gets the value in this elements store, category needed if categorize function used
-- @tparam category[opt] string the category to get such as player name or force name
-- @tparam string category[opt] the category to get such as player name or force name
-- @treturn any the value that is stored for this define
function Gui._prototype:get_store(category)
if not self.store then return end
@@ -427,8 +427,8 @@ function Gui._prototype:get_store(category)
end
--- Sets the value in this elements store, category needed if categorize function used
-- @tparam category[opt] string the category to get such as player name or force name
-- @tparam value any the value to set for this define, must be valid for its type ie boolean for checkbox etc
-- @tparam string category[opt] the category to get such as player name or force name
-- @tparam boolean any value the value to set for this define, must be valid for its type ie for checkbox etc
-- @treturn boolean true if the value was set
function Gui._prototype:set_store(category,value)
if not self.store then return end
@@ -441,7 +441,7 @@ end
--- Gets an element define give the uid, debug name or a copy of the element define
-- @tparam name ?string|table the uid, debug name or define for the element define to get
-- @tparam[opt] internal boolean when true the error trace is one level higher (used internally)
-- @tparam[opt] boolean internal when true the error trace is one level higher (used internally)
-- @treturn table the element define that was found or an error
function Gui.get_define(name,internal)
if type(name) == 'table' then
@@ -465,7 +465,7 @@ end
--- Gets the value that is stored for a given element define, category needed if categorize function used
-- @tparam name ?string|table the uid, debug name or define for the element define to get
-- @tparam[opt] category string the category to get the value for
-- @tparam[opt] string category the category to get the value for
-- @treturn any the value that is stored for this define
function Gui.get_store(name,category)
local define = Gui.get_define(name,true)
@@ -474,8 +474,8 @@ end
--- Sets the value stored for a given element define, category needed if categorize function used
-- @tparam name ?string|table the uid, debug name or define for the element define to set
-- @tparam[opt] category string the category to set the value for
-- @tparam value any the value to set for the define, must be valid for its type ie boolean for a checkbox
-- @tparam[opt] string category the category to set the value for
-- @tparam boolean any value the value to set for the define, must be valid for its type ie for a checkbox
-- @treturn boolean true if the value was set
function Gui.set_store(name,category,value)
local define = Gui.get_define(name,true)
@@ -483,7 +483,7 @@ function Gui.set_store(name,category,value)
end
--- A categorize function to be used with add_store, each player has their own value
-- @tparam element LuaGuiElement the element that will be converted to a string
-- @tparam LuaGuiElement element the element that will be converted to a string
-- @treturn string the player's name who owns this element
function Gui.player_store(element)
local player = Game.get_player_by_index(element.player_index)
@@ -491,7 +491,7 @@ function Gui.player_store(element)
end
--- A categorize function to be used with add_store, each force has its own value
-- @tparam element LuaGuiElement the element that will be converted to a string
-- @tparam LuaGuiElement element the element that will be converted to a string
-- @treturn string the player's force name who owns this element
function Gui.force_store(element)
local player = Game.get_player_by_index(element.player_index)
@@ -499,7 +499,7 @@ function Gui.force_store(element)
end
--- A categorize function to be used with add_store, each surface has its own value
-- @tparam element LuaGuiElement the element that will be converted to a string
-- @tparam LuaGuiElement element the element that will be converted to a string
-- @treturn string the player's surface name who owns this element
function Gui.surface_store(element)
local player = Game.get_player_by_index(element.player_index)
@@ -516,7 +516,7 @@ function Gui.draw(name,element,...)
end
--- Will toggle the enabled state of an element
-- @tparam element LuaGuiElement the gui element to toggle
-- @tparam LuaGuiElement element the gui element to toggle
-- @treturn boolean the new state that the element has
function Gui.toggle_enable(element)
if not element or not element.valid then return end
@@ -529,7 +529,7 @@ function Gui.toggle_enable(element)
end
--- Will toggle the visiblity of an element
-- @tparam element LuaGuiElement the gui element to toggle
-- @tparam LuaGuiElement element the gui element to toggle
-- @treturn boolean the new state that the element has
function Gui.toggle_visible(element)
if not element or not element.valid then return end
@@ -542,11 +542,11 @@ function Gui.toggle_visible(element)
end
--- Sets the padding for a gui element
-- @tparam element LuaGuiElement the element to set the padding for
-- @tparam[opt=0] up number the amount of padding on the top
-- @tparam[opt=0] down number the amount of padding on the bottom
-- @tparam[opt=0] left number the amount of padding on the left
-- @tparam[opt=0] right number the amount of padding on the right
-- @tparam LuaGuiElement element the element to set the padding for
-- @tparam[opt=0] number up the amount of padding on the top
-- @tparam[opt=0] number down the amount of padding on the bottom
-- @tparam[opt=0] number left the amount of padding on the left
-- @tparam[opt=0] number right the amount of padding on the right
function Gui.set_padding(element,up,down,left,right)
local style = element.style
style.top_padding = up or 0
@@ -557,10 +557,10 @@ end
--- Sets the padding for a gui style
-- @tparam element LuaStyle the element to set the padding for
-- @tparam[opt=0] up number the amount of padding on the top
-- @tparam[opt=0] down number the amount of padding on the bottom
-- @tparam[opt=0] left number the amount of padding on the left
-- @tparam[opt=0] right number the amount of padding on the right
-- @tparam[opt=0] number up the amount of padding on the top
-- @tparam[opt=0] number down the amount of padding on the bottom
-- @tparam[opt=0] number left the amount of padding on the left
-- @tparam[opt=0] number right the amount of padding on the right
function Gui.set_padding_style(style,up,down,left,right)
style.top_padding = up or 0
style.bottom_padding = down or 0
@@ -569,8 +569,8 @@ function Gui.set_padding_style(style,up,down,left,right)
end
--- Allows the creation of a right align flow to place elements into
-- @tparam element LuaGuiElement the element to add this flow to,
-- @tparam[opt] flow_name string the name of the flow can be nil
-- @tparam LuaGuiElement element the element to add this flow to,
-- @tparam[opt] string flow_name the name of the flow can be nil
-- @treturn LuaGuiElement the flow that was created
function Gui.create_right_align(element,flow_name)
local right_flow =
@@ -585,7 +585,7 @@ function Gui.create_right_align(element,flow_name)
end
--- Destroies an element but tests for it being present and valid first
-- @tparam element LuaGuiElement the element to be destroied
-- @tparam LuaGuiElement element the element to be destroied
-- @treturn boolean true if it was destoried
function Gui.destory_if_valid(element)
if element and element.valid then

View File

@@ -20,9 +20,9 @@ local Gui = require 'expcore.gui.core'
local Game = require 'utils.game'
--- Event call for on_selection_state_changed and store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value string the new option for the dropdown
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam string value the new option for the dropdown
local function event_call(define,element,value)
local player = Game.get_player_by_index(element.player_index)
@@ -35,11 +35,11 @@ local function event_call(define,element,value)
end
end
--- Store call for store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value string the new option for the dropdown
local _select_value
--- Store call for store update
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam string value the new option for the dropdown
local function store_call(define,element,value)
_select_value(element,value)
event_call(define,element,value)
@@ -55,7 +55,7 @@ local Dropdown = {
}
--- Creates a new dropdown element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new dropdown element define
function Dropdown.new_dropdown(name)
@@ -103,7 +103,7 @@ function Dropdown.new_dropdown(name)
end
--- Creates a new list box element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new list box element define
function Dropdown.new_list_box(name)
local self = Dropdown.new_dropdown(name)
@@ -113,8 +113,8 @@ function Dropdown.new_list_box(name)
end
--- Adds new static options to the dropdown which will trigger the general callback
-- @tparam options ?string|table either a table of option strings or the first option string, with a table values are the options
-- @tparam[opt] ... when options is not a table you can add the options one after each other
-- @tparam table options ?string|table either a of option strings or the first option string, with a table values are the options
-- @tparam[opt] table ... when options is not a you can add the options one after each other
-- @tparam self the define to allow chaining
function Dropdown._prototype:new_static_options(options,...)
if type(options) == 'string' then
@@ -131,11 +131,11 @@ end
Dropdown._prototype.add_options = Dropdown._prototype.new_static_options
--- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options)
-- @tparam callback function the function that will run to get the options for the dropdown
-- @tparam function callback the function that will run to get the options for the dropdown
-- callback param - player LuaPlayer - the player that the element is being drawn to
-- callback param - element LuaGuiElement - the element that is being drawn
-- callback return - table - the values of this table will be appended to the static options of the dropdown
-- @tparam self the define to allow chaining
-- @treturn self the define to allow chaining
function Dropdown._prototype:new_dynamic_options(callback)
if type(callback) ~= 'function' then
return error('Dynamic options callback must be a function',2)
@@ -146,12 +146,12 @@ end
Dropdown._prototype.add_dynamic = Dropdown._prototype.new_dynamic_options
--- Adds a case specific callback which will only run when that option is selected (general case still triggered)
-- @tparam option string the name of the option to trigger the callback on; if not already added then will be added as an option
-- @tparam callback function the function that will be called when that option is selected
-- @tparam string option the name of the option to trigger the callback on; if not already added then will be added as an option
-- @tparam function callback the function that will be called when that option is selected
-- callback param - player LuaPlayer - the player who owns the gui element
-- callback param - element LuaGuiElement - the element which is being effected
-- callback param - value string - the new option that has been selected
-- @tparam self the define to allow chaining
-- @treturn self the define to allow chaining
function Dropdown._prototype:add_option_callback(option,callback)
if not self.option_callbacks then self.option_callbacks = {} end
if not self.options then self.options = {} end
@@ -165,8 +165,8 @@ function Dropdown._prototype:add_option_callback(option,callback)
end
--- Selects the option from a dropdown or list box given the value rather than key
-- @tparam element LuaGuiElement the element that contains the option
-- @tparam value string the option to select from the dropdown
-- @tparam LuaGuiElement element the element that contains the option
-- @tparam string value the option to select from the dropdown
-- @treturn number the key where the value was
function Dropdown.select_value(element,value)
for k,item in pairs(element.items) do
@@ -179,7 +179,7 @@ end
_select_value = Dropdown.select_value
--- Returns the currently selected value rather than index
-- @tparam element LuaGuiElement the gui element that you want to get the value of
-- @tparam LuaGuiElement element the gui element that you want to get the value of
-- @treturn string the value that is currently selected
function Dropdown.get_selected_value(element)
local index = element.selected_index

View File

@@ -15,9 +15,9 @@ local Gui = require 'expcore.gui.core'
local Game = require 'utils.game'
--- Event call for on_elem_changed and store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value string the new value for the elem button
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam string value the new value for the elem button
local function event_call(define,element,value)
local player = Game.get_player_by_index(element.player_index)
@@ -28,12 +28,12 @@ local function event_call(define,element,value)
end
--- Store call for store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value string the new value for the elem button
local function store_call(self,element,value)
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam string value the new value for the elem button
local function store_call(define,element,value)
element.elem_value = value
event_call(self,element,value)
event_call(define,element,value)
end
local ElemButton = {
@@ -46,7 +46,7 @@ local ElemButton = {
}
--- Creates a new elem button element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new elem button element define
function ElemButton.new_elem_button(name)
@@ -90,7 +90,7 @@ function ElemButton.new_elem_button(name)
end
--- Sets the type of the elem button, the type is required so this must be called at least once
-- @tparam type string the type that this elem button is see factorio api
-- @tparam string type the type that this elem button is see factorio api
-- @treturn the element define to allow for chaining
function ElemButton._prototype:set_type(type)
self.draw_data.elem_type = type
@@ -98,7 +98,7 @@ function ElemButton._prototype:set_type(type)
end
--- Sets the default value for the elem button, this may be a function or a string
-- @tparam value ?string|function a string will be a static default and a function will be called when drawn to get the default
-- @tparam ?string|function value string a will be a static default and a function will be called when drawn to get the default
-- @treturn the element define to allow for chaining
function ElemButton._prototype:set_default(value)
self.default = value

View File

@@ -86,22 +86,22 @@ Global.register(Instances.data,function(tbl)
end)
--- Returns if a instnace group has a categorise function; must be registerd
-- @tparam name string the name of the instance group
-- @tparam string name the name of the instance group
-- @treturn boolean true if there is a categorise function
function Instances.has_categories(name)
return type(Instances.categorise[name]) == 'function'
end
--- Returns if the given name is a registered instance group
-- @tparam name string the name of the instance group you are testing
-- @tparam string name the name of the instance group you are testing
-- @treturn boolean true if the name is registered
function Instances.is_registered(name)
return Instances.categorise[name] ~= nil
end
--- Registers the name of an instance group to allow for storing element instances
-- @tparam name string the name of the instance group; must to unique
-- @tparam[opt] categorise function function used to turn the element into a string
-- @tparam string name the name of the instance group; must to unique
-- @tparam[opt] function categorise function used to turn the element into a string
-- categorise param - element LuaGuiElement - the gui element to be turned into a string
-- categorise return - string - the category that the element will be added to like the player's name or force's name
-- @treturn string the name that was added so it can be used as a varible
@@ -123,8 +123,8 @@ function Instances.register(name,categorise)
end
--- Adds an element to the instance group under the correct category; must be registered
-- @tparam name string the name of the instance group to add the element to
-- @tparam element LuaGuiElement the element to add the the instance group
-- @tparam string name the name of the instance group to add the element to
-- @tparam LuaGuiElement element the element to add the the instance group
function Instances.add_element(name,element)
if not Instances.categorise[name] then
return error('Inavlid name for instance group: '..name,2)
@@ -140,8 +140,8 @@ function Instances.add_element(name,element)
end
--- Gets all element instances without first removing any invalid ones; used internally and must be registered
-- @tparam name string the name of the instance group to get the instances of
-- @tparam[opt] category string the category to get the instance from, not needed when no categorise function
-- @tparam string name the name of the instance group to get the instances of
-- @tparam[opt] string category the category to get the instance from, not needed when no categorise function
-- @treturn table the table of element instances of which some may be invalid
function Instances.get_elements_raw(name,category)
if not Instances.categorise[name] then
@@ -156,8 +156,8 @@ function Instances.get_elements_raw(name,category)
end
--- Gets all valid element instances and has the option of running a callback on those that are valid
-- @tparam name string the name of the instance group to get the instances of
-- @tparam[opt] category string the category to get the instances of, not needed when no categorise function
-- @tparam string name the name of the instance group to get the instances of
-- @tparam[opt] string category the category to get the instances of, not needed when no categorise function
-- @tparan[opt] callback function when given the callback will be ran on all valid elements
-- callback param - element LuaGuiElement - the current valid element
-- @treturn table the table of element instances with all invalid ones removed
@@ -185,9 +185,9 @@ Instances.get_elements = Instances.get_valid_elements
Instances.apply_to_elements = Instances.get_valid_elements
--- A version of add_element that does not require the group to be registered
-- @tparam name string the name of the instance group to add the element to
-- @tparam string name the name of the instance group to add the element to
-- @tparam category ?string|nil the category to add the element to, can be nil but must still be given
-- @tparam element LuaGuiElement the element to add to the instance group
-- @tparam LuaGuiElement element the element to add to the instance group
function Instances.unregistered_add_element(name,category,element)
if not Instances.data[name] then Instances.data[name] = {} end
if category then
@@ -199,9 +199,9 @@ function Instances.unregistered_add_element(name,category,element)
end
--- A version of get_elements that does not require the group to be registered
-- @tparam name string the name of the instance group to get the instances of
-- @tparam string name the name of the instance group to get the instances of
-- @tparam category ?string|nil the category to get the instances of, can be nil but must still be given
-- @tparam[opt] callback function when given will be called on all valid instances
-- @tparam[opt] function callback when given will be called on all valid instances
-- callback param - element LuaGuiElement - the current valid element
-- @treturn table the table of element instances with all invalid ones removed
function Instances.unregistered_get_elements(name,category,callback)

View File

@@ -66,7 +66,7 @@ setmetatable(LeftFrames._prototype, {
})
--- Gets the left frame flow for a player
-- @tparam player LuaPlayer the player to get the flow of
-- @tparam LuaPlayer player the player to get the flow of
-- @treturn LuaGuiElement the left frame flow for the player
function LeftFrames.get_flow(player)
player = Game.get_player_from_any(player)
@@ -74,8 +74,8 @@ function LeftFrames.get_flow(player)
end
--- Gets one frame from the left flow by its name
-- @tparam name string the name of the gui frame to get
-- @tparam player LuaPlayer the player to get the frame of
-- @tparam string name the name of the gui frame to get
-- @tparam LuaPlayer player the player to get the frame of
-- @treturn LuaGuiElement the frame in the left frame flow with that name
function LeftFrames.get_frame(name,player)
local define = LeftFrames.frames[name]
@@ -86,7 +86,7 @@ function LeftFrames.get_frame(name,player)
end
--- Gets all open frames for a player, if non are open it will remove the close all button
-- @tparam player LuaPlayer the player to get the flow of
-- @tparam LuaPlayer player the player to get the flow of
-- @treturn table contains all the open (and registered) frames for the player
function LeftFrames.get_open(player)
local open = {}
@@ -104,9 +104,9 @@ function LeftFrames.get_open(player)
end
--- Toggles the visiblty of a left frame, or sets its visiblty state
-- @tparam name string the name of the gui frame to toggle
-- @tparam player LuaPlayer the player to get the frame of
-- @tparam[opt] state boolean when given will be the state that the visiblty is set to
-- @tparam string name the name of the gui frame to toggle
-- @tparam LuaPlayer player the player to get the frame of
-- @tparam[opt] boolean state when given will be the state that the visiblty is set to
-- @treturn boolean the new state of the visiblity
function LeftFrames.toggle_frame(name,player,state)
local define = LeftFrames.frames[name]
@@ -127,7 +127,7 @@ function LeftFrames.toggle_frame(name,player,state)
end
--- Creates a new left frame define
-- @tparam permision_name string the name that can be used with the permision system
-- @tparam string permision_name the name that can be used with the permision system
-- @treturn table the new left frame define
function LeftFrames.new_frame(permision_name)
@@ -147,7 +147,7 @@ function LeftFrames.new_frame(permision_name)
end
--- Sets if the frame is visible when a player joins, can also be a function to return a boolean
-- @tparam[opt=true] state ?boolean|function the default state of the visiblty, can be a function
-- @tparam[opt=true] ?boolean|function state the default state of the visiblty, can be a function
-- state param - player LuaPlayer - the player that has joined the game
-- state param - define_name string - the define name for the frame
-- state return - boolean - false will hide the frame
@@ -163,14 +163,14 @@ function LeftFrames._prototype:set_open_by_default(state)
end
--- Sets the direction of the frame, either vertical or horizontal
-- @tparam direction string the direction to have the elements be added to thef frame
-- @tparam string direction the direction to have the elements be added to thef frame
function LeftFrames._prototype:set_direction(direction)
self.direction = direction
return self
end
--- Gets the frame for this define from the left frame flow
-- @tparam player LuaPlayer the player to get the frame of
-- @tparam LuaPlayer player the player to get the frame of
-- @treturn LuaGuiElement the frame in the left frame flow for this define
function LeftFrames._prototype:get_frame(player)
local flow = LeftFrames.get_flow(player)
@@ -180,7 +180,7 @@ function LeftFrames._prototype:get_frame(player)
end
--- Returns if the player currently has this define visible
-- @tparam player LuaPlayer the player to get the frame of
-- @tparam LuaPlayer player the player to get the frame of
-- @treturn boolean true if it is open/visible
function LeftFrames._prototype:is_open(player)
local frame = self:get_frame(player)
@@ -188,7 +188,7 @@ function LeftFrames._prototype:is_open(player)
end
--- Toggles the visiblty of the left frame
-- @tparam player LuaPlayer the player to toggle the frame of
-- @tparam LuaPlayer player the player to toggle the frame of
-- @treturn boolean the new state of the visiblity
function LeftFrames._prototype:toggle(player)
local frame = self:get_frame(player)
@@ -198,7 +198,7 @@ function LeftFrames._prototype:toggle(player)
end
--- Updates the contents of the left frame, first tries update callback, oter wise will clear and redraw
-- @tparam player LuaPlayer the player to update the frame of
-- @tparam LuaPlayer player the player to update the frame of
function LeftFrames._prototype:update(player)
local frame = self:get_frame(player)
if self.events.on_update then
@@ -210,7 +210,7 @@ function LeftFrames._prototype:update(player)
end
--- Updates the frame for all players, see update
-- @tparam[opt=false] update_offline boolean when true will update the frame for offline players
-- @tparam[opt=false] boolean update_offline when true will update the frame for offline players
function LeftFrames._prototype:update_all(update_offline)
local players = update_offline == true and game.players or game.connected_players
for _,player in pairs(players) do
@@ -219,7 +219,7 @@ function LeftFrames._prototype:update_all(update_offline)
end
--- Redraws the frame by calling on_draw, will always clear the frame
-- @tparam player LuaPlayer the player to update the frame of
-- @tparam LuaPlayer player the player to update the frame of
function LeftFrames._prototype:redraw(player)
local frame = self:get_frame(player)
frame.clear()
@@ -229,7 +229,7 @@ function LeftFrames._prototype:redraw(player)
end
--- Redraws the frame for all players, see redraw
-- @tparam[opt=false] update_offline boolean when true will update the frame for offline players
-- @tparam[opt=false] boolean update_offline when true will update the frame for offline players
function LeftFrames._prototype:redraw_all(update_offline)
local players = update_offline == true and game.players or game.connected_players
for _,player in pairs(players) do
@@ -238,7 +238,7 @@ function LeftFrames._prototype:redraw_all(update_offline)
end
--- Creates an event handler that will trigger one of its functions, use with Event.add
-- @tparam[opt=update] action string the action to take on this event
-- @tparam[opt=update] string action the action to take on this event
function LeftFrames._prototype:event_handler(action)
action = action or 'update'
return function(event)

View File

@@ -34,22 +34,22 @@ Global.register(PopupFrames.paused_popups,function(tbl)
end)
--- Sets the state of the element in the pasued list, nil or true
-- @tparam element LuaGuiElement the element to set the state of
-- @tparam[opt] state boolean the state to set it to, true will pause the the progress bar
-- @tparam LuaGuiElement element the element to set the state of
-- @tparam[opt] boolean state the state to set it to, true will pause the the progress bar
local function set_pasued_state(element,state)
local name = element.player_index..':'..element.index
PopupFrames.paused_popups[name] = state
end
--- Gets the state of the element in the pasued list, nil or true
-- @tparam element LuaGuiElement the element to get the state of
-- @tparam LuaGuiElement element the element to get the state of
local function get_pasued_state(element)
local name = element.player_index..':'..element.index
return PopupFrames.paused_popups[name]
end
--- Gets the left flow that contains the popup frames
-- @tparam player LuaPlayer the player to get the flow for
-- @tparam LuaPlayer player the player to get the flow for
-- @treturn LuaGuiElement the left flow that contains the popup frames
function PopupFrames.get_flow(player)
player = Game.get_player_from_any(player)
@@ -58,10 +58,10 @@ function PopupFrames.get_flow(player)
end
--- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function
-- @tparam define_name string the name of the define that you want to open for the player
-- @tparam player LuaPlayer the player to open the popup for
-- @tparam[opt] open_time number the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default
-- @tparam ... any the other params that you want to pass to your on_draw event
-- @tparam string define_name the name of the define that you want to open for the player
-- @tparam LuaPlayer player the player to open the popup for
-- @tparam[opt] number open_time the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default
-- @tparam any ... the other params that you want to pass to your on_draw event
-- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content
function PopupFrames.open(define_name,player,open_time,...)
local define = Gui.get_define(define_name,true)
@@ -70,7 +70,7 @@ function PopupFrames.open(define_name,player,open_time,...)
end
--- Closes the popup, is called by progress bar and close button
-- @tparam element LuaGuiElement either the progress bar or the close button
-- @tparam LuaGuiElement element either the progress bar or the close button
local function close_popup(element)
local frame = element.parent.parent.parent
if not frame or not frame.valid then return end
@@ -117,7 +117,7 @@ Gui.on_click(PopupFrames.close_frame_name,function(event)
end)
--- Creates a new popup frame define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new popup frame define
function PopupFrames.new_popup(name)
local self = Gui._define_factory(PopupFrames._prototype)
@@ -182,7 +182,7 @@ function PopupFrames.new_popup(name)
end
--- Sets the default open time for the popup, will be used if non is provided with open
-- @tparam amount number the number of ticks, by default, the popup will be open for
-- @tparam number amount the number of ticks, by default, the popup will be open for
-- @treturn table the define to allow for chaining
function PopupFrames._prototype:set_default_open_time(amount)
self.default_open_time = amount
@@ -190,9 +190,9 @@ function PopupFrames._prototype:set_default_open_time(amount)
end
--- Opens this define for a player, can be given open time and any other params for the draw function
-- @tparam player LuaPlayer the player to open the popup for
-- @tparam[opt] open_time number the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default
-- @tparam ... any the other params that you want to pass to your on_draw event
-- @tparam LuaPlayer player the player to open the popup for
-- @tparam[opt] number open_time the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default
-- @tparam any ... the other params that you want to pass to your on_draw event
-- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content
function PopupFrames._prototype:open(player,open_time,...)
open_time = open_time or self.default_open_time or 0

View File

@@ -25,8 +25,8 @@ local Global = require 'utils.global'
local Game = require 'utils.game'
--- Event call for when the value is outside the range 0-1
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
local function event_call(define,element)
local player = Game.get_player_by_index(element.player_index)
@@ -39,8 +39,9 @@ local function event_call(define,element)
end
--- Store call for store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam number value the new value for the progress bar
local function store_call(define,element,value)
if value then
element.value = value
@@ -71,7 +72,7 @@ Global.register({
end)
--- Gets the define data, cant use Gui.get_define as it would error
-- @tparam define ?table|string the define to get
-- @tparam ?table|string define the define to get
-- @treturn table the define or nil
local function get_define(define)
if type(define) == 'table' then
@@ -84,7 +85,7 @@ local function get_define(define)
end
--- Gets the element data, used when there is no define
-- @tparam element LuaGuiElement
-- @tparam LuaGuiElement element the element to get the data of
-- @treturn table the element data simialr to define
local function get_element(element)
if not element.valid then return end
@@ -96,8 +97,8 @@ local function get_element(element)
end
--- Sets the maximum value that represents the end value of the progress bar
-- @tparam element ?LuaGuiElement|string either a gui element or a registered define
-- @tparam amount number the amount to have set as the maximum
-- @tparam ?LuaGuiElement|string element either a gui element or a registered define
-- @tparam number amount the amount to have set as the maximum
function ProgressBar.set_maximum(element,amount)
amount = amount > 0 and amount or error('amount must be greater than 0')
@@ -124,8 +125,8 @@ function ProgressBar.set_maximum(element,amount)
end
--- Increases the value of the progressbar, if a define is given all of its instances are incremented
-- @tapram element ?LuaGuiElement|string either a gui element or a registered define
-- @tparam[opt=1] amount number the amount to increase the progressbar by
-- @tparam ?LuaGuiElement|string element either a gui element or a registered define
-- @tparam[opt=1] number amount the amount to increase the progressbar by
function ProgressBar.increment(element,amount)
amount = type(amount) == 'number' and amount or 1
@@ -151,8 +152,8 @@ function ProgressBar.increment(element,amount)
end
--- Decreases the value of the progressbar, if a define is given all of its instances are decresed
-- @tapram element ?LuaGuiElement|string either a gui element or a registered define
-- @tparam[opt=1] amount number the amount to decrease the progressbar by
-- @tparam ?LuaGuiElement|string element either a gui element or a registered define
-- @tparam[opt=1] number amount the amount to decrease the progressbar by
function ProgressBar.decrement(element,amount)
amount = type(amount) == 'number' and amount or 1
@@ -178,7 +179,7 @@ function ProgressBar.decrement(element,amount)
end
--- Creates a new progressbar element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new progressbar elemente define
function ProgressBar.new_progressbar(name)
local self = Gui._define_factory(ProgressBar._prototype)
@@ -220,7 +221,7 @@ function ProgressBar.new_progressbar(name)
end
--- Sets the maximum value that represents the end value of the progress bar
-- @tparam amount number the amount to have set as the maximum
-- @tparam number amount the amount to have set as the maximum
-- @treturn table the define to allow chaining
function ProgressBar._prototype:set_default_maximum(amount)
amount = amount > 0 and amount or error('amount must be greater than 0')
@@ -229,7 +230,7 @@ function ProgressBar._prototype:set_default_maximum(amount)
end
--- Will set the progress bar to start at 1 and trigger when it hits 0
-- @tparam[opt=true] state boolean when true the bar will start filled, to be used with decrease
-- @tparam[opt=true] boolean state when true the bar will start filled, to be used with decrease
-- @treturn table the define to allow chaining
function ProgressBar._prototype:use_count_down(state)
if state == false then
@@ -241,9 +242,10 @@ function ProgressBar._prototype:use_count_down(state)
end
--- Main logic for changing the value of a progress bar, this only applies when its a registered define
-- @tparam self table the define that is being changed
-- @tparam amount number the amount which it is being changed by, may be negative
-- @tparam[opt] category string the category to use with store
-- @tparam table self the define that is being changed
-- @tparam number amount the amount which it is being changed by, may be negative
-- @tparam[opt] string category the category to use with store
-- @tparam[opt] function filter when given the filter must return true for the value of the element to be changed
local function change_value_prototype(self,amount,category,filter)
local function reset_store()
@@ -298,32 +300,32 @@ local function change_value_prototype(self,amount,category,filter)
end
--- Increases the value of the progressbar
-- @tparam[opt=1] amount number the amount to increase the progressbar by
-- @tparam[opt] category string the category that is used with a store
-- @tparam[opt=1] number amount the amount to increase the progressbar by
-- @tparam[opt] string category the category that is used with a store
function ProgressBar._prototype:increment(amount,category)
amount = type(amount) == 'number' and amount or 1
change_value_prototype(self,amount,category)
end
--- Increases the value of the progressbar, if the filter condition is met, does not work with store
-- @tparam[opt=1] amount number the amount to increase the progressbar by
-- @tparam[opt] category string the category that is used with a store
-- @tparam[opt=1] number amount the amount to increase the progressbar by
-- @tparam function filter the filter to be used
function ProgressBar._prototype:increment_filtered(amount,filter)
amount = type(amount) == 'number' and amount or 1
change_value_prototype(self,amount,nil,filter)
end
--- Decreases the value of the progressbar
-- @tparam[opt=1] amount number the amount to decrease the progressbar by
-- @tparam[opt] category string the category that is used with a store
-- @tparam[opt=1] number amount the amount to decrease the progressbar by
-- @tparam[opt] string category the category that is used with a store
function ProgressBar._prototype:decrement(amount,category)
amount = type(amount) == 'number' and amount or 1
change_value_prototype(self,-amount,category)
end
--- Decreases the value of the progressbar, if the filter condition is met, does not work with store
-- @tparam[opt=1] amount number the amount to decrease the progressbar by
-- @tparam[opt] category string the category that is used with a store
-- @tparam[opt=1] number amount the amount to decrease the progressbar by
-- @tparam function filter the filter to be used
function ProgressBar._prototype:decrement_filtered(amount,filter)
amount = type(amount) == 'number' and amount or 1
change_value_prototype(self,-amount,nil,filter)
@@ -331,8 +333,8 @@ end
--- Adds an element into the list of instances that will are waiting to complete, does not work with store
-- note use store if you want persistent data, this only stores the elements not the values which they have
-- @tparam element LuaGuiElement the element that you want to add into the waiting to complete list
-- @tparam[opt] maximum number the maximum for this element if not given the default for this define is used
-- @tparam LuaGuiElement element the element that you want to add into the waiting to complete list
-- @tparam[opt] number maximum the maximum for this element if not given the default for this define is used
function ProgressBar._prototype:add_element(element,maximum)
if self.store then return end
if not ProgressBar.independent[self.name] then
@@ -345,7 +347,7 @@ function ProgressBar._prototype:add_element(element,maximum)
end
--- Resets an element, or its store, to be back at the start, either 1 or 0
-- @tparam element LuaGuiElement the element that you want to reset the progress of
-- @tparam LuaGuiElement element the element that you want to reset the progress of
function ProgressBar._prototype:reset_element(element)
if not element or not element.valid then return end
local value = self.count_down and 1 or 0
@@ -358,7 +360,7 @@ function ProgressBar._prototype:reset_element(element)
end
--- Event handler factory that counts up by 1 every time the event triggeres, can filter which elements are incremented
-- @tparam[opt] filter function when given will use filtered incerement
-- @tparam[opt] function filter when given will use filtered incerement
-- @treturn function the event handler
function ProgressBar._prototype:event_counter(filter)
if type(filter) == 'function' then
@@ -373,7 +375,7 @@ function ProgressBar._prototype:event_counter(filter)
end
--- Event handler factory that counts down by 1 every time the event triggeres, can filter which elements are decremented
-- @tparam[opt] filter function when given will use filtered decerement
-- @tparam[opt] function filter when given will use filtered decerement
-- @treturn function the event handler
function ProgressBar._prototype:event_countdown(filter)
if type(filter) == 'function' then

View File

@@ -18,9 +18,9 @@ local Instances = require 'expcore.gui.instances'
local Game = require 'utils.game'
--- Event call for on_value_changed and store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value number the new value for the slider
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam number value the new value for the slider
local function event_call(define,element,value)
local player = Game.get_player_by_index(element.player_index)
@@ -43,9 +43,9 @@ local function event_call(define,element,value)
end
--- Store call for store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value number the new value for the slider
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam number value the new value for the slider
local function store_call(define,element,value)
element.slider_value = value
event_call(define,element,value)
@@ -61,7 +61,7 @@ local Slider = {
}
--- Creates a new slider element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new slider element define
function Slider.new_slider(name)
@@ -116,7 +116,7 @@ function Slider.new_slider(name)
end
--- Adds notches to the slider
-- @tparam[opt] state boolean when true will draw notches onto the slider
-- @tparam[opt] boolean state when true will draw notches onto the slider
function Slider._prototype:use_notches(state)
if state == false then
self.draw_data.style = nil
@@ -127,8 +127,8 @@ function Slider._prototype:use_notches(state)
end
--- Sets the range of a slider, if not used will use default values for a slider
-- @tparam[opt] min number the minimum value that the slider can take
-- @tparam[opt] max number the maximum value that the slider can take
-- @tparam[opt] number min the minimum value that the slider can take
-- @tparam[opt] number max the maximum value that the slider can take
-- @treturn self the define to allow chaining
function Slider._prototype:set_range(min,max)
self.min = min
@@ -146,7 +146,7 @@ function Slider._prototype:set_range(min,max)
end
--- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player
-- @tparam element LuaGuiElement the parent element that the lable will be drawn to
-- @tparam LuaGuiElement element the parent element that the lable will be drawn to
-- @treturn LuaGuiElement the new label element so that styles can be applied
function Slider._prototype:draw_label(element)
local name = self.name..'-label'
@@ -173,7 +173,7 @@ function Slider._prototype:draw_label(element)
end
--- Enables auto draw of the label, the label will share the same parent element as the slider
-- @tparam[opt=true] state boolean when false will disable the auto draw of the label
-- @tparam[opt=true] boolean state when false will disable the auto draw of the label
-- @treturn self the define to allow chaining
function Slider._prototype:enable_auto_draw_label(state)
if state == false then

View File

@@ -18,9 +18,9 @@ local Gui = require 'expcore.gui.core'
local Game = require 'utils.game'
--- Event call for on_text_changed and store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value string the new text for the text field
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam string value the new text for the text field
local function event_call(define,element,value)
local player = Game.get_player_by_index(element.player_index)
@@ -31,12 +31,12 @@ local function event_call(define,element,value)
end
--- Store call for store update
-- @tparam define table the define that this is acting on
-- @tparam element LuaGuiElement the element that triggered the event
-- @tparam value string the new text for the text field
local function store_call(self,element,value)
-- @tparam table define the define that this is acting on
-- @tparam LuaGuiElement element the element that triggered the event
-- @tparam string value the new text for the text field
local function store_call(define,element,value)
element.text = value
event_call(self,element,value)
event_call(define,element,value)
end
local Text = {
@@ -55,7 +55,7 @@ local Text = {
}
--- Creates a new text field element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new text field element define
function Text.new_text_field(name)
@@ -105,7 +105,7 @@ function Text.new_text_field(name)
end
--- Creates a new text box element define
-- @tparam[opt] name string the optional debug name that can be added
-- @tparam[opt] string name the optional debug name that can be added
-- @treturn table the new text box element define
function Text.new_text_box(name)
local self = Text.new_text_field(name)
@@ -118,7 +118,7 @@ function Text.new_text_box(name)
end
--- Sets the text box to be selectable
-- @tparam[opt=true] state boolean when false will set the state to false
-- @tparam[opt=true] boolean state when false will set the state to false
-- @treturn self table the define to allow for chaining
function Text._prototype_box:set_selectable(state)
if state == false then
@@ -130,7 +130,7 @@ function Text._prototype_box:set_selectable(state)
end
--- Sets the text box to have word wrap
-- @tparam[opt=true] state boolean when false will set the state to false
-- @tparam[opt=true] boolean state when false will set the state to false
-- @treturn self table the define to allow for chaining
function Text._prototype_box:set_word_wrap(state)
if state == false then
@@ -142,7 +142,7 @@ function Text._prototype_box:set_word_wrap(state)
end
--- Sets the text box to be read only
-- @tparam[opt=true] state boolean when false will set the state to false
-- @tparam[opt=true] boolean state when false will set the state to false
-- @treturn self table the define to allow for chaining
function Text._prototype_box:set_read_only(state)
if state == false then

View File

@@ -36,7 +36,7 @@ function Toolbar.permission_alias(define_name,permisison_name)
end
--- Adds a new button to the toolbar
-- @tparam[opt] name string when given allows an alias to the button for the permission system
-- @tparam[opt] string name when given allows an alias to the button for the permission system
-- @treturn table the button define
function Toolbar.new_button(name)
local button =
@@ -51,7 +51,7 @@ function Toolbar.new_button(name)
end
--- Adds an existing buttton to the toolbar
-- @tparam button table the button define for the button to be added
-- @tparam table button the button define for the button to be added
function Toolbar.add_button(button)
table.insert(Toolbar.buttons,button)
Gui.allow_player_to_toggle_top_element_visibility(button.name)
@@ -66,7 +66,7 @@ function Toolbar.add_button(button)
end
--- Updates the player's toolbar with an new buttons or expected change in auth return
-- @tparam player LuaPlayer the player to update the toolbar for
-- @tparam LuaPlayer player the player to update the toolbar for
function Toolbar.update(player)
local top = Gui.get_top_element_flow(player)
if not top then return end

View File

@@ -59,7 +59,7 @@ local Permissions_Groups = {
}
--- Defines a new permission group that can have it actions set in the config
-- @tparam name string the name of the new group
-- @tparam string name the name of the new group
-- @treturn Permissions_Groups._prototype the new group made with function to allow and disallow actions
function Permissions_Groups.new_group(name)
local group = setmetatable({
@@ -74,14 +74,14 @@ function Permissions_Groups.new_group(name)
end
--- Returns the group with the given name, case sensitive
-- @tparam name string the name of the group to get
-- @tparam string name the name of the group to get
-- @treturn ?Permissions_Groups._prototype|nil the group with that name or nil if non found
function Permissions_Groups.get_group_by_name(name)
return Permissions_Groups.groups[name]
end
--- Returns the group that a player is in
-- @tparam LuaPlayer the player to get the group of can be LuaPlayer name index etc
-- @tparam LuaPlayer player the player to get the group of can be name index etc
-- @treturn ?Permissions_Groups._prototype|nil the group with that player or nil if non found
function Permissions_Groups.get_group_from_player(player)
player = Game.get_player_from_any(player)
@@ -100,7 +100,7 @@ function Permissions_Groups.reload_permissions()
end
--- Removes all permissions from every permission group except for "Default" and any passed as exempt
-- @tparam string|Array<string> any groups that you want to be except, "Default" is always exempt
-- @tparam ?string|Array<string> exempt groups that you want to be except, "Default" is always exempt
-- @treturn number the number of groups that had they permissions removed
function Permissions_Groups.lockdown_permissions(exempt)
local count = 0
@@ -126,8 +126,8 @@ function Permissions_Groups.lockdown_permissions(exempt)
end
--- Sets a player's group to the one given, a player can only have one group at a time
-- @tparam LuaPlayer the player to effect can be LuaPlayer name index etc
-- @tparam string the name of the group to give to the player
-- @tparam LuaPlayer player the player to effect can be name index etc
-- @tparam string group the name of the group to give to the player
-- @treturn boolean true if the player was added successfully, false other wise
function Permissions_Groups.set_player_group(player,group)
player = Game.get_player_from_any(player)
@@ -138,8 +138,8 @@ function Permissions_Groups.set_player_group(player,group)
end
--- Sets the allow state of an action for this group, used internally but is safe to use else where
-- @tparam action ?string|defines.input_action the action that you want to set the state of
-- @tparam state boolean the state that you want to set it to, true = allow, false = disallow
-- @tparam ?string|defines.input_action action the action that you want to set the state of
-- @tparam boolean state the state that you want to set it to, true = allow, false = disallow
-- @treturn Permissions_Groups._prototype returns self so function can be chained
function Permissions_Groups._prototype:set_action(action,state)
if type(action) == 'string' then
@@ -150,7 +150,7 @@ function Permissions_Groups._prototype:set_action(action,state)
end
--- Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime
-- @tparam string|Array<string> the action or actions that you want to allow for this group
-- @tparam string|Array<string> actions the action or actions that you want to allow for this group
-- @treturn Permissions_Groups._prototype returns self so function can be chained
function Permissions_Groups._prototype:allow(actions)
if type(actions) ~= 'table' then
@@ -163,7 +163,7 @@ function Permissions_Groups._prototype:allow(actions)
end
--- Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime
-- @tparam string|Array<string> the action or actions that you want to disallow for this group
-- @tparam string|Array<string> actions the action or actions that you want to disallow for this group
-- @treturn Permissions_Groups._prototype returns self so function can be chained
function Permissions_Groups._prototype:disallow(actions)
if type(actions) ~= 'table' then
@@ -190,7 +190,7 @@ function Permissions_Groups._prototype:disallow_all()
end
--- Returns if an input action is allowed for this group
-- @tparam action ?string|defines.input_action the action that you want to test for
-- @tparam ?string|defines.input_action action the action that you want to test for
-- @treturn boolean true if the group is allowed the action, false other wise
function Permissions_Groups._prototype:is_allowed(action)
if type(action) == 'string' then
@@ -223,7 +223,7 @@ function Permissions_Groups._prototype:create()
end
--- Adds a player to this group
-- @tparam player LuaPlayer the player you want to add to this group can be LuaPlayer name or index etc
-- @tparam LuaPlayer player LuaPlayer the player you want to add to this group can be name or index etc
-- @treturn boolean true if the player was added successfully, false other wise
function Permissions_Groups._prototype:add_player(player)
player = Game.get_player_from_any(player)
@@ -234,7 +234,7 @@ function Permissions_Groups._prototype:add_player(player)
end
--- Removes a player from this group
-- @tparam player LuaPlayer the player you want to remove from this group can be LuaPlayer name or index etc
-- @tparam LuaPlayer player LuaPlayer the player you want to remove from this group can be name or index etc
-- @treturn boolean true if the player was removed successfully, false other wise
function Permissions_Groups._prototype:remove_player(player)
player = Game.get_player_from_any(player)
@@ -245,7 +245,7 @@ function Permissions_Groups._prototype:remove_player(player)
end
--- Returns all player that are in this group with the option to filter to online/offline only
-- @tparam[opt] online boolean if nil returns all players, if true online players only, if false returns online players only
-- @tparam[opt] boolean online if nil returns all players, if true online players only, if false returns online players only
-- @treturn table a table of players that are in this group; filtered if online param is given
function Permissions_Groups._prototype:get_players(online)
local players = {}
@@ -265,7 +265,7 @@ function Permissions_Groups._prototype:get_players(online)
end
--- Prints a message to every player in this group
-- @tparam message string the message that you want to send to the players
-- @tparam string message the message that you want to send to the players
-- @treturn number the number of players that received the message
function Permissions_Groups._prototype:print(message)
local players = self:get_players(true)

View File

@@ -246,8 +246,8 @@ function Roles.debug()
end
--- Prints a message to all players in the given roles, may send duplicate message however factorio blocks spam
-- @tparam roles table a table of roles which to send the message to
-- @tparam message string the message to send to the players
-- @tparam table roles table a of roles which to send the message to
-- @tparam string message the message to send to the players
function Roles.print_to_roles(roles,message)
for _,role in pairs(roles) do
role = Roles.get_role_from_any(role)
@@ -256,8 +256,8 @@ function Roles.print_to_roles(roles,message)
end
--- Prints a message to all players who have the given role or one which is higher (excluding default)
-- @tparam role string the name of the role to send the message to
-- @tparam message string the message to send to the players
-- @tparam string role the name of the role to send the message to
-- @tparam string message the message to send to the players
function Roles.print_to_roles_higher(role,message)
role = Roles.get_role_from_any(role)
if not role then return end
@@ -271,8 +271,8 @@ function Roles.print_to_roles_higher(role,message)
end
--- Prints a message to all players who have the given role or one which is lower (excluding default)
-- @tparam role string the name of the role to send the message to
-- @tparam message string the message to send to the players
-- @tparam string role the name of the role to send the message to
-- @tparam string message the message to send to the players
function Roles.print_to_roles_lower(role,message)
role = Roles.get_role_from_any(role)
if not role then return end
@@ -286,14 +286,14 @@ function Roles.print_to_roles_lower(role,message)
end
--- Get a role for the given name
-- @tparam name string the name of the role to get
-- @tparam string name the name of the role to get
-- @treturn Roles._prototype the role with that name or nil
function Roles.get_role_by_name(name)
return Roles.config.roles[name]
end
--- Get a role with the given order index
-- @tparam index number the place in the oder list of the role to get
-- @tparam number index the place in the oder list of the role to get
-- @treturn Roles._prototype the role with that index in the order list or nil
function Roles.get_role_by_order(index)
local name = Roles.config.order[index]
@@ -302,7 +302,7 @@ end
--- Gets a role from a name,index or role object (where it is just returned)
-- nb: this function is used for the input for most outward facing functions
-- @tparam any ?number|string|table the value used to find the role
-- @tparam ?number|string|table any the value used to find the role
-- @treturn Roles._prototype the role that was found or nil see above
function Roles.get_role_from_any(any)
local tany = type(any)
@@ -317,7 +317,7 @@ function Roles.get_role_from_any(any)
end
--- Gets all the roles of the given player, this will always contain the default role
-- @tparam player LuaPlayer the player to get the roles of
-- @tparam LuaPlayer player the player to get the roles of
-- @treturn table a table where the values are the roles which the player has
function Roles.get_player_roles(player)
player = Game.get_player_from_any(player)
@@ -332,7 +332,7 @@ function Roles.get_player_roles(player)
end
--- Gets the highest role which the player has, can be used to compeer one player to another
-- @tparam player LuaPlayer the player to get the highest role of
-- @tparam LuaPlayer player the player to get the highest role of
-- @treturn the role with the highest order index which this player has
function Roles.get_player_highest_role(player)
local roles = Roles.get_player_roles(player)
@@ -347,10 +347,10 @@ function Roles.get_player_highest_role(player)
end
--- Gives a player the given role(s) with an option to pass a by player name used in the log
-- @tparam player LuaPlayer the player that will be assigned the roles
-- @tparam role table a table of roles that the player will be given, can be one role and can be role names
-- @tparam[opt=<server>] by_player_name string the name of the player that will be shown in the log
-- @tparam[opt=false] silent boolean when true there will be no game message printed
-- @tparam LuaPlayer player the player that will be assigned the roles
-- @tparam table roles table a of roles that the player will be given, can be one role and can be role names
-- @tparam[opt=<server>] string by_player_name the name of the player that will be shown in the log
-- @tparam[opt=false] boolean silent when true there will be no game message printed
function Roles.assign_player(player,roles,by_player_name,silent)
player = Game.get_player_from_any(player)
if not player then return end
@@ -367,10 +367,10 @@ function Roles.assign_player(player,roles,by_player_name,silent)
end
--- Removes a player from the given role(s) with an option to pass a by player name used in the log
-- @tparam player LuaPlayer the player that will have the roles removed
-- @tparam roles table a table of roles to be removed from the player, can be one role and can be role names
-- @tparam[opt=<server>] by_player_name string the name of the player that will be shown in the logs
-- @tparam[opt=false] silent boolean when true there will be no game message printed
-- @tparam LuaPlayer player the player that will have the roles removed
-- @tparam table roles table a of roles to be removed from the player, can be one role and can be role names
-- @tparam[opt=<server>] string by_player_name the name of the player that will be shown in the logs
-- @tparam[opt=false] boolean silent when true there will be no game message printed
function Roles.unassign_player(player,roles,by_player_name,silent)
player = Game.get_player_from_any(player)
if not player then return end
@@ -387,14 +387,14 @@ function Roles.unassign_player(player,roles,by_player_name,silent)
end
--- Overrides all player roles with the given table of roles, useful to mass set roles on game start
-- @tparam roles table a table which is indexed by case sensitive player names and has the value of a table of role names
-- @tparam table roles table a which is indexed by case sensitive player names and has the value of a table of role names
function Roles.override_player_roles(roles)
Roles.config.players = roles
end
--- A test for weather a player has the given role
-- @tparam player LuaPlayer the player to test the roles of
-- @tparam search_role ?string|number|table a pointer to the role that is being searched for
-- @tparam LuaPlayer player the player to test the roles of
-- @tparam ?string|number|table search_role a pointer to the role that is being searched for
-- @treturn boolean true if the player has the role, false otherwise, nil for errors
function Roles.player_has_role(player,search_role)
local roles = Roles.get_player_roles(player)
@@ -408,8 +408,8 @@ function Roles.player_has_role(player,search_role)
end
--- A test for weather a player has the given flag true for at least one of they roles
-- @tparam player LuaPlayer the player to test the roles of
-- @tparam flag_name string the name of the flag that is being looked for
-- @tparam LuaPlayer player the player to test the roles of
-- @tparam string flag_name the name of the flag that is being looked for
-- @treturn boolean true if the player has at least one role which has the flag set to true, false otherwise, nil for errors
function Roles.player_has_flag(player,flag_name)
local roles = Roles.get_player_roles(player)
@@ -423,8 +423,8 @@ function Roles.player_has_flag(player,flag_name)
end
--- A test for weather a player has at least one role which is allowed the given action
-- @tparam player LuaPlayer the player to test the roles of
-- @tparam action string the name of the action that is being tested for
-- @tparam LuaPlayer player the player to test the roles of
-- @tparam string action the name of the action that is being tested for
-- @treturn boolean true if the player has at least one role which is allowed this action, false otherwise, nil for errors
function Roles.player_allowed(player,action)
local roles = Roles.get_player_roles(player)
@@ -439,7 +439,7 @@ end
--- Used to set the role order, higher in the list is better, must be called at least once in config
-- nb: function also re links parents due to expected position in the config file
-- @tparam order table a table which is keyed only by numbers (start 1) and values are roles in order with highest first
-- @tparam table order table a which is keyed only by numbers (start 1) and values are roles in order with highest first
function Roles.define_role_order(order)
-- Clears and then rebuilds the order table
Roles.config.order = {}
@@ -462,8 +462,8 @@ function Roles.define_role_order(order)
end
--- Defines a new trigger for when a tag is added or removed from a player
-- @tparam name string the name of the flag which the roles will have
-- @tparam callback function the function that is called when roles are assigned
-- @tparam string name the name of the flag which the roles will have
-- @tparam function callback the function that is called when roles are assigned
-- flag param - player - the player that has had they roles changed
-- flag param - state - the state of the flag, aka if the flag is present
function Roles.define_flag_trigger(name,callback)
@@ -471,7 +471,7 @@ function Roles.define_flag_trigger(name,callback)
end
--- Sets the default role which every player will have, this needs to be called at least once
-- @tparam name string the name of the default role
-- @tparam string name the name of the default role
function Roles.set_default(name)
local role = Roles.config.roles[name]
if not role then return end
@@ -479,7 +479,7 @@ function Roles.set_default(name)
end
--- Sets the root role which will always have all permissions, any server actions act from this role
-- @tparam name string the name of the root role
-- @tparam string name the name of the root role
function Roles.set_root(name)
local role = Roles.config.roles[name]
if not role then return end
@@ -488,8 +488,8 @@ function Roles.set_root(name)
end
--- Defines a new role and returns the prototype to allow configuration
-- @tparam name string the name of the new role, must be unique
-- @tparam[opt=name] shirt_hand string the shortened version of the name
-- @tparam string name the name of the new role, must be unique
-- @tparam[opt=name] string short_hand the shortened version of the name
-- @treturn Roles._prototype the start of the config chain for this role
function Roles.new_role(name,short_hand)
if Roles.config.roles[name] then return error('Role name is non unique') end
@@ -505,7 +505,7 @@ function Roles.new_role(name,short_hand)
end
--- Sets the default allow state of the role, true will allow all actions
-- @tparam[opt=true] strate boolean true will allow all actions
-- @tparam[opt=true] boolean state true will allow all actions
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_allow_all(state)
if state == nil then state = true end
@@ -514,7 +514,7 @@ function Roles._prototype:set_allow_all(state)
end
--- Sets the allow actions for this role, actions in this list will be allowed for this role
-- @tparam actions table indexed with numbers and is an array of action names, order has no effect
-- @tparam table actions indexed with numbers and is an array of action names, order has no effect
-- @treturn Roles._prototype allows chaining
function Roles._prototype:allow(actions)
if type(actions) ~= 'table' then
@@ -527,7 +527,7 @@ function Roles._prototype:allow(actions)
end
--- Sets the disallow actions for this role, will prevent actions from being allowed regardless of inheritance
-- @tparam actions table indexed with numbers and is an array of action names, order has no effect
-- @tparam table actions indexed with numbers and is an array of action names, order has no effect
-- @treturn Roles._prototype allows chaining
function Roles._prototype:disallow(actions)
if type(actions) ~= 'table' then
@@ -540,7 +540,7 @@ function Roles._prototype:disallow(actions)
end
--- Test for if a role is allowed the given action, mostly internal see Roles.player_allowed
-- @tparam action string the name of the action to test if it is allowed
-- @tparam string action the name of the action to test if it is allowed
-- @treturn boolean true if action is allowed, false otherwise
function Roles._prototype:is_allowed(action)
local is_root = Roles.config.internal.root.name == self.name
@@ -548,8 +548,8 @@ function Roles._prototype:is_allowed(action)
end
--- Sets the state of a flag for a role, flags can be used to apply effects to players
-- @tparam name string the name of the flag to set the value of
-- @tparam[opt=true] value boolean the state to set the flag to
-- @tparam string name the name of the flag to set the value of
-- @tparam[opt=true] boolean value the state to set the flag to
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_flag(name,value)
if value == nil then value = true end
@@ -565,14 +565,14 @@ function Roles._prototype:clear_flags()
end
--- A test for if the role has a flag set
-- @tparam name string the name of the flag to test for
-- @tparam string name the name of the flag to test for
-- @treturn boolean true if the flag is set, false otherwise
function Roles._prototype:has_flag(name)
return self.flags[name] or false
end
--- Sets a custom player tag for the role, can be accessed by other code
-- @tparam tag string the value that the tag will be
-- @tparam string tag the value that the tag will be
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_custom_tag(tag)
self.custom_tag = tag
@@ -580,7 +580,7 @@ function Roles._prototype:set_custom_tag(tag)
end
--- Sets a custom colour for the role, can be accessed by other code
-- @tparam color ?string|table can either be and rgb colour table or the name of a colour defined in the presets
-- @tparam table color ?string|table can either be and rgb colour or the name of a colour defined in the presets
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_custom_color(color)
if type(color) ~= 'table' then
@@ -591,8 +591,8 @@ function Roles._prototype:set_custom_color(color)
end
--- Sets the permission group for this role, players will be moved to the group of they highest role
-- @tparam name string the name of the permission group to have players moved to
-- @tparam[opt=false] use_factorio_api boolean when true the custom permission group module is ignored
-- @tparam string name the name of the permission group to have players moved to
-- @tparam[opt=false] boolean use_factorio_api when true the custom permission group module is ignored
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_permission_group(name,use_factorio_api)
if use_factorio_api then
@@ -607,7 +607,7 @@ end
--- Sets the parent for a role, any action not in allow or disallow will be looked for in its parents
-- nb: this is a recursive action, and changing the allows and disallows will effect all children roles
-- @tparam role string the name of the role that will be the parent; has imminent effect if role is already defined
-- @tparam string role the name of the role that will be the parent; has imminent effect if role is already defined
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_parent(role)
self.parent = role
@@ -619,7 +619,7 @@ end
--- Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will recive the role
-- nb: this is one way, failing false after already gaining the role will not revoke the role
-- @tparam callback function receives only one param which is player to promote, return true to promote the player
-- @tparam function callback receives only one param which is player to promote, return true to promote the player
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_auto_promote_condition(callback)
self.auto_promote_condition = callback
@@ -627,7 +627,7 @@ function Roles._prototype:set_auto_promote_condition(callback)
end
--- Sets the role to not allow players to have auto promote effect them, useful to keep people locked to a punishment
-- @tparam[opt=true] state boolean when true the players with this role will not be auto promoted
-- @tparam[opt=true] boolean state when true the players with this role will not be auto promoted
-- @treturn Roles._prototype allows chaining
function Roles._prototype:set_block_auto_promote(state)
if state == nil then state = true end
@@ -636,9 +636,9 @@ function Roles._prototype:set_block_auto_promote(state)
end
--- Adds a player to this role, players can have more than one role at a time, used internally see Roles.assign
-- @tparam player LuaPlayer the player that will be given this role
-- @tparam skip_check boolean when true player will be taken as the player name (use when player has not yet joined)
-- @tparam skip_event boolean when true the event emit will be skipped, this is used internally with Roles.assign
-- @tparam LuaPlayer player the player that will be given this role
-- @tparam boolean skip_check when true player will be taken as the player name (use when player has not yet joined)
-- @tparam boolean skip_event when true the event emit will be skipped, this is used internally with Roles.assign
-- @treturn boolean true if the player was added successfully
function Roles._prototype:add_player(player,skip_check,skip_event)
player = Game.get_player_from_any(player)
@@ -670,9 +670,9 @@ function Roles._prototype:add_player(player,skip_check,skip_event)
end
--- Removes a player from this role, players can have more than one role at a time, used internally see Roles.unassign
-- @tparam player LuaPlayer the player that will lose this role
-- @tparam skip_check boolean when true player will be taken as the player name (use when player has not yet joined)
-- @tparam skip_event boolean when true the event emit will be skipped, this is used internally with Roles.unassign
-- @tparam LuaPlayer player the player that will lose this role
-- @tparam boolean skip_check when true player will be taken as the player name (use when player has not yet joined)
-- @tparam boolean skip_event when true the event emit will be skipped, this is used internally with Roles.unassign
-- @treturn boolean true if the player was removed successfully
function Roles._prototype:remove_player(player,skip_check,skip_event)
player = Game.get_player_from_any(player)
@@ -709,7 +709,7 @@ function Roles._prototype:remove_player(player,skip_check,skip_event)
end
--- Returns an array of all the players who have this role, can be filtered by online status
-- @tparam[opt=nil] online boolean when given will filter by this online state, nil will return all players
-- @tparam[opt=nil] boolean online when given will filter by this online state, nil will return all players
-- @treturn table all the players who have this role, indexed order is meaningless
function Roles._prototype:get_players(online)
local players = {}
@@ -740,7 +740,7 @@ function Roles._prototype:get_players(online)
end
--- Will print a message to all players with this role
-- @tparam message string the message that will be printed to the players
-- @tparam string message the message that will be printed to the players
-- @treturn number the number of players who received the message
function Roles._prototype:print(message)
local players = self:get_players(true)

View File

@@ -108,7 +108,7 @@ Global.register(Store.data,function(tbl)
end)
--- Check for if a lcoation is registered
-- @tparam location string the location to test for
-- @tparam string location the location to test for
-- @treturn boolean true if registered
function Store.is_registered(location)
return not not Store.callbacks[location]
@@ -121,9 +121,9 @@ function Store.uid_location()
end
--- Registers a new location with an update callback which is triggered when the value updates
-- @tparam location string a unique string that points to the data, string used rather than token to allow migration
-- @tparam callback function this callback will be called when the stored value is set to a new value
-- @tparam[opt] start_value any this value will be the inital value that is stored at this location
-- @tparam string location string a unique that points to the data, string used rather than token to allow migration
-- @tparam function callback this callback will be called when the stored value is set to a new value
-- @tparam[opt] any start_value this value will be the inital value that is stored at this location
function Store.register(location,callback,start_value)
if _LIFECYCLE ~= _STAGE.control then
return error('Can only be called during the control stage', 2)
@@ -144,9 +144,9 @@ function Store.register(location,callback,start_value)
end
--- Registers a new cross server synced location with an update callback, and external script is required for cross server
-- @tparam location string a unique string that points to the data, string used rather than token to allow migration
-- @tparam callback function this callback will be called when the stored value is set to a new value
-- @tparam[opt] start_value any this value will be the inital value that is stored at this location
-- @tparam string location string a unique that points to the data, string used rather than token to allow migration
-- @tparam function callback this callback will be called when the stored value is set to a new value
-- @tparam[opt] any start_value this value will be the inital value that is stored at this location
function Store.register_synced(location,callback,start_value)
if _LIFECYCLE ~= _STAGE.control then
return error('Can only be called during the control stage', 2)
@@ -166,8 +166,8 @@ function Store.register_synced(location,callback,start_value)
end
--- Adds a function that will be checked every tick for a change in the returned value, when the value changes it will be saved in the store
-- @tparam location string the location where the data will be saved and compeared to, must already be a registered location
-- @tparam callback function this function will be called every tick to check for a change in value
-- @tparam string location the location where the data will be saved and compeared to, must already be a registered location
-- @tparam function callback this function will be called every tick to check for a change in value
function Store.add_watch(location,callback)
if _LIFECYCLE ~= _STAGE.control then
return error('Can only be called during the control stage', 2)
@@ -185,8 +185,8 @@ function Store.add_watch(location,callback)
end
--- Gets the value stored at a location, this location must be registered
-- @tparam location string the location to get the data from
-- @tparam[opt=false] no_error boolean when true no error is returned if the location is not registered
-- @tparam string location the location to get the data from
-- @tparam[opt=false] boolean no_error when true no error is returned if the location is not registered
-- @treturn any the data which was stored at the location
function Store.get(location,no_error)
if not Store.callbacks[location] and not no_error then
@@ -197,8 +197,8 @@ function Store.get(location,no_error)
end
--- Sets the value at a location, this location must be registered, if server synced it will emit the change to file
-- @tparam location string the location to set the data to
-- @tparam value any the new value to set at the location, value may be reverted if there is a watch callback
-- @tparam string location the location to set the data to
-- @tparam any value the new value to set at the location, value may be reverted if there is a watch callback
-- @treturn boolean true if it was successful
function Store.set(location,value)
if not Store.callbacks[location] then
@@ -220,7 +220,7 @@ end
--- Gets all non nil children at a location, children can be added and removed during runtime
-- this is similar to Store.get but will always return a table even if it is empty
-- @tparam location string the location to get the children of
-- @tparam string location the location to get the children of
-- @treturn table a table containg all the children and they values
function Store.get_children(location)
local store = Store.get(location)
@@ -233,8 +233,8 @@ function Store.get_children(location)
end
--- Gets the value of the child to a location, children can be added and removed during runtime
-- @tparam location string the location of which the child is located
-- @tparam child string the child element to get the value of
-- @tparam string location the location of which the child is located
-- @tparam string child the child element to get the value of
-- @treturn any the value which was stored at that location
function Store.get_child(location,child)
local store = Store.get(location)
@@ -249,9 +249,9 @@ end
--- Sets the value of the chlid to a location, children can be added and removed during runtime
-- when a child is set it will call the update handler of the parent allowing children be to added at runtime
-- this may be used when a player joins the game and the child is the players name
-- @tparam location string the location of which the child is located
-- @tparam child string the child element to set the value of
-- @tparam value any the value to set at this location
-- @tparam string location the location of which the child is located
-- @tparam string child the child element to set the value of
-- @tparam any value the value to set at this location
-- @treturn boolean true if it was successful
function Store.set_child(location,child,value)
local store = Store.get(location)