componets json with defaults, minor formatting

This commit is contained in:
Green Sky 2022-11-26 13:48:52 +01:00
parent ab0e5afb94
commit 5148ea7217
No known key found for this signature in database
18 changed files with 24 additions and 23 deletions

View File

@ -4,7 +4,7 @@
namespace MM::Components {
struct Name {
static const size_t max_str_len = 64;
static const size_t max_str_len {64u};
std::string str;
};
}

View File

@ -4,7 +4,7 @@ namespace MM::Components {
// used to lift 2D into 3D space. like a z-index in css/svg
struct Position2D_ZOffset {
float z_offset = 500.f; // default camera allows values to be between 0 and 1000
float z_offset {500.f}; // default camera allows values to be between 0 and 1000
};
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Color, color)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Color, color)
} // MM::Components

View File

@ -9,12 +9,12 @@
namespace glm {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec2, x, y)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec3, x, y, z)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec4, x, y, z, w)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec2, x, y)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec3, x, y, z)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec4, x, y, z, w)
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(mat4x4, [0], y, z, w)
inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) {
inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) {
// TODO: make 2d array?
nlohmann_json_j = nlohmann::json::array_t{};
nlohmann_json_j[0] = nlohmann_json_t[0];
@ -22,7 +22,7 @@ namespace glm {
nlohmann_json_j[2] = nlohmann_json_t[2];
nlohmann_json_j[3] = nlohmann_json_t[3];
}
inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) {
inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) {
if (!nlohmann_json_j.is_array()) {
//throw nlohmann::json::type_error::create(0, "", nlohmann_json_j);
assert(false && "expected array");

View File

@ -5,6 +5,7 @@
#include <mm/components/name.hpp>
namespace MM::Components {
// TODO: manual with str len limit
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Name, str)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D, pos)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D, pos)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D_ZOffset, z_offset)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D_ZOffset, z_offset)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position3D, pos)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position3D, pos)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rotation2D, rot)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Rotation2D, rot)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Scale2D, scale)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Scale2D, scale)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform4x4, trans)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Transform4x4, trans)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPosition, pos_vel)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPosition, pos_vel)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPositionIntent, intent)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPositionIntent, intent)
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DRotation, rot_vel)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DRotation, rot_vel)
} // MM::Components

View File

@ -5,6 +5,6 @@
#include <mm/components/view_dir2d.hpp>
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir2D, dir)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir2D, dir)
} // MM::Components

View File

@ -5,6 +5,6 @@
#include <mm/components/view_dir3d.hpp>
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir3D, yaw, pitch, roll)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir3D, yaw, pitch, roll)
} // MM::Components

View File

@ -3,7 +3,7 @@
namespace MM::Components {
struct ViewDir2D {
float dir = 0.f; // rad
float dir {0.f}; // rad
};
} // MM::Components

View File

@ -3,9 +3,9 @@
namespace MM::Components {
struct ViewDir3D {
float yaw = 0.f; // rad
float pitch = 0.f; // rad
float roll = 0.f; // rad
float yaw {0.f}; // rad
float pitch {0.f}; // rad
float roll {0.f}; // rad
};
} // MM::Components