Exemplo n.º 1
0
    def remove(self, component_class):
        """Removes the Componenet of the specified type. Since there is only
		ever one component of one type, we don't need an instance reference.
		returns the removed component"""
        component_class_index = ComponentType.get_index_for(component_class)
        remove_component = self.components[component_class_index]

        if remove_component != None:
            del self.components[component_class_index]
            self.components_array.remove(remove_component)
            self.component_bits.clear(index=component_class_index)

            self.component_removed(self)
Exemplo n.º 2
0
	def remove(self, component_class):
		"""Removes the Componenet of the specified type. Since there is only
		ever one component of one type, we don't need an instance reference.
		returns the removed component"""
		component_class_index = ComponentType.get_index_for(component_class)
		remove_component = self.components[component_class_index]

		if remove_component != None:
			del self.components[component_class_index]
			self.components_array.remove(remove_component)
			self.component_bits.clear(index=component_class_index)

			self.component_removed(self)
Exemplo n.º 3
0
    def add(self, component):
        """Adds a Component to this Entity. If a Component of the same type already exists,
		it will be replaced.
		Returns self for easy chaining"""
        component_class = component.__class__
        for c in self.components_array:
            if c.__class__ == component_class:
                del self.components_array[c]
                break

        component_class_index = ComponentType.get_index_for(component_class)
        self.components[component_class_index] = component
        self.components_array.append(component)

        self.component_bits.set(component_class_index)

        self.component_added(self)
        return self
Exemplo n.º 4
0
	def add(self, component):
		"""Adds a Component to this Entity. If a Component of the same type already exists,
		it will be replaced.
		Returns self for easy chaining"""
		component_class = component.__class__
		for c in self.components_array:
			if c.__class__ == component_class:
				del self.components_array[c]
				break

		component_class_index = ComponentType.get_index_for(component_class)
		self.components[component_class_index] = component
		self.components_array.append(component)

		self.component_bits.set(component_class_index)

		self.component_added(self)
		return self
Exemplo n.º 5
0
	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()
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
	def __init__(self, component_class):
		self.component_type = ComponentType.get_for(component_class)
Exemplo n.º 8
0
	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())
Exemplo n.º 9
0
 def get_component_by_class(self, component_class):
     return self.get_component(ComponentType.get_for(component_class))
Exemplo n.º 10
0
	def get_component_by_class(self, component_class):
		return self.get_component(ComponentType.get_for(component_class))