From 2bceba75b8f2b6a2b5b235689bf1e1741845ad77 Mon Sep 17 00:00:00 2001 From: Mischa Poslawsky Date: Mon, 26 Oct 2020 22:14:12 +0100 Subject: [PATCH] parse-wormedit: format option overrides image file Save specific extension allowing stdout syntax distinct from pnm. --- parse-wormedit | 55 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/parse-wormedit b/parse-wormedit index 99daaa1..721cec8 100755 --- a/parse-wormedit +++ b/parse-wormedit @@ -54,12 +54,12 @@ else { if ($opt{output}) {{ # derive format from file extension - if ($opt{output} =~ /\.yaml$/) { - $opt{format} //= 'yaml'; + if ($opt{output} =~ /\.(yaml|txt)$/) { + $opt{format} //= $1 } - elsif ($opt{output} !~ /\.txt$/) { - $opt{format} //= 'pnm'; - last; # images are written directly to file + else { + # images are written directly to file + last; } # redirect standard output to given file @@ -70,27 +70,6 @@ if ($opt{output}) {{ # output with user-preferred formatting given ($opt{format}) { -when ('pnm') { - require Games::Wormy::Render; - - my @request; - if ($opt{levels}) { - # find all numeric values in argument - @request = $opt{levels} =~ /(\d+)/g; - } - else { - # default to all singleplayer levels - @request = 0 .. $data->{levelcount}->{single} - 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"; - $img->write( - $opt{output} ? (file => $opt{output}) : (fh => \*STDOUT, type => 'pnm') - ) or die $img->errstr; -} when ('yaml') { # full data in yaml (human-readable) formatting require YAML; @@ -113,7 +92,7 @@ when ('yaml') { print $yml; } -default { +when ('txt') { print $data->{name}; print " ($data->{description})" if defined $data->{description}; print "\n"; @@ -166,6 +145,28 @@ default { } print "\n"; } +default { + require Games::Wormy::Render; + + my @request; + if ($opt{levels}) { + # find all numeric values in argument + @request = $opt{levels} =~ /(\d+)/g; + } + else { + # default to all singleplayer levels + @request = 0 .. $data->{levelcount}->{single} - 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"; + $img->write( + $opt{output} ? (file => $opt{output}) : (fh => \*STDOUT), + type => $opt{format} // 'pnm', + ) or die $img->errstr; +} } __END__ -- 2.30.0