XXX: scmap: restore metadata marking (era-dependant styling)
[perl/schtarr.git] / capture
diff --git a/capture b/capture
index 1ef47e874f079cc4ae42ae9bd76d66cfed3063b0..e9b1ca7caad5d48c2e24d14c2910d577ef3c09e7 100755 (executable)
--- a/capture
+++ b/capture
@@ -3,12 +3,17 @@
 use strict;
 use warnings;
 
+use Getopt::Long 2.33 qw(HelpMessage :config bundling);
 use Data::Dumper;
 use Time::HiRes qw(sleep alarm);
 use Imager;
-use constant {DEBUG => 0};
 
-our $VERSION = '2.00';
+our $VERSION = '2.01';
+
+GetOptions(
+       "verbose|v!" => \our $DEBUG,
+       "map|m!" => \our $GETMAP,
+) or HelpMessage(-exitval => 2);
 
 my %digittime = (
        '.####.'.
@@ -163,8 +168,11 @@ sub getchars {
 sub parsestats {
        my $input = shift;  # (452,6)-(639,13)
        $input->write(file => sprintf "tests%05d.png", $i) or warn $input->errstr
-               if DEBUG;
-       my $stats = filter_color($input, "\020\377\030", "\317\030\030", "\310\030\030"); # ?/10FF18 | C81818/CF1818
+               if $DEBUG;
+       my $stats = filter_color($input,
+               "\020\377\030", "\317\030\030", # CF1818/C81818
+               "\310\030\030", # ?/10FF18
+       );
        my $min = getchars($stats, \%digitgreen, 7, 0, 39);
        my $gas = getchars($stats, \%digitgreen, 7, 68, 107);
        my $unit = getchars($stats, \%digitgreen, 7, 136, 181);
@@ -176,8 +184,10 @@ sub parsestats {
 sub parsetimer {
        my $input = shift;  # (587,396)-(621,402)
        $input->write(file => sprintf "testt%05d.png", $i) or warn $input->errstr
-               if DEBUG;
-       my $play = filter_color($input, "\276\272\357"); # 190, 186, 239
+               if $DEBUG;
+       my $play = filter_color($input,
+               "\276\272\357", # BEBAEF
+       );
        my $time = getchars($play, \%digittime, 6, 0, 33);
        return (
                $time =~ /^(?:(\d):)?(\d\d):(\d\d)$/ ?
@@ -200,7 +210,7 @@ sub capturestats {
                screenshot(left=>452, top=>6, right=>639, bottom=>13)
        );
        my ($sec, $time) = parsetimer(
-               screenshot(left=>586, right=>621, top=>396, bottom=>402)
+               screenshot(left=>587, right=>621, top=>396, bottom=>402)
        );
        $time ne '?' or next;
        printf {$outstats} "%d:\t%s\t%s\t%s\t%s\t%s\n",
@@ -233,14 +243,13 @@ if ($ARGV[0]) {
        require Imager::Screenshot;
        import Imager::Screenshot qw(screenshot);
 
-       local $SIG{ALRM} = \&capturemap;
-       alarm 5, 1;
+       ($SIG{ALRM} = \&capturemap), alarm 5, 1 if $GETMAP;
        while (1) {
                $i++;
                capturestats();
-               sleep .2;
+               sleep .2 if $GETMAP;
        }
-       alarm 0;
+       alarm 0 if $GETMAP;
 }
 
 =cut
@@ -255,3 +264,39 @@ exec 'mencoder' => (
        '-msglevel' => 'all=3',
 );
 
+=head1 NAME
+
+capture - Read and parse StarCraft game screenshots
+
+=head1 SYNOPSIS
+
+B<capture> [OPTIONS] [INPUT]
+
+capture --map dump%04d.png
+
+=head1 OPTIONS
+
+=over 8
+
+=item --verbose | -v
+
+Debug mode.
+Stores captured statistics areas as test[ts]?????.png images.
+
+=item --map | -m
+
+Capture the minimap area every second (StarCraft won't update more often,
+regardless of game speed).
+Images are stored as map?????.png in the current directory.
+
+=back
+
+=head1 AUTHOR
+
+Mischa POSLAWSKY <perl@shiar.org>
+
+=head1 LICENSE
+
+You may distribute under the terms of either the GNU General Public License
+or the Artistic License, as specified in the Perl README file.
+