3 ByoYomi = Struct.new(:time, :periods)
6 # increment = increment per move
7 # byoyomi.time = time per move after main is elapsed
8 # byoyomi.periods = number of times byoyomi.time has to elapse
9 # for the byoyomi to end
11 # byoyomi and increment don't work together
13 # all times are in seconds
15 def initialize(main, increment, byoyomi, timer_class = Qt::Timer)
17 @increment = increment
19 @byoyomi = byoyomi.dup
20 @byoyomi_time = @byoyomi.time
23 @timer = timer_class.new
24 @timer.single_shot = true
25 @timer.on(:timeout) { tick }
38 @elapsed += @time.elapsed
43 fire :timer => { :main => @main }
47 # milliseconds for the next tick
48 delta = (@count + 1) * 100 - @elapsed
61 # if we get here, there must be
62 # a byoyomi, otherwise the timer would
67 @byoyomi.time = @byoyomi_time
68 if @byoyomi.periods <= 0
74 if @main <= 0 and (not @byoyomi)
82 fire :timer => { :main => @main }
84 fire :timer => { :byoyomi => @byoyomi.dup }
90 delta = (@count + 1) * 100 - @elapsed - @time.elapsed