mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
add files that should have been pushed with last commit
oops
This commit is contained in:
37
state.cpp
Normal file
37
state.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "state.hpp"
|
||||
|
||||
void to_json(nlohmann::json &j, const ExpansionStateRoot &m) {
|
||||
if (m.Children.empty()) {
|
||||
j = nlohmann::json::object();
|
||||
} else {
|
||||
for (const auto &[id, state] : m.Children)
|
||||
j[std::to_string(id)] = state;
|
||||
}
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, ExpansionStateRoot &m) {
|
||||
for (const auto &[key, value] : j.items())
|
||||
m.Children[key] = value;
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const ExpansionState &m) {
|
||||
j["e"] = m.IsExpanded;
|
||||
j["c"] = m.Children;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, ExpansionState &m) {
|
||||
j.at("e").get_to(m.IsExpanded);
|
||||
j.at("c").get_to(m.Children);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const AbaddonApplicationState &m) {
|
||||
j["active_channel"] = m.ActiveChannel;
|
||||
j["expansion"] = m.Expansion;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, AbaddonApplicationState &m) {
|
||||
if (j.contains("active_channel"))
|
||||
j.at("active_channel").get_to(m.ActiveChannel);
|
||||
if (j.contains("expansion"))
|
||||
j.at("expansion").get_to(m.Expansion);
|
||||
}
|
||||
27
state.hpp
Normal file
27
state.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "discord/snowflake.hpp"
|
||||
|
||||
struct ExpansionState;
|
||||
struct ExpansionStateRoot {
|
||||
std::map<Snowflake, ExpansionState> Children;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const ExpansionStateRoot &m);
|
||||
friend void from_json(const nlohmann::json &j, ExpansionStateRoot &m);
|
||||
};
|
||||
|
||||
struct ExpansionState {
|
||||
bool IsExpanded;
|
||||
ExpansionStateRoot Children;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const ExpansionState &m);
|
||||
friend void from_json(const nlohmann::json &j, ExpansionState &m);
|
||||
};
|
||||
|
||||
struct AbaddonApplicationState {
|
||||
Snowflake ActiveChannel;
|
||||
ExpansionStateRoot Expansion;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const AbaddonApplicationState &m);
|
||||
friend void from_json(const nlohmann::json &j, AbaddonApplicationState &m);
|
||||
};
|
||||
Reference in New Issue
Block a user