1 | #!@PERL@ |
1 | #!@PERL@ |
2 | |
2 | |
3 | use strict; |
3 | # |
|
|
4 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
5 | # |
|
|
6 | # Copyright (©) 2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
7 | # |
|
|
8 | # Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | # the terms of the Affero GNU General Public License as published by the |
|
|
10 | # Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | # option) any later version. |
|
|
12 | # |
|
|
13 | # This program is distributed in the hope that it will be useful, |
|
|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | # GNU General Public License for more details. |
|
|
17 | # |
|
|
18 | # You should have received a copy of the Affero GNU General Public License |
|
|
19 | # and the GNU General Public License along with this program. If not, see |
|
|
20 | # <http://www.gnu.org/licenses/>. |
|
|
21 | # |
|
|
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
|
|
23 | # |
|
|
24 | |
|
|
25 | use common::sense; |
4 | |
26 | |
5 | my $prefix = "@prefix@"; |
27 | my $prefix = "@prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
7 | my $datarootdir = "@datarootdir@"; |
29 | my $datarootdir = "@datarootdir@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
30 | my $DATADIR = "@datadir@/@PACKAGE@"; |
… | |
… | |
21 | use Coro::EV; |
43 | use Coro::EV; |
22 | use AnyEvent; |
44 | use AnyEvent; |
23 | use YAML::XS (); |
45 | use YAML::XS (); |
24 | use JSON::XS (); |
46 | use JSON::XS (); |
25 | use IO::AIO (); |
47 | use IO::AIO (); |
|
|
48 | use Digest::MD5 (); |
26 | |
49 | |
27 | use Coro 5.12; |
50 | use Coro 5.12; |
28 | use Coro::AIO; |
51 | use Coro::AIO; |
29 | use Coro::Util; |
52 | use Coro::Util; |
30 | use Coro::Channel; |
53 | use Coro::Channel; |
31 | use Coro::Storable; $Storable::canonical = 1; |
54 | use Coro::Storable; $Storable::canonical = 1; |
32 | |
55 | |
33 | use Deliantra; |
56 | use Deliantra; |
34 | |
57 | |
35 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
58 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
|
|
59 | |
|
|
60 | sub WRITE_FACEINFO() { 0 } |
36 | |
61 | |
37 | sub usage { |
62 | sub usage { |
38 | warn <<EOF; |
63 | warn <<EOF; |
39 | Usage: cfutil [-v] [-q] [--force] [--cache] |
64 | Usage: cfutil [-v] [-q] [--force] [--cache] |
40 | [--install-arch path] |
65 | [--install-arch path] |
… | |
… | |
51 | my $VERBOSE = 1; |
76 | my $VERBOSE = 1; |
52 | my $CACHE = 0; |
77 | my $CACHE = 0; |
53 | my $FORCE; |
78 | my $FORCE; |
54 | my $TMPDIR = "/tmp/cfutil$$~"; |
79 | my $TMPDIR = "/tmp/cfutil$$~"; |
55 | my $TMPFILE = "aaaa0"; |
80 | my $TMPFILE = "aaaa0"; |
|
|
81 | my @COMMIT; |
56 | |
82 | |
57 | our %COLOR = ( |
83 | our %COLOR = ( |
|
|
84 | # original cf colours |
58 | black => 0, |
85 | black => 0, |
59 | white => 1, |
86 | white => 1, |
60 | navy => 2, |
87 | navy => 2, # "dark blue" |
61 | red => 3, |
88 | red => 3, |
62 | orange => 4, |
89 | orange => 4, |
63 | blue => 5, |
90 | blue => 5, # "light blue" |
64 | darkorange => 6, |
91 | darkorange => 6, |
65 | green => 7, |
92 | green => 7, |
66 | lightgreen => 8, |
93 | lightgreen => 8, |
67 | grey => 9, |
94 | grey => 9, |
|
|
95 | brown => 10, # "yellow" |
|
|
96 | gold => 11, # "light yellow" |
|
|
97 | tan => 12, # yellowish gray |
|
|
98 | |
|
|
99 | # new for deliantra |
68 | brown => 10, |
100 | none => 13, |
|
|
101 | |
|
|
102 | # compatibility to existing archetypes |
|
|
103 | lightblue => 5, |
69 | gold => 11, |
104 | gray => 9, |
|
|
105 | yellow => 11, |
70 | tan => 12, |
106 | khaki => 12, |
71 | ); |
107 | ); |
72 | |
108 | |
73 | END { system "rm", "-rf", $TMPDIR } |
109 | END { system "rm", "-rf", $TMPDIR } |
74 | |
110 | |
75 | my $s_INT = EV::signal INT => sub { exit 1 }; |
111 | my $s_INT = EV::signal INT => sub { exit 1 }; |
76 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
112 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
|
|
113 | |
|
|
114 | our %hash; |
|
|
115 | |
|
|
116 | # here we could try to avoid collisions and reduce chksum size further |
|
|
117 | sub make_hash($\$\$;$) { |
|
|
118 | my ($id, $dataref, $hashref, $clen) = @_; |
|
|
119 | |
|
|
120 | my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
|
|
121 | |
|
|
122 | if (exists $hash{$hash}) { |
|
|
123 | # hash collision, but some files are simply identical |
|
|
124 | if (${$hash{$hash}[1]} ne $$dataref) { |
|
|
125 | warn "hash collision $hash{$hash}[0] vs. $id\n"; |
|
|
126 | exit 1; |
|
|
127 | } else { |
|
|
128 | print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
|
|
129 | } |
|
|
130 | } |
|
|
131 | $hash{$hash} = [$id, $dataref, $hashref]; |
|
|
132 | |
|
|
133 | $$hashref = $hash; |
|
|
134 | } |
77 | |
135 | |
78 | mkdir $TMPDIR, 0700 |
136 | mkdir $TMPDIR, 0700 |
79 | or die "$TMPDIR: $!"; |
137 | or die "$TMPDIR: $!"; |
80 | |
138 | |
81 | sub fork_sub(&) { |
139 | sub fork_sub(&) { |
… | |
… | |
111 | |
169 | |
112 | print "maps installed successfully.\n"; |
170 | print "maps installed successfully.\n"; |
113 | } |
171 | } |
114 | |
172 | |
115 | { |
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 | { |
116 | our %ANIMINFO; |
231 | our %ANIMINFO; |
117 | our %FACEINFO; |
232 | our %FACEINFO; |
118 | our %RESOURCE; |
233 | our %RESOURCE; |
119 | our @ARC; |
234 | our @ARC; |
120 | our %ARC; |
235 | our %ARC; |
… | |
… | |
123 | our $PATH; |
238 | our $PATH; |
124 | |
239 | |
125 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
240 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
126 | |
241 | |
127 | our $c_arc = new Coro::Channel; |
242 | our $c_arc = new Coro::Channel; |
128 | our $c_trs = new Coro::Channel; |
243 | our $c_any = new Coro::Channel; |
129 | our $c_res = new Coro::Channel; |
|
|
130 | |
244 | |
131 | our @c_png; |
245 | our @c_png; |
132 | |
246 | |
133 | sub commit_png($$$) { |
247 | sub commit_png($$$$) { |
134 | my ($name, $data, $T) = @_; |
248 | my ($stem, $name, $data, $T) = @_; |
135 | |
249 | |
|
|
250 | $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; |
136 | $FACEINFO{$name}{"data$T"} = $data; |
251 | $FACEINFO{$name}{"data$T"} = $data; |
137 | } |
252 | } |
138 | |
253 | |
139 | sub process_png { |
254 | sub process_png { |
140 | while (@c_png) { |
255 | while (@c_png) { |
… | |
… | |
358 | |
473 | |
359 | if (0 > aio_load $file, $tile) { |
474 | if (0 > aio_load $file, $tile) { |
360 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
475 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
361 | } |
476 | } |
362 | IO::AIO::aio_unlink $file unless $CACHE; |
477 | IO::AIO::aio_unlink $file unless $CACHE; |
363 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
478 | commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
364 | } |
479 | } |
365 | } else { |
480 | } else { |
366 | # use as-is (either small, use smooth) |
481 | # use as-is (either small, use smooth) |
367 | commit_png $face, $png, $T; |
482 | commit_png $stem, $face, $png, $T; |
368 | } |
483 | } |
369 | |
484 | |
370 | aio_unlink $path if $delete; |
485 | aio_unlink $path if $delete; |
371 | } |
486 | } |
372 | } |
487 | } |
373 | |
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 | |
374 | sub process_arc { |
518 | sub process_arc { |
375 | while (my $job = $c_arc->get) { |
519 | while (my ($dir, $file) = @{ $c_arc->get }) { |
376 | my ($dir, $file) = @$job; |
|
|
377 | |
|
|
378 | my $arc; |
520 | my $arc; |
379 | 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 :/ |
380 | |
522 | |
381 | my $arc = read_arch "$dir/$file"; |
523 | my $arc = read_arch "$dir/$file"; |
382 | for my $o (values %$arc) { |
524 | for my $o (values %$arc) { |
383 | push @ARC, $o; |
525 | push @ARC, $o; |
384 | for (my $m = $o; $m; $m = $m->{more}) { |
526 | for (my $m = $o; $m; $m = $m->{more}) { |
385 | $ARC{$m->{_name}} = $m; |
527 | $ARC{$m->{_name}} = $m; |
386 | } |
528 | } |
387 | |
529 | |
388 | $o->{editor_folder} = $dir; |
530 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
389 | |
|
|
390 | my $visibility = delete $o->{visibility}; |
|
|
391 | my $magicmap = delete $o->{magicmap}; |
|
|
392 | |
531 | |
393 | # find upper left corner :/ |
532 | # find upper left corner :/ |
394 | # omg, this is sooo broken |
533 | # omg, this is sooo broken |
395 | my ($dx, $dy); |
534 | my ($dx, $dy); |
396 | for (my $o = $o; $o; $o = $o->{more}) { |
535 | for (my $o = $o; $o; $o = $o->{more}) { |
… | |
… | |
403 | my $y = $o->{y} - $dy; |
542 | my $y = $o->{y} - $dy; |
404 | |
543 | |
405 | my $ext = $x|$y ? "+$x+$y" : ""; |
544 | my $ext = $x|$y ? "+$x+$y" : ""; |
406 | |
545 | |
407 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
546 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
408 | |
|
|
409 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
|
|
410 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
411 | |
547 | |
412 | my $anim = delete $o->{anim}; |
548 | my $anim = delete $o->{anim}; |
413 | |
549 | |
414 | if ($anim) { |
550 | if ($anim) { |
415 | # possibly add $ext to the animation name to avoid |
551 | # possibly add $ext to the animation name to avoid |
… | |
… | |
443 | |
579 | |
444 | my $info = $FACEINFO{$face} ||= { }; |
580 | my $info = $FACEINFO{$face} ||= { }; |
445 | $info->{arc} = $o; |
581 | $info->{arc} = $o; |
446 | |
582 | |
447 | next if $face =~ /^blank.x11$|^empty.x11$/; |
583 | next if $face =~ /^blank.x11$|^empty.x11$/; |
448 | |
|
|
449 | $info->{visibility} = $visibility if defined $visibility; |
|
|
450 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
451 | } |
584 | } |
452 | |
585 | |
453 | if (my $smooth = delete $o->{smoothface}) { |
586 | if (my $smooth = delete $o->{smoothface}) { |
454 | my %kv = split /\s+/, $smooth; |
587 | my %kv = split /\s+/, $smooth; |
455 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
588 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
… | |
… | |
464 | } |
597 | } |
465 | } |
598 | } |
466 | } |
599 | } |
467 | |
600 | |
468 | sub process_trs { |
601 | sub process_trs { |
469 | while (my $job = $c_trs->get) { |
|
|
470 | my ($dir, $file) = @$job; |
602 | my ($dir, $file) = @_; |
471 | my $path = "$dir/$file"; |
603 | my $path = "$dir/$file"; |
472 | |
604 | |
473 | my $trs; |
605 | my $trs; |
474 | if (0 > aio_load $path, $trs) { |
606 | if (0 > aio_load $path, $trs) { |
475 | warn "$path: $!, skipping.\n"; |
607 | warn "$path: $!, skipping.\n"; |
476 | next; |
608 | return; |
477 | } |
609 | } |
478 | |
610 | |
479 | $TRS .= $trs; |
611 | $TRS .= $trs; |
480 | } |
|
|
481 | } |
612 | } |
482 | |
613 | |
483 | my %FILECACHE; |
614 | my %FILECACHE; |
484 | |
615 | |
485 | sub load_cached($;$) { |
616 | sub load_cached($;$) { |
… | |
… | |
497 | |
628 | |
498 | $FILECACHE{$_[0]} |
629 | $FILECACHE{$_[0]} |
499 | } |
630 | } |
500 | |
631 | |
501 | sub process_res { |
632 | sub process_res { |
502 | while (my $job = $c_res->get) { |
|
|
503 | my ($dir, $file, $type) = @$job; |
633 | my ($dir, $file, $type) = @_; |
504 | |
634 | |
505 | my $data; |
635 | my $data; |
506 | aio_load "$dir/$file", $data; |
636 | aio_load "$dir/$file", $data; |
507 | |
637 | |
508 | 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) }; |
509 | |
639 | |
510 | utf8::decode $dir; |
640 | utf8::decode $dir; |
511 | utf8::decode $file; |
641 | utf8::decode $file; |
512 | |
642 | |
513 | # a meta file for resources is now mandatory |
643 | # a meta file for resources is now mandatory |
514 | unless (exists $meta->{$file}) { |
644 | unless (exists $meta->{$file}) { |
515 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
645 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
516 | next; |
646 | return; |
517 | } |
647 | } |
518 | |
648 | |
519 | $meta = { |
649 | $meta = { |
520 | %{ $meta->{"" } || {} }, |
650 | %{ $meta->{"" } || {} }, |
521 | %{ $meta->{$file} || {} }, |
651 | %{ $meta->{$file} || {} }, |
522 | }; |
652 | }; |
523 | |
653 | |
524 | if ($meta->{license} =~ s/^#//) { |
654 | if ($meta->{license} =~ s/^#//) { |
525 | $meta->{license} = ({ |
655 | $meta->{license} = ({ |
526 | "pd" => "Public Domain", |
656 | "pd" => "Public Domain", |
527 | "gpl" => "GNU General Public License, version 3.0 or any later", |
657 | "gpl" => "GNU General Public License, version 3.0 or any later", |
528 | "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/", |
|
|
659 | "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
529 | "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/", |
530 | "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/", |
531 | })->{$meta->{license}} |
662 | })->{$meta->{license}} |
532 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
663 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
533 | } |
664 | } |
534 | |
665 | |
|
|
666 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
|
|
667 | ($meta->{author} = $1) =~ s/_/ /g; |
|
|
668 | } |
|
|
669 | |
535 | $file =~ s/\.res$//; |
670 | $file =~ s/\.res$//; |
536 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
671 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
537 | |
672 | |
538 | substr $dir, 0, 1 + length $PATH, ""; |
673 | substr $dir, 0, 1 + length $PATH, ""; |
539 | |
674 | |
540 | if (my $filter = $meta->{cfutil_filter}) { |
675 | if (my $filter = $meta->{cfutil_filter}) { |
541 | if ($filter eq "yaml2json") { |
676 | if ($filter eq "yaml2json") { |
542 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
677 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
543 | } elsif ($filter eq "json2json") { |
678 | } elsif ($filter eq "json2json") { |
544 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
679 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
545 | } elsif ($filter eq "perl2json") { |
680 | } elsif ($filter eq "perl2json") { |
546 | $data = eval $data; die if $@; |
681 | $data = eval $data; die if $@; |
547 | $data = JSON::XS::encode_json $data; |
682 | $data = JSON::XS::encode_json $data; |
548 | } else { |
683 | } else { |
549 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
684 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
550 | } |
685 | } |
551 | } |
686 | } |
552 | |
687 | |
553 | $RESOURCE{"$dir/$file"} = { |
688 | $RESOURCE{"$dir/$file"} = { |
554 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
689 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
555 | data => $data, |
690 | data => $data, |
556 | %$meta ? (meta => $meta) : (), |
691 | %$meta ? (meta => $meta) : (), |
557 | }; |
692 | }; |
|
|
693 | } |
|
|
694 | |
|
|
695 | sub process_any { |
|
|
696 | while (my ($func, @args) = @{ $c_any->get }) { |
|
|
697 | $func->(@args); |
558 | } |
698 | } |
559 | } |
699 | } |
560 | |
700 | |
561 | sub find_files; |
701 | sub find_files; |
562 | sub find_files { |
702 | sub find_files { |
563 | my ($path) = @_; |
703 | my ($path) = @_; |
564 | |
704 | |
|
|
705 | my $grp = IO::AIO::aio_group; |
|
|
706 | |
|
|
707 | my $scandir; $scandir = sub { |
|
|
708 | my ($path) = @_; |
|
|
709 | |
565 | IO::AIO::aioreq_pri 4; |
710 | IO::AIO::aioreq_pri 4; |
566 | IO::AIO::aio_scandir $path, 4, sub { |
711 | add $grp IO::AIO::aio_scandir $path, 4, sub { |
567 | my ($dirs, $nondirs) = @_; |
712 | my ($dirs, $nondirs) = @_; |
568 | |
713 | |
569 | find_files "$path/$_" |
714 | $scandir->("$path/$_") |
570 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
715 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
571 | |
716 | |
572 | my $dir = $path; |
717 | my $dir = $path; |
573 | substr $dir, 0, 1 + length $PATH, ""; |
718 | substr $dir, 0, 1 + length $PATH, ""; |
574 | |
719 | |
575 | for my $file (@$nondirs) { |
720 | for my $file (@$nondirs) { |
576 | if ($dir =~ /^music(?:\/|$)/) { |
721 | if ($dir =~ /^music(?:\/|$)/) { |
577 | $c_res->put ([$path, $file, 3]) # FT_MUSIC |
722 | $c_any->put ([\&process_res, $path, $file, 3]) # FT_MUSIC |
578 | if $file =~ /\.(ogg)$/; |
723 | if $file =~ /\.(ogg)$/; |
579 | |
724 | |
580 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
725 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
581 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
726 | $c_any->put ([\&process_res, $path, $file, 5]) # FT_SOUND |
582 | if $file =~ /\.(wav|ogg)$/; |
727 | if $file =~ /\.(wav|ogg)$/; |
583 | |
728 | |
584 | } elsif ($dir =~ /^res(?:\/|$)/) { |
729 | } elsif ($dir =~ /^res(?:\/|$)/) { |
585 | if ($file =~ /\.(jpg|png)$/) { |
730 | if ($file =~ /\.(jpg|png)$/) { |
586 | $c_res->put ([$path, $file, 0]) # FT_FACE |
731 | $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE |
587 | } 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$/) { |
588 | $c_res->put ([$path, $file, 6]) # FT_RSRC |
748 | $c_arc->put ([$path, $file]); |
|
|
749 | |
589 | } else { |
750 | } else { |
590 | $c_res->put ([$path, $file, undef]); |
751 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
591 | } |
752 | } |
592 | |
|
|
593 | } elsif ($file =~ /\.png$/) { |
|
|
594 | push @c_png, ["$path/$file", 0]; |
|
|
595 | |
|
|
596 | } elsif ($file =~ /\.trs$/) { |
|
|
597 | $c_trs->put ([$path, $file]); |
|
|
598 | |
|
|
599 | } elsif ($file =~ /\.arc$/) { |
|
|
600 | $c_arc->put ([$path, $file]); |
|
|
601 | |
|
|
602 | } else { |
753 | } |
603 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
|
|
604 | } |
|
|
605 | } |
754 | }; |
606 | }; |
755 | }; |
|
|
756 | |
|
|
757 | $scandir->($path); |
|
|
758 | aio_wait $grp; |
607 | } |
759 | } |
608 | |
760 | |
609 | sub generate_plurals { |
761 | sub generate_plurals { |
610 | # use Lingua::EN::Inflect (); |
762 | # use Lingua::EN::Inflect (); |
611 | # Lingua::EN::Inflect::classical; |
763 | # Lingua::EN::Inflect::classical; |
612 | # Lingua::EN::Inflect::def_noun 'talisman' => 'talismans'; |
764 | # Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy |
613 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
765 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
614 | # |
766 | # |
615 | # for my $a (@ARC) { |
767 | # for my $a (@ARC) { |
616 | # my $name = $a->{name} || $a->{_name}; |
768 | # my $name = $a->{name} || $a->{_name}; |
617 | # |
769 | # |
618 | # next unless $a->{name_pl}; |
770 | # next unless $a->{name_pl}; |
619 | # |
771 | # next if $a->{invisible}; |
|
|
772 | # next if $a->{is_floor}; |
|
|
773 | # next if $a->{no_pick}; |
620 | # |
774 | # |
621 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
775 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
622 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
776 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
623 | # ? $name |
777 | # ? $name |
624 | # : Lingua::EN::Inflect::PL $name; |
778 | # : Lingua::EN::Inflect::PL $name; |
625 | # die "$test $pl" if $pl =~ /bootss/;#d# |
|
|
626 | # |
779 | # |
627 | # if ($pl ne $a->{name_pl}) { |
780 | # if ($pl ne $a->{name_pl}) { |
628 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
781 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
629 | # } |
782 | # } |
630 | # } |
783 | # } |
… | |
… | |
648 | if (!-d "$path/treasures") { |
801 | if (!-d "$path/treasures") { |
649 | 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"; |
650 | exit 1 unless $FORCE; |
803 | exit 1 unless $FORCE; |
651 | } |
804 | } |
652 | |
805 | |
653 | 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; |
654 | |
810 | |
655 | find_files $path; |
811 | find_files $path; |
656 | |
812 | |
657 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
658 | my @a_res = map +(async \&process_res), 1..2; |
|
|
659 | my @a_trs = map +(async \&process_trs), 1..2; |
|
|
660 | |
|
|
661 | IO::AIO::flush; |
|
|
662 | |
|
|
663 | $c_res->shutdown; |
|
|
664 | $c_arc->shutdown; |
813 | $c_arc->shutdown; |
665 | $c_trs->shutdown; |
814 | $c_any->shutdown; |
666 | |
|
|
667 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
|
|
668 | |
815 | |
669 | $_->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 |
670 | |
817 | |
671 | print "end arc, start png processing...\n" if $VERBOSE; |
818 | print "end arc, start png processing...\n" if $VERBOSE; |
672 | |
819 | |
673 | # eight png crunchers work fine for my 4x smp machine |
820 | # eight png crunchers work fine for my 4x smp machine |
674 | my @a_png = map +(async \&process_png), 1..8; |
821 | my @a_png = map +(async \&process_png), 1..8; |
675 | |
822 | |
676 | $_->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; |
677 | |
828 | |
678 | print "scanning done, processing results...\n" if $VERBOSE; |
829 | print "scanning done, processing results...\n" if $VERBOSE; |
679 | { |
830 | { |
680 | # remove path prefix from editor_folder |
831 | # remove path prefix from editor_folder |
|
|
832 | $_->{editor_folder} =~ /^\x00/ |
681 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
833 | and substr $_->{editor_folder}, 0, 2 + length $path, "" |
682 | for values %ARC; |
834 | for values %ARC; |
683 | |
835 | |
684 | print "resolving inheritance tree...\n" if $VERBOSE; |
836 | print "resolving inheritance tree...\n" if $VERBOSE; |
685 | # resolve inherit |
837 | # resolve inherit |
686 | while () { |
838 | while () { |
687 | my $progress; |
839 | my $progress; |
688 | my $loop; |
840 | my $loop; |
689 | |
841 | |
690 | for my $o (values %ARC) { |
842 | for my $o (values %ARC) { |
691 | if (my $other = $o->{inherit}) { |
843 | for my $other (split /,/, $o->{inherit}) { |
692 | if (my $s = $ARC{$other}) { |
844 | if (my $s = $ARC{$other}) { |
693 | if ($s->{inherit}) { |
845 | if ($s->{inherit}) { |
694 | $loop = $s; |
846 | $loop = $s; |
695 | } else { |
847 | } else { |
696 | delete $o->{inherit}; |
848 | delete $o->{inherit}; |
… | |
… | |
698 | delete @s{qw(_name more name name_pl)}; |
850 | delete @s{qw(_name more name name_pl)}; |
699 | %$o = ( %s, %$o ); |
851 | %$o = ( %s, %$o ); |
700 | ++$progress; |
852 | ++$progress; |
701 | } |
853 | } |
702 | } else { |
854 | } else { |
703 | 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"; |
704 | delete $ARC{$o->{_name}}; |
856 | delete $ARC{$o->{_name}}; |
705 | } |
857 | } |
706 | } |
858 | } |
707 | } |
859 | } |
708 | |
860 | |
… | |
… | |
715 | } |
867 | } |
716 | |
868 | |
717 | # 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 |
718 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
870 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
719 | |
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 | |
720 | print "generating plurals...\n" if $VERBOSE; |
883 | #print "generating plurals...\n" if $VERBOSE; |
721 | generate_plurals; |
884 | #generate_plurals; |
722 | |
885 | |
723 | print "writing archetypes...\n" if $VERBOSE; |
886 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
724 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
887 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
725 | or die "$DATADIR/archetypes~: $!"; |
888 | or die "$DATADIR/archetypes~: $!"; |
726 | 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]; |
727 | } |
890 | } |
728 | |
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; |
|
|
917 | } |
|
|
918 | |
729 | { |
919 | { |
730 | print "writing treasures...\n" if $VERBOSE; |
920 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
731 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
921 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
732 | or die "$DATADIR/treasures~: $!"; |
922 | or die "$DATADIR/treasures~: $!"; |
733 | print $fh $TRS; |
923 | print $fh $TRS; |
734 | } |
924 | } |
735 | |
925 | |
736 | { |
926 | { |
737 | print "processing facedata...\n" if $VERBOSE; |
927 | print "processing facedata...\n" if $VERBOSE; |
738 | while (my ($k, $v) = each %FACEINFO) { |
928 | while (my ($k, $v) = each %FACEINFO) { |
739 | 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"; |
740 | 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"; |
741 | |
931 | |
|
|
932 | make_hash $k, $v->{data32}, $v->{hash32}; |
|
|
933 | make_hash $k, $v->{data64}, $v->{hash64}; |
|
|
934 | |
742 | #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"; |
743 | #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"; |
744 | |
937 | |
745 | if (my $magicmap = $v->{magicmap}) { |
938 | exists $v->{visibility} |
746 | $magicmap =~ y/A-Z_\-/a-z/d; |
939 | or warn "WARNING: face '$k' has no visibility info, missing faceinfo entry?\n"; |
747 | $v->{magicmap} = $COLOR{$magicmap}; |
940 | |
748 | } |
941 | my $stem = delete $v->{stem}; |
|
|
942 | $v->{glyph} // warn "WARNING: face '$k' has glyph, cannot autoglyph at the moment."; |
|
|
943 | #$v->{glyph} //= autoglyph $stem, $v; |
749 | |
944 | |
750 | delete $v->{arc}; |
945 | delete $v->{arc}; |
751 | } |
946 | } |
752 | |
947 | |
753 | print "writing facedata...\n" if $VERBOSE; |
948 | print "processing resources...\n" if $VERBOSE; |
|
|
949 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
|
|
950 | while (my ($k, $v) = each %RESOURCE) { |
|
|
951 | |
|
|
952 | if ($v->{meta} && $v->{meta}{datadir}) { |
|
|
953 | delete $RESOURCE{$k}; |
|
|
954 | |
|
|
955 | $k =~ s/^res\/// or die "$k: datadir files must be in res/"; |
|
|
956 | |
|
|
957 | printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE; |
|
|
958 | open my $fh, ">:raw", "$DATADIR/$k~" |
|
|
959 | or die "$DATADIR/$k~: $!"; |
|
|
960 | syswrite $fh, $v->{data}; |
|
|
961 | push @COMMIT, $k; |
|
|
962 | |
|
|
963 | } else { |
|
|
964 | if ($v->{type} & 1) { |
|
|
965 | # prepend meta info |
|
|
966 | |
|
|
967 | my $meta = $enc->encode ({ |
|
|
968 | name => $k, |
|
|
969 | %{ $v->{meta} || {} }, |
|
|
970 | }); |
|
|
971 | |
|
|
972 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
|
|
973 | } |
|
|
974 | |
|
|
975 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
|
|
976 | } |
|
|
977 | } |
|
|
978 | |
|
|
979 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
|
|
980 | scalar keys %FACEINFO, |
|
|
981 | scalar keys %ANIMINFO, |
|
|
982 | scalar keys %RESOURCE |
|
|
983 | if $VERBOSE; |
|
|
984 | |
754 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
985 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
755 | or die "$DATADIR/facedata~: $!"; |
986 | or die "$DATADIR/facedata~: $!"; |
756 | |
987 | |
757 | print $fh freeze { |
988 | print $fh nfreeze { |
758 | version => 2, |
989 | version => 2, |
759 | faceinfo => \%FACEINFO, |
990 | faceinfo => \%FACEINFO, |
760 | animinfo => \%ANIMINFO, |
991 | animinfo => \%ANIMINFO, |
761 | resource => \%RESOURCE, |
992 | resource => \%RESOURCE, |
762 | }; |
993 | }; |
|
|
994 | |
763 | } |
995 | } |
764 | |
996 | |
765 | print "committing files...\n" if $VERBOSE; |
997 | print "committing files...\n" if $VERBOSE; |
766 | |
998 | |
767 | for (qw(archetypes facedata treasures)) { |
999 | for (qw(archetypes facedata treasures), @COMMIT) { |
768 | chmod 0644, "$DATADIR/$_~"; |
1000 | chmod 0644, "$DATADIR/$_~"; |
769 | rename "$DATADIR/$_~", "$DATADIR/$_" |
1001 | rename "$DATADIR/$_~", "$DATADIR/$_" |
770 | or die "$DATADIR/$_: $!"; |
1002 | or die "$DATADIR/$_: $!"; |
771 | } |
1003 | } |
772 | |
1004 | |