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');
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;
=head1 SYNOPSIS
- parse-wormedit [--raw] <input.lvl>
+ parse-wormedit [--raw|--render] [--output <file.ext>] <input.lvl>
=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<output> file name is given, its extension determines the format.
=head1 AUTHOR