… | |
… | |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
15 | |
15 | |
16 | use Getopt::Long; |
16 | use Getopt::Long; |
|
|
17 | use File::Temp; |
|
|
18 | use POSIX (); |
|
|
19 | use Carp; |
|
|
20 | |
17 | use Coro::Event; |
21 | use Coro::EV; |
18 | use AnyEvent; |
22 | use AnyEvent; |
19 | use YAML::Syck (); |
23 | use YAML::XS (); |
20 | use JSON::XS (); |
24 | use JSON::XS (); |
21 | use IO::AIO (); |
25 | use IO::AIO (); |
22 | use File::Temp; |
26 | |
23 | use Crossfire; |
|
|
24 | use Coro; |
27 | use Coro 5.12; |
25 | use Coro::AIO; |
28 | use Coro::AIO; |
26 | use Coro::Util; |
29 | use Coro::Util; |
27 | use POSIX (); |
|
|
28 | use Carp; |
|
|
29 | use Coro::Channel; |
30 | use Coro::Channel; |
30 | use Coro::Storable; $Storable::canonical = 1; |
31 | use Coro::Storable; $Storable::canonical = 1; |
|
|
32 | |
|
|
33 | use Deliantra; |
31 | |
34 | |
32 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
35 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
33 | |
36 | |
34 | sub usage { |
37 | sub usage { |
35 | warn <<EOF; |
38 | warn <<EOF; |
… | |
… | |
67 | tan => 12, |
70 | tan => 12, |
68 | ); |
71 | ); |
69 | |
72 | |
70 | END { system "rm", "-rf", $TMPDIR } |
73 | END { system "rm", "-rf", $TMPDIR } |
71 | |
74 | |
72 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
75 | my $s_INT = EV::signal INT => sub { exit 1 }; |
73 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
76 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
74 | |
77 | |
75 | mkdir $TMPDIR, 0700 |
78 | mkdir $TMPDIR, 0700 |
76 | or die "$TMPDIR: $!"; |
79 | or die "$TMPDIR: $!"; |
77 | |
80 | |
78 | sub fork_sub(&) { |
81 | sub fork_sub(&) { |
… | |
… | |
273 | fork_sub { |
276 | fork_sub { |
274 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
277 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
275 | system $OPTIPNG, "-i0", "-q", "$other~"; |
278 | system $OPTIPNG, "-i0", "-q", "$other~"; |
276 | |
279 | |
277 | # reduce smoothfaces >10000 bytes |
280 | # reduce smoothfaces >10000 bytes |
|
|
281 | # obsolete, no longer required |
278 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
282 | if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { |
279 | my $ncolor = 256; |
283 | my $ncolor = 256; |
280 | while () { |
284 | while () { |
281 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
285 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
282 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
286 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
283 | last if 10000 > -s "$other~~"; |
287 | last if 10000 > -s "$other~~"; |
… | |
… | |
379 | push @ARC, $o; |
383 | push @ARC, $o; |
380 | for (my $m = $o; $m; $m = $m->{more}) { |
384 | for (my $m = $o; $m; $m = $m->{more}) { |
381 | $ARC{$m->{_name}} = $m; |
385 | $ARC{$m->{_name}} = $m; |
382 | } |
386 | } |
383 | |
387 | |
384 | $o->{editor_folder} = $dir; |
388 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
385 | |
389 | |
386 | my $visibility = delete $o->{visibility}; |
390 | my $visibility = delete $o->{visibility}; |
387 | my $magicmap = delete $o->{magicmap}; |
391 | my $magicmap = delete $o->{magicmap}; |
388 | |
392 | |
389 | # find upper left corner :/ |
393 | # find upper left corner :/ |
… | |
… | |
507 | utf8::decode $file; |
511 | utf8::decode $file; |
508 | |
512 | |
509 | # a meta file for resources is now mandatory |
513 | # a meta file for resources is now mandatory |
510 | unless (exists $meta->{$file}) { |
514 | unless (exists $meta->{$file}) { |
511 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
515 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
|
|
516 | next; |
512 | } |
517 | } |
513 | |
518 | |
514 | $meta = { |
519 | $meta = { |
515 | %{ $meta->{"" } || {} }, |
520 | %{ $meta->{"" } || {} }, |
516 | %{ $meta->{$file} || {} }, |
521 | %{ $meta->{$file} || {} }, |
… | |
… | |
532 | |
537 | |
533 | substr $dir, 0, 1 + length $PATH, ""; |
538 | substr $dir, 0, 1 + length $PATH, ""; |
534 | |
539 | |
535 | if (my $filter = $meta->{cfutil_filter}) { |
540 | if (my $filter = $meta->{cfutil_filter}) { |
536 | if ($filter eq "yaml2json") { |
541 | if ($filter eq "yaml2json") { |
537 | $data = JSON::XS::encode_json YAML::Syck::Load $data; |
542 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
|
|
543 | } elsif ($filter eq "json2json") { |
|
|
544 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
|
|
545 | } elsif ($filter eq "perl2json") { |
|
|
546 | $data = eval $data; die if $@; |
|
|
547 | $data = JSON::XS::encode_json $data; |
538 | } else { |
548 | } else { |
539 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
549 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
540 | } |
550 | } |
541 | } |
551 | } |
542 | |
552 | |
… | |
… | |
573 | |
583 | |
574 | } elsif ($dir =~ /^res(?:\/|$)/) { |
584 | } elsif ($dir =~ /^res(?:\/|$)/) { |
575 | if ($file =~ /\.(jpg|png)$/) { |
585 | if ($file =~ /\.(jpg|png)$/) { |
576 | $c_res->put ([$path, $file, 0]) # FT_FACE |
586 | $c_res->put ([$path, $file, 0]) # FT_FACE |
577 | } elsif ($file =~ /\.(res)$/) { |
587 | } elsif ($file =~ /\.(res)$/) { |
578 | $c_res->put ([$path, $file, 7]) # FT_RSRC |
588 | $c_res->put ([$path, $file, 6]) # FT_RSRC |
579 | } else { |
589 | } else { |
580 | $c_res->put ([$path, $file, undef]); |
590 | $c_res->put ([$path, $file, undef]); |
581 | } |
591 | } |
582 | |
592 | |
583 | } elsif ($file =~ /\.png$/) { |
593 | } elsif ($file =~ /\.png$/) { |
… | |
… | |
592 | } else { |
602 | } else { |
593 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
603 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
594 | } |
604 | } |
595 | } |
605 | } |
596 | }; |
606 | }; |
|
|
607 | } |
|
|
608 | |
|
|
609 | sub generate_plurals { |
|
|
610 | # use Lingua::EN::Inflect (); |
|
|
611 | # Lingua::EN::Inflect::classical; |
|
|
612 | # Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy |
|
|
613 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
|
|
614 | # |
|
|
615 | # for my $a (@ARC) { |
|
|
616 | # my $name = $a->{name} || $a->{_name}; |
|
|
617 | # |
|
|
618 | # next unless $a->{name_pl}; |
|
|
619 | # next if $a->{invisible}; |
|
|
620 | # next if $a->{is_floor}; |
|
|
621 | # next if $a->{no_pick}; |
|
|
622 | # |
|
|
623 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
|
|
624 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
|
|
625 | # ? $name |
|
|
626 | # : Lingua::EN::Inflect::PL $name; |
|
|
627 | # |
|
|
628 | # if ($pl ne $a->{name_pl}) { |
|
|
629 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
|
|
630 | # } |
|
|
631 | # } |
597 | } |
632 | } |
598 | |
633 | |
599 | sub inst_arch($) { |
634 | sub inst_arch($) { |
600 | my (undef, $path) = @_; |
635 | my (undef, $path) = @_; |
601 | |
636 | |
… | |
… | |
624 | my @a_res = map +(async \&process_res), 1..2; |
659 | my @a_res = map +(async \&process_res), 1..2; |
625 | my @a_trs = map +(async \&process_trs), 1..2; |
660 | my @a_trs = map +(async \&process_trs), 1..2; |
626 | |
661 | |
627 | IO::AIO::flush; |
662 | IO::AIO::flush; |
628 | |
663 | |
629 | $c_res->put (undef) for @a_res; |
664 | $c_res->shutdown; |
630 | $c_arc->put (undef) for @a_arc; |
665 | $c_arc->shutdown; |
631 | $c_trs->put (undef) for @a_trs; |
666 | $c_trs->shutdown; |
632 | |
667 | |
633 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
668 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
634 | |
669 | |
635 | $_->join for @a_arc; # need to parse all archetypes before png processing |
670 | $_->join for @a_arc; # need to parse all archetypes before png processing |
636 | |
671 | |
637 | print "end arc, start png processing...\n" if $VERBOSE; |
672 | print "end arc, start png processing...\n" if $VERBOSE; |
638 | |
673 | |
639 | # four png crunchers work fine for my 2x smp machine |
674 | # eight png crunchers work fine for my 4x smp machine |
640 | my @a_png = map +(async \&process_png), 1..4; |
675 | my @a_png = map +(async \&process_png), 1..8; |
641 | |
676 | |
642 | $_->join for (@a_trs, @a_res, @a_png); |
677 | $_->join for (@a_trs, @a_res, @a_png); |
643 | |
678 | |
644 | print "scanning done, processing results...\n" if $VERBOSE; |
679 | print "scanning done, processing results...\n" if $VERBOSE; |
645 | { |
680 | { |
646 | # remove path prefix from editor_folder |
681 | # remove path prefix from editor_folder |
|
|
682 | $_->{editor_folder} =~ /^\x00/ |
647 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
683 | and substr $_->{editor_folder}, 0, 2 + length $path, "" |
648 | for values %ARC; |
684 | for values %ARC; |
649 | |
685 | |
650 | print "resolving inheritance tree...\n" if $VERBOSE; |
686 | print "resolving inheritance tree...\n" if $VERBOSE; |
651 | # resolve inherit |
687 | # resolve inherit |
652 | while () { |
688 | while () { |
653 | my $progress; |
689 | my $progress; |
… | |
… | |
681 | } |
717 | } |
682 | |
718 | |
683 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
719 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
684 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
720 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
685 | |
721 | |
|
|
722 | print "generating plurals...\n" if $VERBOSE; |
|
|
723 | generate_plurals; |
|
|
724 | |
686 | print "writing archetypes...\n" if $VERBOSE; |
725 | print "writing archetypes...\n" if $VERBOSE; |
687 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
726 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
688 | or die "$DATADIR/archetypes~: $!"; |
727 | or die "$DATADIR/archetypes~: $!"; |
689 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
728 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
690 | } |
729 | } |
691 | |
730 | |
692 | { |
731 | { |
693 | print "writing treasures...\n" if $VERBOSE; |
732 | print "writing treasures...\n" if $VERBOSE; |
694 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
733 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
… | |
… | |
700 | print "processing facedata...\n" if $VERBOSE; |
739 | print "processing facedata...\n" if $VERBOSE; |
701 | while (my ($k, $v) = each %FACEINFO) { |
740 | while (my ($k, $v) = each %FACEINFO) { |
702 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
741 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
703 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
742 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
704 | |
743 | |
705 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
744 | #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
706 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
745 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
707 | |
746 | |
708 | if (my $magicmap = $v->{magicmap}) { |
747 | if (my $magicmap = $v->{magicmap}) { |
709 | $magicmap =~ y/A-Z_\-/a-z/d; |
748 | $magicmap =~ y/A-Z_\-/a-z/d; |
710 | $v->{magicmap} = $COLOR{$magicmap}; |
749 | $v->{magicmap} = $COLOR{$magicmap}; |