From 5f038fb3e000dfac421901388bbe977b23803acb Mon Sep 17 00:00:00 2001 From: Shiar Date: Sun, 10 Feb 2008 08:13:54 +0100 Subject: [PATCH] capture and graphplay scripts take command line options 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 | 51 +++++++++++++++++++++++++++++++++++++++++++-------- graphplay | 7 +++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/capture b/capture index 828f1fd..d363a49 100755 --- 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 [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 + diff --git a/graphplay b/graphplay index 9956168..bbbbc28 100755 --- 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, -- 2.30.0