/tg/ Station 13 - Modules - TypesDefine Details

code/__DEFINES/rust_g.dm

/proc/rustg_get_versionGets the version of rust_g
rustg_setup_acreplaceSets up the Aho-Corasick automaton with its default options.
rustg_setup_acreplace_with_optionsSets up the Aho-Corasick automaton using supplied options.
rustg_acreplaceRun the specified replacement engine with the provided haystack text to replace, returning replaced text.
rustg_acreplace_with_replacementsRun the specified replacement engine with the provided haystack text to replace, returning replaced text.
rustg_cnoise_generateThis proc generates a cellular automata noise grid which can be used in procedural generation methods.
rustg_dbp_generateThis proc generates a grid of perlin-like noise
rustg_dmi_icon_statesinput: must be a path, not an /icon; you have to do your own handling if it is one, as icon objects can't be directly passed to rustg.
rustg_dmi_read_metadataThe below functions involve dmi metadata represented in the following format: list( "width": number, "height": number, "states": list([STATE_DATA], ...) )
rustg_dmi_inject_metadataInject dmi metadata into a png file located at path. metadata must be a json_encode'd list in the metadata format listed above.
rustg_git_revparseReturns the git hash of the given revision, ex. "HEAD".
/proc/rustg_git_commit_dateReturns the date of the given revision using the provided format. Defaults to returning %F which is YYYY-MM-DD.
/proc/rustg_git_commit_date_headReturns the formatted datetime string of HEAD using the provided format. Defaults to returning %F which is YYYY-MM-DD. This is different to rustg_git_commit_date because it only needs the logs directory.
rustg_encode_base64Encode a given string into base64
rustg_decode_base64Decode a given base64 string
rustg_iconforge_generateBANDASTATION REMOVAL START - Rust Utils This is basically just rustg_http_request_async if you don't care about the response. This will either return "ok" or an error, as this does not create a job. BANDASTATION REMOVAL END - Rust Utils Generates a spritesheet at: [file_path][spritesheet_name]_[size_id].[png or dmi] The resulting spritesheet arranges icons in a random order, with the position being denoted in the "sprites" return value. All icons have the same y coordinate, and their x coordinate is equal to icon_width * position.
rustg_iconforge_generate_asyncReturns a job_id for use with rustg_iconforge_check()
rustg_iconforge_checkReturns the status of an async job_id, or its result if it is completed. See RUSTG_JOB DEFINEs.
rustg_iconforge_cleanupClears all cached DMIs and images, freeing up memory. This should be used after spritesheets are done being generated.
rustg_iconforge_cache_validTakes in a set of hashes, generate inputs, and DMI filepaths, and compares them to determine cache validity. input_hash: xxh64 hash of "sprites" from the cache. dmi_hashes: xxh64 hashes of the DMIs in a spritesheet, given by rustg_iconforge_generate with hash_icons enabled. From the cache. sprites: The new input that will be passed to rustg_iconforge_generate(). Returns a CacheResult with the following structure: list( "result": "1" (if cache is valid) or "0" (if cache is invalid) "fail_reason": "" (emtpy string if valid, otherwise a string containing the invalidation reason or an error with ERROR: prefixed.) ) In the case of an unrecoverable panic from within Rust, this function ONLY returns a string containing the error.
rustg_iconforge_cache_valid_asyncReturns a job_id for use with rustg_iconforge_check()
rustg_iconforge_load_gags_configProvided a /datum/greyscale_config typepath, JSON string containing the greyscale config, and path to a DMI file containing the base icons, Loads that config into memory for later use by rustg_iconforge_gags(). The config_path is the unique identifier used later. JSON Config schema: https://hackmd.io/@tgstation/GAGS-Layer-Types Adding dirs or frames (via blending larger icons) to icons with more than 1 dir or 1 frame is not supported. Returns "OK" if successful, otherwise, returns a string containing the error.
rustg_iconforge_gagsGiven a config_path (previously loaded by rustg_iconforge_load_gags_config), and a string of hex colors formatted as "#ff00ff#ffaa00" Outputs a DMI containing all of the states within the config JSON to output_dmi_path, creating any directories leading up to it if necessary. Returns "OK" if successful, otherwise, returns a string containing the error.
rustg_iconforge_load_gags_config_asyncReturns a job_id for use with rustg_iconforge_check()
rustg_iconforge_gags_asyncReturns a job_id for use with rustg_iconforge_check()
rustg_noise_poisson_mapGenerates a 2D poisson disk distribution ('blue noise'), which is relatively uniform.
rustg_register_nodes_astarRegister a list of nodes into a rust library. This list of nodes must have been serialized in a json. Node {// Index of this node in the list of nodes unique_id: usize, // Position of the node in byond x: usize, y: usize, z: usize, // Indexes of nodes connected to this one connected_nodes_id: Vec} It is important that the node with the unique_id 0 is the first in the json, unique_id 1 right after that, etc. It is also important that all unique ids follow. {0, 1, 2, 4} is not a correct list and the registering will fail Nodes should not link across z levels. A node cannot link twice to the same node and shouldn't link itself either
rustg_add_node_astarAdd a new node to the static list of nodes. Same rule as registering_nodes applies. This node unique_id must be equal to the current length of the static list of nodes
rustg_remove_node_astarRemove every link to the node with unique_id. Replace that node by null
rustg_generate_path_astarCompute the shortest path between start_node and goal_node using A*. Heuristic used is simple geometric distance
/proc/rustg_sound_lengthProvided a static RSC file path or a raw text file path, returns the duration of the file in deciseconds as a float.
rustg_sound_length_listReturns a nested key-value list containing "successes" and "errors" The format is as follows: list( RUSTG_SOUNDLEN_SUCCESES = list("sounds/test.ogg" = 25.34), RUSTG_SOUNDLEN_ERRORS = list("sound/bad.png" = "SoundLen: Unable to decode file."), )
rustg_formatted_timestampReturns the current timestamp (in local time), formatted with the given format string. See https://docs.rs/chrono/latest/chrono/format/strftime/index.html for documentation on the formatting syntax.
rustg_formatted_timestamp_tzReturns the current timestamp (with the given UTC offset in hours), formatted with the given format string. See https://docs.rs/chrono/latest/chrono/format/strftime/index.html for documentation on the formatting syntax.
/proc/rustg_unix_timestampReturns the timestamp as a string

Define Details

rustg_acreplace

Run the specified replacement engine with the provided haystack text to replace, returning replaced text.

Arguments:

rustg_acreplace_with_replacements

Run the specified replacement engine with the provided haystack text to replace, returning replaced text.

Arguments:

rustg_add_node_astar

Add a new node to the static list of nodes. Same rule as registering_nodes applies. This node unique_id must be equal to the current length of the static list of nodes

rustg_cnoise_generate

This proc generates a cellular automata noise grid which can be used in procedural generation methods.

Returns a single string that goes row by row, with values of 1 representing an alive cell, and a value of 0 representing a dead cell.

Arguments:

rustg_dbp_generate

This proc generates a grid of perlin-like noise

Returns a single string that goes row by row, with values of 1 representing an turned on cell, and a value of 0 representing a turned off cell.

Arguments:

rustg_decode_base64

Decode a given base64 string

rustg_dmi_icon_states

input: must be a path, not an /icon; you have to do your own handling if it is one, as icon objects can't be directly passed to rustg.

output: json_encode'd list. json_decode to get a flat list with icon states in the order they're in inside the .dmi

rustg_dmi_inject_metadata

Inject dmi metadata into a png file located at path. metadata must be a json_encode'd list in the metadata format listed above.

rustg_dmi_read_metadata

The below functions involve dmi metadata represented in the following format: list( "width": number, "height": number, "states": list([STATE_DATA], ...) )

STATE_DATA format: list( "name": string, "dirs": 1 | 4 | 8, "delays"?: list(number, ...), "rewind"?: TRUE | FALSE, "movement"?: TRUE | FALSE, "loop"?: number )

Get the dmi metadata of the file located at fname. Returns a list in the metadata format listed above, or an error message.

rustg_encode_base64

Encode a given string into base64

rustg_formatted_timestamp

Returns the current timestamp (in local time), formatted with the given format string. See https://docs.rs/chrono/latest/chrono/format/strftime/index.html for documentation on the formatting syntax.

rustg_formatted_timestamp_tz

Returns the current timestamp (with the given UTC offset in hours), formatted with the given format string. See https://docs.rs/chrono/latest/chrono/format/strftime/index.html for documentation on the formatting syntax.

rustg_generate_path_astar

Compute the shortest path between start_node and goal_node using A*. Heuristic used is simple geometric distance

rustg_git_revparse

Returns the git hash of the given revision, ex. "HEAD".

rustg_iconforge_cache_valid

Takes in a set of hashes, generate inputs, and DMI filepaths, and compares them to determine cache validity. input_hash: xxh64 hash of "sprites" from the cache. dmi_hashes: xxh64 hashes of the DMIs in a spritesheet, given by rustg_iconforge_generate with hash_icons enabled. From the cache. sprites: The new input that will be passed to rustg_iconforge_generate(). Returns a CacheResult with the following structure: list( "result": "1" (if cache is valid) or "0" (if cache is invalid) "fail_reason": "" (emtpy string if valid, otherwise a string containing the invalidation reason or an error with ERROR: prefixed.) ) In the case of an unrecoverable panic from within Rust, this function ONLY returns a string containing the error.

rustg_iconforge_cache_valid_async

Returns a job_id for use with rustg_iconforge_check()

rustg_iconforge_check

Returns the status of an async job_id, or its result if it is completed. See RUSTG_JOB DEFINEs.

rustg_iconforge_cleanup

Clears all cached DMIs and images, freeing up memory. This should be used after spritesheets are done being generated.

rustg_iconforge_gags

Given a config_path (previously loaded by rustg_iconforge_load_gags_config), and a string of hex colors formatted as "#ff00ff#ffaa00" Outputs a DMI containing all of the states within the config JSON to output_dmi_path, creating any directories leading up to it if necessary. Returns "OK" if successful, otherwise, returns a string containing the error.

rustg_iconforge_gags_async

Returns a job_id for use with rustg_iconforge_check()

rustg_iconforge_generate

BANDASTATION REMOVAL START - Rust Utils This is basically just rustg_http_request_async if you don't care about the response. This will either return "ok" or an error, as this does not create a job. BANDASTATION REMOVAL END - Rust Utils Generates a spritesheet at: [file_path][spritesheet_name]_[size_id].[png or dmi] The resulting spritesheet arranges icons in a random order, with the position being denoted in the "sprites" return value. All icons have the same y coordinate, and their x coordinate is equal to icon_width * position.

hash_icons is a boolean (0 or 1), and determines if the generator will spend time creating hashes for the output field dmi_hashes. These hashes can be helpful for 'smart' caching (see rustg_iconforge_cache_valid), but require extra computation.

generate_dmi is a boolean (0 or 1), and determines if the generator will save the sheet as a DMI or stripped PNG file. DMI files can be used to replace bulk Insert() operations, PNGs are more useful for asset transport or UIs. DMI generation is slower due to more metadata. flatten is a boolean (0 or 1), and determines if the DMI output will be flattened to a single frame/dir if unscoped (null/0 dir or frame values). PNGs are always flattened, regardless of argument.

Spritesheet will contain all sprites listed within "sprites". "sprites" format: list( "sprite_name" = list( // <--- this list is a [SPRITE_OBJECT] icon_file = 'icons/path_to/an_icon.dmi', icon_state = "some_icon_state", dir = SOUTH, frame = 1, transform = list([TRANSFORM_OBJECT], ...) ), ..., ) TRANSFORM_OBJECT format: list("type" = RUSTG_ICONFORGE_BLEND_COLOR, "color" = "#ff0000", "blend_mode" = ICON_MULTIPLY) list("type" = RUSTG_ICONFORGE_BLEND_ICON, "icon" = [SPRITE_OBJECT], "blend_mode" = ICON_OVERLAY, "x" = 1, "y" = 1) // offsets optional list("type" = RUSTG_ICONFORGE_SCALE, "width" = 32, "height" = 32) list("type" = RUSTG_ICONFORGE_CROP, "x1" = 1, "y1" = 1, "x2" = 32, "y2" = 32) // (BYOND icons index from 1,1 to the upper bound, inclusive) list("type" = RUSTG_ICONFORGE_MAP_COLORS, "rr" = 0.5, "rg" = 0.5, "rb" = 0.5, "ra" = 1, "gr" = 1, "gg" = 1, "gb" = 1, "ga" = 1, ...) // alpha arguments and rgba0 optional list("type" = RUSTG_ICONFORGE_FLIP, "dir" = SOUTH) list("type" = RUSTG_ICONFORGE_TURN, "angle" = 90.0) list("type" = RUSTG_ICONFORGE_SHIFT, "dir" = EAST, "offset" = 10, "wrap" = FALSE) list("type" = RUSTG_ICONFORGE_SWAP_COLOR, "src_color" = "#ff0000", "dst_color" = "#00ff00") // alpha bits supported list("type" = RUSTG_ICONFORGE_DRAW_BOX, "color" = "#ff0000", "x1" = 1, "y1" = 1, "x2" = 32, "y2" = 32) // alpha bits supported. color can be null/omitted for transparency. x2 and y2 will default to x1 and y1 if omitted

Returns a SpritesheetResult as JSON, containing fields: list( "sizes" = list("32x32", "64x64", ...), "sprites" = list("sprite_name" = list("size_id" = "32x32", "position" = 0), ...), "dmi_hashes" = list("icons/path_to/an_icon.dmi" = "d6325c5b4304fb03", ...), "sprites_hash" = "a2015e5ff403fb5c", // This is the xxh64 hash of the INPUT field "sprites". "error" = "[A string, empty if there were no errors.]" ) In the case of an unrecoverable panic from within Rust, this function ONLY returns a string containing the error.

rustg_iconforge_generate_async

Returns a job_id for use with rustg_iconforge_check()

rustg_iconforge_load_gags_config

Provided a /datum/greyscale_config typepath, JSON string containing the greyscale config, and path to a DMI file containing the base icons, Loads that config into memory for later use by rustg_iconforge_gags(). The config_path is the unique identifier used later. JSON Config schema: https://hackmd.io/@tgstation/GAGS-Layer-Types Adding dirs or frames (via blending larger icons) to icons with more than 1 dir or 1 frame is not supported. Returns "OK" if successful, otherwise, returns a string containing the error.

rustg_iconforge_load_gags_config_async

Returns a job_id for use with rustg_iconforge_check()

rustg_noise_poisson_map

Generates a 2D poisson disk distribution ('blue noise'), which is relatively uniform.

params: seed: str width: int, width of the noisemap (see world.maxx) length: int, height of the noisemap (see world.maxy) radius: int, distance between points on the noisemap

returns: a width*length length string of 1s and 0s representing a 2D poisson sample collapsed into a 1D string

rustg_register_nodes_astar

Register a list of nodes into a rust library. This list of nodes must have been serialized in a json. Node {// Index of this node in the list of nodes unique_id: usize, // Position of the node in byond x: usize, y: usize, z: usize, // Indexes of nodes connected to this one connected_nodes_id: Vec} It is important that the node with the unique_id 0 is the first in the json, unique_id 1 right after that, etc. It is also important that all unique ids follow. {0, 1, 2, 4} is not a correct list and the registering will fail Nodes should not link across z levels. A node cannot link twice to the same node and shouldn't link itself either

rustg_remove_node_astar

Remove every link to the node with unique_id. Replace that node by null

rustg_setup_acreplace

Sets up the Aho-Corasick automaton with its default options.

The search patterns list and the replacements must be of the same length when replace is run, but an empty replacements list is allowed if replacements are supplied with the replace call Arguments:

rustg_setup_acreplace_with_options

Sets up the Aho-Corasick automaton using supplied options.

The search patterns list and the replacements must be of the same length when replace is run, but an empty replacements list is allowed if replacements are supplied with the replace call Arguments:

rustg_sound_length_list

Returns a nested key-value list containing "successes" and "errors" The format is as follows: list( RUSTG_SOUNDLEN_SUCCESES = list("sounds/test.ogg" = 25.34), RUSTG_SOUNDLEN_ERRORS = list("sound/bad.png" = "SoundLen: Unable to decode file."), )