diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index 36b898dc..eb5c0880 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -6,7 +6,6 @@ */ #include "DeathSystems.hpp" -#include #include #include #include "CustomTypes.hpp" @@ -14,47 +13,40 @@ namespace Systems { - // REPLACE BY YOUR DEATH FUNCTION + const std::function setPlayerAnimRectToDeath = [](std::size_t id) { + Registry::components arrAnimRect = + Registry::getInstance().getComponents(); - const std::function testFuncPlayer = [](std::size_t id) { - std::cout << "Player " << id << " is dead" << std::endl; + if (arrAnimRect.exist(id)) { + Types::AnimRect &anim = arrAnimRect[id]; + if (anim.currentRectList != Types::RectListType::DEAD) { + anim.changeRectList(Types::RectListType::DEAD); + } + } }; - // MAP FOR DEATH FUNCTIONS + // MAP FOR DEATH FUNCTIONS FOR EACH ENTITY const std::unordered_map> deathFunctions = { - {std::type_index(typeid(Types::Player)), testFuncPlayer}, + {std::type_index(typeid(Types::Player)), setPlayerAnimRectToDeath}, }; - static void addDeathFunction( - Registry::components &arrDead, - Registry::components &arrPlayer, - std::size_t id) - { - try { - if (arrPlayer.exist(id)) { - arrDead[id].deathFunction = - deathFunctions.at(std::type_index(typeid(Types::Player))); - } - } catch (std::out_of_range &) { - std::cerr << "No death function for this entity" << std::endl; - } - } - void DeathSystems::setEntityDeathFunction( std::size_t /*unused*/, std::size_t /*unused*/) { Registry::components arrDead = Registry::getInstance().getComponents(); - Registry::components arrPlayer = - Registry::getInstance().getComponents(); std::vector ids = arrDead.getExistingsId(); - for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { - if (arrDead[*itIds].deathFunction == std::nullopt) { - addDeathFunction(arrDead, arrPlayer, *itIds); + for (const auto& [typeIndex, function] : deathFunctions) { + std::vector entities = + Registry::getInstance().getEntitiesByComponents({typeIndex}); + for (std::size_t id : entities) { + if (arrDead.exist(id) && arrDead[id].deathFunction == std::nullopt) { + arrDead[id].deathFunction = function; + } } } }