Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,19 @@ ClassDB::APIType ClassDB::class_get_api_type(const StringName &p_class) const {
return (APIType)api_type;
}

Error ClassDB::class_override_api_type(const StringName &p_class, ClassDB::APIType p_api) const {
return ::ClassDB::override_api_type(p_class, (::ClassDB::APIType)p_api);
}

ClassDB::APIType ClassDB::get_current_api() const {
::ClassDB::APIType api_type = ::ClassDB::get_current_api();
return (APIType)api_type;
}

void ClassDB::set_current_api(ClassDB::APIType p_api) const {
::ClassDB::set_current_api((::ClassDB::APIType)p_api);
}

bool ClassDB::class_has_signal(const StringName &p_class, const StringName &p_signal) const {
return ::ClassDB::has_signal(p_class, p_signal);
}
Expand Down Expand Up @@ -1838,7 +1851,7 @@ void ClassDB::get_argument_options(const StringName &p_function, int p_idx, List
pf == "class_has_method" || pf == "class_get_method_list" ||
pf == "class_get_integer_constant_list" || pf == "class_has_integer_constant" || pf == "class_get_integer_constant" ||
pf == "class_has_enum" || pf == "class_get_enum_list" || pf == "class_get_enum_constants" || pf == "class_get_integer_constant_enum" ||
pf == "is_class_enabled" || pf == "is_class_enum_bitfield" || pf == "class_get_api_type");
pf == "is_class_enabled" || pf == "is_class_enum_bitfield" || pf == "class_get_api_type" || pf == "get_current_api");
}
if (first_argument_is_class || pf == "is_parent_class") {
for (const String &E : get_class_list()) {
Expand All @@ -1860,6 +1873,9 @@ void ClassDB::_bind_methods() {
::ClassDB::bind_method(D_METHOD("instantiate", "class"), &ClassDB::instantiate);

::ClassDB::bind_method(D_METHOD("class_get_api_type", "class"), &ClassDB::class_get_api_type);
::ClassDB::bind_method(D_METHOD("class_override_api_type", "class", "api"), &ClassDB::class_override_api_type);
::ClassDB::bind_method(D_METHOD("get_current_api"), &ClassDB::get_current_api);
::ClassDB::bind_method(D_METHOD("set_current_api", "api"), &ClassDB::set_current_api);

::ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &ClassDB::class_has_signal);
::ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &ClassDB::class_get_signal);
Expand Down
4 changes: 4 additions & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ class ClassDB : public Object {
Variant instantiate(const StringName &p_class) const;

APIType class_get_api_type(const StringName &p_class) const;
Error class_override_api_type(const StringName &p_class, APIType p_api) const;
APIType get_current_api() const;
void set_current_api(APIType p_api) const;

bool class_has_signal(const StringName &p_class, const StringName &p_signal) const;
Dictionary class_get_signal(const StringName &p_class, const StringName &p_signal) const;
TypedArray<Dictionary> class_get_signal_list(const StringName &p_class, bool p_no_inheritance = false) const;
Expand Down
11 changes: 11 additions & 0 deletions core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
return ti->api;
}

Error ClassDB::override_api_type(const StringName &p_class, ClassDB::APIType p_api) {
Locker::Lock lock(Locker::STATE_WRITE);

ClassInfo *ti = classes.getptr(p_class);

ERR_FAIL_NULL_V_MSG(ti, Error::ERR_DOES_NOT_EXIST, vformat("Cannot get class '%s'.", String(p_class)));
ti->api = p_api;

return Error::OK;
}

uint32_t ClassDB::get_api_hash(APIType p_api) {
#ifdef DEBUG_ENABLED
Locker::Lock lock(Locker::STATE_WRITE);
Expand Down
1 change: 1 addition & 0 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class ClassDB {
static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);

static APIType get_api_type(const StringName &p_class);
static Error override_api_type(const StringName &p_class, APIType p_api);

static uint32_t get_api_hash(APIType p_api);

Expand Down
23 changes: 23 additions & 0 deletions doc/classes/ClassDB.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@
Returns whether [param class] or its ancestry has a signal called [param signal] or not.
</description>
</method>
<method name="class_override_api_type" qualifiers="const">
<return type="int" enum="Error" />
<param index="0" name="class" type="StringName" />
<param index="1" name="api" type="int" enum="ClassDB.APIType" />
<description>
Overrides the API type of [param class] to [param api]. See [enum ClassDB.APIType].
[b]Note:[/b] This should only be used with a thorough understanding of its implications.
</description>
</method>
<method name="class_set_property" qualifiers="const">
<return type="int" enum="Error" />
<param index="0" name="object" type="Object" />
Expand All @@ -205,6 +214,12 @@
[b]Note:[/b] Script-defined classes with [code]class_name[/code] are not included in this list. Use [method ProjectSettings.get_global_class_list] to get a list of script-defined classes instead.
</description>
</method>
<method name="get_current_api" qualifiers="const">
<return type="int" enum="ClassDB.APIType" />
<description>
Returns the currently active API type. See [enum ClassDB.APIType].
</description>
</method>
<method name="get_inheriters_from_class" qualifiers="const">
<return type="PackedStringArray" />
<param index="0" name="class" type="StringName" />
Expand Down Expand Up @@ -250,6 +265,14 @@
Returns whether [param inherits] is an ancestor of [param class] or not.
</description>
</method>
<method name="set_current_api" qualifiers="const">
<return type="void" />
<param index="0" name="api" type="int" enum="ClassDB.APIType" />
<description>
Sets the globally active API type to [param api]. See [enum ClassDB.APIType].
[b]Note:[/b] This should only be used with a thorough understanding of its implications.
</description>
</method>
</methods>
<constants>
<constant name="API_CORE" value="0" enum="APIType">
Expand Down
Loading