--- cfmaps/cfmap2png 2005/11/17 11:51:08 1.1 +++ cfmaps/cfmap2png 2005/11/18 12:50:24 1.6 @@ -1,9 +1,6 @@ #!/opt/bin/perl -# bugs: http://cfmaps.schmorp.de/brest/apartments/brest_town_house.html <- walls -# whaling... icecaves... water is red? # tower of stars: missing craters? -# http://cfmaps.schmorp.de/pup_land/raffle/raffle3_u2.html <-> yellow "doors" show as grey stone as surrounding use strict; @@ -12,6 +9,8 @@ use Gtk2; +our $VERSION = '1.0'; + #init Gtk2::Gdk; my $LIB = $ENV{CROSSFIRE_LIBDIR} @@ -87,7 +86,12 @@ if (/^end$/i) { last; } elsif (/^arch (\S+)$/) { - push @{ $arc{subarch} }, $parse_block->(_name => $1); + push @{ $arc{inventory} }, $parse_block->(_name => $1); + } elsif (/^lore$/) { + while (<$fh>) { + last if /^endlore\s*$/i; + $arc{lore} .= $_; + } } elsif (/^msg$/) { while (<$fh>) { last if /^endmsg\s*$/i; @@ -113,8 +117,11 @@ my $name = $1; my $arc = $parse_block->(_name => $name); - $arc{$name} = $arc; - $more->{more} = $arc if $more; + if ($more) { + $more->{more} = $arc; + } else { + $arc{$name} = $arc; + } $prev = $arc; $more = undef; @@ -190,11 +197,8 @@ $meta{width} = $mapx; $meta{height} = $mapy; - my %map_face; my %draw_info; - my $OBJ_LEVEL = 2**32; # higher than any valid (or in-use) smooth_level - # first pass, gather face stacking order, border and corner info for my $x (0 .. $mapx - 1) { my $col = $map->[$x]; @@ -207,53 +211,50 @@ my $o = $arch->{$a->{_name}} or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; - $o = $arch->{$o->{other_arch}} while $o->{other_arch} && !$o->{face}; - - $o or die "arch $a->{_name} undefined at ($x|$y)\n"; - - my $smooth_level = $o->{smoothlevel}; - my $level = $smooth_level ? $smooth_level - : $o->{is_floor} ? 0 - : $OBJ_LEVEL + $layer; + my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; + my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; + my $level = $smoothlevel ? $smoothlevel + : $is_floor ? 0 + : 256 + $layer; while ($o) { - my $pb = tile $o->{face} - or (warn "$mapname: face '$o->{face}' not found for arch '$a->{_name}' at ($x|$y)\n"), last; + my $face = $a->{face} || $o->{face}; + + my $pb = tile $face + or (warn "$mapname: face '$face' not found for arch '$a->{_name}' at ($x|$y)\n"), last; my $mx = $x + $o->{x}; my $my = $y + $o->{y}; - last if $mx >= $mapx - || $my >= $mapy; + last if 0 > $mx || $mx >= $mapx + || 0 > $my || $my >= $mapy; # this is very ugly (some tiles are 32x33 or worse) my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; - if (my $sface = $smooth->{$o->{face}}) { - $bigface and die "can't handle big faces with smoothing ($o->{face})\n"; + if (my $sface = $smooth->{$face}) { + $bigface and die "can't handle bigfaces with smoothing ($face)\n"; # full tile - $draw_info{$smooth_level}{$sface}{$mx , $my } |= 0x1000; + $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000; # borders - $draw_info{$smooth_level}{$sface}{$mx + 1, $my } |= 0x0031; - $draw_info{$smooth_level}{$sface}{$mx , $my + 1} |= 0x0092; - $draw_info{$smooth_level}{$sface}{$mx - 1, $my } |= 0x0064; - $draw_info{$smooth_level}{$sface}{$mx , $my - 1} |= 0x00c8; + $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0031; + $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0092; + $draw_info{$smoothlevel}{$sface}{$mx - 1, $my } |= 0x0064; + $draw_info{$smoothlevel}{$sface}{$mx , $my - 1} |= 0x00c8; # corners - $draw_info{$smooth_level}{$sface}{$mx + 1, $my + 1} |= 0x0100; - $draw_info{$smooth_level}{$sface}{$mx - 1, $my + 1} |= 0x0200; - $draw_info{$smooth_level}{$sface}{$mx - 1, $my - 1} |= 0x0400; - $draw_info{$smooth_level}{$sface}{$mx + 1, $my - 1} |= 0x0800; - } else { - $smooth_level = 0; + $draw_info{$smoothlevel}{$sface}{$mx + 1, $my + 1} |= 0x0100; + $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200; + $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; + $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; } my $dx = $bigface ? $o->{x} : 0; my $dy = $bigface ? $o->{y} : 0; - $draw_info{$level}{$o->{face}}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16); + $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16); $o = $o->{more}; } @@ -328,7 +329,11 @@ for my $file (@ARGV) { my $mapa = read_arch $file; my ($pb, $meta) = cfmap_render $mapa, $file; - $pb->save ("$file.png", "png"); + $pb->save ("$file.png~", "png"); + system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; + #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency + system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png"; + unlink "$file.png~"; Storable::nstore $meta, "$file.pst"; }