Class: Entity
- Inherits:
-
Object
- Object
- Entity
- Defined in:
- lib/delve/entity.rb
Instance Method Summary collapse
- #act ⇒ Object
- #add(component) ⇒ Object
- #get(component_id) ⇒ Object
- #has?(component_id) ⇒ Boolean
-
#initialize ⇒ Entity
constructor
A new instance of Entity.
Constructor Details
#initialize ⇒ Entity
Returns a new instance of Entity.
2 3 4 |
# File 'lib/delve/entity.rb', line 2 def initialize @components = Hash.new end |
Instance Method Details
#act ⇒ Object
20 21 22 |
# File 'lib/delve/entity.rb', line 20 def act get(:actor).act if has?(:actor) end |
#add(component) ⇒ Object
10 11 12 13 |
# File 'lib/delve/entity.rb', line 10 def add(component) raise 'Cannot add the same component more than once' if has?(component.id) @components[component.id] = component end |
#get(component_id) ⇒ Object
15 16 17 18 |
# File 'lib/delve/entity.rb', line 15 def get(component_id) return nil unless has?(component_id) @components[component_id] end |
#has?(component_id) ⇒ Boolean
6 7 8 |
# File 'lib/delve/entity.rb', line 6 def has?(component_id) @components.keys.include? component_id end |