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()
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
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)
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
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
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
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 }
def test_add_listener(): entity_manager = EntityManager() test_listener = EventListener() entity_manager.add_listener(test_listener) assert test_listener in entity_manager._listeners
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]))
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
def test_add_system(): entity_manager = EntityManager() system = UpdateSystem() entity_manager.add_system(system) assert system in entity_manager._systems
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]
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}
def test_create_entity(): entity_manager = EntityManager() entity = entity_manager.create_entity() assert entity_manager.entity_exists(entity)
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)
def test_add_entity(): entity_manager = EntityManager() entity = Entity() entity_manager.add_entity(entity) assert entity_manager.entity_exists(entity)