class Chione::Entity
The Entity
(identity) class
Attributes
The Entity’s ID
The World the Entity
belongs to
Public Class Methods
Return an ID for an Entity
.
# File lib/chione/entity.rb, line 21 def self::make_new_id return Chione.uuid.generate end
Create a new Entity
for the specified world
, and use the specified id
if given. If no id
is given, one will be automatically generated.
# File lib/chione/entity.rb, line 28 def initialize( world, id=nil ) @world = world @id = id || self.class.make_new_id end
Public Instance Methods
Equality operator – returns true
if the receiver and other
belong to the same world, have the same ID, and have equal components.
# File lib/chione/entity.rb, line 83 def ==( other ) return other.instance_of?( self.class ) && self.id == other.id end
Add the specified component
to the entity. The component
can be a subclass of Chione::Component
, an instance of such a subclass, or the name of a subclass. It will replace any existing component of the same type.
# File lib/chione/entity.rb, line 55 def add_component( component, **init_values ) self.world.add_component_to( self, component, **init_values ) end
Return the components that the entity’s World has registered for it as a Hash keyed by the Component class.
# File lib/chione/entity.rb, line 47 def components return self.world.components_for( self ) end
Fetch the component of the specified component_class
that corresponds with the receiving entity. Returns nil
if so much component exists.
# File lib/chione/entity.rb, line 62 def get_component( component_class ) return self.world.get_component_for( self, component_class ) end
Returns true
if this entity has a component of the specified component_class
.
# File lib/chione/entity.rb, line 76 def has_component?( component_class ) return self.world.has_component_for?( self, component_class ) end
Remove the component of the specified component_class
that corresponds with the receiving entity. Returns the component instance if it was removed, or nil
if no Component of the specified type was registered to the entity.
# File lib/chione/entity.rb, line 70 def remove_component( component_class ) return self.world.remove_component_from( self, component_class ) end
Protected Instance Methods
Return the detailed part of the Entity’s inspect
output
# File lib/chione/entity.rb, line 95 def inspect_details return "ID=%s (%s)" % [ self.id, self.components.keys.map( &:name ).sort.join( '+' ) ] end