Reworking drawable components

This commit is contained in:
Zoe Roux
2021-06-02 16:18:26 +02:00
parent 1cc6907ff0
commit 09d8b1a90b
15 changed files with 118 additions and 268 deletions
+13
View File
@@ -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);
+13
View File
@@ -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 {};
}