46 lines
912 B
C++
46 lines
912 B
C++
#pragma once
|
|
|
|
#include "boost/json.hpp"
|
|
|
|
namespace toid
|
|
{
|
|
class GameElement
|
|
{
|
|
public:
|
|
GameElement(double x, double y, double width, double height)
|
|
: x_(x), y_(y), width_(width), height_(height)
|
|
{
|
|
}
|
|
|
|
void start(double & x, double & y) const
|
|
{
|
|
x = this->x_;
|
|
y = this->y_;
|
|
}
|
|
|
|
void end(double & x, double & y) const
|
|
{
|
|
x = this->x_ + this->width_;
|
|
y = this->y_ + this->height_;
|
|
}
|
|
|
|
private:
|
|
double x_;
|
|
double y_;
|
|
double width_;
|
|
double height_;
|
|
};
|
|
|
|
inline GameElement tag_invoke(
|
|
boost::json::value_to_tag<GameElement>, boost::json::value const & jv)
|
|
{
|
|
auto const& obj = jv.as_object();
|
|
return GameElement{
|
|
boost::json::value_to<double>(obj.at("x")) - 1.5,
|
|
boost::json::value_to<double>(obj.at("y")) - 1.0,
|
|
boost::json::value_to<double>(obj.at("width")),
|
|
boost::json::value_to<double>(obj.at("height"))
|
|
};
|
|
}
|
|
|
|
} // namespace toid
|