Class: CooldownTimer
- Defined in:
- tomes/components/timer/cooldown_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 some given time and counts down.
Instance Attribute Summary collapse
-
#reset_time ⇒ Object
readonly
The default time (in frames) to reset to.
Attributes inherited from Timer
Instance Method Summary collapse
-
#count(auto_reset: false, auto_restart: false) ⇒ Void
This decrements the frame counter every tick the Timer is active.
-
#reset! ⇒ Object
Sets the frame counter to the #reset_time.
-
#signal ⇒ Boolean
Returns whether the frame counter is zero.
Methods inherited from Timer
#flip!, #to_s, #turn_off!, #turn_on!
Methods included from TimerConverter
#calculate_current_time, #formatted_time, #formatted_time_table, #frames_to_seconds, #full_status, #seconds_to_minutes
Instance Attribute Details
#reset_time ⇒ Object
The default time (in frames) to reset to.
12 |
# File 'tomes/components/timer/cooldown_timer.rb', line 12 attr_writer :reset_time |
Instance Method Details
#count(auto_reset: false, auto_restart: false) ⇒ Void
This decrements the frame counter every tick the Timer is active.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'tomes/components/timer/cooldown_timer.rb', line 38 def count(auto_reset: false, auto_restart: false) return unless on? if frames.positive? && on? self.frames -= 1 else turn_off! reset! if auto_reset || auto_restart self.on = true if auto_restart end end |
#reset! ⇒ Object
Sets the frame counter to the #reset_time.
51 52 53 |
# File 'tomes/components/timer/cooldown_timer.rb', line 51 def reset! self.frames = reset_time end |
#signal ⇒ Boolean
Returns whether the frame counter is zero. It is ‘true’ if the count is at zero and ‘false’ otherwise. Other objects or methods can use #signal to determine logic. (i.e. Player can’t attack if #signal is true.)
27 28 29 |
# File 'tomes/components/timer/cooldown_timer.rb', line 27 def signal frames.zero? end |