def test_component(self): global COMPONENT_REMOVED global COMPONENT_ADDED Engine.reset_indices() engine = Engine() e1 = Entity() c = VelocityComponent() e1.component_added.append(TestComponentAddedListener()) e1.component_removed.append(TestComponentRemovedListener()) engine.add_entity(e1) e1.add(c) self.assertEqual(COMPONENT_ADDED, e1) reset_component_listener_test() family = Family.get_for_bits(ComponentType.get_bits_for(VelocityComponent)) entities = engine.get_entities_for(family) self.assertEqual(entities[0], e1) e1.remove(VelocityComponent) self.assertEqual(COMPONENT_REMOVED, e1) reset_component_listener_test()
def test_component(self): global COMPONENT_REMOVED global COMPONENT_ADDED Engine.reset_indices() engine = Engine() e1 = Entity() c = VelocityComponent() e1.component_added.append(TestComponentAddedListener()) e1.component_removed.append(TestComponentRemovedListener()) engine.add_entity(e1) e1.add(c) self.assertEqual(COMPONENT_ADDED, e1) reset_component_listener_test() family = Family.get_for_bits( ComponentType.get_bits_for(VelocityComponent)) entities = engine.get_entities_for(family) self.assertEqual(entities[0], e1) e1.remove(VelocityComponent) self.assertEqual(COMPONENT_REMOVED, e1) reset_component_listener_test()
def get_for_classes(cls, *component_classes): """returns a family with the passed Component classes as a descriptor. each set of component types will always return the same family instance.""" return cls.get_for_bits(ComponentType.get_bits_for(*component_classes), Bits(), Bits())