parse-wormedit: json format option
[wormy.git] / parse-wormedit
index 721cec841e15a519862aae501dd8d7484550ec7c..aa220513657bfdaf49507b9311e97ea627334025 100755 (executable)
@@ -54,7 +54,7 @@ else {
 
 if ($opt{output}) {{
        # derive format from file extension
-       if ($opt{output} =~ /\.(yaml|txt)$/) {
+       if ($opt{output} =~ /\.(yaml|json|txt)$/) {
                $opt{format} //= $1
        }
        else {
@@ -70,6 +70,10 @@ if ($opt{output}) {{
 
 # output with user-preferred formatting
 given ($opt{format}) {
+when ('json') {
+       require JSON;
+       say JSON->new->encode($data);
+}
 when ('yaml') {
        # full data in yaml (human-readable) formatting
        require YAML;
@@ -162,6 +166,10 @@ default {
        my $img = Games::Wormy::Render->composite(
                map { $data->{levels}->[$_] } @request
        ) or die "empty result for levels\n";
+       if ($opt{format} ~~ 'pbm') {
+               $img = $img->to_paletted({make_colors => 'mono'});
+               $opt{format} = 'pnm';
+       }
        $img->write(
                $opt{output} ? (file => $opt{output}) : (fh => \*STDOUT),
                type => $opt{format} // 'pnm',
@@ -197,6 +205,10 @@ Plain text summary of levelpack contents.
 
 All parsed data in YAML syntax.
 
+=item json
+
+Parsed data in JSON syntax.
+
 =item pnm, png, bmp, ...
 
 Image drawing of rendered levels.