Class: ComplexMove
- Inherits:
-
Object
- Object
- ComplexMove
- Includes:
- Serializable
- Defined in:
- lib/game_2d/complex_move.rb
Overview
A complex move is any move that has its own state. Moves that span multiple ticks are complex, because the server may have to tell the client how much of the complex move has been completed by a player.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#actor_id ⇒ Object
Returns the value of attribute actor_id.
Instance Method Summary collapse
- #all_state ⇒ Object
- #as_json ⇒ Object
-
#initialize(actor = nil) ⇒ ComplexMove
constructor
A new instance of ComplexMove.
-
#on_completion(actor) ⇒ Object
Take a final action after the complex move is done.
- #to_s ⇒ Object
-
#update(actor) ⇒ Object
Execute one tick of the move.
- #update_from_json(json) ⇒ Object
Methods included from Serializable
#<=>, #==, as_json, #eql?, from_json, #hash, #to_json
Constructor Details
#initialize(actor = nil) ⇒ ComplexMove
Returns a new instance of ComplexMove.
13 14 15 |
# File 'lib/game_2d/complex_move.rb', line 13 def initialize(actor=nil) self.actor_id = actor.nullsafe_registry_id end |
Instance Attribute Details
#actor_id ⇒ Object
Returns the value of attribute actor_id.
11 12 13 |
# File 'lib/game_2d/complex_move.rb', line 11 def actor_id @actor_id end |
Instance Method Details
#all_state ⇒ Object
32 33 34 |
# File 'lib/game_2d/complex_move.rb', line 32 def all_state [actor_id] end |
#as_json ⇒ Object
35 36 37 |
# File 'lib/game_2d/complex_move.rb', line 35 def as_json Serializable.as_json(self).merge!(:actor_id => actor_id) end |
#on_completion(actor) ⇒ Object
Take a final action after the complex move is done
30 |
# File 'lib/game_2d/complex_move.rb', line 30 def on_completion(actor); end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/game_2d/complex_move.rb', line 42 def to_s self.class.name end |
#update(actor) ⇒ Object
Execute one tick of the move. Return true if there is more work to do, false if the move has completed.
24 25 26 |
# File 'lib/game_2d/complex_move.rb', line 24 def update(actor) false end |
#update_from_json(json) ⇒ Object
38 39 40 41 |
# File 'lib/game_2d/complex_move.rb', line 38 def update_from_json(json) self.actor_id = json[:actor_id] if json[:actor_id] self end |