Core Module - Common Library - Adds some commonly used functions used in many modules
resources.color_presets |
utils.game |
util |
type_check(value[, test_type=nil]) | Compare types faster for faster validation of params |
type_check_error(value, test_type, error_message, level) | Raises an error if the value is of the wrong type |
param_check(value, test_type, param_name, param_number) | Raises an error when the value is the incorrect type, uses a consistent error message format |
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 |
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 |
ext_require(path, ...) | Calls a require and returns only the keys given, file must return a table |
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 |
string_contains(s, contains) | Tests if a string contains a given substring. |
extract_keys(tbl, ...) | Extracts certain keys from a table |
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 |
table_values(tbl[, sorted][, as_string]) | Returns a copy of all of the values in the table. |
table_keys(tbl[, sorted][, as_string]) | Returns a copy of all of the keys in the table. |
table_alphanumsort(tbl) | Returns the list is a sorted way that would be expected by people (this is by key) |
table_keysort(tbl) | Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above) |
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 |
Compare types faster for faster validation of params
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_check_error('foo','number','Value must be a number') -- will raise error "Value must be a number"
Raises an error when the value is the incorrect type, uses a consistent error message format
Parameters:param_check('foo','number','repeat_count',2) -- will raise error "Invalid param #02 given to <anon>; repeat_count is not of type number"
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
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
Calls a require and returns only the keys given, file must return a table
Parameters:local extract, param_check = ext_require('expcore.common','extract','param_check') --- @dep expcore.common
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:Tests if a string contains a given substring.
Parameters: Returns:Extracts certain keys from a table
Parameters:local key_three, key_one = extract({key_one='foo',key_two='bar',key_three=true},'key_three','key_one')
Converts a table to an enum
Parameters:Returns the closest match to the input
Parameters:Returns a copy of all of the values in the table.
Parameters:Returns a copy of all of the keys in the table.
Parameters:Returns the list is a sorted way that would be expected by people (this is by key)
Parameters:Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)
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: