godot-cpp-utils
A collection of utility classes, functions and macros for use with Godot and GDExtension.
Loading...
Searching...
No Matches
godot_macros.h
1#ifndef UC_GODOT_MACROS_H
2#define UC_GODOT_MACROS_H
3
5
6#include "godot_cpp/classes/engine.hpp"
7#include "godot_cpp/core/class_db.hpp"
8#include "godot_cpp/variant/string.hpp"
9
10
11#define MACRO_STRING_INNER(_Arg) #_Arg
12#define MACRO_STRING(_Arg) MACRO_STRING_INNER(_Arg)
13
19#define GDPROPERTY(PropName_, PropType_) \
20 godot::ClassDB::bind_method(godot::D_METHOD("get_" #PropName_), &CLASSNAME::get_##PropName_); \
21 godot::ClassDB::bind_method(godot::D_METHOD("set_" #PropName_, "value"), &CLASSNAME::set_##PropName_); \
22 godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_), "set_" #PropName_, "get_" #PropName_)
23
29#define GDPROPERTY_HINTED(PropName_, PropType_, ...) \
30 godot::ClassDB::bind_method(godot::D_METHOD("get_" #PropName_), &CLASSNAME::get_##PropName_); \
31 godot::ClassDB::bind_method(godot::D_METHOD("set_" #PropName_, "value"), &CLASSNAME::set_##PropName_); \
32 godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_, __VA_ARGS__), "set_" #PropName_, "get_" #PropName_)
33
39#define GDFUNCTION(_FnName) godot::ClassDB::bind_method(godot::D_METHOD(#_FnName), &CLASSNAME::_FnName)
40
46#define GDFUNCTION_ARGS(_FnName, ...) godot::ClassDB::bind_method(godot::D_METHOD(#_FnName, __VA_ARGS__), &CLASSNAME::_FnName)
47
53#define GDFUNCTION_STATIC(_FnName) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#_FnName), &CLASSNAME::_FnName)
54
60#define GDFUNCTION_STATIC_ARGS(_FnName, ...) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#_FnName, __VA_ARGS__), &CLASSNAME::_FnName)
61
66#define GDSIGNAL(...) godot::ClassDB::add_signal(MACRO_STRING(CLASSNAME), godot::MethodInfo(__VA_ARGS__))
67
72#define GDRESOURCETYPE(_Class) godot::vformat("%s/%s:%s", godot::Variant::OBJECT, godot::PROPERTY_HINT_RESOURCE_TYPE, #_Class)
73
78#define GDEDITORONLY() if(!godot::Engine::get_singleton()->is_editor_hint()) return;
83#define GDGAMEONLY() if(godot::Engine::get_singleton()->is_editor_hint()) return;
84
89#define GDENUM(Name_, ...) struct Name_ {\
90 enum Value {__VA_ARGS__};\
91 private:\
92 Value value{};\
93 public:\
94 static inline godot::String get_property_hint() { return godot::String(#__VA_ARGS__); }\
95 inline Name_(Value value): value{value} {}\
96 inline Name_(Name_ const &value): value{value.value} {}\
97}
98
99#endif // !UC_GODOT_MACROS_H