コード例 #1
0
 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
コード例 #2
0
    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])
コード例 #3
0
def try_base():
    context = Context()
    entity = context.create_entity()
    configure_base(entity)
    print(entity)

    processors = Processors()
    processors.add(MoveProcessor(context))

    processors.initialize()
    processors.activate_reactive_processors()

    running = True
    while running:
        processors.execute()
        processors.cleanup()

        break

    processors.clear_reactive_processors()
    processors.tear_down()
コード例 #4
0
    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)
コード例 #5
0
def try_base():
    context = Context()
    entity1 = context.create_entity()
    configure_collidable(entity, point)
    print(entity)

    processors = Processors()
    processors.add(CollisionProcessor(context))
    processors.add(DamageByCollisionProcessor(context))

    processors.initialize()
    processors.activate_reactive_processors()

    running = True
    while running:
        processors.execute()
        processors.cleanup()

        break

    processors.clear_reactive_processors()
    processors.tear_down()
コード例 #6
0
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
コード例 #7
0
 def setup_method(self, method):
     self.context = Context()
     point = self.context.create_entity()
     base.configure_point(point)
     zone = self.context.create_entity()
     base.configure_base(zone)
コード例 #8
0
class TestBaseSystems(object):
    def setup_method(self, method):
        self.context = Context()
        point = self.context.create_entity()
        base.configure_point(point)
        zone = self.context.create_entity()
        base.configure_base(zone)

    def teardown_method(self, method):
        pass

    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_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_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


    def test_reset_zone_precessor(self):
        processor = base.ResetZoneProcessor(self.context)
        processor.activate()

        zone = self.context.get_group(Matcher(base.CircularZone)).single_entity
        zone.replace(base.Score, 5, 10, 1)
        zone.replace(base.Owner, 1)

        processor.execute()
        assert zone.get(base.Owner).owner_team_id == 1

        zone.replace(base.Score, 0, 10, 0)

        processor.execute()
        assert zone.get(base.Owner).owner_team_id == 0
コード例 #9
0
import pytest
from entitas import Context, Entity, MissingEntity

_context = Context()
_entity = _context.create_entity()


class TestContext(object):
    def test_entry_points(self):
        Context.create_entity
        Context.has_entity
        Context.destroy_entity
        Context.entities
        Context.get_group
        Context.set_unique_component
        Context.get_unique_component

    def test_has_entity(self):
        assert _context.has_entity(_entity)
        assert isinstance(_entity, Entity)

    def test_entities(self):
        assert len(_context.entities) == 1

    def test_destroy_entity(self):
        _context.destroy_entity(_entity)
        assert not _context.has_entity(_entity)

        with pytest.raises(MissingEntity):
            _context.destroy_entity(_entity)