summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-14 02:47:07 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-14 02:47:07 +0100
commitc9ee4387c330fa257a5e682f542feb4329475200 (patch)
treef25f587687fe250fde7774b9ba2e9c8bdb428529 /src
parentFixed chat error (diff)
downloadAltCraft-c9ee4387c330fa257a5e682f542feb4329475200.tar
AltCraft-c9ee4387c330fa257a5e682f542feb4329475200.tar.gz
AltCraft-c9ee4387c330fa257a5e682f542feb4329475200.tar.bz2
AltCraft-c9ee4387c330fa257a5e682f542feb4329475200.tar.lz
AltCraft-c9ee4387c330fa257a5e682f542feb4329475200.tar.xz
AltCraft-c9ee4387c330fa257a5e682f542feb4329475200.tar.zst
AltCraft-c9ee4387c330fa257a5e682f542feb4329475200.zip
Diffstat (limited to '')
-rw-r--r--src/Chat.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/Chat.cpp b/src/Chat.cpp
index 0857d6c..193c1fd 100644
--- a/src/Chat.cpp
+++ b/src/Chat.cpp
@@ -1,33 +1,29 @@
#include "Chat.hpp"
#include <nlohmann/json.hpp>
-#include <easylogging++.h>
-Chat::Chat(const std::string &str) {
- using nlohmann::json;
- json j = json::parse(str);
+using nlohmann::json;
- /*LOG(WARNING) << j.dump(4);
+void Recursive(const json::iterator &iter, bool isIterObj, std::string &str) {
+ if (isIterObj && iter.key() == "text") {
+ str.append(iter->get<std::string>() + " ");
+ }
- std::function<void(json::iterator)> iterating = [&](json::iterator iter) {
- json val = *iter;
+ if (iter->is_structured()) {
+ for (json::iterator it = iter->begin(); it != iter->end(); ++it)
+ Recursive(it, iter->is_object(), str);
+ }
+}
- if (val.is_object() && val.find("text") != val.end()) {
- text.append(val["text"].get<std::string>());
- }
+Chat::Chat(const std::string &str) {
+ json j = json::parse(str);
- if (val.is_array() || val.is_object()) {
- for (auto it = val.begin(); it != val.end(); ++it) {
- iterating(it);
- }
+ if (j["translate"] == "chat.type.text") {
+ text = j["with"][0]["text"].get<std::string>() + ": " + j["with"][1].get<std::string>();
+ } else
+ for (json::iterator it = j.begin(); it != j.end(); ++it) {
+ Recursive(it, j.is_object(), text);
}
- };
-
- for (auto it = j.begin(); it != j.end(); ++it) {
- iterating(it);
- }*/
-
- text = j.dump(4);
}
std::string Chat::ToJson() const {