Skip to content

Commit

Permalink
ECS: Add current progress
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeAbel committed Nov 3, 2023
1 parent ef67940 commit 562bfde
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Client/Systems/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@ namespace Menu {

static void initFromSprite(nlohmann::json &elem)
{
Logger::fatal("start initFromSprite");
Types::SpriteDatas spriteDatas(
Json::getInstance().getDataFromJson<std::string>(elem, "spritePath"),
Json::getInstance().getDataFromJson<int>(elem, "width"),
Json::getInstance().getDataFromJson<int>(elem, "height"),
FRONTLAYER,
static_cast<std::size_t>(FRONT));
Logger::fatal("initFromSprite2");
Types::Rect rect = {Types::Rect(Json::getInstance().getDataFromJson<Types::Rect>(elem, "rect"))};
nlohmann::basic_json<> animRectData =
Json::getInstance().getDataFromJson<nlohmann::basic_json<>>(elem, "animRect");
Logger::fatal("initFromSprite2");
Types::AnimRect animRect(rect, animRectData);
Registry::getInstance().getComponents<Types::AnimRect>().insertBack(animRect);
Logger::fatal("initFromSprite3");
Registry::getInstance().getComponents<Types::SpriteDatas>().insertBack(spriteDatas);
Logger::fatal("initFromSprite4");
Registry::getInstance().getComponents<Types::Rect>().insertBack(rect);
Logger::fatal("end initFromSprite");
}

static void initInputBox(nlohmann::json &elem)
{
Logger::fatal("start initInputBox");
std::size_t id = Registry::getInstance().addEntity();

Types::Position position(Json::getInstance().getDataFromJson<Types::Position>(elem, "position"));
Expand Down Expand Up @@ -77,13 +84,16 @@ namespace Menu {
Registry::getInstance().getComponents<Types::InputBox>().insertBack(inputBox);
Registry::getInstance().getComponents<Types::Position>().insertBack(position);
Registry::getInstance().getComponents<Types::CollisionRect>().insertBack(collisionRect);
Logger::fatal("end initInputBox");
}

static void initButtonFromSprite(nlohmann::json &elem, std::function<void()> &callback)
{
Logger::fatal("start initButtonFromSprite");
nlohmann::basic_json<> animRectData =
Json::getInstance().getDataFromJson<nlohmann::basic_json<>>(elem, "animRect");
Types::Button button(callback);
Logger::fatal("initButtonFromSprite2");

Registry::getInstance().addEntity();
Types::SpriteDatas spriteDatas(
Expand All @@ -92,23 +102,29 @@ namespace Menu {
Json::getInstance().getDataFromJson<int>(elem, "height"),
FRONTLAYER,
static_cast<std::size_t>(FRONT));
Logger::fatal("initButtonFromSprite3");
Types::Rect rect = {Types::Rect(Json::getInstance().getDataFromJson<Types::Rect>(elem, "rect"))};
Types::Position position = {
Types::Position(Json::getInstance().getDataFromJson<Types::Position>(elem, "position"))};
Types::CollisionRect collisionRect = {Types::CollisionRect(
Json::getInstance().getDataFromJson<Types::CollisionRect>(elem, "collisionRect"))};
Logger::fatal("initButtonFromSprite4");
Types::AnimRect animRect(rect, animRectData, Types::RectListType::MOVE);
Logger::fatal("initButtonFromSprite5");

Registry::getInstance().getComponents<Types::Position>().insertBack(position);
Registry::getInstance().getComponents<Types::Rect>().insertBack(rect);
Registry::getInstance().getComponents<Types::AnimRect>().insertBack(animRect);
Logger::fatal("initButtonFromSprite6");
Registry::getInstance().getComponents<Types::CollisionRect>().insertBack(collisionRect);
Registry::getInstance().getComponents<Types::SpriteDatas>().insertBack(spriteDatas);
Registry::getInstance().getComponents<Types::Button>().insertBack(button);
Logger::fatal("end initButtonFromSprite");
}

static void initButtonFromRectangle(nlohmann::json &elem, std::function<void()> &callback)
{
Logger::fatal("start initButtonFromRect");
std::size_t id = Registry::getInstance().addEntity();

Types::Position position = {
Expand All @@ -124,25 +140,30 @@ namespace Menu {
Registry::getInstance().getComponents<Types::CollisionRect>().insertBack(collisionRect);
Registry::getInstance().getComponents<Types::Button>().insertBack(button);
Registry::getInstance().setToFrontLayers(id);
Logger::fatal("end initButtonFromRect");
}

static void initButton(nlohmann::json &elem, std::function<void()> &callback)
{
Logger::fatal("start initButton");
if (Json::isDataExist(elem, "spritePath")) {
initButtonFromSprite(elem, callback);
} else {
initButtonFromRectangle(elem, callback);
}
Logger::fatal("end initButton");
}

void MenuBuilder::initMenuEntity(nlohmann::json &elem, std::function<void()> callback)
{
Logger::fatal("start initMenuEntity");
switch (Json::getInstance().getDataFromJson<ObjectType>(elem, "type")) {
case ObjectType::BUTTON: initButton(elem, callback); break;
case ObjectType::TEXT: break; // no clickable text for now
case ObjectType::INPUT_BOX: initInputBox(elem); break;
default: Logger::error("Object type is undefined, check your json data"); break;
}
Logger::fatal("end initMenuEntity");
}

bool checkClick(std::size_t &idEntity)
Expand Down

0 comments on commit 562bfde

Please sign in to comment.