-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.h
104 lines (99 loc) · 2.44 KB
/
Entity.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once
#include <json.hpp>
#include <map>
// The order of the definitions is relevant for compiling (Classes have to be defined before they are used)
namespace Entity
{
class Reward {
public:
Reward(const nlohmann::json& json)
{
name = json["name"];
type = json["type"];
id = json["id"];
on_event = json["on_event"];
once = json["once"];
if (json.find("data") != json.end()) {
nlohmann::json jsonData = json["data"]; // CHeck if data exists
for (auto it = jsonData.begin(); it != jsonData.end(); ++it) {
data[it.key()] = it.value().get<std::string>();
}
}
}
std::string name, type, id, on_event;
std::map<std::string, std::string> data;
bool once;
};
class Packet {
public:
Packet(const nlohmann::json& json)
{
id = json["id"];
title = json["title"];
}
std::string id, title;
};
class Purchase {
public:
Purchase(const nlohmann::json& json)
{
id = json["id"];
amount_text = json["amount_text"];
}
std::string id, amount_text;
};
class AppliedPacket {
public:
AppliedPacket(const nlohmann::json& json) : id(json["id"]), packet(json["packet"]) {
auto purchaseField = json.find("purchase");
if (purchaseField != json.end() && !purchaseField->is_null()) {
purchase = std::make_unique<Purchase>(*purchaseField); // Purchase exists
}
else {
purchase = nullptr; // Assuming Purchase has a default constructor
}
}
std::string id;
Packet packet;
std::shared_ptr<Purchase> purchase;
};
class AppliedReward {
public:
AppliedReward(const nlohmann::json& json): id(json["id"]), applied_packet_id(json["applied_packet_id"]), reward(json["reward"]), applied_packet(json["applied_packet"]) {}
std::string id, applied_packet_id;
Reward reward;
AppliedPacket applied_packet;
};
class Server {
public:
Server(const nlohmann::json& json)
{
id = json["id"];
name = json["name"];
serverbundle_id = json["serverbundle_id"];
extra = json["extra"];
}
std::string id, name, serverbundle_id, extra;
};
class VyHubUser {
public:
VyHubUser(const nlohmann::json& json)
{
id = json["id"];
type = json["type"];
identifier = json["identifier"];
registered_on = json["registered_on"];
username = json["username"];
avatar = json["avatar"];
}
std::string id, type, identifier, registered_on, username, avatar;
};
class Definition {
public:
Definition(const nlohmann::json& json)
{
id = json["id"];
}
std::string id;
};
}