From 855970b4e533556aaf5799ca3641bcea4648d2ac Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 15 Oct 2025 22:53:44 +0200 Subject: [PATCH] feat: improved networkdata enum integration --- modules/you_done_it/ydi_networking.cpp | 3 -- modules/you_done_it/ydi_networking.h | 54 +++++++++++++++----------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/modules/you_done_it/ydi_networking.cpp b/modules/you_done_it/ydi_networking.cpp index 465bce8d..901326b0 100644 --- a/modules/you_done_it/ydi_networking.cpp +++ b/modules/you_done_it/ydi_networking.cpp @@ -3,9 +3,6 @@ #include #include -MAKE_TYPE_INFO(NetworkData::ClueID, Variant::INT); -MAKE_TYPE_INFO(NetworkData::ConnectionStatus, Variant::INT); - void NetworkData::_bind_methods() { BIND_ENUM_CONSTANT(CLUE_FIRST); BIND_ENUM_CONSTANT(CLUE_SECOND); diff --git a/modules/you_done_it/ydi_networking.h b/modules/you_done_it/ydi_networking.h index f922f0bf..fcb16394 100644 --- a/modules/you_done_it/ydi_networking.h +++ b/modules/you_done_it/ydi_networking.h @@ -8,36 +8,41 @@ #include #include +#define __VA_ARGS__STRING(...) String(#__VA_ARGS__) + +#define GDENUM(M_Name, ...) \ + enum M_Name { __VA_ARGS__ }; \ + static String M_Name##_hint() { \ + return __VA_ARGS__STRING(__VA_ARGS__); \ + } + class NetworkData : Object { GDCLASS(NetworkData, Object); static void _bind_methods(); public: - enum MessageType { - MSG_NONE = 0u, - // connection management messages - MSG_CONNECT = 1u, - MSG_OK, - MSG_NOK, - MSG_HEART, - MSG_BEAT, - // gameplay messages - MSG_REVEAL, - // end of messages - MSG_INVALID - }; + GDENUM(MessageType, + MSG_NONE, + // connection management messages + MSG_CONNECT, + MSG_OK, + MSG_NOK, + MSG_HEART, + MSG_BEAT, + // gameplay messages + MSG_REVEAL, + // end of messages + MSG_INVALID); - enum ClueID { - CLUE_FIRST, - CLUE_SECOND, - CLUE_MAX - }; + GDENUM(ClueID, + CLUE_FIRST, + CLUE_SECOND, + CLUE_MAX); - enum ConnectionStatus { - CONNECTION_DISCONNECTED, - CONNECTION_CONNECTED, - CONNECTION_AUTHENTICATED - }; + GDENUM(ConnectionStatus, + CONNECTION_DISCONNECTED, + CONNECTION_CONNECTED, + CONNECTION_AUTHENTICATED); enum NOKReason { NOK_UNAUTHENTICATED, //!< message sender is not known by recipient. @@ -48,6 +53,9 @@ public: }; }; +MAKE_TYPE_INFO(NetworkData::ClueID, Variant::INT); +MAKE_TYPE_INFO(NetworkData::ConnectionStatus, Variant::INT); + namespace ydi { int to_int(zmq::message_t const &msg, int failure = 0); NetworkData::MessageType to_message_type(zmq::message_t const &msg);