mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-21 13:55:10 +00:00
62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
//
|
|
// Created by Zoe Roux on 2021-05-14.
|
|
//
|
|
|
|
#include "Entity/Entity.hpp"
|
|
|
|
#include <utility>
|
|
|
|
namespace WAL
|
|
{
|
|
unsigned Entity::nextID = 0;
|
|
|
|
Entity::Entity(std::string name)
|
|
: _uid(Entity::nextID++),
|
|
_name(std::move(name))
|
|
{ }
|
|
|
|
Entity::Entity(const Entity &other)
|
|
: _uid(Entity::nextID++),
|
|
_name(other._name),
|
|
_disabled(other._disabled)
|
|
{
|
|
for (const auto &cmp : other._components)
|
|
this->addComponent(*cmp);
|
|
}
|
|
|
|
unsigned Entity::getUid() const
|
|
{
|
|
return this->_uid;
|
|
}
|
|
|
|
std::string Entity::getName() const
|
|
{
|
|
return this->_name;
|
|
}
|
|
|
|
bool Entity::isDisable() const
|
|
{
|
|
return this->_disabled;
|
|
}
|
|
|
|
void Entity::setDisable(bool disabled)
|
|
{
|
|
this->_disabled = disabled;
|
|
}
|
|
|
|
Entity &Entity::addComponent(const Component &component)
|
|
{
|
|
if (this->hasComponent(typeid(component)))
|
|
throw DuplicateError("A component of the type \"" + std::string(typeid(component).name()) + "\" already exists.");
|
|
this->_components.emplace_back(component.clone(*this));
|
|
return *this;
|
|
}
|
|
|
|
bool Entity::hasComponent(const std::type_info &type) const
|
|
{
|
|
auto existing = std::find_if(this->_components.begin(), this->_components.end(), [&type] (const auto &cmp) {
|
|
return typeid(*cmp) == type;
|
|
});
|
|
return existing != this->_components.end();
|
|
}
|
|
} |