… | |
… | |
20 | use Crossfire; |
20 | use Crossfire; |
21 | use Coro; |
21 | use Coro; |
22 | use Coro::AIO; |
22 | use Coro::AIO; |
23 | use POSIX (); |
23 | use POSIX (); |
24 | use Digest::MD5; |
24 | use Digest::MD5; |
25 | use Storable; $Storable::canonical = 1; |
25 | use Coro::Storable; $Storable::canonical = 1; |
26 | |
26 | |
27 | sub usage { |
27 | sub usage { |
28 | warn <<EOF; |
28 | warn <<EOF; |
29 | Usage: cfutil [-v] [-q] [--force] [--cache] |
29 | Usage: cfutil [-v] [-q] [--force] [--cache] |
30 | [--install-arch path] |
30 | [--install-arch path] |
… | |
… | |
82 | |
82 | |
83 | print "maps installed successfully.\n"; |
83 | print "maps installed successfully.\n"; |
84 | } |
84 | } |
85 | |
85 | |
86 | { |
86 | { |
|
|
87 | our %ANIMINFO; |
87 | our %FACEINFO; |
88 | our %FACEINFO; |
88 | our @ARC; |
89 | our @ARC; |
89 | our $TRS; |
90 | our $TRS; |
90 | our $NFILE; |
91 | our $NFILE; |
91 | our %ANIM; |
|
|
92 | |
92 | |
93 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
93 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
94 | |
94 | |
95 | our (@png, @trs, @arc); # files we are interested in |
95 | our (@png, @trs, @arc); # files we are interested in |
96 | |
96 | |
… | |
… | |
284 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
284 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
285 | |
285 | |
286 | my $anim = delete $o->{anim}; |
286 | my $anim = delete $o->{anim}; |
287 | |
287 | |
288 | if ($anim) { |
288 | if ($anim) { |
|
|
289 | # possibly add $ext to the animation name to avoid |
|
|
290 | # the need to specify archnames for all parts |
|
|
291 | # of a multipart archetype. |
289 | $o->{animation} = "$o->{_name}"; |
292 | $o->{animation} = "$o->{_name}"; |
|
|
293 | my $facings = 1; |
|
|
294 | my @frames; |
290 | |
295 | |
291 | for (@$anim) { |
296 | for (@$anim) { |
292 | $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; |
297 | if (/^facings\s+(\d+)/) { |
|
|
298 | $facings = $1*1; |
|
|
299 | } elsif (/^blank.x11$|^empty.x11$/) { |
|
|
300 | push @frames, $_; |
|
|
301 | } else { |
|
|
302 | push @frames, "$_$ext"; |
|
|
303 | } |
293 | } |
304 | } |
294 | |
305 | |
295 | $ANIM{"$o->{_name}$ext"} = |
306 | $ANIMINFO{$o->{animation}} = { |
296 | join "", map "$_\n", |
307 | facings => $facings, |
297 | "anim $o->{_name}", |
308 | frames => \@frames, |
298 | @$anim, |
309 | }; |
299 | "mina"; |
|
|
300 | } |
310 | } |
301 | |
311 | |
302 | for my $face ($o->{face} || (), @{$anim || []}) { |
312 | for my $face ($o->{face} || (), @{$anim || []}) { |
303 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
313 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
304 | |
314 | |
… | |
… | |
382 | (async \&process_trs), (async \&process_trs), |
392 | (async \&process_trs), (async \&process_trs), |
383 | (async \&process_arc), (async \&process_arc), |
393 | (async \&process_arc), (async \&process_arc), |
384 | ); |
394 | ); |
385 | |
395 | |
386 | { |
396 | { |
387 | open my $fh, ">:utf8", "$DATADIR/animations~" |
|
|
388 | or die "$DATADIR/animations~: $!"; |
|
|
389 | print $fh join "", map $ANIM{$_}, sort keys %ANIM |
|
|
390 | } |
|
|
391 | |
|
|
392 | { |
|
|
393 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
397 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
394 | or die "$DATADIR/archetypes~: $!"; |
398 | or die "$DATADIR/archetypes~: $!"; |
395 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
399 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
396 | print $fh Crossfire::archlist_to_string \@ARC; |
400 | print $fh Crossfire::archlist_to_string \@ARC; |
397 | } |
401 | } |
… | |
… | |
415 | } |
419 | } |
416 | |
420 | |
417 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
421 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
418 | or die "$DATADIR/facedata~: $!"; |
422 | or die "$DATADIR/facedata~: $!"; |
419 | |
423 | |
420 | $FACEINFO{""} = { version => 1}; |
424 | print $fh freeze { |
421 | print $fh Storable::nfreeze \%FACEINFO; |
425 | version => 2, |
|
|
426 | faceinfo => \%FACEINFO, |
|
|
427 | animinfo => \%ANIMINFO, |
422 | } |
428 | }; |
|
|
429 | } |
423 | |
430 | |
424 | for (qw(archetypes facedata animations treasures)) { |
431 | for (qw(archetypes facedata treasures)) { |
425 | chmod 0644, "$DATADIR/$_~"; |
432 | chmod 0644, "$DATADIR/$_~"; |
426 | rename "$DATADIR/$_~", "$DATADIR/$_" |
433 | rename "$DATADIR/$_~", "$DATADIR/$_" |
427 | or die "$DATADIR/$_: $!"; |
434 | or die "$DATADIR/$_: $!"; |
428 | } |
435 | } |
429 | |
436 | |