1 | #!@PERL@ |
1 | #!@PERL@ |
|
|
2 | |
|
|
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 | # |
2 | |
24 | |
3 | use strict; |
25 | use strict; |
4 | |
26 | |
5 | my $prefix = "@prefix@"; |
27 | my $prefix = "@prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
… | |
… | |
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; |
|
|
45 | use YAML::XS (); |
|
|
46 | use JSON::XS (); |
19 | use IO::AIO (); |
47 | use IO::AIO (); |
20 | use File::Temp; |
48 | |
21 | use Crossfire; |
|
|
22 | use Coro; |
49 | use Coro 5.12; |
23 | use Coro::AIO; |
50 | use Coro::AIO; |
24 | use POSIX (); |
51 | use Coro::Util; |
25 | use Digest::MD5; |
52 | use Coro::Channel; |
26 | use Carp; |
|
|
27 | use Coro::Storable; $Storable::canonical = 1; |
53 | use Coro::Storable; $Storable::canonical = 1; |
|
|
54 | |
|
|
55 | use Deliantra; |
28 | |
56 | |
29 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
57 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
30 | |
58 | |
31 | sub usage { |
59 | sub usage { |
32 | warn <<EOF; |
60 | warn <<EOF; |
… | |
… | |
64 | tan => 12, |
92 | tan => 12, |
65 | ); |
93 | ); |
66 | |
94 | |
67 | END { system "rm", "-rf", $TMPDIR } |
95 | END { system "rm", "-rf", $TMPDIR } |
68 | |
96 | |
69 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
97 | my $s_INT = EV::signal INT => sub { exit 1 }; |
70 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
98 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
71 | |
99 | |
72 | mkdir $TMPDIR, 0700 |
100 | mkdir $TMPDIR, 0700 |
73 | or die "$TMPDIR: $!"; |
101 | or die "$TMPDIR: $!"; |
74 | |
102 | |
75 | sub fork_sub(&) { |
103 | sub fork_sub(&) { |
… | |
… | |
95 | if (!-f "$path/regions") { |
123 | if (!-f "$path/regions") { |
96 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
124 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
97 | exit 1 unless $FORCE; |
125 | exit 1 unless $FORCE; |
98 | } |
126 | } |
99 | |
127 | |
100 | system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
128 | system $RSYNC, "-av", "--chmod=u=rwX,go=rX", |
|
|
129 | "$path/.", "$DATADIR/maps/.", |
|
|
130 | "--exclude", "CVS", "--exclude", "/world-precomposed", |
|
|
131 | "--delete", "--delete-excluded" |
101 | and die "map installation failed.\n"; |
132 | and die "map installation failed.\n"; |
102 | |
133 | |
103 | print "maps installed successfully.\n"; |
134 | print "maps installed successfully.\n"; |
104 | } |
135 | } |
105 | |
136 | |
… | |
… | |
113 | our $NFILE; |
144 | our $NFILE; |
114 | our $PATH; |
145 | our $PATH; |
115 | |
146 | |
116 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
147 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
117 | |
148 | |
118 | our (@png, @trs, @arc, @res); # files we are interested in |
149 | our $c_arc = new Coro::Channel; |
|
|
150 | our $c_trs = new Coro::Channel; |
|
|
151 | our $c_res = new Coro::Channel; |
|
|
152 | |
|
|
153 | our @c_png; |
119 | |
154 | |
120 | sub commit_png($$$) { |
155 | sub commit_png($$$) { |
121 | my ($name, $data, $T) = @_; |
156 | my ($name, $data, $T) = @_; |
122 | |
157 | |
123 | $FACEINFO{$name}{"data$T"} = $data; |
158 | $FACEINFO{$name}{"data$T"} = $data; |
124 | } |
159 | } |
125 | |
160 | |
126 | sub process_png { |
161 | sub process_png { |
127 | while (@png) { |
162 | while (@c_png) { |
128 | my ($path, $delete) = @{pop @png}; |
163 | my ($path, $delete) = @{pop @c_png}; |
129 | |
164 | |
130 | my $png; |
165 | my $png; |
131 | aio_lstat $path; |
166 | aio_lstat $path; |
132 | my ($size, $mtime) = (stat _)[7,9]; |
167 | my ($size, $mtime) = (stat _)[7,9]; |
133 | |
168 | |
… | |
… | |
164 | if ($w % $T || $h % $T) { |
199 | if ($w % $T || $h % $T) { |
165 | warn "$path: weird png size ($w $h), skipping.\n"; |
200 | warn "$path: weird png size ($w $h), skipping.\n"; |
166 | next; |
201 | next; |
167 | } |
202 | } |
168 | |
203 | |
|
|
204 | (my $base = $stem) =~ s/^.*\///; |
|
|
205 | |
|
|
206 | my $fi = $FACEINFO{$base}; |
|
|
207 | unless ($fi) { |
|
|
208 | #warn "$path: <$base> not referenced by any archetype, skipping.\n"; |
|
|
209 | #next; |
|
|
210 | } |
|
|
211 | |
|
|
212 | my $arc = $fi->{arc} || { }; |
|
|
213 | |
169 | unless ($path =~ /~$/) { |
214 | unless ($path =~ /~$/) { |
170 | # possibly enlarge |
215 | # possibly enlarge |
171 | if (0 > aio_stat "$stem.64x64.png") { |
216 | if (0 > aio_stat "$stem.64x64.png") { |
172 | my $other = "$stem.64x64.png~"; |
217 | my $other = "$stem.64x64.png~"; |
173 | |
218 | |
174 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
219 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
175 | my $wrap = 0; # for the time being |
|
|
176 | fork_sub { |
220 | fork_sub { |
|
|
221 | my $CROP; |
|
|
222 | my $SRC = "png:\Q$path\E"; |
|
|
223 | |
|
|
224 | my $is_floor = $arc->{is_floor}; |
|
|
225 | my $is_wall = 0; |
|
|
226 | |
|
|
227 | my ($wall_pfx, $wall_dir, $wall_sfx); |
|
|
228 | |
|
|
229 | if ( |
|
|
230 | !$is_floor |
|
|
231 | && !$arc->{alive} |
|
|
232 | && $arc->{move_block} eq "all" |
|
|
233 | && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/ |
|
|
234 | ) { |
|
|
235 | ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3); |
|
|
236 | |
|
|
237 | unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) { |
|
|
238 | $is_wall = 1; |
|
|
239 | } |
|
|
240 | } |
|
|
241 | |
|
|
242 | if ($is_wall || $is_floor) { |
|
|
243 | # add a 4px border and add other images around it |
|
|
244 | $CROP = "-shave 8x8 +repage"; |
|
|
245 | |
|
|
246 | $w += 8; |
|
|
247 | $h += 8; |
|
|
248 | |
|
|
249 | $SRC = "-size ${w}x${h} xc:transparent"; |
|
|
250 | $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; |
|
|
251 | |
|
|
252 | # 8 surrounding images |
|
|
253 | for ( |
|
|
254 | # x y b r0 r1 |
|
|
255 | [-1, -1, 0, 6], |
|
|
256 | [ 0, -1, 1, 10, 14], |
|
|
257 | [+1, -1, 0, 12], |
|
|
258 | |
|
|
259 | [-1, 0, 8, 5, 7], |
|
|
260 | # |
|
|
261 | [+1, 0, 2, 5, 13], |
|
|
262 | |
|
|
263 | [-1, +1, 0, 3], |
|
|
264 | [ 0, +1, 4, 10, 11], |
|
|
265 | [+1, +1, 0, 9], |
|
|
266 | ) { |
|
|
267 | my ($x, $y, $d, $r0, $r1) = @$_; |
|
|
268 | |
|
|
269 | my $tile = $is_floor ? $path |
|
|
270 | : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx |
|
|
271 | : die; |
|
|
272 | |
|
|
273 | $SRC .= sprintf " png:%s -geometry %+d%+d -composite", |
|
|
274 | "\Q$tile", |
|
|
275 | $x * ($w - 8) + 4, |
|
|
276 | $y * ($h - 8) + 4; |
|
|
277 | } |
|
|
278 | } |
|
|
279 | |
177 | system "convert png:\Q$path\E -depth 8 rgba:-" |
280 | system "convert -depth 8 $SRC rgba:-" |
178 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
281 | . "| $exec_prefix/bin/cfhq2xa $w $h 0" |
179 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
282 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~" |
180 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
283 | and die "convert/cfhq2xa pipeline error: status $? ($!)"; |
181 | system $OPTIPNG, "-i0", "-q", "$other~"; |
284 | system $OPTIPNG, "-i0", "-q", "$other~"; |
182 | die "$other~ has zero size, aborting." unless -s "$other~"; |
285 | die "$other~ has zero size, aborting." unless -s "$other~"; |
183 | rename "$other~", $other; |
286 | rename "$other~", $other; |
184 | }; |
287 | }; |
185 | } |
288 | } |
186 | |
289 | |
187 | push @png, [$other, !$CACHE]; |
290 | push @c_png, [$other, !$CACHE]; |
188 | } |
291 | } |
189 | |
292 | |
190 | # possibly scale down |
293 | # possibly scale down |
191 | if (0 > aio_stat "$stem.32x32.png") { |
294 | if (0 > aio_stat "$stem.32x32.png") { |
192 | my $other = "$stem.32x32.png~"; |
295 | my $other = "$stem.32x32.png~"; |
… | |
… | |
195 | fork_sub { |
298 | fork_sub { |
196 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
299 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
197 | system $OPTIPNG, "-i0", "-q", "$other~"; |
300 | system $OPTIPNG, "-i0", "-q", "$other~"; |
198 | |
301 | |
199 | # reduce smoothfaces >10000 bytes |
302 | # reduce smoothfaces >10000 bytes |
|
|
303 | # obsolete, no longer required |
200 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
304 | if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { |
201 | my $ncolor = 256; |
305 | my $ncolor = 256; |
202 | while () { |
306 | while () { |
203 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
307 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
204 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
308 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
205 | last if 10000 > -s "$other~~"; |
309 | last if 10000 > -s "$other~~"; |
… | |
… | |
217 | rename "$other~", $other; |
321 | rename "$other~", $other; |
218 | }; |
322 | }; |
219 | } |
323 | } |
220 | |
324 | |
221 | #warn "scaled down $path to $other\n";#d# |
325 | #warn "scaled down $path to $other\n";#d# |
222 | push @png, [$other, !$CACHE]; |
326 | push @c_png, [$other, !$CACHE]; |
223 | } |
327 | } |
224 | } |
328 | } |
225 | |
329 | |
226 | (my $face = $stem) =~ s/^.*\///; |
330 | (my $face = $stem) =~ s/^.*\///; |
227 | |
331 | |
… | |
… | |
288 | aio_unlink $path if $delete; |
392 | aio_unlink $path if $delete; |
289 | } |
393 | } |
290 | } |
394 | } |
291 | |
395 | |
292 | sub process_arc { |
396 | sub process_arc { |
293 | while (@arc) { |
397 | while (my $job = $c_arc->get) { |
294 | my ($dir, $file) = @{pop @arc}; |
398 | my ($dir, $file) = @$job; |
295 | |
399 | |
296 | my $arc; |
400 | my $arc; |
297 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
401 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
298 | |
402 | |
299 | my $arc = read_arch "$dir/$file"; |
403 | my $arc = read_arch "$dir/$file"; |
… | |
… | |
301 | push @ARC, $o; |
405 | push @ARC, $o; |
302 | for (my $m = $o; $m; $m = $m->{more}) { |
406 | for (my $m = $o; $m; $m = $m->{more}) { |
303 | $ARC{$m->{_name}} = $m; |
407 | $ARC{$m->{_name}} = $m; |
304 | } |
408 | } |
305 | |
409 | |
306 | $o->{editor_folder} = $dir; |
410 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
307 | |
411 | |
308 | my $visibility = delete $o->{visibility}; |
412 | my $visibility = delete $o->{visibility}; |
309 | my $magicmap = delete $o->{magicmap}; |
413 | my $magicmap = delete $o->{magicmap}; |
310 | |
414 | |
311 | # find upper left corner :/ |
415 | # find upper left corner :/ |
… | |
… | |
351 | facings => $facings, |
455 | facings => $facings, |
352 | frames => \@frames, |
456 | frames => \@frames, |
353 | }; |
457 | }; |
354 | } |
458 | } |
355 | |
459 | |
356 | for my $face ($o->{face} || (), @{$anim || []}) { |
460 | for ($o->{face} || (), @{$anim || []}) { |
357 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
461 | next if /^facings\s/; |
358 | |
462 | |
|
|
463 | my $face = $_; |
|
|
464 | $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates |
|
|
465 | |
359 | my $info = $FACEINFO{$face} ||= {}; |
466 | my $info = $FACEINFO{$face} ||= { }; |
|
|
467 | $info->{arc} = $o; |
|
|
468 | |
|
|
469 | next if $face =~ /^blank.x11$|^empty.x11$/; |
360 | |
470 | |
361 | $info->{visibility} = $visibility if defined $visibility; |
471 | $info->{visibility} = $visibility if defined $visibility; |
362 | $info->{magicmap} = $magicmap if defined $magicmap; |
472 | $info->{magicmap} = $magicmap if defined $magicmap; |
363 | } |
473 | } |
364 | |
474 | |
365 | if (my $smooth = delete $o->{smoothface}) { |
475 | if (my $smooth = delete $o->{smoothface}) { |
366 | my %kv =split /\s+/, $smooth; |
476 | my %kv = split /\s+/, $smooth; |
367 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
477 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
368 | while (my ($face, $smooth) = each %kv) { |
478 | while (my ($face, $smooth) = each %kv) { |
|
|
479 | $FACEINFO{$smooth}{arc} = $o; |
|
|
480 | |
369 | $FACEINFO{$face}{smooth} = $smooth; |
481 | $FACEINFO{$face}{smooth} = $smooth; |
370 | $FACEINFO{$face}{smoothlevel} = $level; |
482 | $FACEINFO{$face}{smoothlevel} = $level; |
371 | } |
483 | } |
372 | } |
484 | } |
373 | } |
485 | } |
374 | } |
486 | } |
375 | } |
487 | } |
376 | } |
488 | } |
377 | |
489 | |
378 | sub process_trs { |
490 | sub process_trs { |
379 | while (@trs) { |
491 | while (my $job = $c_trs->get) { |
380 | my ($dir, $file) = @{pop @trs}; |
492 | my ($dir, $file) = @$job; |
381 | my $path = "$dir/$file"; |
493 | my $path = "$dir/$file"; |
382 | |
494 | |
383 | my $trs; |
495 | my $trs; |
384 | if (0 > aio_load $path, $trs) { |
496 | if (0 > aio_load $path, $trs) { |
385 | warn "$path: $!, skipping.\n"; |
497 | warn "$path: $!, skipping.\n"; |
… | |
… | |
394 | |
506 | |
395 | sub load_cached($;$) { |
507 | sub load_cached($;$) { |
396 | unless (exists $FILECACHE{$_[0]}) { |
508 | unless (exists $FILECACHE{$_[0]}) { |
397 | my $data; |
509 | my $data; |
398 | if (0 < aio_load $_[0], $data) { |
510 | if (0 < aio_load $_[0], $data) { |
|
|
511 | if ($_[1]) { |
399 | $data = $_[1]->($data) |
512 | $data = eval { $_[1]->($data) }; |
400 | if $_[1]; |
513 | warn "$_[0]: $@" if $@; |
|
|
514 | } |
401 | } |
515 | } |
402 | |
516 | |
403 | $FILECACHE{$_[0]} = $data; |
517 | $FILECACHE{$_[0]} = $data; |
404 | } |
518 | } |
405 | |
519 | |
406 | $FILECACHE{$_[0]} |
520 | $FILECACHE{$_[0]} |
407 | } |
521 | } |
408 | |
522 | |
409 | sub process_res { |
523 | sub process_res { |
410 | while (@res) { |
524 | while (my $job = $c_res->get) { |
411 | my ($dir, $file, $type) = @{pop @res}; |
525 | my ($dir, $file, $type) = @$job; |
412 | |
526 | |
413 | my $data; |
527 | my $data; |
414 | aio_load "$dir/$file", $data; |
528 | aio_load "$dir/$file", $data; |
415 | |
529 | |
416 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
530 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
|
|
531 | |
|
|
532 | utf8::decode $dir; |
|
|
533 | utf8::decode $file; |
|
|
534 | |
|
|
535 | # a meta file for resources is now mandatory |
|
|
536 | unless (exists $meta->{$file}) { |
|
|
537 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
|
|
538 | next; |
|
|
539 | } |
417 | |
540 | |
418 | $meta = { |
541 | $meta = { |
419 | %{ $meta->{"" } || {} }, |
542 | %{ $meta->{"" } || {} }, |
420 | %{ $meta->{$file} || {} }, |
543 | %{ $meta->{$file} || {} }, |
421 | }; |
544 | }; |
422 | |
545 | |
|
|
546 | if ($meta->{license} =~ s/^#//) { |
|
|
547 | $meta->{license} = ({ |
|
|
548 | "pd" => "Public Domain", |
|
|
549 | "gpl" => "GNU General Public License, version 3.0 or any later", |
|
|
550 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
551 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
|
|
552 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
|
|
553 | })->{$meta->{license}} |
|
|
554 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
|
|
555 | } |
|
|
556 | |
423 | $file =~ s/\.res$//; |
557 | $file =~ s/\.res$//; |
424 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
558 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
425 | |
559 | |
426 | substr $dir, 0, 1 + length $PATH, ""; |
560 | substr $dir, 0, 1 + length $PATH, ""; |
427 | |
561 | |
|
|
562 | if (my $filter = $meta->{cfutil_filter}) { |
|
|
563 | if ($filter eq "yaml2json") { |
|
|
564 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
|
|
565 | } elsif ($filter eq "json2json") { |
|
|
566 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
|
|
567 | } elsif ($filter eq "perl2json") { |
|
|
568 | $data = eval $data; die if $@; |
|
|
569 | $data = JSON::XS::encode_json $data; |
|
|
570 | } else { |
|
|
571 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
|
|
572 | } |
|
|
573 | } |
|
|
574 | |
428 | $RESOURCE{"$dir/$file"} = { |
575 | $RESOURCE{"$dir/$file"} = { |
429 | type => (delete $meta->{type}) || $type, |
576 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
430 | data => $data, |
577 | data => $data, |
431 | chksum => (Digest::MD5::md5 $data), |
|
|
432 | %$meta ? (meta => $meta) : (), |
578 | %$meta ? (meta => $meta) : (), |
433 | }; |
579 | }; |
434 | } |
580 | } |
435 | } |
581 | } |
436 | |
582 | |
… | |
… | |
448 | my $dir = $path; |
594 | my $dir = $path; |
449 | substr $dir, 0, 1 + length $PATH, ""; |
595 | substr $dir, 0, 1 + length $PATH, ""; |
450 | |
596 | |
451 | for my $file (@$nondirs) { |
597 | for my $file (@$nondirs) { |
452 | if ($dir =~ /^music(?:\/|$)/) { |
598 | if ($dir =~ /^music(?:\/|$)/) { |
453 | push @res, [$path, $file, 3] # FT_MUSIC |
599 | $c_res->put ([$path, $file, 3]) # FT_MUSIC |
454 | if $file =~ /\.(ogg)$/; |
600 | if $file =~ /\.(ogg)$/; |
455 | |
601 | |
456 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
602 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
457 | push @res, [$path, $file, 5] # FT_SOUND |
603 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
458 | if $file =~ /\.(wav|ogg)$/; |
604 | if $file =~ /\.(wav|ogg)$/; |
459 | |
605 | |
460 | } elsif ($dir =~ /^res(?:\/|$)/) { |
606 | } elsif ($dir =~ /^res(?:\/|$)/) { |
461 | push @res, [$path, $file, 0] # FT_FACE |
|
|
462 | if $file =~ /\.(jpg|png)$/; |
607 | if ($file =~ /\.(jpg|png)$/) { |
463 | push @res, [$path, $file, 7] # FT_RSRC |
608 | $c_res->put ([$path, $file, 0]) # FT_FACE |
464 | if $file =~ /\.(res)$/; |
609 | } elsif ($file =~ /\.(res)$/) { |
|
|
610 | $c_res->put ([$path, $file, 6]) # FT_RSRC |
|
|
611 | } else { |
|
|
612 | $c_res->put ([$path, $file, undef]); |
|
|
613 | } |
465 | |
614 | |
466 | } elsif ($file =~ /\.png$/) { |
615 | } elsif ($file =~ /\.png$/) { |
467 | push @png, ["$path/$file", 0]; |
616 | push @c_png, ["$path/$file", 0]; |
468 | |
617 | |
469 | } elsif ($file =~ /\.trs$/) { |
618 | } elsif ($file =~ /\.trs$/) { |
470 | push @trs, [$path, $file]; |
619 | $c_trs->put ([$path, $file]); |
471 | |
620 | |
472 | } elsif ($file =~ /\.arc$/) { |
621 | } elsif ($file =~ /\.arc$/) { |
473 | push @arc, [$path, $file]; |
622 | $c_arc->put ([$path, $file]); |
474 | |
623 | |
475 | } else { |
624 | } else { |
476 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
625 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
477 | } |
626 | } |
478 | } |
627 | } |
479 | }; |
628 | }; |
|
|
629 | } |
|
|
630 | |
|
|
631 | sub generate_plurals { |
|
|
632 | # use Lingua::EN::Inflect (); |
|
|
633 | # Lingua::EN::Inflect::classical; |
|
|
634 | # Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy |
|
|
635 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
|
|
636 | # |
|
|
637 | # for my $a (@ARC) { |
|
|
638 | # my $name = $a->{name} || $a->{_name}; |
|
|
639 | # |
|
|
640 | # next unless $a->{name_pl}; |
|
|
641 | # next if $a->{invisible}; |
|
|
642 | # next if $a->{is_floor}; |
|
|
643 | # next if $a->{no_pick}; |
|
|
644 | # |
|
|
645 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
|
|
646 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
|
|
647 | # ? $name |
|
|
648 | # : Lingua::EN::Inflect::PL $name; |
|
|
649 | # |
|
|
650 | # if ($pl ne $a->{name_pl}) { |
|
|
651 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
|
|
652 | # } |
|
|
653 | # } |
480 | } |
654 | } |
481 | |
655 | |
482 | sub inst_arch($) { |
656 | sub inst_arch($) { |
483 | my (undef, $path) = @_; |
657 | my (undef, $path) = @_; |
484 | |
658 | |
… | |
… | |
497 | if (!-d "$path/treasures") { |
671 | if (!-d "$path/treasures") { |
498 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
672 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
499 | exit 1 unless $FORCE; |
673 | exit 1 unless $FORCE; |
500 | } |
674 | } |
501 | |
675 | |
|
|
676 | print "scanning files...\n" if $VERBOSE; |
|
|
677 | |
502 | find_files $path; |
678 | find_files $path; |
|
|
679 | |
|
|
680 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
681 | my @a_res = map +(async \&process_res), 1..2; |
|
|
682 | my @a_trs = map +(async \&process_trs), 1..2; |
|
|
683 | |
503 | IO::AIO::flush; |
684 | IO::AIO::flush; |
504 | |
685 | |
505 | $_->join for ( |
686 | $c_res->shutdown; |
|
|
687 | $c_arc->shutdown; |
|
|
688 | $c_trs->shutdown; |
|
|
689 | |
|
|
690 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
|
|
691 | |
|
|
692 | $_->join for @a_arc; # need to parse all archetypes before png processing |
|
|
693 | |
|
|
694 | print "end arc, start png processing...\n" if $VERBOSE; |
|
|
695 | |
506 | # four png crunchers work fine for my 2x smp machine |
696 | # eight png crunchers work fine for my 4x smp machine |
507 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
697 | my @a_png = map +(async \&process_png), 1..8; |
508 | (async \&process_trs), (async \&process_trs), |
|
|
509 | (async \&process_arc), (async \&process_arc), |
|
|
510 | (async \&process_res), (async \&process_res), |
|
|
511 | ); |
|
|
512 | |
698 | |
|
|
699 | $_->join for (@a_trs, @a_res, @a_png); |
|
|
700 | |
|
|
701 | print "scanning done, processing results...\n" if $VERBOSE; |
513 | { |
702 | { |
514 | # remove path prefix from editor_folder |
703 | # remove path prefix from editor_folder |
|
|
704 | $_->{editor_folder} =~ /^\x00/ |
515 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
705 | and substr $_->{editor_folder}, 0, 2 + length $path, "" |
516 | for values %ARC; |
706 | for values %ARC; |
517 | |
707 | |
|
|
708 | print "resolving inheritance tree...\n" if $VERBOSE; |
518 | # resolve inherit |
709 | # resolve inherit |
519 | while () { |
710 | while () { |
520 | my $progress; |
711 | my $progress; |
521 | my $loop; |
712 | my $loop; |
522 | |
713 | |
… | |
… | |
548 | } |
739 | } |
549 | |
740 | |
550 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
741 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
551 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
742 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
552 | |
743 | |
|
|
744 | print "generating plurals...\n" if $VERBOSE; |
|
|
745 | generate_plurals; |
|
|
746 | |
|
|
747 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
553 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
748 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
554 | or die "$DATADIR/archetypes~: $!"; |
749 | or die "$DATADIR/archetypes~: $!"; |
555 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
750 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
556 | } |
751 | } |
557 | |
752 | |
558 | { |
753 | { |
|
|
754 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
559 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
755 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
560 | or die "$DATADIR/treasures~: $!"; |
756 | or die "$DATADIR/treasures~: $!"; |
561 | print $fh $TRS; |
757 | print $fh $TRS; |
562 | } |
758 | } |
563 | |
759 | |
564 | { |
760 | { |
|
|
761 | print "processing facedata...\n" if $VERBOSE; |
565 | while (my ($k, $v) = each %FACEINFO) { |
762 | while (my ($k, $v) = each %FACEINFO) { |
566 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
763 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
567 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
764 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
568 | |
765 | |
569 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
766 | #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
570 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
767 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
571 | |
|
|
572 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
|
|
573 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
|
|
574 | |
768 | |
575 | if (my $magicmap = $v->{magicmap}) { |
769 | if (my $magicmap = $v->{magicmap}) { |
576 | $magicmap =~ y/A-Z_\-/a-z/d; |
770 | $magicmap =~ y/A-Z_\-/a-z/d; |
577 | $v->{magicmap} = $COLOR{$magicmap}; |
771 | $v->{magicmap} = $COLOR{$magicmap}; |
578 | } |
772 | } |
|
|
773 | |
|
|
774 | delete $v->{arc}; |
579 | } |
775 | } |
|
|
776 | |
|
|
777 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
|
|
778 | scalar keys %FACEINFO, |
|
|
779 | scalar keys %ANIMINFO, |
|
|
780 | scalar keys %RESOURCE |
|
|
781 | if $VERBOSE; |
580 | |
782 | |
581 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
783 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
582 | or die "$DATADIR/facedata~: $!"; |
784 | or die "$DATADIR/facedata~: $!"; |
583 | |
785 | |
584 | print $fh freeze { |
786 | print $fh freeze { |
585 | version => 2, |
787 | version => 2, |
586 | faceinfo => \%FACEINFO, |
788 | faceinfo => \%FACEINFO, |
587 | animinfo => \%ANIMINFO, |
789 | animinfo => \%ANIMINFO, |
588 | resource => \%RESOURCE, |
790 | resource => \%RESOURCE, |
589 | }; |
791 | }; |
|
|
792 | |
590 | } |
793 | } |
|
|
794 | |
|
|
795 | print "committing files...\n" if $VERBOSE; |
591 | |
796 | |
592 | for (qw(archetypes facedata treasures)) { |
797 | for (qw(archetypes facedata treasures)) { |
593 | chmod 0644, "$DATADIR/$_~"; |
798 | chmod 0644, "$DATADIR/$_~"; |
594 | rename "$DATADIR/$_~", "$DATADIR/$_" |
799 | rename "$DATADIR/$_~", "$DATADIR/$_" |
595 | or die "$DATADIR/$_: $!"; |
800 | or die "$DATADIR/$_: $!"; |