godot-cpp-utils
A collection of utility classes, functions and macros for use with Godot and GDExtension.
Loading...
Searching...
No Matches
godot_macros.h
Go to the documentation of this file.
1#ifndef UC_GODOT_MACROS_H
2#define UC_GODOT_MACROS_H
3
8#include "godot_cpp/classes/engine.hpp"
9#include "godot_cpp/core/class_db.hpp"
10#include "godot_cpp/variant/string.hpp"
11
12
13#define MACRO_STRING_INNER(_Arg) #_Arg
14#define MACRO_STRING(_Arg) MACRO_STRING_INNER(_Arg)
15
22#define GDPROPERTY(PropName_, PropType_) \
23 godot::ClassDB::bind_method(godot::D_METHOD("get_" #PropName_), &CLASSNAME::get_##PropName_); \
24 godot::ClassDB::bind_method(godot::D_METHOD("set_" #PropName_, "value"), &CLASSNAME::set_##PropName_); \
25 godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_), "set_" #PropName_, "get_" #PropName_)
26
33#define GDPROPERTY_HINTED(PropName_, PropType_, ...) \
34 godot::ClassDB::bind_method(godot::D_METHOD("get_" #PropName_), &CLASSNAME::get_##PropName_); \
35 godot::ClassDB::bind_method(godot::D_METHOD("set_" #PropName_, "value"), &CLASSNAME::set_##PropName_); \
36 godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_, __VA_ARGS__), "set_" #PropName_, "get_" #PropName_)
37
44#define GDFUNCTION(FnName_) godot::ClassDB::bind_method(godot::D_METHOD(#FnName_), &CLASSNAME::FnName_)
45
52#define GDFUNCTION_ARGS(FnName_, ...) godot::ClassDB::bind_method(godot::D_METHOD(#FnName_, __VA_ARGS__), &CLASSNAME::FnName_)
53
60#define GDFUNCTION_STATIC(FnName_) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#FnName_), &CLASSNAME::_FnName)
61
68#define GDFUNCTION_STATIC_ARGS(FnName_, ...) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#FnName_, __VA_ARGS__), &CLASSNAME::FnName_)
69
75#define GDSIGNAL(...) godot::ClassDB::add_signal(MACRO_STRING(CLASSNAME), godot::MethodInfo(__VA_ARGS__))
76
82#define GDRESOURCETYPE(Class_) godot::vformat("%s/%s:%s", godot::Variant::OBJECT, godot::PROPERTY_HINT_RESOURCE_TYPE, #Class_)
83
89#define GDEDITORONLY() if(!godot::Engine::get_singleton()->is_editor_hint()) return;
95#define GDGAMEONLY() if(godot::Engine::get_singleton()->is_editor_hint()) return;
96
102#define GDENUM(Name_, ...) struct Name_ {\
103 enum Value {__VA_ARGS__};\
104 private:\
105 Value value{};\
106 public:\
107 static inline godot::String get_property_hint() { return godot::String(#__VA_ARGS__); }\
108 inline Name_(Value value): value{value} {}\
109 inline Name_(Name_ const &value): value{value.value} {}\
110}
111
112#endif // !UC_GODOT_MACROS_H