Class: Timer
- Includes:
- TimerConverter
- Defined in:
- tomes/components/timer/timer.rb
Overview
This class operates under the assumption that #count will be called every frame it is active.
A basic timer. This version starts at zero (or some given time) and counts up.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#frames ⇒ Object
(also: #time)
Returns the value of attribute frames.
-
#name ⇒ String
readonly
The given name of the Timer.
-
#on ⇒ Object
(also: #on?)
readonly
Returns the value of attribute on.
Instance Method Summary collapse
-
#count ⇒ Void
This increments the frame counter every tick the Timer is active.
-
#flip! ⇒ Object
Turns activates the timer if inactive; deactivates the timer if active.
-
#reset! ⇒ Void
Resets the frame counter to zero.
-
#signal ⇒ Boolean
(also: #true?)
Returns whether the frame counter is zero.
- #to_s ⇒ Object
-
#turn_off! ⇒ Void
(also: #stop, #stop!)
Deactivates the timer in place.
-
#turn_on! ⇒ Void
(also: #start, #start!)
Sets the timer active.
Methods included from TimerConverter
#calculate_current_time, #formatted_time, #formatted_time_table, #frames_to_seconds, #full_status, #seconds_to_minutes
Instance Attribute Details
#frames ⇒ Object Also known as: time
Returns the value of attribute frames.
32 33 34 |
# File 'tomes/components/timer/timer.rb', line 32 def frames @frames end |
#name ⇒ String
Returns The given name of the Timer.
28 29 30 |
# File 'tomes/components/timer/timer.rb', line 28 def name @name end |
#on ⇒ Object Also known as: on?
Returns the value of attribute on.
28 |
# File 'tomes/components/timer/timer.rb', line 28 attr_reader :name, :on |
Instance Method Details
#count ⇒ Void
This increments the frame counter every tick the Timer is active.
39 40 41 42 43 |
# File 'tomes/components/timer/timer.rb', line 39 def count return unless on? self.frames += 1 end |
#flip! ⇒ Object
Turns activates the timer if inactive; deactivates the timer if active.
62 63 64 |
# File 'tomes/components/timer/timer.rb', line 62 def flip! on? ? turn_off! : turn_on! end |
#reset! ⇒ Void
Resets the frame counter to zero.
68 69 70 |
# File 'tomes/components/timer/timer.rb', line 68 def reset! self.frames = 0 end |
#signal ⇒ Boolean Also known as: true?
Returns whether the frame counter is zero. It is ‘true’ if the count is above zero and ‘false’ otherwise. Other objects or methods can use #signal to determine logic. (i.e. Player takes no damage if #signal is true.)
77 78 79 |
# File 'tomes/components/timer/timer.rb', line 77 def signal frames.positive? end |
#to_s ⇒ Object
82 83 84 |
# File 'tomes/components/timer/timer.rb', line 82 def to_s format('%s %s', name, formatted_time) end |
#turn_off! ⇒ Void Also known as: stop, stop!
Deactivates the timer in place.
55 56 57 |
# File 'tomes/components/timer/timer.rb', line 55 def turn_off! self.on = false end |
#turn_on! ⇒ Void Also known as: start, start!
Sets the timer active.
47 48 49 |
# File 'tomes/components/timer/timer.rb', line 47 def turn_on! self.on = true end |