Class: CooldownTimer

Inherits:
Timer show all
Defined in:
tomes/components/timer/cooldown_timer.rb

Overview

Note:

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

Attributes inherited from Timer

#frames, #name, #on

Instance Method Summary collapse

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_timeObject

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.

Parameters:

  • auto_reset (Boolean) (defaults to: false)

    If this is ‘true’ the timer will reset the frame counter to the #reset_time the frame after it hits zero.

  • auto_restart (Boolean) (defaults to: false)

    If this is ‘true’ the timer will reset itself and immediately start itself again after it hits zero. You do not have to set auto_reset to ‘true’ if this is set to ‘true’.

Returns:

  • (Void)


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

#signalBoolean

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.)

Returns:

  • (Boolean)


27
28
29
# File 'tomes/components/timer/cooldown_timer.rb', line 27

def signal
  frames.zero?
end