Class: ShatteredPack::Timer::TimedEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/shattered_pack/timer/timed_event.rb

Direct Known Subclasses

ContinuousTimedEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, seconds, options = {}, &block) ⇒ TimedEvent

Returns a new instance of TimedEvent.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shattered_pack/timer/timed_event.rb', line 31

def initialize(context, seconds, options={}, &block)
  @context=context
  @event = block
  @options = options
  if(seconds != :frame)
    @time_remaining = seconds
    @initial_time = @time_remaining
  else
    @time_remaining = 0
    @initial_time = 0
  end
end

Instance Attribute Details

#time_remainingObject

Returns the value of attribute time_remaining.



30
31
32
# File 'lib/shattered_pack/timer/timed_event.rb', line 30

def time_remaining
  @time_remaining
end

Instance Method Details

#processed?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/shattered_pack/timer/timed_event.rb', line 51

def processed?
  return @processed == true
end

#resetObject



54
55
56
# File 'lib/shattered_pack/timer/timed_event.rb', line 54

def reset
  @time_remaining = @initial_time
end

#stopObject

Stop the timer



58
59
60
# File 'lib/shattered_pack/timer/timed_event.rb', line 58

def stop
  @stopped = true
end

#stopped?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/shattered_pack/timer/timed_event.rb', line 61

def stopped?
  !@stopped.nil?
end

#update(time_elapsed) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/shattered_pack/timer/timed_event.rb', line 43

def update(time_elapsed)
  return if processed? || stopped?
  @time_remaining -= time_elapsed
  if time_up?
    process_event
    @processed=true
  end
end