… | |
… | |
20 | # <http://www.gnu.org/licenses/>. |
20 | # <http://www.gnu.org/licenses/>. |
21 | # |
21 | # |
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
23 | # |
23 | # |
24 | |
24 | |
25 | use strict; |
25 | use common::sense; |
26 | |
26 | |
27 | my $prefix = "@prefix@"; |
27 | my $prefix = "@prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
29 | my $datarootdir = "@datarootdir@"; |
29 | my $datarootdir = "@datarootdir@"; |
30 | my $DATADIR = "@datadir@/@PACKAGE@"; |
30 | my $DATADIR = "@datadir@/@PACKAGE@"; |
… | |
… | |
54 | use Coro::Storable; $Storable::canonical = 1; |
54 | use Coro::Storable; $Storable::canonical = 1; |
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 | |
|
|
60 | sub WRITE_FACEINFO() { 0 } |
59 | |
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] |
… | |
… | |
74 | my $VERBOSE = 1; |
76 | my $VERBOSE = 1; |
75 | my $CACHE = 0; |
77 | my $CACHE = 0; |
76 | my $FORCE; |
78 | my $FORCE; |
77 | my $TMPDIR = "/tmp/cfutil$$~"; |
79 | my $TMPDIR = "/tmp/cfutil$$~"; |
78 | my $TMPFILE = "aaaa0"; |
80 | my $TMPFILE = "aaaa0"; |
|
|
81 | my @COMMIT; |
79 | |
82 | |
80 | our %COLOR = ( |
83 | our %COLOR = ( |
|
|
84 | # original cf colours |
81 | black => 0, |
85 | black => 0, |
82 | white => 1, |
86 | white => 1, |
83 | navy => 2, |
87 | navy => 2, # "dark blue" |
84 | red => 3, |
88 | red => 3, |
85 | orange => 4, |
89 | orange => 4, |
86 | blue => 5, |
90 | blue => 5, # "light blue" |
87 | darkorange => 6, |
91 | darkorange => 6, |
88 | green => 7, |
92 | green => 7, |
89 | lightgreen => 8, |
93 | lightgreen => 8, |
90 | grey => 9, |
94 | grey => 9, |
|
|
95 | brown => 10, # "yellow" |
|
|
96 | gold => 11, # "light yellow" |
|
|
97 | tan => 12, # yellowish gray |
|
|
98 | |
|
|
99 | # new for deliantra |
91 | brown => 10, |
100 | none => 13, |
|
|
101 | |
|
|
102 | # compatibility to existing archetypes |
|
|
103 | lightblue => 5, |
92 | gold => 11, |
104 | gray => 9, |
|
|
105 | yellow => 11, |
93 | tan => 12, |
106 | khaki => 12, |
94 | ); |
107 | ); |
95 | |
108 | |
96 | END { system "rm", "-rf", $TMPDIR } |
109 | END { system "rm", "-rf", $TMPDIR } |
97 | |
110 | |
98 | my $s_INT = EV::signal INT => sub { exit 1 }; |
111 | my $s_INT = EV::signal INT => sub { exit 1 }; |
… | |
… | |
105 | my ($id, $dataref, $hashref, $clen) = @_; |
118 | my ($id, $dataref, $hashref, $clen) = @_; |
106 | |
119 | |
107 | my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
120 | my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
108 | |
121 | |
109 | if (exists $hash{$hash}) { |
122 | if (exists $hash{$hash}) { |
110 | # hahs collinion, but some files are simply identical |
123 | # hash collision, but some files are simply identical |
111 | if (${$hash{$hash}[1]} ne $$dataref) { |
124 | if (${$hash{$hash}[1]} ne $$dataref) { |
112 | warn "hash collision $hash{$hash}[0] vs. $id\n"; |
125 | warn "hash collision $hash{$hash}[0] vs. $id\n"; |
113 | exit 1; |
126 | exit 1; |
114 | } else { |
127 | } else { |
115 | print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
128 | print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
… | |
… | |
156 | |
169 | |
157 | print "maps installed successfully.\n"; |
170 | print "maps installed successfully.\n"; |
158 | } |
171 | } |
159 | |
172 | |
160 | { |
173 | { |
|
|
174 | no utf8; # == values are utf-8 encoded |
|
|
175 | |
|
|
176 | our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋); |
|
|
177 | |
|
|
178 | # used to create crude text glyphs for text-based clients |
|
|
179 | sub autoglyph { |
|
|
180 | my ($stem, $face) = @_; |
|
|
181 | |
|
|
182 | if ($stem =~ /^wall\/|Nimwall/) { |
|
|
183 | return $WALL_SUFFIX[hex $1] |
|
|
184 | if $stem =~ /(_[0-9A-F]).x11/; |
|
|
185 | |
|
|
186 | "█" |
|
|
187 | |
|
|
188 | } elsif ($stem =~ /^traps\//) { |
|
|
189 | "☠" |
|
|
190 | |
|
|
191 | } elsif ($stem =~ /^armour\/shield/) { |
|
|
192 | "Ø" |
|
|
193 | |
|
|
194 | } elsif ($stem =~ /^armour\//) { |
|
|
195 | "A" |
|
|
196 | |
|
|
197 | } elsif ($stem =~ /^weapon\//) { |
|
|
198 | "†" |
|
|
199 | |
|
|
200 | } elsif ($stem =~ /^readable\//) { |
|
|
201 | "✉" |
|
|
202 | |
|
|
203 | } elsif ($stem =~ /^river\//) { |
|
|
204 | "~" |
|
|
205 | |
|
|
206 | } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
|
|
207 | "·" |
|
|
208 | |
|
|
209 | } elsif ($stem =~ /^spells\//) { |
|
|
210 | "!" |
|
|
211 | |
|
|
212 | } elsif ($stem =~ /^exit\//) { |
|
|
213 | "⎆" |
|
|
214 | |
|
|
215 | } elsif ($stem =~ /^construct\//) { |
|
|
216 | "⌂" |
|
|
217 | |
|
|
218 | } elsif ($stem =~ /^player\//) { |
|
|
219 | "\@" |
|
|
220 | |
|
|
221 | } elsif ($stem =~ /^(?:monster|misc|class|connect|gods|indoor|inorganic|mining|music|skills).*\/(.)/) { |
|
|
222 | $1 |
|
|
223 | |
|
|
224 | } else { |
|
|
225 | substr $stem, 0, 1 |
|
|
226 | } |
|
|
227 | } |
|
|
228 | } |
|
|
229 | |
|
|
230 | { |
161 | our %ANIMINFO; |
231 | our %ANIMINFO; |
162 | our %FACEINFO; |
232 | our %FACEINFO; |
163 | our %RESOURCE; |
233 | our %RESOURCE; |
164 | our @ARC; |
234 | our @ARC; |
165 | our %ARC; |
235 | our %ARC; |
… | |
… | |
168 | our $PATH; |
238 | our $PATH; |
169 | |
239 | |
170 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
240 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
171 | |
241 | |
172 | our $c_arc = new Coro::Channel; |
242 | our $c_arc = new Coro::Channel; |
173 | our $c_trs = new Coro::Channel; |
243 | our $c_any = new Coro::Channel; |
174 | our $c_res = new Coro::Channel; |
|
|
175 | |
244 | |
176 | our @c_png; |
245 | our @c_png; |
177 | |
246 | |
178 | sub commit_png($$$) { |
247 | sub commit_png($$$$) { |
179 | my ($name, $data, $T) = @_; |
248 | my ($stem, $name, $data, $T) = @_; |
180 | |
249 | |
|
|
250 | $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; |
181 | $FACEINFO{$name}{"data$T"} = $data; |
251 | $FACEINFO{$name}{"data$T"} = $data; |
182 | } |
252 | } |
183 | |
253 | |
184 | sub process_png { |
254 | sub process_png { |
185 | while (@c_png) { |
255 | while (@c_png) { |
… | |
… | |
403 | |
473 | |
404 | if (0 > aio_load $file, $tile) { |
474 | if (0 > aio_load $file, $tile) { |
405 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
475 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
406 | } |
476 | } |
407 | IO::AIO::aio_unlink $file unless $CACHE; |
477 | IO::AIO::aio_unlink $file unless $CACHE; |
408 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
478 | commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
409 | } |
479 | } |
410 | } else { |
480 | } else { |
411 | # use as-is (either small, use smooth) |
481 | # use as-is (either small, use smooth) |
412 | commit_png $face, $png, $T; |
482 | commit_png $stem, $face, $png, $T; |
413 | } |
483 | } |
414 | |
484 | |
415 | aio_unlink $path if $delete; |
485 | aio_unlink $path if $delete; |
416 | } |
486 | } |
417 | } |
487 | } |
418 | |
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 | # bg not used except for text clients |
|
|
514 | } |
|
|
515 | } |
|
|
516 | |
419 | sub process_arc { |
517 | sub process_arc { |
420 | while (my $job = $c_arc->get) { |
518 | while (my ($dir, $file) = @{ $c_arc->get }) { |
421 | my ($dir, $file) = @$job; |
|
|
422 | |
|
|
423 | my $arc; |
519 | my $arc; |
424 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
520 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
425 | |
521 | |
426 | my $arc = read_arch "$dir/$file"; |
522 | my $arc = read_arch "$dir/$file"; |
427 | for my $o (values %$arc) { |
523 | for my $o (values %$arc) { |
… | |
… | |
429 | for (my $m = $o; $m; $m = $m->{more}) { |
525 | for (my $m = $o; $m; $m = $m->{more}) { |
430 | $ARC{$m->{_name}} = $m; |
526 | $ARC{$m->{_name}} = $m; |
431 | } |
527 | } |
432 | |
528 | |
433 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
529 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
434 | |
|
|
435 | my $visibility = delete $o->{visibility}; |
|
|
436 | my $magicmap = delete $o->{magicmap}; |
|
|
437 | |
530 | |
438 | # find upper left corner :/ |
531 | # find upper left corner :/ |
439 | # omg, this is sooo broken |
532 | # omg, this is sooo broken |
440 | my ($dx, $dy); |
533 | my ($dx, $dy); |
441 | for (my $o = $o; $o; $o = $o->{more}) { |
534 | for (my $o = $o; $o; $o = $o->{more}) { |
… | |
… | |
448 | my $y = $o->{y} - $dy; |
541 | my $y = $o->{y} - $dy; |
449 | |
542 | |
450 | my $ext = $x|$y ? "+$x+$y" : ""; |
543 | my $ext = $x|$y ? "+$x+$y" : ""; |
451 | |
544 | |
452 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
545 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
453 | |
|
|
454 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
|
|
455 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
456 | |
546 | |
457 | my $anim = delete $o->{anim}; |
547 | my $anim = delete $o->{anim}; |
458 | |
548 | |
459 | if ($anim) { |
549 | if ($anim) { |
460 | # possibly add $ext to the animation name to avoid |
550 | # possibly add $ext to the animation name to avoid |
… | |
… | |
488 | |
578 | |
489 | my $info = $FACEINFO{$face} ||= { }; |
579 | my $info = $FACEINFO{$face} ||= { }; |
490 | $info->{arc} = $o; |
580 | $info->{arc} = $o; |
491 | |
581 | |
492 | next if $face =~ /^blank.x11$|^empty.x11$/; |
582 | next if $face =~ /^blank.x11$|^empty.x11$/; |
493 | |
|
|
494 | $info->{visibility} = $visibility if defined $visibility; |
|
|
495 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
496 | } |
583 | } |
497 | |
584 | |
498 | if (my $smooth = delete $o->{smoothface}) { |
585 | if (my $smooth = delete $o->{smoothface}) { |
499 | my %kv = split /\s+/, $smooth; |
586 | my %kv = split /\s+/, $smooth; |
500 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
587 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
… | |
… | |
509 | } |
596 | } |
510 | } |
597 | } |
511 | } |
598 | } |
512 | |
599 | |
513 | sub process_trs { |
600 | sub process_trs { |
514 | while (my $job = $c_trs->get) { |
|
|
515 | my ($dir, $file) = @$job; |
601 | my ($dir, $file) = @_; |
516 | my $path = "$dir/$file"; |
602 | my $path = "$dir/$file"; |
517 | |
603 | |
518 | my $trs; |
604 | my $trs; |
519 | if (0 > aio_load $path, $trs) { |
605 | if (0 > aio_load $path, $trs) { |
520 | warn "$path: $!, skipping.\n"; |
606 | warn "$path: $!, skipping.\n"; |
521 | next; |
607 | return; |
522 | } |
608 | } |
523 | |
609 | |
524 | $TRS .= $trs; |
610 | $TRS .= $trs; |
525 | } |
|
|
526 | } |
611 | } |
527 | |
612 | |
528 | my %FILECACHE; |
613 | my %FILECACHE; |
529 | |
614 | |
530 | sub load_cached($;$) { |
615 | sub load_cached($;$) { |
… | |
… | |
542 | |
627 | |
543 | $FILECACHE{$_[0]} |
628 | $FILECACHE{$_[0]} |
544 | } |
629 | } |
545 | |
630 | |
546 | sub process_res { |
631 | sub process_res { |
547 | while (my $job = $c_res->get) { |
|
|
548 | my ($dir, $file, $type) = @$job; |
632 | my ($dir, $file, $type) = @_; |
549 | |
633 | |
550 | my $data; |
634 | my $data; |
551 | aio_load "$dir/$file", $data; |
635 | aio_load "$dir/$file", $data; |
552 | |
636 | |
553 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
637 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
554 | |
638 | |
555 | utf8::decode $dir; |
639 | utf8::decode $dir; |
556 | utf8::decode $file; |
640 | utf8::decode $file; |
557 | |
641 | |
558 | # a meta file for resources is now mandatory |
642 | # a meta file for resources is now mandatory |
559 | unless (exists $meta->{$file}) { |
643 | unless (exists $meta->{$file}) { |
560 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
644 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
561 | next; |
645 | return; |
562 | } |
646 | } |
563 | |
647 | |
564 | $meta = { |
648 | $meta = { |
565 | %{ $meta->{"" } || {} }, |
649 | %{ $meta->{"" } || {} }, |
566 | %{ $meta->{$file} || {} }, |
650 | %{ $meta->{$file} || {} }, |
567 | }; |
651 | }; |
568 | |
652 | |
569 | if ($meta->{license} =~ s/^#//) { |
653 | if ($meta->{license} =~ s/^#//) { |
570 | $meta->{license} = ({ |
654 | $meta->{license} = ({ |
571 | "pd" => "Public Domain", |
655 | "pd" => "Public Domain", |
572 | "gpl" => "GNU General Public License, version 3.0 or any later", |
656 | "gpl" => "GNU General Public License, version 3.0 or any later", |
573 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
657 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
658 | "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
574 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
659 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
575 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
660 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
576 | })->{$meta->{license}} |
661 | })->{$meta->{license}} |
577 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
662 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
578 | } |
663 | } |
579 | |
664 | |
|
|
665 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
|
|
666 | ($meta->{author} = $1) =~ s/_/ /g; |
|
|
667 | } |
|
|
668 | |
580 | $file =~ s/\.res$//; |
669 | $file =~ s/\.res$//; |
581 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
670 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
582 | |
671 | |
583 | substr $dir, 0, 1 + length $PATH, ""; |
672 | substr $dir, 0, 1 + length $PATH, ""; |
584 | |
673 | |
585 | if (my $filter = $meta->{cfutil_filter}) { |
674 | if (my $filter = $meta->{cfutil_filter}) { |
586 | if ($filter eq "yaml2json") { |
675 | if ($filter eq "yaml2json") { |
587 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
676 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
588 | } elsif ($filter eq "json2json") { |
677 | } elsif ($filter eq "json2json") { |
589 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
678 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
590 | } elsif ($filter eq "perl2json") { |
679 | } elsif ($filter eq "perl2json") { |
591 | $data = eval $data; die if $@; |
680 | $data = eval $data; die if $@; |
592 | $data = JSON::XS::encode_json $data; |
681 | $data = JSON::XS::encode_json $data; |
593 | } else { |
682 | } else { |
594 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
683 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
595 | } |
684 | } |
596 | } |
685 | } |
597 | |
686 | |
598 | $RESOURCE{"$dir/$file"} = { |
687 | $RESOURCE{"$dir/$file"} = { |
599 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
688 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
600 | data => $data, |
689 | data => $data, |
601 | %$meta ? (meta => $meta) : (), |
690 | %$meta ? (meta => $meta) : (), |
602 | }; |
691 | }; |
|
|
692 | } |
|
|
693 | |
|
|
694 | sub process_any { |
|
|
695 | while (my ($func, @args) = @{ $c_any->get }) { |
|
|
696 | $func->(@args); |
603 | } |
697 | } |
604 | } |
698 | } |
605 | |
699 | |
606 | sub find_files; |
700 | sub find_files; |
607 | sub find_files { |
701 | sub find_files { |
608 | my ($path) = @_; |
702 | my ($path) = @_; |
609 | |
703 | |
|
|
704 | my $grp = IO::AIO::aio_group; |
|
|
705 | |
|
|
706 | my $scandir; $scandir = sub { |
|
|
707 | my ($path) = @_; |
|
|
708 | |
610 | IO::AIO::aioreq_pri 4; |
709 | IO::AIO::aioreq_pri 4; |
611 | IO::AIO::aio_scandir $path, 4, sub { |
710 | add $grp IO::AIO::aio_scandir $path, 4, sub { |
612 | my ($dirs, $nondirs) = @_; |
711 | my ($dirs, $nondirs) = @_; |
613 | |
712 | |
614 | find_files "$path/$_" |
713 | $scandir->("$path/$_") |
615 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
714 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
616 | |
715 | |
617 | my $dir = $path; |
716 | my $dir = $path; |
618 | substr $dir, 0, 1 + length $PATH, ""; |
717 | substr $dir, 0, 1 + length $PATH, ""; |
619 | |
718 | |
620 | for my $file (@$nondirs) { |
719 | for my $file (@$nondirs) { |
621 | if ($dir =~ /^music(?:\/|$)/) { |
720 | if ($dir =~ /^music(?:\/|$)/) { |
622 | $c_res->put ([$path, $file, 3]) # FT_MUSIC |
721 | $c_any->put ([\&process_res, $path, $file, 3]) # FT_MUSIC |
623 | if $file =~ /\.(ogg)$/; |
722 | if $file =~ /\.(ogg)$/; |
624 | |
723 | |
625 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
724 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
626 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
725 | $c_any->put ([\&process_res, $path, $file, 5]) # FT_SOUND |
627 | if $file =~ /\.(wav|ogg)$/; |
726 | if $file =~ /\.(wav|ogg)$/; |
628 | |
727 | |
629 | } elsif ($dir =~ /^res(?:\/|$)/) { |
728 | } elsif ($dir =~ /^res(?:\/|$)/) { |
630 | if ($file =~ /\.(jpg|png)$/) { |
729 | if ($file =~ /\.(jpg|png)$/) { |
631 | $c_res->put ([$path, $file, 0]) # FT_FACE |
730 | $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE |
632 | } elsif ($file =~ /\.(res)$/) { |
731 | } elsif ($file =~ /\.(res)$/) { |
|
|
732 | $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC |
|
|
733 | } else { |
|
|
734 | $c_any->put ([\&process_res, $path, $file, undef]); |
|
|
735 | } |
|
|
736 | |
|
|
737 | } elsif ($file =~ /\.png$/) { |
|
|
738 | push @c_png, ["$path/$file", 0]; |
|
|
739 | |
|
|
740 | } elsif ($file =~ /\.faceinfo$/) { |
|
|
741 | $c_any->put ([\&process_faceinfo, $path, $file]); |
|
|
742 | |
|
|
743 | } elsif ($file =~ /\.trs$/) { |
|
|
744 | $c_any->put ([\&process_trs, $path, $file]); |
|
|
745 | |
|
|
746 | } elsif ($file =~ /\.arc$/) { |
633 | $c_res->put ([$path, $file, 6]) # FT_RSRC |
747 | $c_arc->put ([$path, $file]); |
|
|
748 | |
634 | } else { |
749 | } else { |
635 | $c_res->put ([$path, $file, undef]); |
750 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
636 | } |
751 | } |
637 | |
|
|
638 | } elsif ($file =~ /\.png$/) { |
|
|
639 | push @c_png, ["$path/$file", 0]; |
|
|
640 | |
|
|
641 | } elsif ($file =~ /\.trs$/) { |
|
|
642 | $c_trs->put ([$path, $file]); |
|
|
643 | |
|
|
644 | } elsif ($file =~ /\.arc$/) { |
|
|
645 | $c_arc->put ([$path, $file]); |
|
|
646 | |
|
|
647 | } else { |
752 | } |
648 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
|
|
649 | } |
|
|
650 | } |
753 | }; |
651 | }; |
754 | }; |
|
|
755 | |
|
|
756 | $scandir->($path); |
|
|
757 | aio_wait $grp; |
652 | } |
758 | } |
653 | |
759 | |
654 | sub generate_plurals { |
760 | sub generate_plurals { |
655 | # use Lingua::EN::Inflect (); |
761 | # use Lingua::EN::Inflect (); |
656 | # Lingua::EN::Inflect::classical; |
762 | # Lingua::EN::Inflect::classical; |
… | |
… | |
694 | if (!-d "$path/treasures") { |
800 | if (!-d "$path/treasures") { |
695 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
801 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
696 | exit 1 unless $FORCE; |
802 | exit 1 unless $FORCE; |
697 | } |
803 | } |
698 | |
804 | |
699 | print "scanning files...\n" if $VERBOSE; |
805 | print "start file scan, arc, any processing...\n" if $VERBOSE; |
|
|
806 | |
|
|
807 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
808 | my @a_any = map +(async \&process_any), 1..4; |
700 | |
809 | |
701 | find_files $path; |
810 | find_files $path; |
702 | |
811 | |
703 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
704 | my @a_res = map +(async \&process_res), 1..2; |
|
|
705 | my @a_trs = map +(async \&process_trs), 1..2; |
|
|
706 | |
|
|
707 | IO::AIO::flush; |
|
|
708 | |
|
|
709 | $c_res->shutdown; |
|
|
710 | $c_arc->shutdown; |
812 | $c_arc->shutdown; |
711 | $c_trs->shutdown; |
813 | $c_any->shutdown; |
712 | |
|
|
713 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
|
|
714 | |
814 | |
715 | $_->join for @a_arc; # need to parse all archetypes before png processing |
815 | $_->join for @a_arc; # need to parse all archetypes before png processing |
716 | |
816 | |
717 | print "end arc, start png processing...\n" if $VERBOSE; |
817 | print "end arc, start png processing...\n" if $VERBOSE; |
718 | |
818 | |
719 | # eight png crunchers work fine for my 4x smp machine |
819 | # eight png crunchers work fine for my 4x smp machine |
720 | my @a_png = map +(async \&process_png), 1..8; |
820 | my @a_png = map +(async \&process_png), 1..8; |
721 | |
821 | |
722 | $_->join for (@a_trs, @a_res, @a_png); |
822 | print "end any processing...\n" if $VERBOSE; |
|
|
823 | $_->join for @a_any; |
|
|
824 | |
|
|
825 | print "end png processing...\n" if $VERBOSE; |
|
|
826 | $_->join for @a_png; |
723 | |
827 | |
724 | print "scanning done, processing results...\n" if $VERBOSE; |
828 | print "scanning done, processing results...\n" if $VERBOSE; |
725 | { |
829 | { |
726 | # remove path prefix from editor_folder |
830 | # remove path prefix from editor_folder |
727 | $_->{editor_folder} =~ /^\x00/ |
831 | $_->{editor_folder} =~ /^\x00/ |
… | |
… | |
733 | while () { |
837 | while () { |
734 | my $progress; |
838 | my $progress; |
735 | my $loop; |
839 | my $loop; |
736 | |
840 | |
737 | for my $o (values %ARC) { |
841 | for my $o (values %ARC) { |
738 | if (my $other = $o->{inherit}) { |
842 | for my $other (split /,/, $o->{inherit}) { |
739 | if (my $s = $ARC{$other}) { |
843 | if (my $s = $ARC{$other}) { |
740 | if ($s->{inherit}) { |
844 | if ($s->{inherit}) { |
741 | $loop = $s; |
845 | $loop = $s; |
742 | } else { |
846 | } else { |
743 | delete $o->{inherit}; |
847 | delete $o->{inherit}; |
… | |
… | |
745 | delete @s{qw(_name more name name_pl)}; |
849 | delete @s{qw(_name more name name_pl)}; |
746 | %$o = ( %s, %$o ); |
850 | %$o = ( %s, %$o ); |
747 | ++$progress; |
851 | ++$progress; |
748 | } |
852 | } |
749 | } else { |
853 | } else { |
750 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
854 | warn "WARNING: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
751 | delete $ARC{$o->{_name}}; |
855 | delete $ARC{$o->{_name}}; |
752 | } |
856 | } |
753 | } |
857 | } |
754 | } |
858 | } |
755 | |
859 | |
… | |
… | |
769 | |
873 | |
770 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
874 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
771 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
875 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
772 | or die "$DATADIR/archetypes~: $!"; |
876 | or die "$DATADIR/archetypes~: $!"; |
773 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
877 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
|
|
878 | } |
|
|
879 | |
|
|
880 | if (WRITE_FACEINFO) { |
|
|
881 | my @table; |
|
|
882 | for my $face (sort keys %FACEINFO) { |
|
|
883 | my $v = $FACEINFO{$face}; |
|
|
884 | (my $xf = $face) =~ s/\+\d+\+\d+$//; |
|
|
885 | |
|
|
886 | $v->{magicmap} //= $FACEINFO{$xf}{magicmap}; |
|
|
887 | $v->{glyph} //= $FACEINFO{$xf}{glyph}; |
|
|
888 | |
|
|
889 | $v->{magicmap} =~ y/A-Z_\-/a-z/d; |
|
|
890 | |
|
|
891 | delete $v->{glyph} if $v->{glyph} =~ /^\?./; |
|
|
892 | |
|
|
893 | my $stem = $v->{stem}; |
|
|
894 | $v->{glyph} = $v->{glyph} // ("?" . (autoglyph $stem, $v)); |
|
|
895 | |
|
|
896 | push @table, [$face, $v->{visibility} || 0, $v->{magicmap} || "none", "none ", $v->{glyph}]; |
|
|
897 | } |
|
|
898 | use Text::Table; |
|
|
899 | my $tb = new Text::Table undef, { align => "num" }, undef, undef, undef; |
|
|
900 | $tb->load (@table); |
|
|
901 | open my $fh, ">:raw", "default.faceinfo"or die; |
|
|
902 | print $fh $tb; |
|
|
903 | print "default.faceinfo written, exiting.\n"; |
|
|
904 | exit 77; |
774 | } |
905 | } |
775 | |
906 | |
776 | { |
907 | { |
777 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
908 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
778 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
909 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
… | |
… | |
781 | } |
912 | } |
782 | |
913 | |
783 | { |
914 | { |
784 | print "processing facedata...\n" if $VERBOSE; |
915 | print "processing facedata...\n" if $VERBOSE; |
785 | while (my ($k, $v) = each %FACEINFO) { |
916 | while (my ($k, $v) = each %FACEINFO) { |
786 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
917 | length $v->{data32} or warn "WARNING: face '$k' has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
787 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
918 | length $v->{data64} or warn "WARNING: face '$k' has no png64. this will not work very well.\n"; |
788 | |
919 | |
789 | make_hash $k, $v->{data32}, $v->{hash32}; |
920 | make_hash $k, $v->{data32}, $v->{hash32}; |
790 | make_hash $k, $v->{data64}, $v->{hash64}; |
921 | make_hash $k, $v->{data64}, $v->{hash64}; |
791 | |
922 | |
792 | #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
923 | #length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
793 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
924 | #length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n"; |
794 | |
925 | |
795 | if (my $magicmap = $v->{magicmap}) { |
926 | exists $v->{visibility} |
796 | $magicmap =~ y/A-Z_\-/a-z/d; |
927 | or warn "WARNING: face '$k' has no visibility info, missing faceinfo entry?\n"; |
797 | $v->{magicmap} = $COLOR{$magicmap}; |
928 | |
798 | } |
929 | my $stem = delete $v->{stem}; |
|
|
930 | $v->{glyph} // warn "WARNING: face '$k' has glyph, cannot autoglyph at the moment."; |
|
|
931 | #$v->{glyph} //= autoglyph $stem, $v; |
799 | |
932 | |
800 | delete $v->{arc}; |
933 | delete $v->{arc}; |
801 | } |
934 | } |
802 | |
935 | |
803 | print "processing resources...\n" if $VERBOSE; |
936 | print "processing resources...\n" if $VERBOSE; |
804 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
937 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
805 | while (my ($k, $v) = each %RESOURCE) { |
938 | while (my ($k, $v) = each %RESOURCE) { |
806 | |
939 | |
|
|
940 | if ($v->{meta} && $v->{meta}{datadir}) { |
|
|
941 | delete $RESOURCE{$k}; |
|
|
942 | |
|
|
943 | $k =~ s/^res\/// or die "$k: datadir files must be in res/"; |
|
|
944 | |
|
|
945 | printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE; |
|
|
946 | open my $fh, ">:raw", "$DATADIR/$k~" |
|
|
947 | or die "$DATADIR/$k~: $!"; |
|
|
948 | syswrite $fh, $v->{data}; |
|
|
949 | push @COMMIT, $k; |
|
|
950 | |
|
|
951 | } else { |
807 | if ($v->{type} & 1) { |
952 | if ($v->{type} & 1) { |
808 | # prepend meta info |
953 | # prepend meta info |
809 | |
954 | |
810 | my $meta = $enc->encode ({ |
955 | my $meta = $enc->encode ({ |
811 | name => $k, |
956 | name => $k, |
812 | %{ $v->{meta} || {} }, |
957 | %{ $v->{meta} || {} }, |
813 | }); |
958 | }); |
814 | |
959 | |
815 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
960 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
816 | } |
961 | } |
817 | |
962 | |
818 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
963 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
|
|
964 | } |
819 | } |
965 | } |
820 | |
966 | |
821 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
967 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
822 | scalar keys %FACEINFO, |
968 | scalar keys %FACEINFO, |
823 | scalar keys %ANIMINFO, |
969 | scalar keys %ANIMINFO, |
… | |
… | |
825 | if $VERBOSE; |
971 | if $VERBOSE; |
826 | |
972 | |
827 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
973 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
828 | or die "$DATADIR/facedata~: $!"; |
974 | or die "$DATADIR/facedata~: $!"; |
829 | |
975 | |
830 | print $fh freeze { |
976 | print $fh nfreeze { |
831 | version => 2, |
977 | version => 2, |
832 | faceinfo => \%FACEINFO, |
978 | faceinfo => \%FACEINFO, |
833 | animinfo => \%ANIMINFO, |
979 | animinfo => \%ANIMINFO, |
834 | resource => \%RESOURCE, |
980 | resource => \%RESOURCE, |
835 | }; |
981 | }; |
836 | |
982 | |
837 | } |
983 | } |
838 | |
984 | |
839 | print "committing files...\n" if $VERBOSE; |
985 | print "committing files...\n" if $VERBOSE; |
840 | |
986 | |
841 | for (qw(archetypes facedata treasures)) { |
987 | for (qw(archetypes facedata treasures), @COMMIT) { |
842 | chmod 0644, "$DATADIR/$_~"; |
988 | chmod 0644, "$DATADIR/$_~"; |
843 | rename "$DATADIR/$_~", "$DATADIR/$_" |
989 | rename "$DATADIR/$_~", "$DATADIR/$_" |
844 | or die "$DATADIR/$_: $!"; |
990 | or die "$DATADIR/$_: $!"; |
845 | } |
991 | } |
846 | |
992 | |