Skip to content

Commit

Permalink
Systems check new entities against self.filters, not self.entity_filt…
Browse files Browse the repository at this point in the history
…ers, as the former is the rewritten version.
  • Loading branch information
Schwarzbaer committed Jul 18, 2020
1 parent be24b23 commit e871652
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
17 changes: 17 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,29 @@ def update(self, entities_by_filter):
self.updates.append(entities_by_filter)


class BareNullSystem(NullSystem):
entity_filters = {
"null": NullComponent,
}


@pytest.fixture
def null_system():
return NullSystem()


@pytest.fixture
def bare_null_system():
return BareNullSystem()


@pytest.fixture
def null_system_world(world, null_system):
world.add_system(null_system, 0)
return world


@pytest.fixture
def bare_null_world(world, bare_null_system):
world.add_system(bare_null_system, 0)
return world
19 changes: 19 additions & 0 deletions tests/test_core/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from wecs.core import and_filter, or_filter

from fixtures import world, entity
from fixtures import bare_null_world, bare_null_system, NullComponent


@Component()
Expand Down Expand Up @@ -240,3 +241,21 @@ def test_multiarg_creation():

s = set([ComponentA, ComponentB, ComponentC])
assert f(s)


# Test whether bare component types in entity_filters work as expected

def test_bare_system(bare_null_world, bare_null_system):
entity = bare_null_world.create_entity(NullComponent())
bare_null_world._flush_component_updates()
assert entity in bare_null_system.entities["null"]
assert len(bare_null_system.entries) == 1
assert bare_null_system.entries[0] == (['null'], entity)


def test_bare_system_not_adding(bare_null_world, bare_null_system):
entity_a = bare_null_world.create_entity()
entity_b = bare_null_world.create_entity(ComponentA())
bare_null_world._flush_component_updates()
assert entity_a not in bare_null_system.entities["null"]
assert entity_b not in bare_null_system.entities["null"]
4 changes: 2 additions & 2 deletions wecs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def _trigger_update(self):
def _propose_removal(self, entity):
exited_filters = []
future_components = entity._get_post_removal_component_types()
for filter_name, filter_func in self.entity_filters.items():
for filter_func, filter_name in self.filters.items():
matches = filter_func(future_components)
present = entity in self.entities[filter_name]
if present and not matches:
Expand All @@ -526,7 +526,7 @@ def _propose_removal(self, entity):
def _propose_addition(self, entity):
entered_filters = []
future_components = entity._get_post_addition_component_types()
for filter_name, filter_func in self.entity_filters.items():
for filter_func, filter_name in self.filters.items():
matches = filter_func(future_components)
present = entity in self.entities[filter_name]
if matches and not present:
Expand Down

0 comments on commit e871652

Please sign in to comment.