Skip to content

Commit 654ed03

Browse files
committed
Add __bool__ to queries
1 parent 42c4331 commit 654ed03

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Queries are now truthy if they match any entity.
13+
1014
## [5.1.0] - 2024-02-13
1115

1216
### Changed

tcod/ecs/query.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ def get_entities(self) -> AbstractSet[Entity]:
352352
"""
353353
return _get_query(self.registry, self._query)
354354

355+
def __bool__(self) -> bool:
356+
"""Return True if any entity matches this query."""
357+
return bool(self.get_entities())
358+
355359
@staticmethod
356360
def __as_queries(
357361
components: Iterable[ComponentKey[object]] = (),

0 commit comments

Comments
 (0)