Finishing the replay button

This commit is contained in:
Zoe Roux
2021-06-17 22:31:21 +02:00
parent a886b50239
commit d424c07744
17 changed files with 59 additions and 64 deletions
-10
View File
@@ -10,16 +10,6 @@ namespace WAL
: _entity(entity)
{ }
bool Component::isDisabled() const
{
return this->_disabled;
}
void Component::setDisable(bool disabled)
{
this->_disabled = disabled;
}
void Component::onStart()
{
// TODO handle events here
-8
View File
@@ -16,9 +16,6 @@ namespace WAL
//! @brief Represent a single component of WAL.
class Component
{
private:
//! @brief Is this component disabled?
bool _disabled = false;
protected:
//! @brief The entity that own this component
Entity &_entity;
@@ -37,11 +34,6 @@ namespace WAL
//! @param entity The entity that owns the ne component.
virtual Component *clone(Entity &entity) const = 0;
//! @brief Used if the component is disabled
bool isDisabled() const;
//! @brief Disable this component.
void setDisable(bool disabled);
//! @brief The entity or this component has just been enabled.
virtual void onStart();
+5 -10
View File
@@ -52,7 +52,7 @@ namespace WAL
Entity &Entity::addComponent(const Component &component)
{
const std::type_index &type = typeid(component);
if (this->hasComponent(type, false))
if (this->hasComponent(type))
throw DuplicateError("A component of the type \"" + std::string(type.name()) + "\" already exists.");
this->_components.emplace(type, component.clone(*this));
if (this->_notifyScene)
@@ -60,19 +60,14 @@ namespace WAL
return *this;
}
bool Entity::hasComponent(const std::type_info &type, bool skipDisabled) const
bool Entity::hasComponent(const std::type_info &type) const
{
return this->hasComponent(static_cast<const std::type_index &>(type), skipDisabled);
return this->hasComponent(static_cast<const std::type_index &>(type));
}
bool Entity::hasComponent(const std::type_index &type, bool skipDisabled) const
bool Entity::hasComponent(const std::type_index &type) const
{
auto cmp = this->_components.find(type);
if (cmp == this->_components.end())
return false;
if (skipDisabled)
return !cmp->second->isDisabled();
return true;
return this->_components.contains(type);
}
void Entity::_componentAdded(const std::type_index &type)
+4 -7
View File
@@ -117,24 +117,21 @@ namespace WAL
}
//! @brief Check if this entity has a component.
//! @param skipDisabled True if you want to skip disabled components (consider them non present), false otherwise.
//! @tparam T The type of the component
template<typename T>
bool hasComponent(bool skipDisabled = true) const
bool hasComponent() const
{
const std::type_info &type = typeid(T);
return this->hasComponent(type, skipDisabled);
return this->hasComponent(type);
}
//! @brief Check if this entity has a component.
//! @param skipDisabled True if you want to skip disabled components (consider them non present), false otherwise.
//! @param type The type of the component
bool hasComponent(const std::type_info &type, bool skipDisabled = true) const;
bool hasComponent(const std::type_info &type) const;
//! @brief Check if this entity has a component.
//! @param skipDisabled True if you want to skip disabled components (consider them non present), false otherwise.
//! @param type The type of the component
bool hasComponent(const std::type_index &type, bool skipDisabled = true) const;
bool hasComponent(const std::type_index &type) const;
//! @brief Add a component to this entity. The component is constructed in place.
//! @throw DuplicateError is thrown if a component with the same type already exist.