git.shiar.nl
/
wormy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
parse-wormedit: include multiplayer levels in images
[wormy.git]
/
parse-wormedit
diff --git
a/parse-wormedit
b/parse-wormedit
index 721cec841e15a519862aae501dd8d7484550ec7c..06a261de805704128f6fd603206b17b6833927c2 100755
(executable)
--- a/
parse-wormedit
+++ b/
parse-wormedit
@@
-52,24
+52,31
@@
else {
die "Unrecognised file type\n";
}
die "Unrecognised file type\n";
}
+my $format = $opt{format}; # override distinct from image fallback
if ($opt{output}) {{
# derive format from file extension
if ($opt{output}) {{
# derive format from file extension
- if ($opt{output} =~ /\.(yaml|txt)$/) {
- $opt{format} //= $1
+ $format //= $1 if $opt{output} =~ /\.([^.]+)$/;
+
+ if ($format ~~ [qw{ yaml json txt }]) {
+ # redirect standard output to given file
+ open my $output, '>', $opt{output}
+ or die "Cannot output to '$opt{output}': $!";
+ select $output;
}
else {
# images are written directly to file
}
else {
# images are written directly to file
- last;
}
}
-
- # redirect standard output to given file
- open my $output, '>', $opt{output}
- or die "Cannot output to '$opt{output}': $!";
- select $output;
}}
}}
+else {
+ $format //= 'txt';
+}
# output with user-preferred formatting
# output with user-preferred formatting
-given ($opt{format}) {
+given ($format) {
+when ('json') {
+ require JSON;
+ say JSON->new->encode($data);
+}
when ('yaml') {
# full data in yaml (human-readable) formatting
require YAML;
when ('yaml') {
# full data in yaml (human-readable) formatting
require YAML;
@@
-154,17
+161,21
@@
default {
@request = $opt{levels} =~ /(\d+)/g;
}
else {
@request = $opt{levels} =~ /(\d+)/g;
}
else {
- # default to all
singleplayer
levels
- @request = 0 .. $data->{levelcount}->{
single
} - 1;
+ # default to all levels
+ @request = 0 .. $data->{levelcount}->{
total
} - 1;
}
@request or die "no levels found or specified\n";
my $img = Games::Wormy::Render->composite(
map { $data->{levels}->[$_] } @request
) or die "empty result for levels\n";
}
@request or die "no levels found or specified\n";
my $img = Games::Wormy::Render->composite(
map { $data->{levels}->[$_] } @request
) or die "empty result for levels\n";
+ if ($format ~~ 'pbm') {
+ $img = $img->to_paletted({make_colors => 'mono'});
+ $opt{format} = 'pnm';
+ }
$img->write(
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT),
$img->write(
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT),
- type => $opt{format}
// 'pnm'
,
+ type => $opt{format},
) or die $img->errstr;
}
}
) or die $img->errstr;
}
}
@@
-177,7
+188,7
@@
parse-wormedit - Wormy level data parser
=head1 SYNOPSIS
=head1 SYNOPSIS
- parse-wormedit [--format=<type>] [--level
s
=<number>] [--output=<file.ext>] <input.lvl>
+ parse-wormedit [--format=<type>] [--level=<number>] [--output=<file.ext>] <input.lvl>
=head1 DESCRIPTION
=head1 DESCRIPTION
@@
-197,6
+208,10
@@
Plain text summary of levelpack contents.
All parsed data in YAML syntax.
All parsed data in YAML syntax.
+=item json
+
+Parsed data in JSON syntax.
+
=item pnm, png, bmp, ...
Image drawing of rendered levels.
=item pnm, png, bmp, ...
Image drawing of rendered levels.