StagUtils

Experimental: Changes may be made for organizational purposes.

Inherits: RefCounted

Utility constants and functions that are not bundled with Godot, but I wish were.

Methods

Dictionary[String, String]

get_args() static

float

factorial(n: int) static

Variant

default(dictionary: Dictionary, key: Variant, valuetype: Variant.Type, override: Variant = null, salvage: bool = true) static

PackedStringArray

walk_directory(directory: String, allowed_extensions: PackedStringArray, list: PackedStringArray = []) static


Constants

INT64_MIN = -9223372036854775808 🔗

Minimum value for a 64-bit integer.

Godot uses 64-bit integers by default for int types, but may use 32-bit in some cases for less memory usage, such as Vector2i.

INT64_MAX = 9223372036854775807 🔗

Maximum value for a 64-bit integer.

Godot uses 64-bit integers by default for int types, but may use 32-bit in some cases for less memory usage, such as Vector2i.

INT32_MIN = -2147483648 🔗

Minimum value for a 32-bit integer.

INT32_MAX = 2147483647 🔗

Maximum value for a 32-bit integer.


Method Descriptions

Dictionary[String, String] get_args() static 🔗

Returns a dictionary of command-line arguments used to launch the program. Note that all values will be strings.

For example launching a StagTest scenario:

$ godot --headless --stagtest --test=res://test/scenarios/test_island_builder.tscn --timeout=60

print(StagUtils.get_args())
# outputs
{
   "stagtest": "",
   "test": "res://test/scenarios/test_island_builder.tscn",
   "timeout": "60"
}

float factorial(n: int) static 🔗

Performs a simple factorial of the given integer. Returned as a floating-point for large numbers. Returns NAN if n is negative, as it is undefined behavior.


Variant default(dictionary: Dictionary, key: Variant, valuetype: Variant.Type, override: Variant = null, salvage: bool = true) static 🔗

Fetches the given key out of the dictionary, or null if not found.

If the fetched value does not match the specified Variant type (valuetype), the value is forcibly converted to that type (applying default when necessary), unless an override of the same type is specified, at which point the override is used.

If salvage is true, similiar types (such as integers and floats) are converted instead of using the provided override. The override is still applied in cases where types are not similiar (such as string and float).


PackedStringArray walk_directory(directory: String, allowed_extensions: PackedStringArray, list: PackedStringArray = []) static 🔗

Recursively walks the given directory and its subdirectories, looking for all files with the given extension list.

Note that extensions are compared against the entire filename, rather than just the file extension. This helps with cases where Godot might append a .remap extension onto files when exporting. For example, res://data/level_info/data.tres might be exported as res://data/level_info/data.tres.remap, which causes String.get_extension() to just return remap instead of the original tres.

Returns a packed array of all filepaths. File paths that are closer to top-level directories will be ordered first in the list.

print(StagUtils.walk_directory("res://test/scenarios/", [".tscn"]))

# outputs
[
    "res://test/scenarios/example/test_hello_world.tscn",
    "res://test/scenarios/example/test_signals.tscn",
    "res://test/scenarios/example/test_tick_timers.tscn",
    "res://test/scenarios/example/test_workflow.tscn",
    "res://test/scenarios/island_builder/test_island_builder.tscn",
    "res://test/scenarios/island_builder/test_settings.tscn",
    "res://test/scenarios/physics_server/test_raycast.tscn",
    "res://test/scenarios/queues/test_queuefloat.tscn",
    "res://test/scenarios/rope/test_interface.tscn",
    "res://test/scenarios/rope/test_tension.tscn",
    "res://test/scenarios/utils/test_utils.tscn"
]