… | |
… | |
55 | |
55 | |
56 | use Deliantra; |
56 | use Deliantra; |
57 | |
57 | |
58 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
58 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
59 | |
59 | |
|
|
60 | sub WRITE_FACEINFO() { 0 } |
|
|
61 | |
60 | sub usage { |
62 | sub usage { |
61 | warn <<EOF; |
63 | warn <<EOF; |
62 | Usage: cfutil [-v] [-q] [--force] [--cache] |
64 | Usage: cfutil [-v] [-q] [--force] [--cache] |
63 | [--install-arch path] |
65 | [--install-arch path] |
64 | [--install-maps maps] |
66 | [--install-maps maps] |
… | |
… | |
77 | my $TMPDIR = "/tmp/cfutil$$~"; |
79 | my $TMPDIR = "/tmp/cfutil$$~"; |
78 | my $TMPFILE = "aaaa0"; |
80 | my $TMPFILE = "aaaa0"; |
79 | my @COMMIT; |
81 | my @COMMIT; |
80 | |
82 | |
81 | our %COLOR = ( |
83 | our %COLOR = ( |
|
|
84 | # original cf colours |
82 | black => 0, |
85 | black => 0, |
83 | white => 1, |
86 | white => 1, |
84 | navy => 2, |
87 | navy => 2, # "dark blue" |
85 | red => 3, |
88 | red => 3, |
86 | orange => 4, |
89 | orange => 4, |
87 | blue => 5, |
90 | blue => 5, # "light blue" |
88 | darkorange => 6, |
91 | darkorange => 6, |
89 | green => 7, |
92 | green => 7, |
90 | lightgreen => 8, |
93 | lightgreen => 8, |
91 | grey => 9, |
94 | grey => 9, |
|
|
95 | brown => 10, # "yellow" |
|
|
96 | gold => 11, # "light yellow" |
|
|
97 | tan => 12, # yellowish gray |
|
|
98 | |
|
|
99 | # new for deliantra |
92 | brown => 10, |
100 | none => 13, |
|
|
101 | |
|
|
102 | # compatibility to existing archetypes |
|
|
103 | lightblue => 5, |
93 | gold => 11, |
104 | gray => 9, |
|
|
105 | yellow => 11, |
94 | tan => 12, |
106 | khaki => 12, |
95 | ); |
107 | ); |
96 | |
108 | |
97 | END { system "rm", "-rf", $TMPDIR } |
109 | END { system "rm", "-rf", $TMPDIR } |
98 | |
110 | |
99 | my $s_INT = EV::signal INT => sub { exit 1 }; |
111 | my $s_INT = EV::signal INT => sub { exit 1 }; |
… | |
… | |
156 | and die "map installation failed.\n"; |
168 | and die "map installation failed.\n"; |
157 | |
169 | |
158 | print "maps installed successfully.\n"; |
170 | print "maps installed successfully.\n"; |
159 | } |
171 | } |
160 | |
172 | |
|
|
173 | { |
|
|
174 | no utf8; # == values are utf-8 encoded |
|
|
175 | |
161 | our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋); |
176 | our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋); |
162 | |
177 | |
|
|
178 | # used to create crude text glyphs for text-based clients |
163 | sub autoglyph { |
179 | sub autoglyph { |
164 | my ($stem, $face) = @_; |
180 | my ($stem, $face) = @_; |
165 | |
181 | |
166 | if ($stem =~ /^wall\/|Nimwall/) { |
182 | if ($stem =~ /^wall\/|Nimwall/) { |
167 | return $WALL_SUFFIX[hex $1] |
183 | return $WALL_SUFFIX[hex $1] |
168 | if $stem =~ /(_[0-9A-F]).x11/; |
184 | if $stem =~ /(_[0-9A-F]).x11/; |
169 | |
185 | |
170 | "+" |
186 | "█" |
171 | |
187 | |
|
|
188 | } elsif ($stem =~ /^traps\//) { |
|
|
189 | "☠" |
|
|
190 | |
|
|
191 | } elsif ($stem =~ /^armour\/shield/) { |
|
|
192 | "Ø" |
|
|
193 | |
172 | } elsif ($stem =~ /^monster.*\/(.)/) { |
194 | } elsif ($stem =~ /^armour\//) { |
173 | $1 |
195 | "A" |
174 | |
196 | |
|
|
197 | } elsif ($stem =~ /^weapon\//) { |
|
|
198 | "†" |
|
|
199 | |
|
|
200 | } elsif ($stem =~ /^readable\//) { |
|
|
201 | "✉" |
|
|
202 | |
|
|
203 | } elsif ($stem =~ /^river\//) { |
|
|
204 | "~" |
|
|
205 | |
175 | } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
206 | } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
|
|
207 | "·" |
|
|
208 | |
|
|
209 | } elsif ($stem =~ /^spells\//) { |
176 | "." |
210 | "!" |
177 | |
211 | |
|
|
212 | } elsif ($stem =~ /^exit\//) { |
|
|
213 | "⎆" |
|
|
214 | |
|
|
215 | } elsif ($stem =~ /^construct\//) { |
|
|
216 | "⌂" |
|
|
217 | |
178 | } elsif ($stem =~ /^player\//) { |
218 | } elsif ($stem =~ /^player\//) { |
179 | "\@" |
219 | "\@" |
180 | |
220 | |
|
|
221 | } elsif ($stem =~ /^(?:monster|misc|class|connect|gods|indoor|inorganic|mining|music|skills).*\/(.)/) { |
|
|
222 | $1 |
|
|
223 | |
181 | } else { |
224 | } else { |
182 | substr $stem, 0, 1 |
225 | substr $stem, 0, 1 |
|
|
226 | } |
183 | } |
227 | } |
184 | } |
228 | } |
185 | |
229 | |
186 | { |
230 | { |
187 | our %ANIMINFO; |
231 | our %ANIMINFO; |
… | |
… | |
194 | our $PATH; |
238 | our $PATH; |
195 | |
239 | |
196 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
240 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
197 | |
241 | |
198 | our $c_arc = new Coro::Channel; |
242 | our $c_arc = new Coro::Channel; |
199 | our $c_trs = new Coro::Channel; |
243 | our $c_any = new Coro::Channel; |
200 | our $c_res = new Coro::Channel; |
|
|
201 | |
244 | |
202 | our @c_png; |
245 | our @c_png; |
203 | |
246 | |
204 | sub commit_png($$$$) { |
247 | sub commit_png($$$$) { |
205 | my ($stem, $name, $data, $T) = @_; |
248 | my ($stem, $name, $data, $T) = @_; |
… | |
… | |
441 | |
484 | |
442 | aio_unlink $path if $delete; |
485 | aio_unlink $path if $delete; |
443 | } |
486 | } |
444 | } |
487 | } |
445 | |
488 | |
|
|
489 | sub process_faceinfo { |
|
|
490 | my ($dir, $file) = @_; |
|
|
491 | my $path = "$dir/$file"; |
|
|
492 | |
|
|
493 | my $data; |
|
|
494 | if (0 > aio_load $path, $data) { |
|
|
495 | warn "$path: $!, skipping.\n"; |
|
|
496 | return; |
|
|
497 | } |
|
|
498 | |
|
|
499 | for (split /\n/, $data) { |
|
|
500 | my ($face, $visibility, $fg, $bg, $glyph) = split /\s+/; |
|
|
501 | |
|
|
502 | $glyph =~ s/^\?(?=.)//; # remove "autoglyph" flag |
|
|
503 | |
|
|
504 | (my $fgi = $COLOR{$fg}) |
|
|
505 | // warn "WARNING: $path: $face specifies unknown foreground colour '$fg'.\n"; |
|
|
506 | (my $bgi = $COLOR{$bg}) |
|
|
507 | // warn "WARNING: $path: $face specifies unknown background colour '$bg'.\n"; |
|
|
508 | |
|
|
509 | my $fi = $FACEINFO{$face} ||= { }; |
|
|
510 | $fi->{visibility} = $visibility * 1; |
|
|
511 | $fi->{magicmap} = $fgi; # foreground colour becomes magicmap |
|
|
512 | $fi->{glyph} = (chr $fgi) . (chr $bgi) . $glyph; |
|
|
513 | #$fi->{glyph} = (chr $fgi) . $glyph;#d#TOOD remove |
|
|
514 | # bg not used except for text clients |
|
|
515 | } |
|
|
516 | } |
|
|
517 | |
446 | sub process_arc { |
518 | sub process_arc { |
447 | while (my $job = $c_arc->get) { |
519 | while (my ($dir, $file) = @{ $c_arc->get }) { |
448 | my ($dir, $file) = @$job; |
|
|
449 | |
|
|
450 | my $arc; |
520 | my $arc; |
451 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
521 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
452 | |
522 | |
453 | my $arc = read_arch "$dir/$file"; |
523 | my $arc = read_arch "$dir/$file"; |
454 | for my $o (values %$arc) { |
524 | for my $o (values %$arc) { |
… | |
… | |
456 | for (my $m = $o; $m; $m = $m->{more}) { |
526 | for (my $m = $o; $m; $m = $m->{more}) { |
457 | $ARC{$m->{_name}} = $m; |
527 | $ARC{$m->{_name}} = $m; |
458 | } |
528 | } |
459 | |
529 | |
460 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
530 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
461 | |
|
|
462 | my $visibility = delete $o->{visibility}; |
|
|
463 | my $magicmap = delete $o->{magicmap}; |
|
|
464 | my $glyph = delete $o->{glyph}; |
|
|
465 | |
531 | |
466 | # find upper left corner :/ |
532 | # find upper left corner :/ |
467 | # omg, this is sooo broken |
533 | # omg, this is sooo broken |
468 | my ($dx, $dy); |
534 | my ($dx, $dy); |
469 | for (my $o = $o; $o; $o = $o->{more}) { |
535 | for (my $o = $o; $o; $o = $o->{more}) { |
… | |
… | |
476 | my $y = $o->{y} - $dy; |
542 | my $y = $o->{y} - $dy; |
477 | |
543 | |
478 | my $ext = $x|$y ? "+$x+$y" : ""; |
544 | my $ext = $x|$y ? "+$x+$y" : ""; |
479 | |
545 | |
480 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
546 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
481 | |
|
|
482 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
|
|
483 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
484 | $glyph = delete $o->{glyph} if exists $o->{glyph}; |
|
|
485 | |
547 | |
486 | my $anim = delete $o->{anim}; |
548 | my $anim = delete $o->{anim}; |
487 | |
549 | |
488 | if ($anim) { |
550 | if ($anim) { |
489 | # possibly add $ext to the animation name to avoid |
551 | # possibly add $ext to the animation name to avoid |
… | |
… | |
517 | |
579 | |
518 | my $info = $FACEINFO{$face} ||= { }; |
580 | my $info = $FACEINFO{$face} ||= { }; |
519 | $info->{arc} = $o; |
581 | $info->{arc} = $o; |
520 | |
582 | |
521 | next if $face =~ /^blank.x11$|^empty.x11$/; |
583 | next if $face =~ /^blank.x11$|^empty.x11$/; |
522 | |
|
|
523 | $info->{visibility} = $visibility if defined $visibility; |
|
|
524 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
525 | $info->{glyph} = $glyph if defined $glyph; |
|
|
526 | } |
584 | } |
527 | |
585 | |
528 | if (my $smooth = delete $o->{smoothface}) { |
586 | if (my $smooth = delete $o->{smoothface}) { |
529 | my %kv = split /\s+/, $smooth; |
587 | my %kv = split /\s+/, $smooth; |
530 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
588 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
… | |
… | |
539 | } |
597 | } |
540 | } |
598 | } |
541 | } |
599 | } |
542 | |
600 | |
543 | sub process_trs { |
601 | sub process_trs { |
544 | while (my $job = $c_trs->get) { |
|
|
545 | my ($dir, $file) = @$job; |
602 | my ($dir, $file) = @_; |
546 | my $path = "$dir/$file"; |
603 | my $path = "$dir/$file"; |
547 | |
604 | |
548 | my $trs; |
605 | my $trs; |
549 | if (0 > aio_load $path, $trs) { |
606 | if (0 > aio_load $path, $trs) { |
550 | warn "$path: $!, skipping.\n"; |
607 | warn "$path: $!, skipping.\n"; |
551 | next; |
608 | return; |
552 | } |
609 | } |
553 | |
610 | |
554 | $TRS .= $trs; |
611 | $TRS .= $trs; |
555 | } |
|
|
556 | } |
612 | } |
557 | |
613 | |
558 | my %FILECACHE; |
614 | my %FILECACHE; |
559 | |
615 | |
560 | sub load_cached($;$) { |
616 | sub load_cached($;$) { |
… | |
… | |
572 | |
628 | |
573 | $FILECACHE{$_[0]} |
629 | $FILECACHE{$_[0]} |
574 | } |
630 | } |
575 | |
631 | |
576 | sub process_res { |
632 | sub process_res { |
577 | while (my $job = $c_res->get) { |
|
|
578 | my ($dir, $file, $type) = @$job; |
633 | my ($dir, $file, $type) = @_; |
579 | |
634 | |
580 | my $data; |
635 | my $data; |
581 | aio_load "$dir/$file", $data; |
636 | aio_load "$dir/$file", $data; |
582 | |
637 | |
583 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
638 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
584 | |
639 | |
585 | utf8::decode $dir; |
640 | utf8::decode $dir; |
586 | utf8::decode $file; |
641 | utf8::decode $file; |
587 | |
642 | |
588 | # a meta file for resources is now mandatory |
643 | # a meta file for resources is now mandatory |
589 | unless (exists $meta->{$file}) { |
644 | unless (exists $meta->{$file}) { |
590 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
645 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
591 | next; |
646 | return; |
592 | } |
647 | } |
593 | |
648 | |
594 | $meta = { |
649 | $meta = { |
595 | %{ $meta->{"" } || {} }, |
650 | %{ $meta->{"" } || {} }, |
596 | %{ $meta->{$file} || {} }, |
651 | %{ $meta->{$file} || {} }, |
597 | }; |
652 | }; |
598 | |
653 | |
599 | if ($meta->{license} =~ s/^#//) { |
654 | if ($meta->{license} =~ s/^#//) { |
600 | $meta->{license} = ({ |
655 | $meta->{license} = ({ |
601 | "pd" => "Public Domain", |
656 | "pd" => "Public Domain", |
602 | "gpl" => "GNU General Public License, version 3.0 or any later", |
657 | "gpl" => "GNU General Public License, version 3.0 or any later", |
603 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
658 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
604 | "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
659 | "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
605 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
660 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
606 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
661 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
607 | })->{$meta->{license}} |
662 | })->{$meta->{license}} |
608 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
663 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
609 | } |
664 | } |
610 | |
665 | |
611 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
666 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
612 | ($meta->{author} = $1) =~ s/_/ /g; |
667 | ($meta->{author} = $1) =~ s/_/ /g; |
613 | } |
668 | } |
614 | |
669 | |
615 | $file =~ s/\.res$//; |
670 | $file =~ s/\.res$//; |
616 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
671 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
617 | |
672 | |
618 | substr $dir, 0, 1 + length $PATH, ""; |
673 | substr $dir, 0, 1 + length $PATH, ""; |
619 | |
674 | |
620 | if (my $filter = $meta->{cfutil_filter}) { |
675 | if (my $filter = $meta->{cfutil_filter}) { |
621 | if ($filter eq "yaml2json") { |
676 | if ($filter eq "yaml2json") { |
622 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
677 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
623 | } elsif ($filter eq "json2json") { |
678 | } elsif ($filter eq "json2json") { |
624 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
679 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
625 | } elsif ($filter eq "perl2json") { |
680 | } elsif ($filter eq "perl2json") { |
626 | $data = eval $data; die if $@; |
681 | $data = eval $data; die if $@; |
627 | $data = JSON::XS::encode_json $data; |
682 | $data = JSON::XS::encode_json $data; |
628 | } else { |
683 | } else { |
629 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
684 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
630 | } |
685 | } |
631 | } |
686 | } |
632 | |
687 | |
633 | $RESOURCE{"$dir/$file"} = { |
688 | $RESOURCE{"$dir/$file"} = { |
634 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
689 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
635 | data => $data, |
690 | data => $data, |
636 | %$meta ? (meta => $meta) : (), |
691 | %$meta ? (meta => $meta) : (), |
637 | }; |
692 | }; |
|
|
693 | } |
|
|
694 | |
|
|
695 | sub process_any { |
|
|
696 | while (my ($func, @args) = @{ $c_any->get }) { |
|
|
697 | $func->(@args); |
638 | } |
698 | } |
639 | } |
699 | } |
640 | |
700 | |
641 | sub find_files; |
701 | sub find_files; |
642 | sub find_files { |
702 | sub find_files { |
643 | my ($path) = @_; |
703 | my ($path) = @_; |
644 | |
704 | |
|
|
705 | my $grp = IO::AIO::aio_group; |
|
|
706 | |
|
|
707 | my $scandir; $scandir = sub { |
|
|
708 | my ($path) = @_; |
|
|
709 | |
645 | IO::AIO::aioreq_pri 4; |
710 | IO::AIO::aioreq_pri 4; |
646 | IO::AIO::aio_scandir $path, 4, sub { |
711 | add $grp IO::AIO::aio_scandir $path, 4, sub { |
647 | my ($dirs, $nondirs) = @_; |
712 | my ($dirs, $nondirs) = @_; |
648 | |
713 | |
649 | find_files "$path/$_" |
714 | $scandir->("$path/$_") |
650 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
715 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
651 | |
716 | |
652 | my $dir = $path; |
717 | my $dir = $path; |
653 | substr $dir, 0, 1 + length $PATH, ""; |
718 | substr $dir, 0, 1 + length $PATH, ""; |
654 | |
719 | |
655 | for my $file (@$nondirs) { |
720 | for my $file (@$nondirs) { |
656 | if ($dir =~ /^music(?:\/|$)/) { |
721 | if ($dir =~ /^music(?:\/|$)/) { |
657 | $c_res->put ([$path, $file, 3]) # FT_MUSIC |
722 | $c_any->put ([\&process_res, $path, $file, 3]) # FT_MUSIC |
658 | if $file =~ /\.(ogg)$/; |
723 | if $file =~ /\.(ogg)$/; |
659 | |
724 | |
660 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
725 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
661 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
726 | $c_any->put ([\&process_res, $path, $file, 5]) # FT_SOUND |
662 | if $file =~ /\.(wav|ogg)$/; |
727 | if $file =~ /\.(wav|ogg)$/; |
663 | |
728 | |
664 | } elsif ($dir =~ /^res(?:\/|$)/) { |
729 | } elsif ($dir =~ /^res(?:\/|$)/) { |
665 | if ($file =~ /\.(jpg|png)$/) { |
730 | if ($file =~ /\.(jpg|png)$/) { |
666 | $c_res->put ([$path, $file, 0]) # FT_FACE |
731 | $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE |
667 | } elsif ($file =~ /\.(res)$/) { |
732 | } elsif ($file =~ /\.(res)$/) { |
|
|
733 | $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC |
|
|
734 | } else { |
|
|
735 | $c_any->put ([\&process_res, $path, $file, undef]); |
|
|
736 | } |
|
|
737 | |
|
|
738 | } elsif ($file =~ /\.png$/) { |
|
|
739 | push @c_png, ["$path/$file", 0]; |
|
|
740 | |
|
|
741 | } elsif ($file =~ /\.faceinfo$/) { |
|
|
742 | $c_any->put ([\&process_faceinfo, $path, $file]); |
|
|
743 | |
|
|
744 | } elsif ($file =~ /\.trs$/) { |
|
|
745 | $c_any->put ([\&process_trs, $path, $file]); |
|
|
746 | |
|
|
747 | } elsif ($file =~ /\.arc$/) { |
668 | $c_res->put ([$path, $file, 6]) # FT_RSRC |
748 | $c_arc->put ([$path, $file]); |
|
|
749 | |
669 | } else { |
750 | } else { |
670 | $c_res->put ([$path, $file, undef]); |
751 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
671 | } |
752 | } |
672 | |
|
|
673 | } elsif ($file =~ /\.png$/) { |
|
|
674 | push @c_png, ["$path/$file", 0]; |
|
|
675 | |
|
|
676 | } elsif ($file =~ /\.trs$/) { |
|
|
677 | $c_trs->put ([$path, $file]); |
|
|
678 | |
|
|
679 | } elsif ($file =~ /\.arc$/) { |
|
|
680 | $c_arc->put ([$path, $file]); |
|
|
681 | |
|
|
682 | } else { |
753 | } |
683 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
|
|
684 | } |
|
|
685 | } |
754 | }; |
686 | }; |
755 | }; |
|
|
756 | |
|
|
757 | $scandir->($path); |
|
|
758 | aio_wait $grp; |
687 | } |
759 | } |
688 | |
760 | |
689 | sub generate_plurals { |
761 | sub generate_plurals { |
690 | # use Lingua::EN::Inflect (); |
762 | # use Lingua::EN::Inflect (); |
691 | # Lingua::EN::Inflect::classical; |
763 | # Lingua::EN::Inflect::classical; |
… | |
… | |
729 | if (!-d "$path/treasures") { |
801 | if (!-d "$path/treasures") { |
730 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
802 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
731 | exit 1 unless $FORCE; |
803 | exit 1 unless $FORCE; |
732 | } |
804 | } |
733 | |
805 | |
734 | print "scanning files...\n" if $VERBOSE; |
806 | print "start file scan, arc, any processing...\n" if $VERBOSE; |
|
|
807 | |
|
|
808 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
809 | my @a_any = map +(async \&process_any), 1..4; |
735 | |
810 | |
736 | find_files $path; |
811 | find_files $path; |
737 | |
812 | |
738 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
739 | my @a_res = map +(async \&process_res), 1..2; |
|
|
740 | my @a_trs = map +(async \&process_trs), 1..2; |
|
|
741 | |
|
|
742 | IO::AIO::flush; |
|
|
743 | |
|
|
744 | $c_res->shutdown; |
|
|
745 | $c_arc->shutdown; |
813 | $c_arc->shutdown; |
746 | $c_trs->shutdown; |
814 | $c_any->shutdown; |
747 | |
|
|
748 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
|
|
749 | |
815 | |
750 | $_->join for @a_arc; # need to parse all archetypes before png processing |
816 | $_->join for @a_arc; # need to parse all archetypes before png processing |
751 | |
817 | |
752 | print "end arc, start png processing...\n" if $VERBOSE; |
818 | print "end arc, start png processing...\n" if $VERBOSE; |
753 | |
819 | |
754 | # eight png crunchers work fine for my 4x smp machine |
820 | # eight png crunchers work fine for my 4x smp machine |
755 | my @a_png = map +(async \&process_png), 1..8; |
821 | my @a_png = map +(async \&process_png), 1..8; |
756 | |
822 | |
757 | $_->join for (@a_trs, @a_res, @a_png); |
823 | print "end any processing...\n" if $VERBOSE; |
|
|
824 | $_->join for @a_any; |
|
|
825 | |
|
|
826 | print "end png processing...\n" if $VERBOSE; |
|
|
827 | $_->join for @a_png; |
758 | |
828 | |
759 | print "scanning done, processing results...\n" if $VERBOSE; |
829 | print "scanning done, processing results...\n" if $VERBOSE; |
760 | { |
830 | { |
761 | # remove path prefix from editor_folder |
831 | # remove path prefix from editor_folder |
762 | $_->{editor_folder} =~ /^\x00/ |
832 | $_->{editor_folder} =~ /^\x00/ |
… | |
… | |
780 | delete @s{qw(_name more name name_pl)}; |
850 | delete @s{qw(_name more name name_pl)}; |
781 | %$o = ( %s, %$o ); |
851 | %$o = ( %s, %$o ); |
782 | ++$progress; |
852 | ++$progress; |
783 | } |
853 | } |
784 | } else { |
854 | } else { |
785 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
855 | warn "WARNING: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
786 | delete $ARC{$o->{_name}}; |
856 | delete $ARC{$o->{_name}}; |
787 | } |
857 | } |
788 | } |
858 | } |
789 | } |
859 | } |
790 | |
860 | |
… | |
… | |
797 | } |
867 | } |
798 | |
868 | |
799 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
869 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
800 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
870 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
801 | |
871 | |
|
|
872 | # fix up archetypes without names, where the archanme doesn't work at all |
|
|
873 | for (@ARC) { |
|
|
874 | if (!exists $_->{name} and $_->{_name} =~ /_/) { |
|
|
875 | for ($_->{name} = $_->{_name}) { |
|
|
876 | s/(?:_\d+)+$//; |
|
|
877 | s/_[nesw]+$//; |
|
|
878 | y/_/ /; |
|
|
879 | } |
|
|
880 | } |
|
|
881 | } |
|
|
882 | |
802 | print "generating plurals...\n" if $VERBOSE; |
883 | #print "generating plurals...\n" if $VERBOSE; |
803 | generate_plurals; |
884 | #generate_plurals; |
804 | |
885 | |
805 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
886 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
806 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
887 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
807 | or die "$DATADIR/archetypes~: $!"; |
888 | or die "$DATADIR/archetypes~: $!"; |
808 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
889 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
|
|
890 | } |
|
|
891 | |
|
|
892 | if (WRITE_FACEINFO) { |
|
|
893 | my @table; |
|
|
894 | for my $face (sort keys %FACEINFO) { |
|
|
895 | my $v = $FACEINFO{$face}; |
|
|
896 | (my $xf = $face) =~ s/\+\d+\+\d+$//; |
|
|
897 | |
|
|
898 | $v->{magicmap} //= $FACEINFO{$xf}{magicmap}; |
|
|
899 | $v->{glyph} //= $FACEINFO{$xf}{glyph}; |
|
|
900 | |
|
|
901 | $v->{magicmap} =~ y/A-Z_\-/a-z/d; |
|
|
902 | |
|
|
903 | delete $v->{glyph} if $v->{glyph} =~ /^\?./; |
|
|
904 | |
|
|
905 | my $stem = $v->{stem}; |
|
|
906 | $v->{glyph} = $v->{glyph} // ("?" . (autoglyph $stem, $v)); |
|
|
907 | |
|
|
908 | push @table, [$face, $v->{visibility} || 0, $v->{magicmap} || "none", "none ", $v->{glyph}]; |
|
|
909 | } |
|
|
910 | use Text::Table; |
|
|
911 | my $tb = new Text::Table undef, { align => "num" }, undef, undef, undef; |
|
|
912 | $tb->load (@table); |
|
|
913 | open my $fh, ">:raw", "default.faceinfo"or die; |
|
|
914 | print $fh $tb; |
|
|
915 | print "default.faceinfo written, exiting.\n"; |
|
|
916 | exit 77; |
809 | } |
917 | } |
810 | |
918 | |
811 | { |
919 | { |
812 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
920 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
813 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
921 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
… | |
… | |
816 | } |
924 | } |
817 | |
925 | |
818 | { |
926 | { |
819 | print "processing facedata...\n" if $VERBOSE; |
927 | print "processing facedata...\n" if $VERBOSE; |
820 | while (my ($k, $v) = each %FACEINFO) { |
928 | while (my ($k, $v) = each %FACEINFO) { |
821 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
929 | length $v->{data32} or warn "WARNING: face '$k' has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
822 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
930 | length $v->{data64} or warn "WARNING: face '$k' has no png64. this will not work very well.\n"; |
823 | |
931 | |
824 | make_hash $k, $v->{data32}, $v->{hash32}; |
932 | make_hash $k, $v->{data32}, $v->{hash32}; |
825 | make_hash $k, $v->{data64}, $v->{hash64}; |
933 | make_hash $k, $v->{data64}, $v->{hash64}; |
826 | |
934 | |
827 | #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
935 | #length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
828 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
936 | #length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n"; |
829 | |
937 | |
830 | if (my $magicmap = $v->{magicmap}) { |
938 | exists $v->{visibility} |
831 | $magicmap =~ y/A-Z_\-/a-z/d; |
939 | or warn "WARNING: face '$k' has no visibility info, missing faceinfo entry?\n"; |
832 | $v->{magicmap} = $COLOR{$magicmap}; |
|
|
833 | } |
|
|
834 | |
940 | |
835 | my $stem = delete $v->{stem}; |
941 | my $stem = delete $v->{stem}; |
|
|
942 | $v->{glyph} // warn "WARNING: face '$k' has glyph, cannot autoglyph at the moment."; |
836 | $v->{glyph} //= autoglyph $stem, $v; |
943 | #$v->{glyph} //= autoglyph $stem, $v; |
837 | utf8::encode $v->{glyph}; |
|
|
838 | $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph}; |
|
|
839 | |
944 | |
840 | delete $v->{arc}; |
945 | delete $v->{arc}; |
841 | } |
946 | } |
842 | |
947 | |
843 | print "processing resources...\n" if $VERBOSE; |
948 | print "processing resources...\n" if $VERBOSE; |