… | |
… | |
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 (); |
… | |
… | |
20 | use Crossfire; |
21 | use Crossfire; |
21 | use Coro; |
22 | use Coro; |
22 | use Coro::AIO; |
23 | use Coro::AIO; |
23 | use POSIX (); |
24 | use POSIX (); |
24 | use Digest::MD5; |
25 | use Digest::MD5; |
25 | use Storable; $Storable::canonical = 1; |
26 | use Coro::Storable; $Storable::canonical = 1; |
26 | |
27 | |
27 | sub usage { |
28 | sub usage { |
28 | warn <<EOF; |
29 | warn <<EOF; |
29 | Usage: cfutil [-v] [-q] [--force] [--cache] |
30 | Usage: cfutil [-v] [-q] [--force] [--cache] |
30 | [--install-arch path] |
31 | [--install-arch path] |
… | |
… | |
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 | } |
… | |
… | |
82 | |
83 | |
83 | print "maps installed successfully.\n"; |
84 | print "maps installed successfully.\n"; |
84 | } |
85 | } |
85 | |
86 | |
86 | { |
87 | { |
87 | our %PNG32; |
88 | our %ANIMINFO; |
88 | our %FACEINFO; |
89 | our %FACEINFO; |
89 | our @ARC; |
90 | our @ARC; |
|
|
91 | our %ARC; |
90 | our $TRS; |
92 | our $TRS; |
91 | our $NFILE; |
93 | our $NFILE; |
92 | our %ANIM; |
94 | |
|
|
95 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
93 | |
96 | |
94 | our (@png, @trs, @arc); # files we are interested in |
97 | our (@png, @trs, @arc); # files we are interested in |
95 | |
98 | |
96 | sub commit_png { |
99 | sub commit_png($$$) { |
97 | my ($name, $data) = @_; |
100 | my ($name, $data, $T) = @_; |
98 | |
101 | |
99 | $PNG32{$name} = $data; |
102 | $FACEINFO{$name}{"data$T"} = $data; |
100 | $FACEINFO{$name} ||= {}; |
|
|
101 | } |
103 | } |
102 | |
104 | |
103 | sub process_png { |
105 | sub process_png { |
104 | while (@png) { |
106 | while (@png) { |
105 | my $path = pop @png; |
107 | my ($path, $delete) = @{pop @png}; |
106 | |
108 | |
107 | my $png; |
109 | my $png; |
108 | aio_lstat $path; |
110 | aio_lstat $path; |
109 | my ($size, $mtime) = (stat _)[7,9]; |
111 | my ($size, $mtime) = (stat _)[7,9]; |
110 | |
112 | |
111 | if (0 > aio_load $path, $png) { |
113 | if (0 > aio_load $path, $png) { |
112 | warn "$path: $!, skipping.\n"; |
114 | warn "$path: $!, skipping.\n"; |
113 | next; |
115 | next; |
114 | } |
116 | } |
115 | |
117 | |
|
|
118 | my $stem = $path; |
|
|
119 | my $T; |
|
|
120 | |
|
|
121 | if ($stem =~ s/\.32x32\.png~?$//) { |
|
|
122 | $T = 32; |
|
|
123 | } elsif ($stem =~ s/\.64x64\.png~?$//) { |
|
|
124 | $T = 64; |
|
|
125 | } else { |
|
|
126 | warn "$path: weird filename, skipping.\n"; |
|
|
127 | next; |
|
|
128 | } |
|
|
129 | |
116 | # quickly extract width and height of the (necessarily PNG) image |
130 | # quickly extract width and height of the (necessarily PNG) image |
117 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
131 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
118 | warn "$path: not a recongized png file, skipping.\n"; |
132 | warn "$path: not a recognized png file, skipping.\n"; |
119 | next; |
133 | next; |
120 | } |
134 | } |
121 | |
135 | |
122 | my ($w, $h) = unpack "NN", $1; |
136 | my ($w, $h) = unpack "NN", $1; |
123 | |
|
|
124 | (my $face = $path) =~ s/^.*\///; |
|
|
125 | my $T = 32; |
|
|
126 | |
|
|
127 | unless ($face =~ s/\.base\.(...)\.png$/.$1/) { |
|
|
128 | warn "$path: weird filename, skipping.\n"; |
|
|
129 | next; |
|
|
130 | } |
|
|
131 | |
137 | |
132 | if ($w < $T || $h < $T) { |
138 | if ($w < $T || $h < $T) { |
133 | warn "$path: too small ($w $h), skipping.\n"; |
139 | warn "$path: too small ($w $h), skipping.\n"; |
134 | next; |
140 | next; |
135 | } |
141 | } |
… | |
… | |
137 | if ($w % $T || $h % $T) { |
143 | if ($w % $T || $h % $T) { |
138 | warn "$path: weird png size ($w $h), skipping.\n"; |
144 | warn "$path: weird png size ($w $h), skipping.\n"; |
139 | next; |
145 | next; |
140 | } |
146 | } |
141 | |
147 | |
|
|
148 | unless ($path =~ /~$/) { |
|
|
149 | # possibly enlarge |
|
|
150 | if (0 > aio_stat "$stem.64x64.png") { |
|
|
151 | my $other = "$stem.64x64.png~"; |
|
|
152 | |
|
|
153 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
|
|
154 | my $wrap = 0; # for the time being |
|
|
155 | fork_sub { |
|
|
156 | system "convert png:\Q$path\E -depth 8 rgba:-" |
|
|
157 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
|
|
158 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
|
|
159 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
|
|
160 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
161 | die "$other~ has zero size, aborting." unless -s "$other~"; |
|
|
162 | rename "$other~", $other; |
|
|
163 | }; |
|
|
164 | } |
|
|
165 | |
|
|
166 | push @png, [$other, !$CACHE]; |
|
|
167 | } |
|
|
168 | |
|
|
169 | # possibly scale down |
|
|
170 | if (0 > aio_stat "$stem.32x32.png") { |
|
|
171 | my $other = "$stem.32x32.png~"; |
|
|
172 | |
|
|
173 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
|
|
174 | fork_sub { |
|
|
175 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
|
|
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 | |
|
|
195 | die "$other~ has zero size, aborting." unless -s "$other~"; |
|
|
196 | rename "$other~", $other; |
|
|
197 | }; |
|
|
198 | } |
|
|
199 | |
|
|
200 | #warn "scaled down $path to $other\n";#d# |
|
|
201 | push @png, [$other, !$CACHE]; |
|
|
202 | } |
|
|
203 | } |
|
|
204 | |
|
|
205 | (my $face = $stem) =~ s/^.*\///; |
|
|
206 | |
|
|
207 | # split all bigfaces, but avoid smoothfaces (*_S) |
142 | if (($w > $T || $h > $T) && $face !~ /_S\./) { |
208 | if (($w > $T || $h > $T) && $face !~ /_S\./) { |
143 | # split |
209 | # split |
144 | my @tile; |
210 | my @tile; |
145 | for my $x (0 .. (int $w / $T) - 1) { |
211 | for my $x (0 .. (int $w / $T) - 1) { |
146 | for my $y (0 .. (int $h / $T) - 1) { |
212 | for my $y (0 .. (int $h / $T) - 1) { |
… | |
… | |
160 | ( |
226 | ( |
161 | "(", |
227 | "(", |
162 | "+clone", |
228 | "+clone", |
163 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
229 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
164 | "+repage", |
230 | "+repage", |
|
|
231 | -quality => "00", |
165 | -write => "png:$_->[2]~", |
232 | -write => "png32:$_->[2]~", |
166 | "+delete", |
233 | "+delete", |
167 | ")", |
234 | ")", |
168 | ) |
235 | ) |
169 | } @todo), |
236 | } @todo), |
170 | "null:"; |
237 | "null:"; |
… | |
… | |
174 | close $convert; |
241 | close $convert; |
175 | |
242 | |
176 | # pass 2, optimise, and rename |
243 | # pass 2, optimise, and rename |
177 | for (@todo) { |
244 | for (@todo) { |
178 | system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; |
245 | system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; |
|
|
246 | die "$_->[2]~ has zero size, aborting." unless -s "$_->[2]~"; |
179 | rename "$_->[2]~", $_->[2]; |
247 | rename "$_->[2]~", $_->[2]; |
180 | } |
248 | } |
181 | }; |
249 | }; |
182 | } |
250 | } |
183 | |
251 | |
… | |
… | |
187 | |
255 | |
188 | if (0 > aio_load $file, $tile) { |
256 | if (0 > aio_load $file, $tile) { |
189 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
257 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
190 | } |
258 | } |
191 | IO::AIO::aio_unlink $file unless $CACHE; |
259 | IO::AIO::aio_unlink $file unless $CACHE; |
192 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile; |
260 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
193 | } |
261 | } |
194 | } else { |
262 | } else { |
195 | # use as-is (either small, use smooth) |
263 | # use as-is (either small, use smooth) |
196 | commit_png $face, $png; |
264 | commit_png $face, $png, $T; |
197 | } |
265 | } |
|
|
266 | |
|
|
267 | aio_unlink $path if $delete; |
198 | } |
268 | } |
199 | } |
269 | } |
200 | |
270 | |
201 | sub process_arc { |
271 | sub process_arc { |
202 | while (@arc) { |
272 | while (@arc) { |
… | |
… | |
206 | 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 :/ |
207 | |
277 | |
208 | my $arc = read_arch "$dir/$file"; |
278 | my $arc = read_arch "$dir/$file"; |
209 | for my $o (values %$arc) { |
279 | for my $o (values %$arc) { |
210 | push @ARC, $o; |
280 | push @ARC, $o; |
|
|
281 | for (my $m = $o; $m; $m = $m->{more}) { |
|
|
282 | $ARC{$m->{_name}} = $m; |
|
|
283 | } |
211 | |
284 | |
212 | $o->{editor_folder} = $dir; |
285 | $o->{editor_folder} = $dir; |
213 | |
286 | |
214 | my $visibility = delete $o->{visibility}; |
287 | my $visibility = delete $o->{visibility}; |
215 | my $magicmap = delete $o->{magicmap}; |
288 | my $magicmap = delete $o->{magicmap}; |
… | |
… | |
226 | my $x = $o->{x} - $dx; |
299 | my $x = $o->{x} - $dx; |
227 | my $y = $o->{y} - $dy; |
300 | my $y = $o->{y} - $dy; |
228 | |
301 | |
229 | my $ext = $x|$y ? "+$x+$y" : ""; |
302 | my $ext = $x|$y ? "+$x+$y" : ""; |
230 | |
303 | |
231 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; |
304 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
232 | |
305 | |
233 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
306 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
234 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
307 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
235 | |
308 | |
236 | my $anim = delete $o->{anim}; |
309 | my $anim = delete $o->{anim}; |
237 | |
310 | |
238 | if ($anim) { |
311 | if ($anim) { |
|
|
312 | # possibly add $ext to the animation name to avoid |
|
|
313 | # the need to specify archnames for all parts |
|
|
314 | # of a multipart archetype. |
239 | $o->{animation} = "$o->{_name}"; |
315 | $o->{animation} = "$o->{_name}"; |
|
|
316 | my $facings = 1; |
|
|
317 | my @frames; |
240 | |
318 | |
241 | for (@$anim) { |
319 | for (@$anim) { |
242 | $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; |
320 | if (/^facings\s+(\d+)/) { |
|
|
321 | $facings = $1*1; |
|
|
322 | } elsif (/^blank.x11$|^empty.x11$/) { |
|
|
323 | push @frames, $_; |
|
|
324 | } else { |
|
|
325 | push @frames, "$_$ext"; |
|
|
326 | } |
243 | } |
327 | } |
244 | |
328 | |
245 | $ANIM{"$o->{_name}$ext"} = |
329 | $ANIMINFO{$o->{animation}} = { |
246 | join "", map "$_\n", |
330 | facings => $facings, |
247 | "anim $o->{_name}", |
331 | frames => \@frames, |
248 | @$anim, |
332 | }; |
249 | "mina"; |
|
|
250 | } |
333 | } |
251 | |
334 | |
252 | for my $face ($o->{face} || (), @{$anim || []}) { |
335 | for my $face ($o->{face} || (), @{$anim || []}) { |
253 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
336 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
254 | |
337 | |
… | |
… | |
257 | $info->{visibility} = $visibility if defined $visibility; |
340 | $info->{visibility} = $visibility if defined $visibility; |
258 | $info->{magicmap} = $magicmap if defined $magicmap; |
341 | $info->{magicmap} = $magicmap if defined $magicmap; |
259 | } |
342 | } |
260 | |
343 | |
261 | if (my $smooth = delete $o->{smoothface}) { |
344 | if (my $smooth = delete $o->{smoothface}) { |
262 | my ($face, $smooth) = split /\s+/, $smooth; |
345 | my %kv =split /\s+/, $smooth; |
263 | # skip empty_S.x11, it seems to server no purpose whatsoever |
346 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
264 | # but increases bandwidth demands and worse. |
347 | while (my ($face, $smooth) = each %kv) { |
265 | unless ($smooth eq "empty_S.x11") { |
|
|
266 | $FACEINFO{$face}{smooth} = $smooth; |
348 | $FACEINFO{$face}{smooth} = $smooth; |
|
|
349 | $FACEINFO{$face}{smoothlevel} = $level; |
267 | } |
350 | } |
268 | } |
351 | } |
269 | } |
352 | } |
270 | } |
353 | } |
271 | } |
354 | } |
… | |
… | |
297 | find_files "$path/$_" |
380 | find_files "$path/$_" |
298 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
381 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
299 | |
382 | |
300 | for my $file (@$nondirs) { |
383 | for my $file (@$nondirs) { |
301 | if ($file =~ /\.png$/) { |
384 | if ($file =~ /\.png$/) { |
302 | push @png, "$path/$file"; |
385 | push @png, ["$path/$file", 0]; |
303 | } elsif ($file =~ /\.trs$/) { |
386 | } elsif ($file =~ /\.trs$/) { |
304 | push @trs, [$path, $file]; |
387 | push @trs, [$path, $file]; |
305 | } elsif ($file =~ /\.arc$/) { |
388 | } elsif ($file =~ /\.arc$/) { |
306 | push @arc, [$path, $file]; |
389 | push @arc, [$path, $file]; |
307 | } else { |
390 | } else { |
308 | warn "ignoring $path/$file\n" if $VERBOSE >= 2; |
391 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
309 | } |
392 | } |
310 | } |
393 | } |
311 | }; |
394 | }; |
312 | } |
395 | } |
313 | |
396 | |
314 | sub inst_arch($) { |
397 | sub inst_arch($) { |
315 | my (undef, $path) = @_; |
398 | my (undef, $path) = @_; |
316 | |
399 | |
|
|
400 | print "\n", |
317 | print "installing '$path' to '$DATADIR'\n"; |
401 | "Installing '$path' to '$DATADIR'\n", |
|
|
402 | "\n", |
|
|
403 | "This can take a long time if you run this\n", |
|
|
404 | "for the first time or do not use --cache.\n", |
|
|
405 | "\n", |
|
|
406 | "Unless you run verbosely, all following warning\n", |
|
|
407 | "or error messages indicate serious problems.\n", |
|
|
408 | "\n"; |
318 | |
409 | |
319 | if (!-d "$path/treasures") { |
410 | if (!-d "$path/treasures") { |
320 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
411 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
321 | exit 1 unless $FORCE; |
412 | exit 1 unless $FORCE; |
322 | } |
413 | } |
323 | |
414 | |
324 | find_files $path; |
415 | find_files $path; |
325 | IO::AIO::flush; |
416 | IO::AIO::flush; |
326 | |
417 | |
327 | $_->join for ( |
418 | $_->join for ( |
328 | (async \&process_png), (async \&process_png), |
419 | # four png crunchers work fine for my 2x smp machine |
|
|
420 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
329 | (async \&process_trs), (async \&process_trs), |
421 | (async \&process_trs), (async \&process_trs), |
330 | (async \&process_arc), (async \&process_arc), |
422 | (async \&process_arc), (async \&process_arc), |
331 | ); |
423 | ); |
332 | |
424 | |
333 | { |
425 | { |
334 | open my $fh, ">:utf8", "$DATADIR/animations~" |
426 | # remove path prefix from editor_folder |
335 | or die "$DATADIR/animations~: $!"; |
427 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
336 | print $fh join "", map $ANIM{$_}, sort keys %ANIM |
428 | for values %ARC; |
|
|
429 | |
|
|
430 | # resolve inherit |
|
|
431 | while () { |
|
|
432 | my $progress; |
|
|
433 | my $loop; |
|
|
434 | |
|
|
435 | for my $o (values %ARC) { |
|
|
436 | if (my $other = $o->{inherit}) { |
|
|
437 | if (my $s = $ARC{$other}) { |
|
|
438 | if ($s->{inherit}) { |
|
|
439 | $loop = $s; |
|
|
440 | } else { |
|
|
441 | delete $o->{inherit}; |
|
|
442 | my %s = %$s; |
|
|
443 | delete @s{qw(_name more name name_pl)}; |
|
|
444 | %$o = ( %s, %$o ); |
|
|
445 | ++$progress; |
|
|
446 | } |
|
|
447 | } else { |
|
|
448 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
|
|
449 | delete $ARC{$o->{_name}}; |
|
|
450 | } |
|
|
451 | } |
|
|
452 | } |
|
|
453 | |
|
|
454 | unless ($progress) { |
|
|
455 | die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n" |
|
|
456 | if $loop; |
|
|
457 | |
|
|
458 | last; |
|
|
459 | } |
337 | } |
460 | } |
338 | |
461 | |
339 | { |
|
|
340 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
462 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
341 | or die "$DATADIR/archetypes~: $!"; |
463 | or die "$DATADIR/archetypes~: $!"; |
342 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
464 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
343 | print $fh Crossfire::archlist_to_string \@ARC; |
|
|
344 | } |
465 | } |
345 | |
466 | |
346 | { |
467 | { |
347 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
468 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
348 | or die "$DATADIR/treasures~: $!"; |
469 | or die "$DATADIR/treasures~: $!"; |
349 | print $fh $TRS; |
470 | print $fh $TRS; |
350 | } |
471 | } |
351 | |
472 | |
352 | { |
473 | { |
353 | while (my ($k, $v) = each %FACEINFO) { |
474 | while (my ($k, $v) = each %FACEINFO) { |
354 | $v->{data32} ||= delete $PNG32{$k}; |
|
|
355 | } |
|
|
356 | |
|
|
357 | while (my ($k, $v) = each %FACEINFO) { |
|
|
358 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
475 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
|
|
476 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
|
|
477 | |
|
|
478 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
|
|
479 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
359 | |
480 | |
360 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
481 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
|
|
482 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
361 | } |
483 | } |
362 | |
484 | |
363 | open my $fh, ">:perlio", "$DATADIR/faces~" |
485 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
364 | or die "$DATADIR/faces~: $!"; |
486 | or die "$DATADIR/facedata~: $!"; |
365 | |
487 | |
366 | $FACEINFO{""} = { version => 1}; |
488 | print $fh freeze { |
367 | print $fh Storable::nfreeze \%FACEINFO; |
489 | version => 2, |
|
|
490 | faceinfo => \%FACEINFO, |
|
|
491 | animinfo => \%ANIMINFO, |
368 | } |
492 | }; |
|
|
493 | } |
369 | |
494 | |
370 | for (qw(archetypes faces animations treasures)) { |
495 | for (qw(archetypes facedata treasures)) { |
371 | chmod 0644, "$DATADIR/$_~"; |
496 | chmod 0644, "$DATADIR/$_~"; |
372 | rename "$DATADIR/$_~", "$DATADIR/$_" |
497 | rename "$DATADIR/$_~", "$DATADIR/$_" |
373 | or die "$DATADIR/$_: $!"; |
498 | or die "$DATADIR/$_: $!"; |
374 | } |
499 | } |
375 | |
500 | |