mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-06 03:12:01 +00:00
Reworking drawable components
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <memory>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Exception/WalError.hpp"
|
||||
#include "Models/TypeHolder.hpp"
|
||||
|
||||
namespace WAL
|
||||
{
|
||||
@@ -83,6 +84,18 @@ namespace WAL
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @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.
|
||||
//! @return This entity is returned
|
||||
template<typename T, typename TNested, typename ...Types>
|
||||
Entity &addComponent(Types &&...params)
|
||||
{
|
||||
if (this->hasComponent<T>())
|
||||
throw DuplicateError("A component of the type \"" + std::string(typeid(T).name()) + "\" already exists.");
|
||||
this->_components.push_back(std::make_unique<T>(*this, TypeHolder<TNested>(), std::forward<Types>(params)...));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Copy a component to this entity.
|
||||
//! @return This entity is returned.
|
||||
Entity &addComponent(const Component &component);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by Zoe Roux on 2021-06-02.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace WAL
|
||||
{
|
||||
//! @brief A class only used to specify template arguments.
|
||||
template<typename T>
|
||||
class TypeHolder {};
|
||||
}
|
||||
Reference in New Issue
Block a user