forked from penma/guckets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog2input
executable file
·62 lines (54 loc) · 1.15 KB
/
log2input
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Time::HiRes qw(sleep time);
$| = 1;
# we'll face a dialog box...
print "\cM";
sub moveto {
my $new = shift;
state $old = 0;
if ($new > $old) {
print "" . ("l" x ($new - $old));
} else {
print "" . ("h" x ($old - $new));
}
$old = $new;
}
# read the actions.
my $basetime = undef;
my $starttime = time();
while (<>) {
chomp;
my ($time, $action) = /time=([^,]+), .*? action=(.*)$/;
if (!defined($basetime)) {
$basetime = $time;
}
# sleep the appropriate amount of time.
my $diff = ($time - $basetime) - (time() - $starttime);
if ($diff < 0) {
$starttime += $diff;
} else {
sleep($diff);
}
# now do the stuff
if ($action =~ /^fill (\d+)$/) {
moveto($1);
print "k";
} elsif ($action =~ /^empty (\d+)$/) {
moveto($1);
print "j";
} elsif ($action =~ /^pour (\d+) -> (\d+)$/) {
moveto($1); print " "; moveto($2); print " ";
} elsif ($action =~ /^(fill|empty|pour) completed$/) {
# nothing
} elsif ($action =~ /^hook executed, replied/) {
# be sure to display the message
sleep(1);
$starttime += 1;
print "\cJ";
} elsif ($action =~ /^goals /) {
print "\cJ";
}
}