mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-21 13:55:10 +00:00
Making block solids
This commit is contained in:
@@ -79,6 +79,32 @@ namespace WAL
|
||||
return static_cast<T *>(existing->second.get());
|
||||
}
|
||||
|
||||
//! @brief Get a component of a specific type
|
||||
//! @tparam The type of the component
|
||||
//! @throw NotFoundError if the component could not be found
|
||||
//! @return The component of the requested type.
|
||||
template<typename T>
|
||||
const T &getComponent() const
|
||||
{
|
||||
const T *ret = this->tryGetComponent<T>();
|
||||
if (ret == nullptr)
|
||||
throw NotFoundError("No component could be found with the type \"" + std::string(typeid(T).name()) + "\".");
|
||||
return *ret;
|
||||
}
|
||||
|
||||
//! @brief Get a component of a specific type or null if not found.
|
||||
//! @tparam The type of the component
|
||||
//! @return The component or nullptr if not found.
|
||||
template<typename T>
|
||||
const T *tryGetComponent() const
|
||||
{
|
||||
const std::type_index &type = typeid(T);
|
||||
auto existing = this->_components.find(type);
|
||||
if (existing == this->_components.end())
|
||||
return nullptr;
|
||||
return static_cast<T *>(existing->second.get());
|
||||
}
|
||||
|
||||
//! @brief Check if this entity has a component.
|
||||
//! @tparam T The type of the component
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user