Clean syntax identifier instead of adding new options for every (sub)format.
Retains support for previous options.
use strict;
use warnings;
use strict;
use warnings;
+use experimental 'switch';
use lib 'lib'; # make runnable for simple cases
use Data::Dumper;
use lib 'lib'; # make runnable for simple cases
use Data::Dumper;
use Games::Wormy::TICalcLevels;
use Games::Wormy::WormEdit;
use Games::Wormy::TICalcLevels;
use Games::Wormy::WormEdit;
+ 'format|f=s', # output type
+ 'raw|r!', # compatibility for yaml format
'version=i', # force version
'version=i', # force version
- 'render:i', # image of level(s)
+ 'levels|render:i', # image of level(s)
'output|o=s', # output file
) or HelpMessage(-exitval => 2);
'output|o=s', # output file
) or HelpMessage(-exitval => 2);
+$opt{format} //= 'yaml' if $opt{raw};
+$opt{format} //= 'pnm' if defined $opt{levels};
my @OBJTYPE = ('none', 'line', 'fat line', 'bar', 'circle');
my @ENDTYPE = ('none', 'message', 'small message');
my @OBJTYPE = ('none', 'line', 'fat line', 'bar', 'circle');
my @ENDTYPE = ('none', 'message', 'small message');
if ($opt{output}) {{
# derive format from file extension
if ($opt{output} =~ /\.yaml$/) {
if ($opt{output}) {{
# derive format from file extension
if ($opt{output} =~ /\.yaml$/) {
+ $opt{format} //= 'yaml';
}
elsif ($opt{output} !~ /\.txt$/) {
}
elsif ($opt{output} !~ /\.txt$/) {
+ $opt{format} //= 'pnm';
last; # images are written directly to file
}
last; # images are written directly to file
}
}}
# output with user-preferred formatting
}}
# output with user-preferred formatting
-if (defined $opt{render}) {
+given ($opt{format}) {
+when ('pnm') {
require Games::Wormy::Render;
my @request;
require Games::Wormy::Render;
my @request;
# find all numeric values in argument
# find all numeric values in argument
- @request = $opt{render} =~ /(\d+)/g;
+ @request = $opt{levels} =~ /(\d+)/g;
}
else {
# default to all singleplayer levels
}
else {
# default to all singleplayer levels
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT, type => 'pnm')
) or die $img->errstr;
}
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT, type => 'pnm')
) or die $img->errstr;
}
# full data in yaml (human-readable) formatting
require YAML;
local $YAML::CompressSeries;
# full data in yaml (human-readable) formatting
require YAML;
local $YAML::CompressSeries;
print $data->{name};
print " ($data->{description})" if defined $data->{description};
print "\n";
print $data->{name};
print " ($data->{description})" if defined $data->{description};
print "\n";
- parse-wormedit [--raw|--render] [--output <file.ext>] <input.lvl>
+ parse-wormedit [--format=<type>] [--levels=<number>] [--output=<file.ext>] <input.lvl>
=head1 DESCRIPTION
Reads Wormy levels (either original WormEdit source or compiled TI-86 string)
=head1 DESCRIPTION
Reads Wormy levels (either original WormEdit source or compiled TI-86 string)
-from STDIN or given file, and prints summarised contents to STDOUT.
+from STDIN or given file, and prints parsed data to STDOUT.
+
+If an I<output> file name is given, its extension determines the format,
+otherwise explicitly given by the I<format> option:
+
+=over 6
+
+=item txt
+
+Plain text summary of levelpack contents.
+
+=item yaml
+
+All parsed data in YAML syntax.
+
+=item pnm, png, bmp, ...
+
+Image drawing of rendered levels.
+Unrecognised values are interpreted as file type and converted by Imager.
-If an I<output> file name is given, its extension determines the format.