Example #1
0
def test_remove_component():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    component = Component()
    entity_manager.add_component_to_entity(entity, component)
    entity_manager.remove_component_from_entity(entity, type(component))
    assert entity_manager.get_entity_components(entity) == set()
Example #2
0
def test_update_family():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    family = entity_manager.get_family(PositionComponent)
    assert entity not in family._entities
    entity_manager.add_component_to_entity(entity, PositionComponent())
    assert entity in family._entities
    entity_manager.remove_component_from_entity(entity, PositionComponent)
    assert entity not in family._entities
Example #3
0
def test_listener_entity_added():
    entity_manager = EntityManager()
    test_listener = EventListener()
    entity_manager.add_listener(test_listener)
    entity = entity_manager.create_entity()
    assert test_listener.event_queue[-1] == ("entity_added", entity)
    entity = Entity()
    entity_manager.add_entity(entity)
    assert test_listener.event_queue[-1] == ("entity_added", entity)
Example #4
0
def test_remove_listener():
    entity_manager = EntityManager()
    test_listener = EventListener()
    entity_manager.add_listener(test_listener)
    assert test_listener in entity_manager._listeners
    entity_manager.remove_listener(test_listener)
    assert test_listener not in entity_manager._listeners
Example #5
0
def test_update_systems():
    entity_manager = EntityManager()
    system = UpdateSystem()
    entity_manager.add_system(system)
    assert system.updates == 0
    entity_manager.update(1)
    assert system.updates == 1
Example #6
0
def test_remove_system():
    entity_manager = EntityManager()
    system = UpdateSystem()
    entity_manager.add_system(system)
    assert system in entity_manager._systems
    entity_manager.remove_system(system)
    assert system not in entity_manager._systems
Example #7
0
def test_component_map():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    component = Component()
    entity_manager.add_component_to_entity(entity, component)
    assert entity_manager.get_component_map(type(component)) == {
        entity: component
    }
Example #8
0
def test_add_listener():
    entity_manager = EntityManager()
    test_listener = EventListener()
    entity_manager.add_listener(test_listener)
    assert test_listener in entity_manager._listeners
Example #9
0
def test_listener_entity_removed():
    entity_manager = EntityManager()
    test_listener = EventListener()
    entity_manager.add_listener(test_listener)
    entity = entity_manager.create_entity()
    entity_manager.remove_entity(entity)
    assert test_listener.event_queue[-1] == ("entity_removed", entity, set())
    entity = entity_manager.create_entity()
    component = Component()
    entity_manager.add_component_to_entity(entity, component)
    entity_manager.remove_entity(entity)
    assert test_listener.event_queue[-1] == ("entity_removed", entity,
                                             set([component]))
Example #10
0
def test_get_family():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    assert entity not in entity_manager.get_family(PositionComponent)._entities
    entity_manager.add_component_to_entity(entity, PositionComponent())
    assert entity in entity_manager.get_family(PositionComponent)._entities
    assert entity not in entity_manager.get_family(VelocityComponent)._entities
    entity_manager.add_component_to_entity(entity, VelocityComponent())
    assert entity in entity_manager.get_family(PositionComponent, VelocityComponent)._entities
Example #11
0
def test_add_system():
    entity_manager = EntityManager()
    system = UpdateSystem()
    entity_manager.add_system(system)
    assert system in entity_manager._systems
Example #12
0
def test_system_priority():
    entity_manager = EntityManager()
    system_1 = UpdateSystem()
    system_2 = UpdateSystem()
    entity_manager.add_system(system_1, system_2)
    assert entity_manager._systems == [system_1, system_2]
    system_3 = UpdateSystem(1)
    entity_manager.add_system(system_3)
    assert entity_manager._systems == [system_3, system_1, system_2]
    system_4 = UpdateSystem(2)
    entity_manager.add_system(system_4)
    entity_manager.remove_system(system_1)
    assert entity_manager._systems == [system_4, system_3, system_2]
    entity_manager.remove_system(system_4)
    assert entity_manager._systems == [system_3, system_2]
Example #13
0
def test_add_component():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    component = Component()
    entity_manager.add_component_to_entity(entity, component)
    assert entity_manager.get_entity_components(entity) == {component}
Example #14
0
def test_create_entity():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    assert entity_manager.entity_exists(entity)
Example #15
0
def test_remove_entity():
    entity_manager = EntityManager()
    entity = entity_manager.create_entity()
    assert entity_manager.entity_exists(entity)
    entity_manager.remove_entity(entity)
    assert not entity_manager.entity_exists(entity)
Example #16
0
def test_add_entity():
    entity_manager = EntityManager()
    entity = Entity()
    entity_manager.add_entity(entity)
    assert entity_manager.entity_exists(entity)