def test_neutral_zone_score_processor(self): processor = base.NeutralZoneScoreProcessor(self.context) point = self.context.get_group(Matcher(base.Movable)).single_entity zone = self.context.get_group(Matcher(base.CircularZone)).single_entity point.add(base.Invader, zone._creation_index) assert zone.get(base.Score).cur_score == 0 assert zone.get(base.Score).score_team_id == 0 processor.execute() assert zone.get(base.Score).cur_score == 1 assert zone.get(base.Score).score_team_id == 1 point.replace(base.Team, 2) processor.execute() assert zone.get(base.Score).cur_score == 0 assert zone.get(base.Score).score_team_id == 0 processor.execute() assert zone.get(base.Score).cur_score == 1 assert zone.get(base.Score).score_team_id == 2
def test_matches(): ea = Entity() eb = Entity() ec = Entity() ea.activate(0) eb.activate(1) ec.activate(2) ea.add(CompA) ea.add(CompB) ea.add(CompC) ea.add(CompE) eb.add(CompA) eb.add(CompB) eb.add(CompC) eb.add(CompE) eb.add(CompF) ec.add(CompB) ec.add(CompC) ec.add(CompD) matcher = Matcher(all_of=[CompA, CompB, CompC], any_of=[CompD, CompE], none_of=[CompF]) assert matcher.matches(ea) assert not matcher.matches(eb) assert not matcher.matches(ec)
def test_triger_zone_processor(self): processor = base.TriggerZoneProcessor(self.context) point = self.context.get_group(Matcher(base.Movable)).single_entity zone = self.context.get_group(Matcher(base.CircularZone)).single_entity point.replace(base.Position, 1, 1) processor.execute() assert point.has(base.Invader) point.replace(base.Position, 3, 3) processor.execute() assert not point.has(base.Invader)
def test_primary_index_exception(self): context = Context() group = context.get_group(Matcher(Person)) primary_index = PrimaryEntityIndex(Person, group, 'age') context.add_entity_index(primary_index) adam = context.create_entity() adam.add(Person, 'Adam', 42) eve = context.create_entity() with pytest.raises(EntitasException): eve.add(Person, 'Eve', 42)
def test_primary_index(self): context = Context() group = context.get_group(Matcher(Person)) primary_index = PrimaryEntityIndex(Person, group, 'name') context.add_entity_index(primary_index) adam = context.create_entity() adam.add(Person, 'Adam', 42) eve = context.create_entity() eve.add(Person, 'Eve', 42) entity = context.get_entity_index(Person).get_entity('Eve') assert entity == eve
def test_index(self): context = Context() group = context.get_group(Matcher(Person)) index = EntityIndex(Person, group, 'age') context.add_entity_index(index) adam = context.create_entity() adam.add(Person, 'Adam', 42) eve = context.create_entity() eve.add(Person, 'Eve', 42) entities = context.get_entity_index(Person).get_entities(42) assert entities == set([adam, eve])
def test_capture_zone_precessor(self): processor = base.CaptureZoneProcessor(self.context) processor.activate() zone = self.context.get_group(Matcher(base.CircularZone)).single_entity zone.replace(base.Score, 5, 10, 1) processor.execute() assert zone.get(base.Owner).owner_team_id == 0 zone.replace(base.Score, 10, 10, 1) processor.execute() assert zone.get(base.Owner).owner_team_id == 1
from entitas import Context, Matcher from .test_components import Movable _context = Context() _entity = _context.create_entity() _entity.add(Movable) _group = _context.get_group(Matcher(Movable)) class TestGroup(object): def test_entities(self): assert len(_group.entities) == 1 def test_single_entity(self): assert _group.single_entity.has(Movable) def test_events(self): assert _group.single_entity == _entity _entity.replace(Movable) assert _group.single_entity == _entity _entity.remove(Movable) assert not _group.single_entity
def __init__(self, context): self._zoneGroup = context.get_group(Matcher(CircularZone, Position)) self._invaderGroup = context.get_group(Matcher(Invader))
def __init__(self, context): self._zoneGroup = context.get_group(Matcher(CircularZone, Position)) self._outPointsGroup = context.get_group( Matcher(all_of=(Position, Movable), none_of=(Invader, ))) self._inPointsGroup = context.get_group( Matcher(Position, Movable, Invader))
def __init__(self, context): super().__init__(context) self._group = context.get_group(Matcher(Movable, Position, Speed))
def get_trigger(self): return {Matcher(Score): GroupEvent.ADDED}
from entitas import Matcher, ReactiveProcessor, ExecuteProcessor, EntityIndex, GroupEvent Collider2D = namedtuple('Collider2D', 'maxX maxY minX minY') Collidable = namedtuple('Collidable', '') Collision = namedtuple('Collision', '') def configure_collidable(entity, point): entity.add(Collider2D, 1 + point, 1+point, 0+point, 0+point) entity.add(Collidable) class CollisionProcessor(ExecuteProcessor): def __init__(self, context) self._collidableGroup = context.get_group(Matcher(Collider2D, Collidable)) def execute(self): for a, b in itertools.permutations(self._collidableGroup.entities, 2): if self.intersect(a.get(Collider2D), b.get(Collider2D)): a.add(Collision) @staticmethod def intersect(a, b): return (a.minX <= b.maxX and a.maxX >= b.minX) and (a.minY <= b.maxY and a.maxY >= b.minY) def collider_modifier(entity, next_point): entity.replace(Collider2D, 1 + next_point, 1+next_point, 0+next_point, 0+next_point)
def get_trigger(self): return {Matcher(Collision): GroupEvent.ADDED}