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 }
34 @elapsed += @time.elapsed
40 fire :timer => { :main => @main }
46 # milliseconds for the next tick
47 delta = [0, (@count + 1) * 100 - @elapsed].max
62 # if we get here, there must be
63 # a byoyomi, otherwise the timer would
68 @byoyomi.time = @byoyomi_time
69 if @byoyomi.periods <= 0
75 if @main <= 0 and (not @byoyomi)
89 delta = [0, (@count + 1) * 100 - @elapsed - @time.elapsed].max
98 { :byoyomi => @byoyomi.dup }