Moving stuff around

This commit is contained in:
2026-09-25 20:21:25 -07:00
parent 09706507cf
commit 4ebae57cf8
3 changed files with 1 additions and 1 deletions
+62
View File
@@ -0,0 +1,62 @@
#pragma once
#include <entt/entt.hpp>
#include <sophia/scene.hpp>
#include <sophia/types.hpp>
#include <sophia/util/assert.hpp>
namespace sophia {
class Entity {
public:
Entity(const Entity&) = default;
Entity& operator=(const Entity&) = default;
Entity() = default;
Entity(entt::entity handle, Scene* scene);
template <typename T, typename... Args>
T& addComponent(Args&&... args) {
SOPHIA_ASSERT(!hasComponent<T>(), "Entity already has component!");
T& component =
scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
// scene->OnComponentAdded<T>(*this, component);
return component;
}
template <typename T>
T& getComponent() {
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
return scene->registry.get<T>(handle);
}
template <typename T>
bool hasComponent() {
return scene->registry.all_of<T>(handle);
}
template <typename T>
void removeComponent() {
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
scene->registry.remove<T>(handle);
}
operator bool() const { return handle != entt::null; }
operator entt::entity() const { return handle; }
operator u32() const { return (u32)handle; }
// UUID GetUUID() { return GetComponent<IDComponent>().ID; }
// const std::string& GetName() { return GetComponent<TagComponent>().Tag; }
bool operator==(const Entity& other) const {
return handle == other.handle && scene == other.scene;
}
bool operator!=(const Entity& other) const { return !(*this == other); }
private:
entt::entity handle{entt::null};
Scene* scene = nullptr;
};
} // namespace sophia