From 4f5749b2a45313708f800e609abff971ba7e47b4 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Mon, 27 Jul 2020 04:13:39 +0500 Subject: Improved ChatComponent support #13 --- src/Chat.hpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 15 deletions(-) (limited to 'src/Chat.hpp') diff --git a/src/Chat.hpp b/src/Chat.hpp index 9ab5691..f9dde98 100644 --- a/src/Chat.hpp +++ b/src/Chat.hpp @@ -3,23 +3,83 @@ #include #include -struct TextModifier { - size_t offset; - size_t length; - enum { - Italic, - Bold, - Underline, - } type; + +struct ClickEvent { + enum ActionType { + NONE, + OPEN_URL, + OPEN_FILE, + RUN_COMMAND, + SUGGEST_COMMAND, + CHANGE_PAGE, + } action = NONE; + std::string value; +}; + +struct HoverEvent { + enum ActionType { + NONE, + SHOW_TEXT, + SHOW_ITEM, + SHOW_ENTITY, + SHOW_ACHIEVEMENT, + } action = NONE; + std::string value; }; -struct Chat { - std::vector modifiers; - std::string text; +struct Component { + enum ComponentType { + DEFAULT, + STRING, + TRANSLATION, + KEYBIND, + SCORE, + SELECTOR, + UNKNOWN, + } type = DEFAULT; + + bool isBold = false; + bool isItalic = false; + bool isUnderlined = false; + bool isStrikethrough = false; + bool isObfuscated = false; + std::string color; + std::string insertion; + ClickEvent clickEvent; + HoverEvent hoverEvent; + std::vector extra; + + //string component + std::string text; - Chat(const std::string &str); + //tranlation component + std::string translate; + std::vector with; - Chat() = default; + //keybind component + std::string keybind; + + //score component + struct { + std::string name; + std::string objective; + std::string value; + } score; + + //selector component + std::string selector; +}; - std::string ToJson() const; -}; \ No newline at end of file +class Chat { + Component component; + +public: + + Chat() = default; + + Chat(const std::string &json); + + std::string ToPlainText() const; + + std::string ToJson() const; +}; -- cgit v1.2.3