class Chione::Entity

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() click to toggle source

Return an ID for an Entity.

# File lib/chione/entity.rb, line 22
def self::make_new_id
        return Chione.uuid.generate
end
new( world, id=nil ) click to toggle source

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

Public Instance Methods

==( other ) click to toggle source

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

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 56
def add_component( component, **init_values )
        self.world.add_component_to( self, component, **init_values )
end
components() click to toggle source

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

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 63
def get_component( component_class )
        return self.world.get_component_for( self, component_class )
end
has_component?( component_class ) click to toggle source

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

# File lib/chione/entity.rb, line 77
def has_component?( component_class )
        return self.world.has_component_for?( self, component_class )
end
remove_component( component_class ) click to toggle source

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

Protected Instance Methods

inspect_details() click to toggle source

Return the detailed part of the Entity's inspect output

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