added has for tag + entity to test ownership
This commit is contained in:
@@ -568,6 +568,24 @@ public:
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if an entity owns the given tag.
|
||||
*
|
||||
* Syntactic sugar for the following snippet:
|
||||
*
|
||||
* @code{.cpp}
|
||||
* has<Tag>() && attachee<Tag>() == entity
|
||||
* @endcode
|
||||
*
|
||||
* @tparam Tag Type of tag for which to perform the check.
|
||||
* @param entity A valid entity identifier.
|
||||
* @return True if the entity owns the tag, false otherwise.
|
||||
*/
|
||||
template<typename Tag>
|
||||
bool has(tag_t, entity_type entity) const ENTT_NOEXCEPT {
|
||||
return has<Tag>() && attachee<Tag>() == entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if an entity has all the given components.
|
||||
*
|
||||
|
||||
@@ -364,6 +364,7 @@ TEST(DefaultRegistry, AttachSetRemoveTags) {
|
||||
registry.assign<int>(entt::tag_t{}, entity, 42);
|
||||
|
||||
ASSERT_TRUE(registry.has<int>());
|
||||
ASSERT_TRUE(registry.has<int>(entt::tag_t{}, entity));
|
||||
ASSERT_EQ(registry.get<int>(), 42);
|
||||
ASSERT_EQ(cregistry.get<int>(), 42);
|
||||
ASSERT_EQ(registry.attachee<int>(), entity);
|
||||
@@ -371,6 +372,7 @@ TEST(DefaultRegistry, AttachSetRemoveTags) {
|
||||
registry.replace<int>(entt::tag_t{}, 3);
|
||||
|
||||
ASSERT_TRUE(registry.has<int>());
|
||||
ASSERT_TRUE(registry.has<int>(entt::tag_t{}, entity));
|
||||
ASSERT_EQ(registry.get<int>(), 3);
|
||||
ASSERT_EQ(cregistry.get<int>(), 3);
|
||||
ASSERT_EQ(registry.attachee<int>(), entity);
|
||||
@@ -379,6 +381,8 @@ TEST(DefaultRegistry, AttachSetRemoveTags) {
|
||||
registry.move<int>(other);
|
||||
|
||||
ASSERT_TRUE(registry.has<int>());
|
||||
ASSERT_FALSE(registry.has<int>(entt::tag_t{}, entity));
|
||||
ASSERT_TRUE(registry.has<int>(entt::tag_t{}, other));
|
||||
ASSERT_EQ(registry.get<int>(), 3);
|
||||
ASSERT_EQ(cregistry.get<int>(), 3);
|
||||
ASSERT_EQ(registry.attachee<int>(), other);
|
||||
@@ -386,11 +390,15 @@ TEST(DefaultRegistry, AttachSetRemoveTags) {
|
||||
registry.remove<int>();
|
||||
|
||||
ASSERT_FALSE(registry.has<int>());
|
||||
ASSERT_FALSE(registry.has<int>(entt::tag_t{}, entity));
|
||||
ASSERT_FALSE(registry.has<int>(entt::tag_t{}, other));
|
||||
|
||||
registry.assign<int>(entt::tag_t{}, entity, 42);
|
||||
registry.destroy(entity);
|
||||
|
||||
ASSERT_FALSE(registry.has<int>());
|
||||
ASSERT_FALSE(registry.has<int>(entt::tag_t{}, entity));
|
||||
ASSERT_FALSE(registry.has<int>(entt::tag_t{}, other));
|
||||
}
|
||||
|
||||
TEST(DefaultRegistry, StandardView) {
|
||||
|
||||
Reference in New Issue
Block a user