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