commit 0230e4e1098bbf9d4d28bc6ff4174d1c8051d140 Author: Sara Date: Tue Jan 30 10:36:58 2024 +0100 feat: added godot_macros.h diff --git a/godot_macros.h b/godot_macros.h new file mode 100644 index 0000000..708ea53 --- /dev/null +++ b/godot_macros.h @@ -0,0 +1,31 @@ +#ifndef UC_GODOT_MACROS_H +#define UC_GODOT_MACROS_H + +#define MACRO_STRING_INNER(_Arg) #_Arg +#define MACRO_STRING(_Arg) MACRO_STRING_INNER(_Arg) + +#define GDPROPERTY(_PropName, _PropType) \ + ClassDB::bind_method(D_METHOD("get_" #_PropName), &CLASSNAME::get_##_PropName); \ + ClassDB::bind_method(D_METHOD("set_" #_PropName, "value"), &CLASSNAME::set_##_PropName); \ + ClassDB::add_property(MACRO_STRING(CLASSNAME), PropertyInfo(_PropType, #_PropName), "set_" #_PropName, \ + "get_" #_PropName) + +#define GDPROPERTY_HINTED(_PropName, _PropType, ...) \ + ClassDB::bind_method(D_METHOD("get_" #_PropName), &CLASSNAME::get_##_PropName); \ + ClassDB::bind_method(D_METHOD("set_" #_PropName, "value"), &CLASSNAME::set_##_PropName); \ + ClassDB::add_property(MACRO_STRING(CLASSNAME), PropertyInfo(_PropType, #_PropName, __VA_ARGS__), \ + "set_" #_PropName, "get_" #_PropName) + +#define GDFUNCTION(_FnName) ClassDB::bind_method(D_METHOD(#_FnName), &CLASSNAME::_FnName) + +#define GDFUNCTION_ARGS(_FnName, ...) ClassDB::bind_method(D_METHOD(#_FnName, __VA_ARGS__), &CLASSNAME::_FnName) + +#define GDFUNCTION_STATIC(_FnName) \ + ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), D_METHOD(#_FnName), &CLASSNAME::_FnName) + +#define GDFUNCTION_STATIC_ARGS(_FnName, ...) \ + ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), D_METHOD(#_FnName, __VA_ARGS__), &CLASSNAME::_FnName) + +#define GDRESOURCETYPE(_Class) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, #_Class) + +#endif // !UC_GODOT_MACROS_H