or die "Couldn't chunk header\n";
$type =~ s/ +$//;
#printf STDERR "%s: %s\n", $type, $size;
- defined $self->{$type} and warn "duplicate map chunk $type\n";
- $self->{$type} = $self->_read($file, $size);
+ if (defined $self->{$type}) {
+ # redefinitions (partially) override earlier data from start
+ warn "duplicate map chunk $type\n";
+ my $prepend = $self->_read($file, $size);
+ substr($self->{$type}, 0, length($prepend)) = $prepend;
+ next;
+ }
+ else {
+ $self->{$type} = $self->_read($file, $size);
+ }
}
return $self;
}
return $_[0]->info->{x};
}
+sub height {
+ return $_[0]->info->{y};
+}
+
sub tiles {
my $self = shift;
my @map = unpack 'v*', $self->{MTXM};
@map == $#map + 1 or warn(sprintf
- "couldn't parse map: only %d tiles\n", scalar @map
+ "Couldn't parse map: only %d tiles\n", scalar @map
), return;
+ warn sprintf("Only %d tiles in MTXM, but expecting %dx%d",
+ scalar @map, $self->width, $self->height
+ ) if scalar @map != $self->width * $self->height;
return \@map;
}
if ($SHOWMAP eq "ppm") {
use Imager;
- my $img = Imager->new(xsize => $map->width * 4, ysize => $map->width * 4);
+ my $img = Imager->new(xsize => $map->width * 4, ysize => $map->height * 4);
use Data::StarCraft::Tileset;
my $era = world($map);