diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-05-10 10:31:08 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-05-10 10:31:08 +0100 |
commit | 42f9fdc0b88dd819a61593ed053d6b0713c59e45 (patch) | |
tree | 457cd53d93606bce249d7a0016cde68da2a98564 /forward-please | |
parent | a24f29c0e92a70415f679bc8e2fdd4e6410e1948 (diff) |
Diffstat (limited to 'forward-please')
-rwxr-xr-x | forward-please | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/forward-please b/forward-please index ebb6d4b..e8e7933 100755 --- a/forward-please +++ b/forward-please @@ -14,9 +14,9 @@ $level = $levels.shift def help puts <<~EOF Commands: - f {frame} {iface}: forward a frame to iface + f {iface}: forward the frame to iface h: this help - c: click on + n: next frame d: show the level description a: show the click frames and actions q: quit @@ -25,35 +25,27 @@ end $instructions = [] -def forward(frame, iface) - if !$clickframes.keys.include?(frame) - puts "#{frame} is not a frame in this click" - return - end - +def forward(iface) if !$level.interfaces.include?(iface) puts "#{iface} is not an interface in this device" return end - $instructions << [frame, $clickframes[frame].to(iface)] + $instructions << $frame.to(iface) end def clickactions - puts "Click #{$click}:" + puts "Frame #{$click}:" puts " Interfaces:" puts " #{$level.interfaces.join(", ")}" - puts " Frames:" - $clickframes.each do |id, frame| - puts " #{id}: #{frame.description} from Interface #{frame.iface}" - end + puts " Frame:" + puts " #{$frame.description} from Interface #{$frame.iface}" - i = 1 puts " Actions:" - $instructions.each do |instr| - puts " #{i}: Forward frame #{instr[0]} to interface #{instr[1].iface}" + $instructions.each_with_index do |instr, idx| + puts " #{idx + 1}: Forward frame to interface #{instr.iface}" end end @@ -63,13 +55,9 @@ def click right = 0 wrong = 0 - targetframes = [] - $clickframes.each do |id, frame| - targetframes += $level.target(frame) - end - targetframes.flatten! + targetframes = $level.target($frame) - $instructions.each do |id, frame| + $instructions.each do |frame| if targetframes.include?(frame) right += 1 targetframes.delete(frame) @@ -98,24 +86,24 @@ def click puts end - $clickframes = $level.generate + $frame = $level.generate clickactions end def handle(cmd) case cmd.split[0] when ?f - args = cmd.split[1..] - if args.count == 2 - forward(*args) + arg = cmd.split[1] + if arg.nil? + puts "f {iface}" else - puts "f {frame} {iface}" + forward(arg) end when ?d puts $level.description when ?a clickactions - when ?c + when ?n click when ?q exit 0 @@ -128,7 +116,7 @@ end puts $level.description puts -$clickframes = $level.generate +$frame = $level.generate clickactions loop do |