Class: Timer

Inherits:
Object show all
Includes:
TimerConverter
Defined in:
tomes/components/timer/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 zero (or some given time) and counts up.

Direct Known Subclasses

CooldownTimer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TimerConverter

#calculate_current_time, #formatted_time, #formatted_time_table, #frames_to_seconds, #full_status, #seconds_to_minutes

Instance Attribute Details

#framesObject 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

#nameString

Returns The given name of the Timer.

Returns:

  • (String)

    The given name of the Timer.



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

def name
  @name
end

#onObject 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

#countVoid

This increments the frame counter every tick the Timer is active.

Returns:

  • (Void)


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.

Returns:

  • (Void)


68
69
70
# File 'tomes/components/timer/timer.rb', line 68

def reset!
  self.frames = 0
end

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

Returns:

  • (Boolean)


77
78
79
# File 'tomes/components/timer/timer.rb', line 77

def signal
  frames.positive?
end

#to_sObject



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.

Returns:

  • (Void)


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.

Returns:

  • (Void)


47
48
49
# File 'tomes/components/timer/timer.rb', line 47

def turn_on!
  self.on = true
end