Skip to main content
Version: 1.3

SproutyDialogsReferenceUtils

Inherits: RefCounted

Description​

This module is responsible for the resource references used in the plugin. A resource reference is a dictionary that stores the resource UID and its file path, so the resource can still be loaded by its path when the UID is no longer valid. It provides methods to create, check, resolve and load resource references.

Methods​

Return TypeMethod
Dictionarycreate_reference_dict(uid: int = -1, path: String = "")
Dictionarycreate_reference_from_path(path: String)
Dictionarycreate_reference_from_uid(uid: int)
Dictionarynormalize_reference_dict(reference: Variant)
boolis_reference_dict_empty(reference: Variant)
Stringget_reference_path_from_uid(uid: int, path_fallback: String = "")
Stringget_reference_path(reference: Dictionary)
Resourceload_resource(uid: int, path_fallback: String = "")
Resourceload_resource_from_reference(reference: Dictionary)

Method Descriptions​

static func create_reference_dict(uid: int = -1, path: String = "") -> Dictionary

Returns a resource reference dictionary with the given resource UID and file path. This is the format used to store the resource references in the plugin data (e.g. the character references of the dialogue data).


static func create_reference_from_path(path: String) -> Dictionary

Returns a resource reference dictionary for the resource by the given path, storing both its UID and the path itself to load it as a fallback. If the path is not valid, the path is still kept (with no UID) to not lose the reference data, so it can be recovered or resolved later.


static func create_reference_from_uid(uid: int) -> Dictionary

Returns a resource reference dictionary for the resource by the given UID, storing the UID and the path resolved from it. If the UID is not valid, the UID is still kept (with no path) to not lose the reference data, so it can be recovered or resolved later.


static func normalize_reference_dict(reference: Variant) -> Dictionary

Normalizes a resource reference to a reference dictionary with "uid" and "path" keys. Accepts legacy references storing only the resource UID as an int, returning a reference dictionary with the UID and an empty path. Also, accepts a String to create the reference dictionary from a path. Any other value is normalized to an empty reference dictionary.


static func is_reference_dict_empty(reference: Variant) -> bool

Check if a resource reference is empty, meaning that it stores no usable resource UID nor file path.


static func get_reference_path_from_uid(uid: int, path_fallback: String = "") -> String

Returns the file path of a resource UID, using the given path as fallback when the UID is no longer valid (e.g. the resource was renamed or moved outside of the editor). Returns an empty string when none of them is valid.


static func get_reference_path(reference: Dictionary) -> String

Returns the resolved file path of a resource reference. The stored UID is resolved first, using the stored path as fallback when the UID is no longer valid. Returns an empty string when the path cannot be resolved.


static func load_resource(uid: int, path_fallback: String = "") -> Resource

Load a resource by its UID, using the given path as fallback. The resource is loaded from its UID path first; when the UID is no longer valid, the resource is loaded from the fallback path instead, if the file exists there. Returns null when the resource cannot be loaded.


static func load_resource_from_reference(reference: Dictionary) -> Resource

Load a resource from a resource reference. The resource is loaded from its stored UID first, using the stored path as fallback when the UID is no longer valid. Returns null when the reference is invalid or the resource cannot be loaded.