Skip to content

Commit

Permalink
ECS: Remove parallax json
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Oct 31, 2023
1 parent 3800b0b commit b78b003
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions libs/B-luga-graphics/include/B-luga-graphics/ParallaxSystems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,6 @@ namespace Systems::ParallaxSystems {
constexpr int maxOutParallaxLeft = -100;
constexpr int maxOutParallaxRight = 100;

static void initParallaxEntity(nlohmann::basic_json<> &elem, const int maxOffsideParallax = 0)
{
std::size_t id = Registry::getInstance().addEntity();
Raylib::Sprite parralax = {
Json::getInstance().getDataFromJson<std::string>(elem, "spritePath"),
Json::getInstance().getDataFromJson<float>(elem, "width"),
Json::getInstance().getDataFromJson<float>(elem, "height"),
id};

Types::Position position = Json::getInstance().getDataFromJson<Types::Position>(elem, "position");
Types::Velocity velocity = Json::getInstance().getDataFromJson<Types::Velocity>(elem, "velocity");

if (Json::getInstance().isDataExist(elem, "rect")) {
Types::Rect rect = Json::getInstance().getDataFromJson<Types::Rect>(elem, "rect");
Registry::getInstance().getComponents<Types::Rect>().insertBack((rect));
}

if (maxOffsideParallax > 0) {
Maths::addNormalIntToDecimalInt(position.x, maxOffsideParallax);
}
Types::Parallax inst = {
Maths::intToFloatConservingDecimals(position.x),
Maths::intToFloatConservingDecimals(position.y)};
Types::NoRemoveOutside noRem;

Registry::getInstance().getComponents<Types::NoRemoveOutside>().insertBack(noRem);
Registry::getInstance().getComponents<Raylib::Sprite>().insertBack(parralax);
Registry::getInstance().getComponents<Types::Position>().insertBack(position);
Registry::getInstance().getComponents<Types::Velocity>().insertBack(velocity);
Registry::getInstance().getComponents<Types::Parallax>().insertBack(inst);
Registry::getInstance().setToBackLayers(id);
}

void initParalax(std::size_t managerId, std::size_t systemId)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
std::vector<nlohmann::basic_json<>> parallaxData =
Json::getInstance().getDataByJsonType("parallax", JsonType::DEFAULT_PARALLAX);

for (auto &elem : parallaxData) {
initParallaxEntity(elem);
if (Json::getInstance().isDataExist(elem, "copy")
&& Json::getInstance().getDataFromJson<bool>(elem, "copy") == true) {
initParallaxEntity(elem, maxOutParallaxRight);
}
}
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}

static void resetParallaxPosition(
std::size_t id,
Registry::components<Types::Parallax> &arrParallax,
Expand Down Expand Up @@ -94,7 +45,6 @@ namespace Systems::ParallaxSystems {
std::vector<std::function<void(std::size_t, std::size_t)>> getParallaxSystems()
{
return {
initParalax,
manageParallax,
};
}
Expand Down

0 comments on commit b78b003

Please sign in to comment.