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
22 def self::make_new_id
23     return Chione.uuid.generate
24 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
29 def initialize( world, id=nil )
30     @world = world
31     @id    = id || self.class.make_new_id
32 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
84 def ==( other )
85     return other.instance_of?( self.class ) &&
86         self.id == other.id
87 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
56 def add_component( component, **init_values )
57     self.world.add_component_to( self, component, **init_values )
58 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
48 def components
49     return self.world.components_for( self )
50 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
63 def get_component( component_class )
64     return self.world.get_component_for( self, component_class )
65 end
has_component?( component_class )

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

   # File lib/chione/entity.rb
77 def has_component?( component_class )
78     return self.world.has_component_for?( self, component_class )
79 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
71 def remove_component( component_class )
72     return self.world.remove_component_from( self, component_class )
73 end

Protected Instance Methods

inspect_details()

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

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