2025-07-11 01:16:52 +03:30
|
|
|
#include <ecs/components.hpp>
|
|
|
|
#include <ecs/entity.hpp>
|
|
|
|
#include <ecs/scene.hpp>
|
2021-07-25 17:50:08 +04:30
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
namespace lt {
|
2021-07-25 17:50:08 +04:30
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
auto Scene::create_entity(const std::string &name, const TransformComponent &transform) -> Entity
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
2025-07-05 15:36:53 +03:30
|
|
|
return create_entity_with_uuid(name, UUID(), transform);
|
2022-03-07 21:57:00 +03:30
|
|
|
}
|
2021-10-07 01:13:18 +03:30
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
auto Scene::get_entity_by_tag(const std::string &tag) -> Entity
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
|
|
|
// TagComponent tagComp(tag);
|
2025-07-05 14:23:01 +03:30
|
|
|
// entt::entity entity = entt::to_entity(m_registry, tagComp);
|
2025-07-06 14:02:50 +03:30
|
|
|
auto entity = Entity {};
|
2021-10-07 01:13:18 +03:30
|
|
|
|
2025-07-05 14:23:01 +03:30
|
|
|
m_registry.view<TagComponent>().each([&](TagComponent &tagComp) {
|
2025-07-05 11:33:43 +03:30
|
|
|
// if (tagComp.tag == tag)
|
2025-07-05 15:36:53 +03:30
|
|
|
// entity = entity(entt::to_entity(m_registry, tagComp), this);
|
2022-03-07 21:57:00 +03:30
|
|
|
});
|
2021-07-25 17:50:08 +04:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
if (entity.is_valid())
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
2025-07-06 16:30:38 +03:30
|
|
|
return entity;
|
2021-07-25 17:50:08 +04:30
|
|
|
}
|
2025-07-06 16:30:38 +03:30
|
|
|
|
2025-07-11 02:12:55 +03:30
|
|
|
ensure(false, "Scene::get_entity_by_tag: failed to find entity by tag: {}", tag);
|
2025-07-06 16:30:38 +03:30
|
|
|
return {};
|
2022-03-07 21:57:00 +03:30
|
|
|
}
|
2021-07-25 17:50:08 +04:30
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
auto Scene::create_entity_with_uuid(
|
2025-07-05 13:28:41 +03:30
|
|
|
const std::string &name,
|
|
|
|
UUID uuid,
|
|
|
|
const TransformComponent &transform
|
2025-07-06 14:02:50 +03:30
|
|
|
) -> Entity
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
2025-07-06 14:02:50 +03:30
|
|
|
auto entity = Entity { m_registry.create(), this };
|
|
|
|
entity.add_component<TagComponent>(name);
|
|
|
|
entity.add_component<TransformComponent>(transform);
|
|
|
|
entity.add_component<UUIDComponent>(uuid);
|
2022-03-07 21:57:00 +03:30
|
|
|
|
|
|
|
return entity;
|
2021-07-25 17:50:08 +04:30
|
|
|
}
|
2022-03-07 21:57:00 +03:30
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
} // namespace lt
|