… | |
… | |
21 | use Crossfire; |
21 | use Crossfire; |
22 | use Coro; |
22 | use Coro; |
23 | use Coro::AIO; |
23 | use Coro::AIO; |
24 | use Coro::Util; |
24 | use Coro::Util; |
25 | use POSIX (); |
25 | use POSIX (); |
26 | use Digest::MD5; |
|
|
27 | use Carp; |
26 | use Carp; |
28 | use Coro::Channel; |
27 | use Coro::Channel; |
29 | use Coro::Storable; $Storable::canonical = 1; |
28 | use Coro::Storable; $Storable::canonical = 1; |
30 | |
29 | |
31 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
30 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
… | |
… | |
170 | if ($w % $T || $h % $T) { |
169 | if ($w % $T || $h % $T) { |
171 | warn "$path: weird png size ($w $h), skipping.\n"; |
170 | warn "$path: weird png size ($w $h), skipping.\n"; |
172 | next; |
171 | next; |
173 | } |
172 | } |
174 | |
173 | |
|
|
174 | (my $base = $stem) =~ s/^.*\///; |
|
|
175 | |
|
|
176 | my $fi = $FACEINFO{$base}; |
|
|
177 | unless ($fi) { |
|
|
178 | warn "$path: <$base> not referenced by any archetype, skipping.\n"; |
|
|
179 | next; |
|
|
180 | } |
|
|
181 | |
|
|
182 | my $arc = $FACEINFO{$base}{arc} |
|
|
183 | or die "FATAL: internal error <$base>, cannot continue"; |
|
|
184 | |
175 | unless ($path =~ /~$/) { |
185 | unless ($path =~ /~$/) { |
176 | # possibly enlarge |
186 | # possibly enlarge |
177 | if (0 > aio_stat "$stem.64x64.png") { |
187 | if (0 > aio_stat "$stem.64x64.png") { |
178 | my $other = "$stem.64x64.png~"; |
188 | my $other = "$stem.64x64.png~"; |
179 | |
189 | |
180 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
190 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
181 | fork_sub { |
191 | fork_sub { |
182 | my $CROP; |
192 | my $CROP; |
183 | my $SRC = "png:\Q$path\E"; |
193 | my $SRC = "png:\Q$path\E"; |
184 | |
194 | |
185 | # check if this is a wall. ultra-ugly. ultra-ultra-ugly. |
195 | my $is_floor = $arc->{is_floor}; |
|
|
196 | my $is_wall = 0; |
|
|
197 | |
|
|
198 | my ($wall_pfx, $wall_dir, $wall_sfx); |
|
|
199 | |
|
|
200 | if ( |
|
|
201 | !$is_floor |
|
|
202 | && !$arc->{alive} |
|
|
203 | && $arc->{move_block} eq "all" |
186 | if ($path =~ /^(.*\/wall\/.*_)([0-9A-F])(\.x11.*\.png)$/) { |
204 | && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/ |
|
|
205 | ) { |
187 | my ($pfx, $dir, $sfx) = ($1, hex $2, $3); |
206 | ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3); |
188 | #check for 0..F images to be sure(?) this is a wall |
207 | |
189 | unless (grep { !-e sprintf "%s%X%s", $pfx, $_, $sfx } 0..15) { |
208 | unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) { |
|
|
209 | $is_wall = 1; |
|
|
210 | } |
|
|
211 | } |
|
|
212 | |
|
|
213 | if ($is_wall || $is_floor) { |
190 | # add a 4px border and add other images around it |
214 | # add a 4px border and add other images around it |
191 | $CROP = "-shave 8x8 +repage"; |
215 | $CROP = "-shave 8x8 +repage"; |
192 | |
216 | |
193 | $w += 8; |
217 | $w += 8; |
194 | $h += 8; |
218 | $h += 8; |
195 | |
219 | |
196 | $SRC = "-size ${w}x${h} xc:transparent"; |
220 | $SRC = "-size ${w}x${h} xc:transparent"; |
197 | $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; |
221 | $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; |
198 | |
222 | |
199 | # 8 surrounding images |
223 | # 8 surrounding images |
200 | for ( |
224 | for ( |
201 | # x y b r0 r1 |
225 | # x y b r0 r1 |
202 | [-1, -1, 0, 6], |
226 | [-1, -1, 0, 6], |
203 | [ 0, -1, 1, 10, 14], |
227 | [ 0, -1, 1, 10, 14], |
204 | [+1, -1, 0, 12], |
228 | [+1, -1, 0, 12], |
205 | |
229 | |
206 | [-1, 0, 8, 5, 7], |
230 | [-1, 0, 8, 5, 7], |
207 | # |
231 | # |
208 | [+1, 0, 2, 5, 13], |
232 | [+1, 0, 2, 5, 13], |
209 | |
233 | |
210 | [-1, +1, 0, 3], |
234 | [-1, +1, 0, 3], |
211 | [ 0, +1, 4, 10, 11], |
235 | [ 0, +1, 4, 10, 11], |
212 | [+1, +1, 0, 9], |
236 | [+1, +1, 0, 9], |
213 | ) { |
237 | ) { |
214 | my ($x, $y, $d, $r0, $r1) = @$_; |
238 | my ($x, $y, $d, $r0, $r1) = @$_; |
|
|
239 | |
|
|
240 | my $tile = $is_floor ? $path |
|
|
241 | : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx |
|
|
242 | : die; |
|
|
243 | |
215 | $SRC .= sprintf " png:%s%X%s -geometry %+d%+d -composite", |
244 | $SRC .= sprintf " png:%s -geometry %+d%+d -composite", |
216 | "\Q$pfx", |
245 | "\Q$tile", |
217 | ($dir & $d) ? $r1 : $r0, |
|
|
218 | "\Q$sfx", |
|
|
219 | $x * ($w - 8) + 4, |
246 | $x * ($w - 8) + 4, |
220 | $y * ($h - 8) + 4; |
247 | $y * ($h - 8) + 4; |
221 | } |
|
|
222 | } |
248 | } |
223 | } |
249 | } |
224 | |
250 | |
225 | system "convert -depth 8 $SRC rgba:-" |
251 | system "convert -depth 8 $SRC rgba:-" |
226 | . "| $exec_prefix/bin/cfhq2xa $w $h 0" |
252 | . "| $exec_prefix/bin/cfhq2xa $w $h 0" |
… | |
… | |
399 | facings => $facings, |
425 | facings => $facings, |
400 | frames => \@frames, |
426 | frames => \@frames, |
401 | }; |
427 | }; |
402 | } |
428 | } |
403 | |
429 | |
404 | for my $face ($o->{face} || (), @{$anim || []}) { |
430 | for ($o->{face} || (), @{$anim || []}) { |
405 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
431 | next if /^facings\s/; |
406 | |
432 | |
|
|
433 | my $face = $_; |
|
|
434 | $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates |
|
|
435 | |
407 | my $info = $FACEINFO{$face} ||= {}; |
436 | my $info = $FACEINFO{$face} ||= { }; |
408 | |
|
|
409 | $info->{arc} = $o; |
437 | $info->{arc} = $o; |
|
|
438 | |
|
|
439 | next if $face =~ /^blank.x11$|^empty.x11$/; |
|
|
440 | |
410 | $info->{visibility} = $visibility if defined $visibility; |
441 | $info->{visibility} = $visibility if defined $visibility; |
411 | $info->{magicmap} = $magicmap if defined $magicmap; |
442 | $info->{magicmap} = $magicmap if defined $magicmap; |
412 | } |
443 | } |
413 | |
444 | |
414 | if (my $smooth = delete $o->{smoothface}) { |
445 | if (my $smooth = delete $o->{smoothface}) { |
415 | my %kv =split /\s+/, $smooth; |
446 | my %kv = split /\s+/, $smooth; |
416 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
447 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
417 | while (my ($face, $smooth) = each %kv) { |
448 | while (my ($face, $smooth) = each %kv) { |
|
|
449 | $FACEINFO{$smooth}{arc} = $o; |
|
|
450 | |
418 | $FACEINFO{$face}{smooth} = $smooth; |
451 | $FACEINFO{$face}{smooth} = $smooth; |
419 | $FACEINFO{$face}{smoothlevel} = $level; |
452 | $FACEINFO{$face}{smoothlevel} = $level; |
420 | } |
453 | } |
421 | } |
454 | } |
422 | } |
455 | } |
… | |
… | |
490 | substr $dir, 0, 1 + length $PATH, ""; |
523 | substr $dir, 0, 1 + length $PATH, ""; |
491 | |
524 | |
492 | $RESOURCE{"$dir/$file"} = { |
525 | $RESOURCE{"$dir/$file"} = { |
493 | type => (delete $meta->{type}) || $type, |
526 | type => (delete $meta->{type}) || $type, |
494 | data => $data, |
527 | data => $data, |
495 | chksum => (Digest::MD5::md5 $data), |
|
|
496 | %$meta ? (meta => $meta) : (), |
528 | %$meta ? (meta => $meta) : (), |
497 | }; |
529 | }; |
498 | } |
530 | } |
499 | } |
531 | } |
500 | |
532 | |
… | |
… | |
650 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
682 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
651 | |
683 | |
652 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
684 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
653 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
685 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
654 | |
686 | |
655 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
|
|
656 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
|
|
657 | |
|
|
658 | if (my $magicmap = $v->{magicmap}) { |
687 | if (my $magicmap = $v->{magicmap}) { |
659 | $magicmap =~ y/A-Z_\-/a-z/d; |
688 | $magicmap =~ y/A-Z_\-/a-z/d; |
660 | $v->{magicmap} = $COLOR{$magicmap}; |
689 | $v->{magicmap} = $COLOR{$magicmap}; |
661 | } |
690 | } |
662 | |
691 | |