/****************************************************************************** * File - entity.h * Author - Joey Pollack * Date - 2022/05/23 (y/m/d) * Mod Date - 2022/05/23 (y/m/d) * Description - Provides functionality to work with world entities ******************************************************************************/ #ifndef LUNARIUM_ENTITY_H_ #define LUNARIUM_ENTITY_H_ #include #include #include namespace lunarium { class Entity { public: // TODO: Maybe change this to take the World instead of the registry Entity(entt::registry* r); Entity(entt::registry* r, LUUID uuid); // These component methods are based on methods from the Hazel engine, written by Cherno // https://github.com/TheCherno/Hazel/blob/dev/Hazel/src/Hazel/Scene/Entity.h template T& AddComponent(Args&&... args) { if (HasComponent()) { Log::Error(LogCategory::GAME_SYSTEM, "Entity already has component!"); return GetComponent(); } T& component = mpRegistry->emplace(mHandle, std::forward(args)...); //m_Scene->OnComponentAdded(*this, component); return component; } template T& GetComponent() { if (!HasComponent()) { Log::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); } return mpRegistry->get(mHandle); } template bool HasComponent() { return mpRegistry->all_of(mHandle); } template void RemoveComponent() { if (!HasComponent()) { Log::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); } m_Scene->m_Registry.remove(mHandle); } private: LUUID mUUID; entt::entity mHandle; entt::registry* mpRegistry; }; } #endif // LUNARIUM_ENTITY_H_