Class: Chione::Entity
- Inherits:
-
Object
- Object
- Chione::Entity
- Extended by:
- Deprecatable, Loggability
- Includes:
- Inspection
- Defined in:
- lib/chione/entity.rb
Overview
The Entity (identity) class
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The Entity’s ID.
-
#world ⇒ Object
readonly
The World the Entity belongs to.
Class Method Summary collapse
-
.make_new_id ⇒ Object
Return an ID for an Entity.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Equality operator – returns
true
if the receiver andother
belong to the same world, have the same ID, and have equal components. -
#add_component(component, **init_values) ⇒ Object
Add the specified
component
to the entity. -
#components ⇒ Object
Return the components that the entity’s World has registered for it as a Hash keyed by the Component class.
-
#get_component(component_class) ⇒ Object
Fetch the component of the specified
component_class
that corresponds with the receiving entity. -
#has_component?(component_class) ⇒ Boolean
Returns
true
if this entity has a component of the specifiedcomponent_class
. -
#initialize(world, id = nil) ⇒ Entity
constructor
Create a new Entity for the specified
world
, and use the specifiedid
if given. -
#remove_component(component_class) ⇒ Object
Remove the component of the specified
component_class
that corresponds with the receiving entity.
Methods included from Inspection
Constructor Details
#initialize(world, id = nil) ⇒ Entity
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.
30 31 32 33 |
# File 'lib/chione/entity.rb', line 30 def initialize( world, id=nil ) @world = world @id = id || self.class.make_new_id end |
Instance Attribute Details
#id ⇒ Object (readonly)
The Entity’s ID
41 42 43 |
# File 'lib/chione/entity.rb', line 41 def id @id end |
#world ⇒ Object (readonly)
The World the Entity belongs to
44 45 46 |
# File 'lib/chione/entity.rb', line 44 def world @world end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Equality operator – returns true
if the receiver and other
belong to the same world, have the same ID, and have equal components.
85 86 87 88 |
# File 'lib/chione/entity.rb', line 85 def ==( other ) return other.instance_of?( self.class ) && self.id == other.id end |
#add_component(component, **init_values) ⇒ Object
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.
57 58 59 |
# File 'lib/chione/entity.rb', line 57 def add_component( component, **init_values ) self.world.add_component_to( self, component, init_values ) end |
#components ⇒ Object
Return the components that the entity’s World has registered for it as a Hash keyed by the Component class.
49 50 51 |
# File 'lib/chione/entity.rb', line 49 def components return self.world.components_for( self ) end |
#get_component(component_class) ⇒ Object
Fetch the component of the specified component_class
that corresponds with the receiving entity. Returns nil
if so much component exists.
64 65 66 |
# File 'lib/chione/entity.rb', line 64 def get_component( component_class ) return self.world.get_component_for( self, component_class ) end |
#has_component?(component_class) ⇒ Boolean
Returns true
if this entity has a component of the specified component_class
.
78 79 80 |
# File 'lib/chione/entity.rb', line 78 def has_component?( component_class ) return self.world.has_component_for?( self, component_class ) end |
#remove_component(component_class) ⇒ Object
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.
72 73 74 |
# File 'lib/chione/entity.rb', line 72 def remove_component( component_class ) return self.world.remove_component_from( self, component_class ) end |