|
144 | 144 | // File Operations //
|
145 | 145 |
|
146 | 146 | #define rustg_file_read(fname) RUSTG_CALL(RUST_G, "file_read")(fname)
|
147 |
| -#define rustg_file_exists(fname) RUSTG_CALL(RUST_G, "file_exists")(fname) |
| 147 | +#define rustg_file_exists(fname) (RUSTG_CALL(RUST_G, "file_exists")(fname) == "true") |
148 | 148 | #define rustg_file_write(text, fname) RUSTG_CALL(RUST_G, "file_write")(text, fname)
|
149 | 149 | #define rustg_file_append(text, fname) RUSTG_CALL(RUST_G, "file_append")(text, fname)
|
150 | 150 | #define rustg_file_get_line_count(fname) text2num(RUSTG_CALL(RUST_G, "file_get_line_count")(fname))
|
|
157 | 157 |
|
158 | 158 | // Git Operations //
|
159 | 159 |
|
| 160 | +/// Returns the git hash of the given revision, ex. "HEAD". |
160 | 161 | #define rustg_git_revparse(rev) RUSTG_CALL(RUST_G, "rg_git_revparse")(rev)
|
161 |
| -#define rustg_git_commit_date(rev) RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev) |
| 162 | + |
| 163 | +/** |
| 164 | + * Returns the date of the given revision using the provided format. |
| 165 | + * Defaults to returning %F which is YYYY-MM-DD. |
| 166 | + */ |
| 167 | +/proc/rustg_git_commit_date(rev, format = "%F") |
| 168 | + return RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev, format) |
| 169 | + |
| 170 | +/** |
| 171 | + * Returns the formatted datetime string of HEAD using the provided format. |
| 172 | + * Defaults to returning %F which is YYYY-MM-DD. |
| 173 | + * This is different to rustg_git_commit_date because it only needs the logs directory. |
| 174 | + */ |
| 175 | +/proc/rustg_git_commit_date_head(format = "%F") |
| 176 | + return RUSTG_CALL(RUST_G, "rg_git_commit_date_head")(format) |
162 | 177 |
|
163 | 178 | // Hashing Functions //
|
164 | 179 |
|
|
174 | 189 | #define RUSTG_HASH_XXH64 "xxh64"
|
175 | 190 | #define RUSTG_HASH_BASE64 "base64"
|
176 | 191 |
|
| 192 | +/// Encode a given string into base64 |
| 193 | +#define rustg_encode_base64(str) rustg_hash_string(RUSTG_HASH_BASE64, str) |
| 194 | +/// Decode a given base64 string |
| 195 | +#define rustg_decode_base64(str) RUSTG_CALL(RUST_G, "decode_base64")(str) |
| 196 | + |
177 | 197 | #ifdef RUSTG_OVERRIDE_BUILTINS
|
178 | 198 | #define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
|
179 | 199 | #endif
|
|
192 | 212 | /proc/rustg_create_async_http_client() return RUSTG_CALL(RUST_G, "start_http_client")()
|
193 | 213 | /proc/rustg_close_async_http_client() return RUSTG_CALL(RUST_G, "shutdown_http_client")()
|
194 | 214 |
|
| 215 | +// Iconforge Operations // |
| 216 | + |
| 217 | +/// Generates a spritesheet at: [file_path][spritesheet_name]_[size_id].png |
| 218 | +/// The resulting spritesheet arranges icons in a random order, with the position being denoted in the "sprites" return value. |
| 219 | +/// All icons have the same y coordinate, and their x coordinate is equal to `icon_width * position`. |
| 220 | +/// |
| 221 | +/// hash_icons is a boolean (0 or 1), and determines if the generator will spend time creating hashes for the output field dmi_hashes. |
| 222 | +/// These hashes can be heplful for 'smart' caching (see rustg_iconforge_cache_valid), but require extra computation. |
| 223 | +/// |
| 224 | +/// Spritesheet will contain all sprites listed within "sprites". |
| 225 | +/// "sprites" format: |
| 226 | +/// list( |
| 227 | +/// "sprite_name" = list(// <--- this list is a [SPRITE_OBJECT] |
| 228 | +/// icon_file = 'icons/path_to/an_icon.dmi', |
| 229 | +/// icon_state = "some_icon_state", |
| 230 | +/// dir = SOUTH, |
| 231 | +/// frame = 1, |
| 232 | +/// transform = list([TRANSFORM_OBJECT], ...) |
| 233 | +/// ), |
| 234 | +/// ..., |
| 235 | +/// ) |
| 236 | +/// TRANSFORM_OBJECT format: |
| 237 | +/// list("type" = RUSTG_ICONFORGE_BLEND_COLOR, "color" = "#ff0000", "blend_mode" = ICON_MULTIPLY) |
| 238 | +/// list("type" = RUSTG_ICONFORGE_BLEND_ICON, "icon" = [SPRITE_OBJECT], "blend_mode" = ICON_OVERLAY) |
| 239 | +/// list("type" = RUSTG_ICONFORGE_SCALE, "width" = 32, "height" = 32) |
| 240 | +/// list("type" = RUSTG_ICONFORGE_CROP, "x1" = 1, "y1" = 1, "x2" = 32, "y2" = 32) // (BYOND icons index from 1,1 to the upper bound, inclusive) |
| 241 | +/// |
| 242 | +/// Returns a SpritesheetResult as JSON, containing fields: |
| 243 | +/// list( |
| 244 | +/// "sizes" = list("32x32", "64x64", ...), |
| 245 | +/// "sprites" = list("sprite_name" = list("size_id" = "32x32", "position" = 0), ...), |
| 246 | +/// "dmi_hashes" = list("icons/path_to/an_icon.dmi" = "d6325c5b4304fb03", ...), |
| 247 | +/// "sprites_hash" = "a2015e5ff403fb5c", // This is the xxh64 hash of the INPUT field "sprites". |
| 248 | +/// "error" = "[A string, empty if there were no errors.]" |
| 249 | +/// ) |
| 250 | +/// In the case of an unrecoverable panic from within Rust, this function ONLY returns a string containing the error. |
| 251 | +#define rustg_iconforge_generate(file_path, spritesheet_name, sprites, hash_icons) RUSTG_CALL(RUST_G, "iconforge_generate")(file_path, spritesheet_name, sprites, "[hash_icons]") |
| 252 | +/// Returns a job_id for use with rustg_iconforge_check() |
| 253 | +#define rustg_iconforge_generate_async(file_path, spritesheet_name, sprites, hash_icons) RUSTG_CALL(RUST_G, "iconforge_generate_async")(file_path, spritesheet_name, sprites, "[hash_icons]") |
| 254 | +/// Returns the status of an async job_id, or its result if it is completed. See RUSTG_JOB DEFINEs. |
| 255 | +#define rustg_iconforge_check(job_id) RUSTG_CALL(RUST_G, "iconforge_check")("[job_id]") |
| 256 | +/// Clears all cached DMIs and images, freeing up memory. |
| 257 | +/// This should be used after spritesheets are done being generated. |
| 258 | +#define rustg_iconforge_cleanup RUSTG_CALL(RUST_G, "iconforge_cleanup") |
| 259 | +/// Takes in a set of hashes, generate inputs, and DMI filepaths, and compares them to determine cache validity. |
| 260 | +/// input_hash: xxh64 hash of "sprites" from the cache. |
| 261 | +/// dmi_hashes: xxh64 hashes of the DMIs in a spritesheet, given by `rustg_iconforge_generate` with `hash_icons` enabled. From the cache. |
| 262 | +/// sprites: The new input that will be passed to rustg_iconforge_generate(). |
| 263 | +/// Returns a CacheResult with the following structure: list( |
| 264 | +/// "result": "1" (if cache is valid) or "0" (if cache is invalid) |
| 265 | +/// "fail_reason": "" (emtpy string if valid, otherwise a string containing the invalidation reason or an error with ERROR: prefixed.) |
| 266 | +/// ) |
| 267 | +/// In the case of an unrecoverable panic from within Rust, this function ONLY returns a string containing the error. |
| 268 | +#define rustg_iconforge_cache_valid(input_hash, dmi_hashes, sprites) RUSTG_CALL(RUST_G, "iconforge_cache_valid")(input_hash, dmi_hashes, sprites) |
| 269 | +/// Returns a job_id for use with rustg_iconforge_check() |
| 270 | +#define rustg_iconforge_cache_valid_async(input_hash, dmi_hashes, sprites) RUSTG_CALL(RUST_G, "iconforge_cache_valid_async")(input_hash, dmi_hashes, sprites) |
| 271 | + |
| 272 | +#define RUSTG_ICONFORGE_BLEND_COLOR "BlendColor" |
| 273 | +#define RUSTG_ICONFORGE_BLEND_ICON "BlendIcon" |
| 274 | +#define RUSTG_ICONFORGE_CROP "Crop" |
| 275 | +#define RUSTG_ICONFORGE_SCALE "Scale" |
| 276 | + |
195 | 277 | // Jobs Defines //
|
196 | 278 |
|
197 | 279 | #define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET"
|
|
211 | 293 |
|
212 | 294 | #define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)
|
213 | 295 |
|
| 296 | +/** |
| 297 | + * Generates a 2D poisson disk distribution ('blue noise'), which is relatively uniform. |
| 298 | + * |
| 299 | + * params: |
| 300 | + * `seed`: str |
| 301 | + * `width`: int, width of the noisemap (see world.maxx) |
| 302 | + * `length`: int, height of the noisemap (see world.maxy) |
| 303 | + * `radius`: int, distance between points on the noisemap |
| 304 | + * |
| 305 | + * returns: |
| 306 | + * a width*length length string of 1s and 0s representing a 2D poisson sample collapsed into a 1D string |
| 307 | + */ |
| 308 | +#define rustg_noise_poisson_map(seed, width, length, radius) RUSTG_CALL(RUST_G, "noise_poisson_map")(seed, width, length, radius) |
| 309 | + |
214 | 310 | // AStar Operations //
|
215 | 311 |
|
216 | 312 | /**
|
|
236 | 332 | */
|
237 | 333 | #define rustg_add_node_astar(json) RUSTG_CALL(RUST_G, "add_node_astar")(json)
|
238 | 334 |
|
239 |
| -/**² |
| 335 | +/** |
240 | 336 | * Remove every link to the node with unique_id. Replace that node by null
|
241 | 337 | */
|
242 |
| -#define rustg_remove_node_astart(unique_id) RUSTG_CALL(RUST_G, "remove_node_astar")(unique_id) |
| 338 | +#define rustg_remove_node_astar(unique_id) RUSTG_CALL(RUST_G, "remove_node_astar")("[unique_id]") |
243 | 339 |
|
244 | 340 | /**
|
245 | 341 | * Compute the shortest path between start_node and goal_node using A*. Heuristic used is simple geometric distance
|
246 | 342 | */
|
247 |
| -#define rustg_generate_path_astar(start_node_id, goal_node_id) RUSTG_CALL(RUST_G, "generate_path_astar")(start_node_id, goal_node_id) |
| 343 | +#define rustg_generate_path_astar(start_node_id, goal_node_id) RUSTG_CALL(RUST_G, "generate_path_astar")("[start_node_id]", "[goal_node_id]") |
248 | 344 |
|
249 | 345 | // Redis PubSub Operations //
|
250 | 346 |
|
|
256 | 352 | /proc/rustg_redis_get_messages() return RUSTG_CALL(RUST_G, "redis_get_messages")()
|
257 | 353 | #define rustg_redis_publish(channel, message) RUSTG_CALL(RUST_G, "redis_publish")(channel, message)
|
258 | 354 |
|
| 355 | +// Redis Core Operations // |
| 356 | + |
259 | 357 | /**
|
260 | 358 | * Connects to a given redis server.
|
261 | 359 | *
|
|
295 | 393 | */
|
296 | 394 | #define rustg_redis_lpop(key, count) RUSTG_CALL(RUST_G, "redis_lpop")(key, count)
|
297 | 395 |
|
| 396 | +// Sanitisation Operations // |
| 397 | + |
| 398 | +/* |
| 399 | + * Takes in a string and json_encode()"d lists to produce a sanitized string. |
| 400 | + * This function operates on whitelists, there is currently no way to blacklist. |
| 401 | + * Args: |
| 402 | + * * text: the string to sanitize. |
| 403 | + * * attribute_whitelist_json: a json_encode()'d list of HTML attributes to allow in the final string. |
| 404 | + * * tag_whitelist_json: a json_encode()'d list of HTML tags to allow in the final string. |
| 405 | + */ |
| 406 | +#define rustg_sanitize_html(text, attribute_whitelist_json, tag_whitelist_json) RUSTG_CALL(RUST_G, "sanitize_html")(text, attribute_whitelist_json, tag_whitelist_json) |
| 407 | + |
298 | 408 | // SQL Operations //
|
299 | 409 |
|
300 | 410 | #define rustg_sql_connect_pool(options) RUSTG_CALL(RUST_G, "sql_connect_pool")(options)
|
|
0 commit comments