… | |
… | |
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] |
… | |
… | |
84 | } |
84 | } |
85 | |
85 | |
86 | { |
86 | { |
87 | our %ANIMINFO; |
87 | our %ANIMINFO; |
88 | our %FACEINFO; |
88 | our %FACEINFO; |
89 | our @ARC; |
89 | our %ARC; |
90 | our $TRS; |
90 | our $TRS; |
91 | our $NFILE; |
91 | our $NFILE; |
92 | |
92 | |
93 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
93 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
94 | |
94 | |
… | |
… | |
255 | my $arc; |
255 | my $arc; |
256 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
256 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
257 | |
257 | |
258 | my $arc = read_arch "$dir/$file"; |
258 | my $arc = read_arch "$dir/$file"; |
259 | for my $o (values %$arc) { |
259 | for my $o (values %$arc) { |
260 | push @ARC, $o; |
260 | $ARC{$o->{_name}} = $o; |
261 | |
261 | |
262 | $o->{editor_folder} = $dir; |
262 | $o->{editor_folder} = $dir; |
263 | |
263 | |
264 | my $visibility = delete $o->{visibility}; |
264 | my $visibility = delete $o->{visibility}; |
265 | my $magicmap = delete $o->{magicmap}; |
265 | my $magicmap = delete $o->{magicmap}; |
… | |
… | |
276 | my $x = $o->{x} - $dx; |
276 | my $x = $o->{x} - $dx; |
277 | my $y = $o->{y} - $dy; |
277 | my $y = $o->{y} - $dy; |
278 | |
278 | |
279 | my $ext = $x|$y ? "+$x+$y" : ""; |
279 | my $ext = $x|$y ? "+$x+$y" : ""; |
280 | |
280 | |
281 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; |
281 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
282 | |
282 | |
283 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
283 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
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}; |
… | |
… | |
372 | } |
372 | } |
373 | |
373 | |
374 | sub inst_arch($) { |
374 | sub inst_arch($) { |
375 | my (undef, $path) = @_; |
375 | my (undef, $path) = @_; |
376 | |
376 | |
377 | print "installing '$path' to '$DATADIR'\n", |
377 | print "Installing '$path' to '$DATADIR'\n", |
378 | "(this can take a long time if you run this\n", |
378 | "This can take a long time if you run this\n", |
379 | "for the first time or do not use --cache).\n"; |
379 | "for the first time or do not use --cache.\n", |
|
|
380 | "\n", |
|
|
381 | "Unless you run verbosely, all following warning\n", |
|
|
382 | "or error messages indicate serious problems.\n", |
|
|
383 | "\n"; |
380 | |
384 | |
381 | if (!-d "$path/treasures") { |
385 | if (!-d "$path/treasures") { |
382 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
386 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
383 | exit 1 unless $FORCE; |
387 | exit 1 unless $FORCE; |
384 | } |
388 | } |
… | |
… | |
392 | (async \&process_trs), (async \&process_trs), |
396 | (async \&process_trs), (async \&process_trs), |
393 | (async \&process_arc), (async \&process_arc), |
397 | (async \&process_arc), (async \&process_arc), |
394 | ); |
398 | ); |
395 | |
399 | |
396 | { |
400 | { |
|
|
401 | # remove path prefix from editor_folder |
|
|
402 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
|
|
403 | for values %ARC; |
|
|
404 | |
|
|
405 | # resolve inherit |
|
|
406 | while () { |
|
|
407 | my $progress; |
|
|
408 | my $loop; |
|
|
409 | |
|
|
410 | for my $o (values %ARC) { |
|
|
411 | if (my $other = $o->{inherit}) { |
|
|
412 | if (my $s = $ARC{$other}) { |
|
|
413 | if ($s->{inherit}) { |
|
|
414 | $loop = $s; |
|
|
415 | } else { |
|
|
416 | delete $o->{inherit}; |
|
|
417 | %$o = ( %$s, %$o ); |
|
|
418 | ++$progress; |
|
|
419 | } |
|
|
420 | } else { |
|
|
421 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
|
|
422 | delete $ARC{$o->{_name}}; |
|
|
423 | } |
|
|
424 | } |
|
|
425 | } |
|
|
426 | |
|
|
427 | unless ($progress) { |
|
|
428 | die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n" |
|
|
429 | if $loop; |
|
|
430 | |
|
|
431 | last; |
|
|
432 | } |
|
|
433 | } |
|
|
434 | |
397 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
435 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
398 | or die "$DATADIR/archetypes~: $!"; |
436 | or die "$DATADIR/archetypes~: $!"; |
399 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
437 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } values %ARC]; |
400 | print $fh Crossfire::archlist_to_string \@ARC; |
|
|
401 | } |
438 | } |
402 | |
439 | |
403 | { |
440 | { |
404 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
441 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
405 | or die "$DATADIR/treasures~: $!"; |
442 | or die "$DATADIR/treasures~: $!"; |
… | |
… | |
419 | } |
456 | } |
420 | |
457 | |
421 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
458 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
422 | or die "$DATADIR/facedata~: $!"; |
459 | or die "$DATADIR/facedata~: $!"; |
423 | |
460 | |
424 | print $fh Storable::nfreeze { |
461 | print $fh freeze { |
425 | version => 2, |
462 | version => 2, |
426 | faceinfo => \%FACEINFO, |
463 | faceinfo => \%FACEINFO, |
427 | animinfo => \%ANIMINFO, |
464 | animinfo => \%ANIMINFO, |
428 | }; |
465 | }; |
429 | } |
466 | } |