Chione::

Entity class

The Entity (identity) class

Attributes

id R

The Entity’s ID

world R

The World the Entity belongs to

Public Class Methods

make_new_id()

Return an ID for an Entity.

   # File lib/chione/entity.rb
21 def self::make_new_id
22     return Chione.uuid.generate
23 end
new( world, id=nil )

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
28 def initialize( world, id=nil )
29     @world = world
30     @id    = id || self.class.make_new_id
31 end

Public Instance Methods

==( other )

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
83 def ==( other )
84     return other.instance_of?( self.class ) &&
85         self.id == other.id
86 end
Also aliased as: eql?
add_component( component, **init_values )

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
55 def add_component( component, **init_values )
56     self.world.add_component_to( self, component, **init_values )
57 end
components()

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
47 def components
48     return self.world.components_for( self )
49 end
eql?( other )
Alias for: ==
get_component( component_class )

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
62 def get_component( component_class )
63     return self.world.get_component_for( self, component_class )
64 end
has_component?( component_class )

Returns true if this entity has a component of the specified component_class.

   # File lib/chione/entity.rb
76 def has_component?( component_class )
77     return self.world.has_component_for?( self, component_class )
78 end
remove_component( component_class )

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
70 def remove_component( component_class )
71     return self.world.remove_component_from( self, component_class )
72 end

Protected Instance Methods

inspect_details()

Return the detailed part of the Entity’s #inspect output

    # File lib/chione/entity.rb
 95 def inspect_details
 96     return "ID=%s (%s)" % [
 97         self.id,
 98         self.components.keys.map( &:name ).sort.join( '+' )
 99     ]
100 end