parse-wormedit: more details in summarised mode
authorMischa Poslawsky <wormy@shiar.org>
Wed, 25 Feb 2009 08:45:54 +0000 (09:45 +0100)
committerMischa Poslawsky <wormy@shiar.org>
Mon, 2 Mar 2009 21:42:35 +0000 (22:42 +0100)
Display various episode and level properties, giving a more complete
overview (without actually drawing anything that is).

parse-wormedit

index 4f9295904e9d49356bd49034df801aeefbd66e9a..2eb9e277e417596d6d9a72204e5caba48a2815dd 100755 (executable)
@@ -5,7 +5,7 @@ use warnings;
 use Data::Dumper;
 use Getopt::Long 2.33 qw(HelpMessage :config bundling);
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 GetOptions(\my %opt,
        'raw|r',
@@ -82,6 +82,20 @@ my @FORMAT = (
        ],
 );
 
+my @OBJTYPE = ('none', 'line', 'fat line', 'bar', 'circle');
+my @ENDTYPE = ('none', 'message', 'small message');
+
+sub objsummary {
+       my ($objects) = @_;
+       my @objtypes = map { $_->{type} } @$objects;
+       my %count;
+       $count{$_}++ for @objtypes;
+       return (@objtypes > 1 && keys %count == 1 && 'all ') . join(', ',
+               map { $OBJTYPE[$_] ? $OBJTYPE[$_] . ($count{$_} > 1 && 's') : $_ }
+               sort keys %count
+       );
+}
+
 # read and parse all input data
 local $/;
 my @rawdata = unpack Shiar_Parse::Nested->template(\@FORMAT).'a*', readline;
@@ -102,6 +116,12 @@ if ($opt{raw}) {
 }
 else {
        print "$data->{name} ($data->{description})\n";
+       printf "File version: %s\n", "WormEdit v$data->{version}";
+       printf "Defaults: %s\n", join('; ',
+               'sprite ' . scalar @{ $data->{sprite} },
+               'hiscore by ' . $data->{hiname},
+       );
+
        my $startnr = 0;
        for my $variant (qw/single multi race ctf/) {
                print "\n";
@@ -109,14 +129,31 @@ else {
                printf "\u$variant ($count)";
                $count or next;
                print ":";
-               printf("\n- %-22s (%3sx%3s, %d objects)",
-                       $_->{id}, $_->{width}, $_->{height}, scalar @{ $_->{objects} },
+               printf("\n- %-22s%4s:%3s+%2s%3s %3sx%-3s%s",
+                       $_->{id} || $_->{name},
+                       @$_{qw/size bsize growth/},
+                       $variant eq 'single' && "x$_->{peas}",
+                       @$_{qw/width height/},
+                       join(';', map {" $_"} grep {$_}
+                               @{$_->{objects}} && sprintf('%2d object%s (%s)',
+                                       scalar @{$_->{objects}}, @{$_->{objects}} != 1 && 's',
+                                       objsummary($_->{objects}),
+                               ),
+                               @{$_->{sprite}} && sprintf('sprite %d',
+                                       scalar @{$_->{sprite}},
+                               ),
+                       ),
                ) for map { $data->{levels}->[$_ + $startnr] }
                        0 .. $count - 1;
                $startnr += $count;
        }
        continue {
                print "\n";
+               printf("-- %-21s%4d: %s (%s)\n",
+                       '(ending)',
+                       length $data->{enddata},
+                       $ENDTYPE[$data->{endtype}] || 'unknown', $data->{endstr},
+               ) if $variant eq 'single';
        }
 }