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