-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: rustg_sound_length() (#192)
- Loading branch information
Showing
7 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/// Provided a static RSC file path or a raw text file path, returns the duration of the file in deciseconds as a float. | ||
/proc/rustg_sound_length(file_path) | ||
var/static/list/sound_cache | ||
if(isnull(sound_cache)) | ||
sound_cache = list() | ||
|
||
. = 0 | ||
|
||
if(!istext(file_path)) | ||
if(!isfile(file_path)) | ||
CRASH("rustg_sound_length error: Passed non-text object") | ||
|
||
if(length("[file_path]")) // Runtime generated RSC references stringify into 0-length strings. | ||
file_path = "[file_path]" | ||
else | ||
CRASH("rustg_sound_length does not support non-static file refs.") | ||
|
||
var/cached_length = sound_cache[file_path] | ||
if(!isnull(cached_length)) | ||
return cached_length | ||
|
||
var/ret = RUSTG_CALL(RUST_G, "sound_len")(file_path) | ||
var/as_num = text2num(ret) | ||
if(isnull(ret)) | ||
. = 0 | ||
CRASH("rustg_sound_length error: [ret]") | ||
|
||
sound_cache[file_path] = as_num | ||
return as_num | ||
|
||
|
||
#define RUSTG_SOUNDLEN_SUCCESSES "successes" | ||
#define RUSTG_SOUNDLEN_ERRORS "errors" | ||
/** | ||
* 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."), | ||
*) | ||
*/ | ||
#define rustg_sound_length_list(file_paths) json_decode(RUSTG_CALL(RUST_G, "sound_len_list")(json_encode(file_paths))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.