capture and graphplay scripts take command line options
authorShiar <shiar@shiar.org>
Sun, 10 Feb 2008 07:13:54 +0000 (08:13 +0100)
committerShiar <shiar@shiar.org>
Sun, 10 Feb 2008 07:17:17 +0000 (08:17 +0100)
Fix the need to modify code for changing run mode.
Debug mode can be triggered by --verbose (-v).
Map capturing can be enabled by --map (-m).
Common --version and --help are handled as a bonus (short documentation
setup written for capture).

capture
graphplay

diff --git a/capture b/capture
index 828f1fd9af42678dfb9e6989566ae7b7aa1acf3a..d363a49fc08ca8f3d372a865fed4f69b45f04976 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,7 +168,7 @@ 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;
+               if $DEBUG;
        my $stats = filter_color($input,
                "\020\377\030", "\317\030\030", # CF1818/C81818
                "\310\030\030", # ?/10FF18
@@ -179,7 +184,7 @@ 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;
+               if $DEBUG;
        my $play = filter_color($input,
                "\276\272\357", # BEBAEF
        );
@@ -238,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
@@ -260,3 +264,34 @@ 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>
+
index 9956168612fe29ce5ba3903b1eda95d3a109189e..bbbbc28f98c81af6a25c23a2c8bf12b387d2527f 100755 (executable)
--- a/graphplay
+++ b/graphplay
@@ -2,10 +2,17 @@
 use strict;
 use warnings;
 
+use Getopt::Long 2.33 qw(HelpMessage :config bundling);
 use Template;
 use List::Util;
 use Data::Dumper;
 
+our $VERSION = '1.00';
+
+GetOptions(
+       "verbose|v!" => \our $DEBUG,
+) or HelpMessage(-exitval => 2);
+
 my %area = (
        fieldxmin => 45,
        fieldxmax => 1590,