Class: ActorDefinition
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#behavior_blk ⇒ Object
Returns the value of attribute behavior_blk.
-
#behaviors ⇒ Object
Returns the value of attribute behaviors.
-
#source ⇒ Object
Returns the value of attribute source.
-
#view_blk ⇒ Object
Returns the value of attribute view_blk.
Instance Method Summary collapse
-
#behavior(&blk) ⇒ Object
Defines a Behavior with the Actor type as the name and adds it to the Actor.
-
#has_attributes(*attributes) ⇒ Object
(also: #has_attribute)
Setup observable attributes for the Actor and optionally default values.
-
#has_behaviors(*behaviors, &blk) ⇒ Object
(also: #has_behavior)
Setup default behaviors for this Actor.
-
#initialize ⇒ ActorDefinition
constructor
A new instance of ActorDefinition.
-
#view(&blk) ⇒ Object
Defines an ActorView for this Actor with the correct name.
Constructor Details
#initialize ⇒ ActorDefinition
Returns a new instance of ActorDefinition.
3 4 5 6 |
# File 'lib/gamebox/core/actor_definition.rb', line 3 def initialize @behaviors = [] @attributes = [] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
2 3 4 |
# File 'lib/gamebox/core/actor_definition.rb', line 2 def attributes @attributes end |
#behavior_blk ⇒ Object
Returns the value of attribute behavior_blk.
2 3 4 |
# File 'lib/gamebox/core/actor_definition.rb', line 2 def behavior_blk @behavior_blk end |
#behaviors ⇒ Object
Returns the value of attribute behaviors.
2 3 4 |
# File 'lib/gamebox/core/actor_definition.rb', line 2 def behaviors @behaviors end |
#source ⇒ Object
Returns the value of attribute source.
2 3 4 |
# File 'lib/gamebox/core/actor_definition.rb', line 2 def source @source end |
#view_blk ⇒ Object
Returns the value of attribute view_blk.
2 3 4 |
# File 'lib/gamebox/core/actor_definition.rb', line 2 def view_blk @view_blk end |
Instance Method Details
#behavior(&blk) ⇒ Object
Defines a Behavior with the Actor type as the name and adds it to the Actor.
Exactly the same as calling define_behavior with :my_actor, and adding the behavior to the Actor.
Do not call more than once.
69 70 71 |
# File 'lib/gamebox/core/actor_definition.rb', line 69 def behavior(&blk) @behavior_blk = blk end |
#has_attributes(*attributes) ⇒ Object Also known as: has_attribute
Setup observable attributes for the Actor and optionally default values
# takes list of attributes (values will be nil)
has_attributes :x, :y
# takes hash of attributes with values
has_attributes x: 5, y: 12
45 46 47 48 49 |
# File 'lib/gamebox/core/actor_definition.rb', line 45 def has_attributes(*attributes) attributes.each do |att| @attributes << att end end |
#has_behaviors(*behaviors, &blk) ⇒ Object Also known as: has_behavior
Setup default behaviors for this Actor
# takes a block with method missing magic
has_behaviors do
shooter range: 12
end
# takes a list of optionless behaviors
has_behaviors :jumper, :shielded
# takes a hash of behavior name to options
has_behaviors shooter: {range: 12}
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gamebox/core/actor_definition.rb', line 20 def has_behaviors(*behaviors, &blk) if block_given? collector = MethodMissingCollector.new collector.instance_eval &blk collector.calls.each do |name, args| if args.empty? @behaviors << name else @behaviors << {name => args.first} end end end behaviors.each do |beh| @behaviors << beh end end |
#view(&blk) ⇒ Object
Defines an ActorView for this Actor with the correct name.
Exactly the same as calling define_actor_view with :my_actor_view.
Do not call more than once.
59 60 61 |
# File 'lib/gamebox/core/actor_definition.rb', line 59 def view(&blk) @view_blk = blk end |