… | |
… | |
85 | while (<$fh>) { |
85 | while (<$fh>) { |
86 | s/\s+$//; |
86 | s/\s+$//; |
87 | if (/^end$/i) { |
87 | if (/^end$/i) { |
88 | last; |
88 | last; |
89 | } elsif (/^arch (\S+)$/) { |
89 | } elsif (/^arch (\S+)$/) { |
90 | push @{ $arc{subarch} }, $parse_block->(_name => $1); |
90 | push @{ $arc{inventory} }, $parse_block->(_name => $1); |
91 | } elsif (/^msg$/) { |
91 | } elsif (/^msg$/) { |
92 | while (<$fh>) { |
92 | while (<$fh>) { |
93 | last if /^endmsg\s*$/i; |
93 | last if /^endmsg\s*$/i; |
94 | $arc{msg} .= $_; |
94 | $arc{msg} .= $_; |
95 | } |
95 | } |
… | |
… | |
191 | $meta{height} = $mapy; |
191 | $meta{height} = $mapy; |
192 | |
192 | |
193 | my %map_face; |
193 | my %map_face; |
194 | my %draw_info; |
194 | my %draw_info; |
195 | |
195 | |
196 | my $OBJ_LEVEL = 2**32; # higher than any valid (or in-use) smooth_level |
|
|
197 | |
|
|
198 | # first pass, gather face stacking order, border and corner info |
196 | # first pass, gather face stacking order, border and corner info |
199 | for my $x (0 .. $mapx - 1) { |
197 | for my $x (0 .. $mapx - 1) { |
200 | my $col = $map->[$x]; |
198 | my $col = $map->[$x]; |
201 | for my $y (0 .. $mapy - 1) { |
199 | for my $y (0 .. $mapy - 1) { |
202 | my $as = $col->[$y] || []; |
200 | my $as = $col->[$y] || []; |
… | |
… | |
205 | my $a = $as->[$layer]; |
203 | my $a = $as->[$layer]; |
206 | |
204 | |
207 | my $o = $arch->{$a->{_name}} |
205 | my $o = $arch->{$a->{_name}} |
208 | or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; |
206 | or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; |
209 | |
207 | |
210 | $o = $arch->{$o->{other_arch}} while $o->{other_arch} && !$o->{face}; |
208 | my $A = { %$o, %$a }; |
211 | |
209 | |
212 | $o or die "arch $a->{_name} undefined at ($x|$y)\n"; |
|
|
213 | |
|
|
214 | my $smooth_level = $o->{smoothlevel}; |
210 | my $smoothlevel = $A->{smoothlevel}; |
215 | my $level = $smooth_level ? $smooth_level |
211 | my $level = $smoothlevel ? $smoothlevel |
216 | : $o->{is_floor} ? 0 |
212 | : $A->{is_floor} ? 0 |
217 | : $OBJ_LEVEL + $layer; |
213 | : 256 + $layer; |
218 | |
214 | |
219 | while ($o) { |
215 | while ($o) { |
220 | my $pb = tile $o->{face} |
216 | my $pb = tile $A->{face} |
221 | or (warn "$mapname: face '$o->{face}' not found for arch '$a->{_name}' at ($x|$y)\n"), last; |
217 | or (warn "$mapname: face '$A->{face}' not found for arch '$a->{_name}' at ($x|$y)\n"), last; |
222 | |
218 | |
223 | my $mx = $x + $o->{x}; |
219 | my $mx = $x + $o->{x}; |
224 | my $my = $y + $o->{y}; |
220 | my $my = $y + $o->{y}; |
225 | |
221 | |
226 | last if $mx >= $mapx |
222 | last if 0 > $mx || $mx >= $mapx |
227 | || $my >= $mapy; |
223 | || 0 > $my || $my >= $mapy; |
228 | |
224 | |
229 | # this is very ugly (some tiles are 32x33 or worse) |
225 | # this is very ugly (some tiles are 32x33 or worse) |
230 | my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; |
226 | my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; |
231 | |
227 | |
232 | if (my $sface = $smooth->{$o->{face}}) { |
228 | if (my $sface = $smooth->{$A->{face}}) { |
233 | $bigface and die "can't handle big faces with smoothing ($o->{face})\n"; |
229 | $bigface and die "can't handle bigfaces with smoothing ($A->{face})\n"; |
234 | |
230 | |
235 | # full tile |
231 | # full tile |
236 | $draw_info{$smooth_level}{$sface}{$mx , $my } |= 0x1000; |
232 | $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000; |
237 | |
233 | |
238 | # borders |
234 | # borders |
239 | $draw_info{$smooth_level}{$sface}{$mx + 1, $my } |= 0x0031; |
235 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0031; |
240 | $draw_info{$smooth_level}{$sface}{$mx , $my + 1} |= 0x0092; |
236 | $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0092; |
241 | $draw_info{$smooth_level}{$sface}{$mx - 1, $my } |= 0x0064; |
237 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my } |= 0x0064; |
242 | $draw_info{$smooth_level}{$sface}{$mx , $my - 1} |= 0x00c8; |
238 | $draw_info{$smoothlevel}{$sface}{$mx , $my - 1} |= 0x00c8; |
243 | |
239 | |
244 | # corners |
240 | # corners |
245 | $draw_info{$smooth_level}{$sface}{$mx + 1, $my + 1} |= 0x0100; |
241 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my + 1} |= 0x0100; |
246 | $draw_info{$smooth_level}{$sface}{$mx - 1, $my + 1} |= 0x0200; |
242 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200; |
247 | $draw_info{$smooth_level}{$sface}{$mx - 1, $my - 1} |= 0x0400; |
243 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; |
248 | $draw_info{$smooth_level}{$sface}{$mx + 1, $my - 1} |= 0x0800; |
244 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; |
249 | } else { |
|
|
250 | $smooth_level = 0; |
|
|
251 | } |
245 | } |
252 | |
246 | |
253 | my $dx = $bigface ? $o->{x} : 0; |
247 | my $dx = $bigface ? $o->{x} : 0; |
254 | my $dy = $bigface ? $o->{y} : 0; |
248 | my $dy = $bigface ? $o->{y} : 0; |
255 | |
249 | |
… | |
… | |
326 | } |
320 | } |
327 | |
321 | |
328 | for my $file (@ARGV) { |
322 | for my $file (@ARGV) { |
329 | my $mapa = read_arch $file; |
323 | my $mapa = read_arch $file; |
330 | my ($pb, $meta) = cfmap_render $mapa, $file; |
324 | my ($pb, $meta) = cfmap_render $mapa, $file; |
331 | $pb->save ("$file.png", "png"); |
325 | $pb->save ("$file.png~", "png"); |
|
|
326 | system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; |
|
|
327 | system "mogrify", "-colors" => 65536, "$file.png~"; |
|
|
328 | system "pngcrush", "-q", "-m" => 7, "-rem" => "alla", "-reduce", "$file.png~", "$file.png"; |
|
|
329 | unlink "$file.png~"; |
332 | Storable::nstore $meta, "$file.pst"; |
330 | Storable::nstore $meta, "$file.pst"; |
333 | } |
331 | } |
334 | |
332 | |
335 | |
333 | |
336 | |
334 | |