From d2aef4c4396e8d68151c39a71ef08d396a4b0044 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sat, 11 Sep 2021 20:31:11 +0800 Subject: Expose enum related methods in ClassDB --- core/core_bind.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ core/core_bind.h | 5 +++++ doc/classes/ClassDB.xml | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index fd5b3bb731..58aecf39aa 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -2042,6 +2042,42 @@ StringName ClassDB::get_category(const StringName &p_node) const { return ::ClassDB::get_category(p_node); } +bool ClassDB::has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const { + return ::ClassDB::has_enum(p_class, p_name, p_no_inheritance); +} + +PackedStringArray ClassDB::get_enum_list(const StringName &p_class, bool p_no_inheritance) const { + List enums; + ::ClassDB::get_enum_list(p_class, &enums, p_no_inheritance); + + PackedStringArray ret; + ret.resize(enums.size()); + int idx = 0; + for (const StringName &E : enums) { + ret.set(idx++, E); + } + + return ret; +} + +PackedStringArray ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const { + List constants; + ::ClassDB::get_enum_constants(p_class, p_enum, &constants, p_no_inheritance); + + PackedStringArray ret; + ret.resize(constants.size()); + int idx = 0; + for (const StringName &E : constants) { + ret.set(idx++, E); + } + + return ret; +} + +StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const { + return ::ClassDB::get_integer_constant_enum(p_class, p_name, p_no_inheritance); +} + bool ClassDB::is_class_enabled(StringName p_class) const { return ::ClassDB::is_class_enabled(p_class); } @@ -2072,6 +2108,11 @@ void ClassDB::_bind_methods() { ::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::has_integer_constant); ::ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &ClassDB::get_integer_constant); + ::ClassDB::bind_method(D_METHOD("class_has_enum", "class", "name", "no_inheritance"), &ClassDB::has_enum, DEFVAL(false)); + ::ClassDB::bind_method(D_METHOD("class_get_enum_list", "class", "no_inheritance"), &ClassDB::get_enum_list, DEFVAL(false)); + ::ClassDB::bind_method(D_METHOD("class_get_enum_constants", "class", "enum", "no_inheritance"), &ClassDB::get_enum_constants, DEFVAL(false)); + ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_enum", "class", "name", "no_inheritance"), &ClassDB::get_integer_constant_enum, DEFVAL(false)); + ::ClassDB::bind_method(D_METHOD("class_get_category", "class"), &ClassDB::get_category); ::ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &ClassDB::is_class_enabled); } diff --git a/core/core_bind.h b/core/core_bind.h index a6fac63edd..8e95629695 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -592,6 +592,11 @@ public: int get_integer_constant(const StringName &p_class, const StringName &p_name) const; StringName get_category(const StringName &p_node) const; + bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false) const; + PackedStringArray get_enum_list(const StringName &p_class, bool p_no_inheritance = false) const; + PackedStringArray get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance = false) const; + StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false) const; + bool is_class_enabled(StringName p_class) const; ClassDB() {} diff --git a/doc/classes/ClassDB.xml b/doc/classes/ClassDB.xml index 063233fe50..62165a5fce 100644 --- a/doc/classes/ClassDB.xml +++ b/doc/classes/ClassDB.xml @@ -30,6 +30,23 @@ Returns a category associated with the class for use in documentation and the Asset Library. Debug mode required. + + + + + + + Returns an array with all the keys in [code]enum[/code] of [code]class[/code] or its ancestry. + + + + + + + + Returns an array with all the enums of [code]class[/code] or its ancestry. + + @@ -38,6 +55,15 @@ Returns the value of the integer constant [code]name[/code] of [code]class[/code] or its ancestry. Always returns 0 when the constant could not be found. + + + + + + + Returns which enum the integer constant [code]name[/code] of [code]class[/code] or its ancestry belongs to. + + @@ -87,6 +113,15 @@ Returns an array with all the signals of [code]class[/code] or its ancestry if [code]no_inheritance[/code] is [code]false[/code]. Every element of the array is a [Dictionary] as described in [method class_get_signal]. + + + + + + + Returns whether [code]class[/code] or its ancestry has an enum called [code]name[/code] or not. + + -- cgit v1.2.3