My Project
spec.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** B-CPP-500-PAR-5-1-rtype-martin.vanaud
4 ** File description:
5 ** spec
6 */
7 
8 #ifndef SPEC_HPP_
9  #define SPEC_HPP_
10 
11  #include <utility>
12  #include <nlohmann/json.hpp>
13 
14  #include "Serialization.hpp"
15 
19 struct spec_t {
20  spec_t(nlohmann::json const &jsonData) {
21  std::array<int, 2> directionData = jsonData.value("direction", std::array<int, 2>({0, 0}));
22  std::array<std::size_t, 2> hitboxData = jsonData.value("hitbox", std::array<std::size_t, 2>({0, 0}));
23  std::array<float, 2> rectData = jsonData.value("rect", std::array<float, 2>({0, 0}));
24  direction = {directionData.at(0), directionData.at(1)};
25  hitbox = {hitboxData.at(0), hitboxData.at(1)};
26  rect = {rectData.at(0), rectData.at(1)};
27  velocity = jsonData.value("velocity", 1);
28  type = static_cast<ENTITY_TYPE>(jsonData.value("type", 1));
29  health = jsonData.value("health", 1);
30  };
31  std::pair<int, int> direction;
32  std::pair<std::size_t, std::size_t> hitbox;
33  int velocity;
34  ENTITY_TYPE type;
35  std::pair<float, float> rect;
36  int health;
37 };
38 
39 #endif /* !SPEC_HPP_ */
spec_t
A structure representing the specs of an entity from configuration file.
Definition: spec.hpp:19