X-Git-Url: http://git.shiar.nl/wormy.git/blobdiff_plain/6d64bb2aa29809c9c24fb5ee036766440b62bf4a..4a81674950329bfeb881ff6e08792daffd8cf849:/parse-wormedit diff --git a/parse-wormedit b/parse-wormedit index 4c4358f..0c94994 100755 --- a/parse-wormedit +++ b/parse-wormedit @@ -9,11 +9,13 @@ use Getopt::Long 2.33 qw(HelpMessage :config bundling); use Games::Wormy::TICalcLevels; use Games::Wormy::WormEdit; -our $VERSION = '1.05'; +our $VERSION = '1.06'; GetOptions(\my %opt, 'raw|r', # full output 'version=i', # force version + 'render:i', # image of level(s) + 'output|o=s', # output file ) or HelpMessage(-exitval => 2); my @OBJTYPE = ('none', 'line', 'fat line', 'bar', 'circle'); @@ -46,8 +48,44 @@ else { die "Unrecognised file type\n"; } +if ($opt{output}) {{ + # derive format from file extension + if ($opt{output} =~ /\.yaml$/) { + $opt{raw} = 1; + } + elsif ($opt{output} !~ /\.txt$/) { + $opt{render} ||= 0; + last; # images are written directly to file + } + + # redirect standard output to given file + open my $output, '>', $opt{output} + or die "Cannot output to '$opt{output}': $!"; + select $output; +}} + # output with user-preferred formatting -if ($opt{raw}) { +if (defined $opt{render}) { + require Games::Wormy::Render; + + my @request; + if ($opt{render}) { + # find all numeric values in argument + @request = $opt{render} =~ /(\d+)/g; + } + else { + # default to all singleplayer levels + @request = 0 .. $data->{levelcount}->{single} - 1; + } + + my $img = Games::Wormy::Render->composite( + map { $data->{levels}->[$_] } @request + ); + $img->write( + $opt{output} ? (file => $opt{output}) : (fh => \*STDOUT, type => 'pnm') + ) or die $img->errstr; +} +elsif ($opt{raw}) { # full data in yaml (human-readable) formatting require YAML; local $YAML::CompressSeries; @@ -131,12 +169,14 @@ parse-wormedit - Wormy level data parser =head1 SYNOPSIS - parse-wormedit [--raw] + parse-wormedit [--raw|--render] [--output ] =head1 DESCRIPTION Reads Wormy levels (either original WormEdit source or compiled TI-86 string) -from STDIN or given file, and outputs contents, summarised or in full. +from STDIN or given file, and prints summarised contents to STDOUT. + +If an I file name is given, its extension determines the format. =head1 AUTHOR