Core Module - Common Library - Adds some commonly used functions used in many modules
utils.color_presets |
utils.game |
util |
type_check(value[, test_type=nil]) | Asserts the argument is of type test_type |
type_error(value, test_type, error_message, level) | Raises an error if the value is of the wrong type |
multi_type_check(value, test_types) | Asserts the argument is one of type test_types |
multi_type_error(value, test_types, error_message, level) | Raises an error if the value is of the wrong type |
validate_argument_type(value, test_type, param_name, param_number) | Raises an error when the value is the incorrect type, uses a consistent error message format |
validate_argument_multi_type(value, test_types, param_name, param_number) | Raises an error when the value is the incorrect type, uses a consistent error message format |
error_if_runtime() | Will raise an error if called during runtime |
error_if_runetime_closure(func) | Will raise an error if the function is a closure |
string_contains(s, contains) | Tests if a string contains a given substring. |
resolve_value(value) | Used to resolve a value that could also be a function returning that value |
get_actor() | Returns a valid string with the name of the actor of a command. |
cast_bool(var) | Converts a varible into its boolean value, nil and false return false |
ternary(c, t, f) | Returns either the second or third argument based on the first argument |
comma_value(n) | Returns a string for a number with comma seperators |
set_and_return(tbl, key, value) | Sets a table element to value while also returning value. |
write_json(path, tbl) | Writes a table object to a file in json format |
opt_require(path) | Calls a require that will not error if the file is not found |
get_file_path([offset=0]) | Returns a desync safe file path for the current file |
enum(tbl) | Converts a table to an enum |
auto_complete(options, input[, use_key=false][, rtn_key=false]) | Returns the closest match to the input |
format_chat_colour(message, color) | Returns a message with valid chat tags to change its colour |
format_chat_colour_localized(message, color) | Returns a message with valid chat tags to change its colour, using localization |
format_chat_player_name(player[, raw_string=false]) | Returns the players name in the players color |
player_return(value[, colour=defines.colour.white][, player=game.player]) | Will return a value of any type to the player/server console, allows colour for in-game players |
format_time(ticks, options) | Formats tick into a clean format, denominations from highest to lowest long will use words rather than letters 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 |
move_items(items[, surface=navies][, position={0][, radius=32][, chest_type=iron-chest]) | Moves items to the position and stores them in the closest entity of the type given |
print_grid_value(value, surface, position, scale, offset, immutable) | https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31 Prints a colored value on a location. |
print_colored_grid_value(value, surface, position, offset, immutable, color_value, base_color, delta_color, under_bound, over_bound) | Prints a colored value on a location. |
clear_flying_text(surface) | Clears all flying text entities on a surface |
Asserts the argument is of type test_type
Parameters:type_check('foo','string') -- return true
type_check('foo') -- return false
Raises an error if the value is of the wrong type
Parameters:type_error('foo','number','Value must be a number') -- will raise error "Value must be a number"
Asserts the argument is one of type test_types
Parameters:Raises an error if the value is of the wrong type
Parameters:multi_type_error('foo',{'string','table'},'Value must be a string or table') -- will raise error "Value must be a string or table"
Raises an error when the value is the incorrect type, uses a consistent error message format
Parameters:validate_argument_type('foo','number','repeat_count',2) -- will raise error "Bad argument #02 to "<anon>"; "repeat_count" is of type string expected number"
Raises an error when the value is the incorrect type, uses a consistent error message format
Parameters:validate_argument_type('foo',{'string','table'},'repeat_count',2) -- will raise error "Bad argument #02 to "<anon>"; "repeat_count" is of type string expected string or table"
Will raise an error if called during runtime
Usage:error_if_runtime()
Will raise an error if the function is a closure
Parameters:error_if_runetime_closure(func)
Tests if a string contains a given substring.
Parameters: Returns:Used to resolve a value that could also be a function returning that value
Parameters:-- Default value handling
-- if default value is not a function then it is returned
-- if it is a function then it is called with the first argument being self
local value = Common.resolve_value(self.defaut_value,self)
Returns a valid string with the name of the actor of a command.
Returns:Converts a varible into its boolean value, nil and false return false
Parameters:Returns either the second or third argument based on the first argument
Parameters:Returns a string for a number with comma seperators
Parameters:Sets a table element to value while also returning value.
Parameters:Writes a table object to a file in json format
Parameters:Calls a require that will not error if the file is not found
Parameters:local file = opt_require('file.not.present') -- will not cause any error
Returns a desync safe file path for the current file
Parameters:Converts a table to an enum
Parameters:Returns the closest match to the input
Parameters:Returns a message with valid chat tags to change its colour
Parameters:Returns a message with valid chat tags to change its colour, using localization
Parameters:Returns the players name in the players color
Parameters:Will return a value of any type to the player/server console, allows colour for in-game players
Parameters:player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
Formats tick into a clean format, denominations from highest to lowest long will use words rather than letters 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
Parameters:Moves items to the position and stores them in the closest entity of the type given
Parameters:https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31 Prints a colored value on a location.
Parameters:Prints a colored value on a location.
When given a color_value and a delta_color, will change the color of the text from the base to base + value * delta. This will make the color of the text range from 'base_color' to 'base_color + delta_color' as the color_value ranges from 0 to 1
Parameters:Clears all flying text entities on a surface
Parameters: