Skip to content

Commit ceb741c

Browse files
committed
Expose helper methods for converting UIDs
1 parent 4a44078 commit ceb741c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

core/io/resource_uid.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ void ResourceUID::_bind_methods() {
364364
ClassDB::bind_method(D_METHOD("get_id_path", "id"), &ResourceUID::get_id_path);
365365
ClassDB::bind_method(D_METHOD("remove_id", "id"), &ResourceUID::remove_id);
366366

367+
ClassDB::bind_static_method("ResourceUID", D_METHOD("uid_to_path", "uid"), &ResourceUID::uid_to_path);
368+
ClassDB::bind_static_method("ResourceUID", D_METHOD("path_to_uid", "path"), &ResourceUID::path_to_uid);
369+
ClassDB::bind_static_method("ResourceUID", D_METHOD("ensure_path", "path_or_uid"), &ResourceUID::ensure_path);
370+
367371
BIND_CONSTANT(INVALID_ID)
368372
}
369373
ResourceUID *ResourceUID::singleton = nullptr;

doc/classes/ResourceUID.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
Like [method create_id], but the UID is seeded with the provided [param path] and project name. UIDs generated for that path will be always the same within the current project.
3434
</description>
3535
</method>
36+
<method name="ensure_path" qualifiers="static">
37+
<return type="String" />
38+
<param index="0" name="path_or_uid" type="String" />
39+
<description>
40+
Returns a path, converting [param path_or_uid] if necessary. Prints an error if provided an invalid UID.
41+
</description>
42+
</method>
3643
<method name="get_id_path" qualifiers="const">
3744
<return type="String" />
3845
<param index="0" name="id" type="int" />
@@ -55,6 +62,13 @@
5562
Converts the given UID to a [code]uid://[/code] string value.
5663
</description>
5764
</method>
65+
<method name="path_to_uid" qualifiers="static">
66+
<return type="String" />
67+
<param index="0" name="path" type="String" />
68+
<description>
69+
Converts the provided resource [param path] to UID. Returns the unchanged path if it has no associated UID.
70+
</description>
71+
</method>
5872
<method name="remove_id">
5973
<return type="void" />
6074
<param index="0" name="id" type="int" />
@@ -79,6 +93,13 @@
7993
Extracts the UID value from the given [code]uid://[/code] string.
8094
</description>
8195
</method>
96+
<method name="uid_to_path" qualifiers="static">
97+
<return type="String" />
98+
<param index="0" name="uid" type="String" />
99+
<description>
100+
Converts the provided [param uid] to a path. Prints an error if the UID is invalid.
101+
</description>
102+
</method>
82103
</methods>
83104
<constants>
84105
<constant name="INVALID_ID" value="-1">

0 commit comments

Comments
 (0)