8 #ifndef JSONCONVERSION_HPP_
9 #define JSONCONVERSION_HPP_
10 #include <nlohmann/json.hpp>
28 const std::unordered_map<std::string, Key>
strKeyMap = {{
"A",
A}, {
"B",
B}, {
"C",
C}, {
"D",
D}, {
"E",
E}, {
"F",
F},
29 {
"G",
G}, {
"H",
H}, {
"I",
I}, {
"J",
J}, {
"K",
K}, {
"L",
L}, {
"M",
M}, {
"N",
N}, {
"O",
O}, {
"P",
P}, {
"Q",
Q},
30 {
"R",
R}, {
"S",
S}, {
"T",
T}, {
"U",
U}, {
"V",
V}, {
"W",
W}, {
"X",
X}, {
"Y",
Y}, {
"Z",
Z}, {
"Num0",
Num0},
31 {
"Num1",
Num1}, {
"Num2",
Num2}, {
"Num3",
Num3}, {
"Num4",
Num4}, {
"Num5",
Num5}, {
"Num6",
Num6}, {
"Num7",
Num7},
32 {
"Num8",
Num8}, {
"Num9",
Num9}, {
"Escape",
Escape}, {
"LControl",
LControl}, {
"LShift",
LShift}, {
"LAlt",
LAlt},
33 {
"LSystem",
LSystem}, {
"RControl",
RControl}, {
"RShift",
RShift}, {
"RAlt",
RAlt}, {
"RSystem",
RSystem},
34 {
"Menu",
Menu}, {
"LBracket",
LBracket}, {
"RBracket",
RBracket}, {
"Semicolon",
Semicolon}, {
"Comma",
Comma},
35 {
"Period",
Period}, {
"Quote",
Quote}, {
"Slash",
Slash}, {
"Backslash",
Backslash}, {
"Tilde",
Tilde},
36 {
"Equal",
Equal}, {
"Dash",
Dash}, {
"Space",
Space}, {
"Enter",
Enter}, {
"Backspace",
Backspace}, {
"Tab",
Tab},
37 {
"Add",
Add}, {
"Subtract",
Subtract}, {
"Multiply",
Multiply}, {
"Divide",
Divide}, {
"Left",
Left},
38 {
"Right",
Right}, {
"Up",
Up}, {
"Down",
Down}, {
"Numpad0",
Numpad0}, {
"Numpad1",
Numpad1}, {
"Numpad2",
Numpad2},
39 {
"Numpad3",
Numpad3}, {
"Numpad4",
Numpad4}, {
"Numpad5",
Numpad5}, {
"Numpad6",
Numpad6}, {
"Numpad7",
Numpad7},
40 {
"Numpad8",
Numpad8}, {
"Numpad9",
Numpad9}, {
"F1",
F1}, {
"F2",
F2}, {
"F3",
F3}, {
"F4",
F4}, {
"F5",
F5},
41 {
"F6",
F6}, {
"F7",
F7}, {
"F8",
F8}, {
"F9",
F9}, {
"F10",
F10}, {
"F11",
F11}, {
"F12",
F12}, {
"F13",
F13},
52 auto str = j.get<std::string>();
63 j.at(
"left").get_to(rect.
left);
64 j.at(
"top").get_to(rect.
top);
65 j.at(
"width").get_to(rect.
width);
66 j.at(
"height").get_to(rect.
height);
72 j.at(
"x").get_to(vec.
x);
73 j.at(
"y").get_to(vec.
y);
80 std::string path(j.at(
"path").get<std::string>());
82 j.at(
"area").get_to(area);
83 texture.
load(path, area);
91 j.at(
"position").get_to(tc.
position);
92 j.at(
"velocity").get_to(tc.
velocity);
100 hc.
health = j.contains(
"health") ? j.at(
"health").get<
int>() : 5;
117 j.at(
"speed").get_to(cc.
speed);
125 j.at(
"texturePath").get_to(tc.
path);
127 tc.
animated = j.contains(
"animated") ? j.at(
"animated").get<
bool>() :
false;
128 for (
auto &trect : j.at(
"textureRects"))
130 tc.
animationSpeed = j.contains(
"animationSpeed") ? j.at(
"animationSpeed").get<
float>() : 0.0f;
131 tc.
isRendered = j.contains(
"isRendered") ? j.at(
"isRendered").get<
bool>() :
true;
132 tc.
lastUpdate = j.contains(
"lastUpdate") ? j.at(
"lastUpdate").get<
float>() : 0.0f;
142 j.at(
"collider").get_to(cc.
collider);
143 j.at(
"layer").get_to(cc.
layer);
144 cc.
isActive = j.contains(
"isActive") ? j.at(
"isActive").get<
bool>() :
true;
153 j.at(
"isActive").get_to(gc.
isActive);
163 if (j.contains(
"cameraViewport")) {
167 if (j.contains(
"follow_x"))
168 j.at(
"follow_x").get_to(cc.
follow_x);
169 if (j.contains(
"follow_y"))
170 j.at(
"follow_y").get_to(cc.
follow_y);
171 if (j.contains(
"isActive"))
172 j.at(
"isActive").get_to(cc.
isActive);
178 j.at(
"str").get_to(tx.
str);
179 j.at(
"size").get_to(tx.
size);
180 j.at(
"fontPath").get_to(tx.
fontPath);
181 tx.
isRendered = j.contains(
"isRendered") ? j.at(
"isRendered").get<
bool>() :
true;
nlohmann::json json
Definition: JsonConversion.hpp:24
nlohmann::json json
Definition: PrefabManager.hpp:20
class representing a rect
Definition: Rect.hpp:25
T height
Definition: Rect.hpp:40
T top
Definition: Rect.hpp:38
T left
Definition: Rect.hpp:37
T width
Definition: Rect.hpp:39
Class representing a text wrapper for sf::Text with basic functionality.
Definition: SfmlTypes.hpp:224
Class representing a texture wrapper for sf::Texture with an associated area.
Definition: SfmlTypes.hpp:58
void load(const std::string &filename, const IRect< int, sf::Rect > &area) override
Loads a texture from a file with a specified area.
Definition: SfmlTypes.hpp:70
a Vector2 class
Definition: Vector.hpp:20
T y
Definition: Vector.hpp:101
T x
Definition: Vector.hpp:98
Class representing a view wrapper for sf::View.
Definition: SfmlTypes.hpp:81
void setViewPort(const Vector2< float > &startingPoint, float width, float height) override
set a viewport rectangle
Definition: SfmlTypes.hpp:107
Definition: AssetManager.hpp:15
void from_json(const json &j, Input::Keyboard::Key &key)
Function to convert a json object to a key.
Definition: JsonConversion.hpp:50
Definition: CameraComponent.hpp:17
bool follow_y
Definition: CameraComponent.hpp:21
bool isActive
Definition: CameraComponent.hpp:22
View view
Definition: CameraComponent.hpp:18
bool follow_x
Definition: CameraComponent.hpp:20
Definition: CollisionComponent.hpp:17
std::size_t layer
Definition: CollisionComponent.hpp:20
Rectf collider
Definition: CollisionComponent.hpp:18
bool isActive
Definition: CollisionComponent.hpp:21
Definition: ControllableComponent.hpp:15
float speed
Definition: ControllableComponent.hpp:20
Input::Keyboard::Key key_right
Definition: ControllableComponent.hpp:19
Input::Keyboard::Key key_left
Definition: ControllableComponent.hpp:17
Input::Keyboard::Key key_down
Definition: ControllableComponent.hpp:18
Input::Keyboard::Key key_up
Definition: ControllableComponent.hpp:16
Definition: DamageComponent.hpp:16
std::size_t damage
Definition: DamageComponent.hpp:17
Definition: GravityComponent.hpp:15
Vector2< float > gravityForce
Definition: GravityComponent.hpp:16
bool isActive
Definition: GravityComponent.hpp:18
Definition: HealthComponent.hpp:16
int health
Definition: HealthComponent.hpp:17
Definition: TextComponent.hpp:17
size_t size
Definition: TextComponent.hpp:20
Text text
Definition: TextComponent.hpp:21
std::string str
Definition: TextComponent.hpp:18
bool isRendered
Definition: TextComponent.hpp:22
std::string fontPath
Definition: TextComponent.hpp:19
size_t renderLayer
Definition: TextComponent.hpp:23
Definition: TextureComponent.hpp:16
size_t renderLayer
Definition: TextureComponent.hpp:26
bool animated
Definition: TextureComponent.hpp:19
float animationSpeed
Definition: TextureComponent.hpp:22
std::vector< Rect< int > > textureRects
Definition: TextureComponent.hpp:21
float lastUpdate
Definition: TextureComponent.hpp:24
Rect< int > textureSize
Definition: TextureComponent.hpp:20
size_t animeid
Definition: TextureComponent.hpp:25
std::string path
Definition: TextureComponent.hpp:17
bool isRendered
Definition: TextureComponent.hpp:23