… | |
… | |
9 | |
9 | |
10 | my $CONVERT = "@CONVERT@"; |
10 | my $CONVERT = "@CONVERT@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
|
|
14 | my $PNGNQ = "@PNGNQ@"; |
14 | |
15 | |
15 | use Getopt::Long; |
16 | use Getopt::Long; |
16 | use Coro::Event; |
17 | use Coro::Event; |
17 | use AnyEvent; |
18 | use AnyEvent; |
18 | use IO::AIO (); |
19 | use IO::AIO (); |
… | |
… | |
68 | } |
69 | } |
69 | |
70 | |
70 | sub inst_maps($) { |
71 | sub inst_maps($) { |
71 | my (undef, $path) = @_; |
72 | my (undef, $path) = @_; |
72 | |
73 | |
73 | print "installing '$path' to '$DATADIR/maps'\n"; |
74 | print "\nInstalling '$path' to '$DATADIR/maps'\n\n"; |
74 | |
75 | |
75 | if (!-f "$path/regions") { |
76 | if (!-f "$path/regions") { |
76 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
77 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
77 | exit 1 unless $FORCE; |
78 | exit 1 unless $FORCE; |
78 | } |
79 | } |
… | |
… | |
84 | } |
85 | } |
85 | |
86 | |
86 | { |
87 | { |
87 | our %ANIMINFO; |
88 | our %ANIMINFO; |
88 | our %FACEINFO; |
89 | our %FACEINFO; |
|
|
90 | our @ARC; |
89 | our %ARC; |
91 | our %ARC; |
90 | our $TRS; |
92 | our $TRS; |
91 | our $NFILE; |
93 | our $NFILE; |
92 | |
94 | |
93 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
95 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
… | |
… | |
153 | fork_sub { |
155 | fork_sub { |
154 | system "convert png:\Q$path\E -depth 8 rgba:-" |
156 | system "convert png:\Q$path\E -depth 8 rgba:-" |
155 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
157 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
156 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
158 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
157 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
159 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
158 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
160 | system $OPTIPNG, "-i0", "-q", "$other~"; |
159 | die "$other~ has zero size, aborting." unless -s "$other~"; |
161 | die "$other~ has zero size, aborting." unless -s "$other~"; |
160 | rename "$other~", $other; |
162 | rename "$other~", $other; |
161 | }; |
163 | }; |
162 | } |
164 | } |
163 | |
165 | |
… | |
… | |
169 | my $other = "$stem.32x32.png~"; |
171 | my $other = "$stem.32x32.png~"; |
170 | |
172 | |
171 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
173 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
172 | fork_sub { |
174 | fork_sub { |
173 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
175 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
174 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
176 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
177 | |
|
|
178 | # reduce smoothfaces >10000 bytes |
|
|
179 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
|
|
180 | my $ncolor = 256; |
|
|
181 | while () { |
|
|
182 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
|
|
183 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
|
|
184 | last if 10000 > -s "$other~~"; |
|
|
185 | $ncolor = int $ncolor * 0.9; |
|
|
186 | $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; |
|
|
187 | } |
|
|
188 | |
|
|
189 | printf "reduced %s from %d to %d bytes using %d colours.\n", |
|
|
190 | $other, -s "$other~", -s "$other~~", $ncolor |
|
|
191 | if $VERBOSE >= 2; |
|
|
192 | rename "$other~~", "$other~"; |
|
|
193 | } |
|
|
194 | |
175 | die "$other~ has zero size, aborting." unless -s "$other~"; |
195 | die "$other~ has zero size, aborting." unless -s "$other~"; |
176 | rename "$other~", $other; |
196 | rename "$other~", $other; |
177 | }; |
197 | }; |
178 | } |
198 | } |
179 | |
199 | |
… | |
… | |
255 | my $arc; |
275 | my $arc; |
256 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
276 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
257 | |
277 | |
258 | my $arc = read_arch "$dir/$file"; |
278 | my $arc = read_arch "$dir/$file"; |
259 | for my $o (values %$arc) { |
279 | for my $o (values %$arc) { |
|
|
280 | push @ARC, $o; |
|
|
281 | for (my $m = $o; $m; $m = $m->{more}) { |
260 | $ARC{$o->{_name}} = $o; |
282 | $ARC{$m->{_name}} = $m; |
|
|
283 | } |
261 | |
284 | |
262 | $o->{editor_folder} = $dir; |
285 | $o->{editor_folder} = $dir; |
263 | |
286 | |
264 | my $visibility = delete $o->{visibility}; |
287 | my $visibility = delete $o->{visibility}; |
265 | my $magicmap = delete $o->{magicmap}; |
288 | my $magicmap = delete $o->{magicmap}; |
… | |
… | |
363 | } elsif ($file =~ /\.trs$/) { |
386 | } elsif ($file =~ /\.trs$/) { |
364 | push @trs, [$path, $file]; |
387 | push @trs, [$path, $file]; |
365 | } elsif ($file =~ /\.arc$/) { |
388 | } elsif ($file =~ /\.arc$/) { |
366 | push @arc, [$path, $file]; |
389 | push @arc, [$path, $file]; |
367 | } else { |
390 | } else { |
368 | warn "ignoring $path/$file\n" if $VERBOSE >= 2; |
391 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
369 | } |
392 | } |
370 | } |
393 | } |
371 | }; |
394 | }; |
372 | } |
395 | } |
373 | |
396 | |
374 | sub inst_arch($) { |
397 | sub inst_arch($) { |
375 | my (undef, $path) = @_; |
398 | my (undef, $path) = @_; |
376 | |
399 | |
|
|
400 | print "\n", |
377 | print "Installing '$path' to '$DATADIR'\n", |
401 | "Installing '$path' to '$DATADIR'\n", |
378 | "\n", |
402 | "\n", |
379 | "This can take a long time if you run this\n", |
403 | "This can take a long time if you run this\n", |
380 | "for the first time or do not use --cache.\n", |
404 | "for the first time or do not use --cache.\n", |
381 | "\n", |
405 | "\n", |
382 | "Unless you run verbosely, all following warning\n", |
406 | "Unless you run verbosely, all following warning\n", |
… | |
… | |
413 | if (my $s = $ARC{$other}) { |
437 | if (my $s = $ARC{$other}) { |
414 | if ($s->{inherit}) { |
438 | if ($s->{inherit}) { |
415 | $loop = $s; |
439 | $loop = $s; |
416 | } else { |
440 | } else { |
417 | delete $o->{inherit}; |
441 | delete $o->{inherit}; |
|
|
442 | my %s = %$s; |
|
|
443 | delete @s{qw(_name more name name_pl)}; |
418 | %$o = ( %$s, %$o ); |
444 | %$o = ( %s, %$o ); |
419 | ++$progress; |
445 | ++$progress; |
420 | } |
446 | } |
421 | } else { |
447 | } else { |
422 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
448 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
423 | delete $ARC{$o->{_name}}; |
449 | delete $ARC{$o->{_name}}; |
… | |
… | |
433 | } |
459 | } |
434 | } |
460 | } |
435 | |
461 | |
436 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
462 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
437 | or die "$DATADIR/archetypes~: $!"; |
463 | or die "$DATADIR/archetypes~: $!"; |
438 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } values %ARC]; |
464 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
439 | } |
465 | } |
440 | |
466 | |
441 | { |
467 | { |
442 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
468 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
443 | or die "$DATADIR/treasures~: $!"; |
469 | or die "$DATADIR/treasures~: $!"; |