feat: Add GetComponents(Mut) functions to Entity (#1842)

Allows for a really neat way of getting components using structured binding.  Tested that powerups still function

do it again because its neat
This commit is contained in:
David Markowitz
2025-07-01 05:26:05 -07:00
committed by GitHub
parent 9524198044
commit 5e9fe40bec
3 changed files with 21 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
#include <map>
#include <functional>
#include <tuple>
#include <typeinfo>
#include <type_traits>
#include <unordered_map>
@@ -161,6 +162,12 @@ public:
template<typename T>
T* GetComponent() const;
template<typename... T>
auto GetComponents() const;
template<typename... T>
auto GetComponentsMut() const;
template<typename T>
bool TryGetComponent(eReplicaComponentType componentId, T*& component) const;
@@ -579,3 +586,13 @@ inline ComponentType* Entity::AddComponent(VaArgs... args) {
// To allow a static cast here instead of a dynamic one.
return dynamic_cast<ComponentType*>(componentToReturn);
}
template<typename... T>
auto Entity::GetComponents() const {
return GetComponentsMut<const T...>();
}
template<typename... T>
auto Entity::GetComponentsMut() const {
return std::tuple{GetComponent<T>()...};
}