Skip to content

Commit

Permalink
on #383 - use the event facility to find weakness
Browse files Browse the repository at this point in the history
* capture/replay in simple/samples/chipmunk.rb
* work in progress
  • Loading branch information
Cecil committed Dec 15, 2017
1 parent 3cb8390 commit d25fa42
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions Tests/events/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
y = w2.top
w2.move x+80, y-40
$base_t = Time.now
$capture << {captured: @el.text, time: $base_t}
w2.event = proc do |evt|
case evt.type
when :click
#$stderr.puts "click handler2 with #{evt.type}"
$capture << { time: (Time.now - $baset), x: evt.x, y: evt.y}
$capture << { time: (Time.now - $base_t), x: evt.x, y: evt.y}
evt.accept = true
else
evt.accept = true
Expand All @@ -42,9 +43,41 @@
end
end
flow do
button "stop and save" do
button "Stop and save" do
File.open(@sv.text, 'w') {|f| YAML.dump($capture, f)}
end
end
flow do
button "Load events" do
@evts = YAML::load_file(@sv.text)
puts @evts
hdr = @evts[0]
script = hdr[:captured]
eval IO.read(script).force_encoding("UTF-8"), TOPLEVEL_BINDING, script
w2 = Shoes.APPS[-1]
x = w2.left
y = w2.top
w2.move x+80, y-40
end
button "Replay" do
w2 = Shoes.APPS[-1]
# Hard part here
#w2.replay_events = proc do
#end
delay = 0
for r in 1..@evts.size
ev = @evts[r]
t = ev[:time]
delay = t if r==1
wait = t - delay
puts wait
th = Thread.new do
sleep wait
th.join
end
delay = t
end
end
end
end
end

0 comments on commit d25fa42

Please sign in to comment.