Skip to main content

SproutyDialogsVariableUtils

Inherits: RefCounted

Description

This class provides utility methods to handle variables, such as get the UI fields and components needed to edit variables in the editor and get the assignment and comparison operators available for each variable type.

Methods

Return TypeMethod
Arrayget_variables_of_type(type: int = -1, metadata: Dictionary = {}, group: Dictionary = {})
OptionButtonget_types_dropdown(label: bool = true, excluded: Array[String] = [])
Dictionarynew_field_by_type(type: int, init_value: Variant = null, property_data: Dictionary = {}, on_value_changed: Callable = func(value, type, field): return, on_modified_callable: Callable = func(): return)
voidset_field_value(field: Control, type: int, value: Variant)
Dictionaryget_assignment_operators(type: int)
Dictionaryget_comparison_operators()

Enumerations

enum ASSIGN_OPS

Assignment operators for variables

  • ASSIGN_OPS ASSIGN = 0

    Direct assignment operator (=)

  • ASSIGN_OPS ADD_ASSIGN = 1

    Addition assignment operator (+=)

  • ASSIGN_OPS SUB_ASSIGN = 2

    Subtraction assignment operator (-=)

  • ASSIGN_OPS MUL_ASSIGN = 3

    Multiplication assignment operator (*=)

  • ASSIGN_OPS DIV_ASSIGN = 4

    Division assignment operator (/=)

  • ASSIGN_OPS EXP_ASSIGN = 5

    Exponentiation assignment operator (**=)

  • ASSIGN_OPS MOD_ASSIGN = 6

    Modulus assignment operator (%=)


Constants

const VAR_ICON_PATH = "res://addons/sprouty_dialogs/editor/icons/variable.svg"

Path to the variable icon.


const DICTIONARY_FIELD_PATH = "res://addons/sprouty_dialogs/editor/components/dictionary_field.tscn"

Path to the dictionary field scene.


const ARRAY_FIELD_PATH = "res://addons/sprouty_dialogs/editor/components/array_field.tscn"

Path to the array field scene.


const FILE_FIELD_PATH = "res://addons/sprouty_dialogs/editor/components/file_field.tscn"

Path to the file field scene.


Method Descriptions

func get_variables_of_type(type: int = -1, metadata: Dictionary = {}, group: Dictionary = {}) -> Array

Returns a list with the names of variables of the given type. If a type is specified, it returns only the variables of that type. If no type is specified, it returns all variables. If no variables are found, it returns an empty array.


func get_types_dropdown(label: bool = true, excluded: Array[String] = []) -> OptionButton

Returns an OptionButton component with all the variable types that can be selected. You can hide the label text by setting label to false. Also, you can exclude types by passing their names in the excluded array.


func new_field_by_type(type: int, init_value: Variant = null, property_data: Dictionary = , on_value_changed: Callable = func(value, type, field): return , on_modified_callable: Callable = func(): return) -> Dictionary

Create a new field based on the variable type. Returns a dictionary with the field created and its default value. You can pass an initial value and property data for hints. Also, you can pass callables for when the value changes or when the field is modified.


func set_field_value(field: Control, type: int, value: Variant) -> void

Sets a value in the given field based on its type.


func get_assignment_operators(type: int) -> Dictionary

Returns a list of assignment operators by type.


func get_comparison_operators() -> Dictionary

Returns all the comparison operators as a dictionary.