… | |
… | |
6 | my $exec_prefix = "@exec_prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
7 | my $datarootdir = "@datarootdir@"; |
7 | my $datarootdir = "@datarootdir@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
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; |
|
|
26 | use Carp; |
25 | use Storable; $Storable::canonical = 1; |
27 | use Coro::Storable; $Storable::canonical = 1; |
|
|
28 | |
|
|
29 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
26 | |
30 | |
27 | sub usage { |
31 | sub usage { |
28 | warn <<EOF; |
32 | warn <<EOF; |
29 | Usage: cfutil [-v] [-q] [--force] [--cache] |
33 | Usage: cfutil [-v] [-q] [--force] [--cache] |
30 | [--install-arch path] |
34 | [--install-arch path] |
… | |
… | |
42 | my $CACHE = 0; |
46 | my $CACHE = 0; |
43 | my $FORCE; |
47 | my $FORCE; |
44 | my $TMPDIR = "/tmp/cfutil$$~"; |
48 | my $TMPDIR = "/tmp/cfutil$$~"; |
45 | my $TMPFILE = "aaaa0"; |
49 | my $TMPFILE = "aaaa0"; |
46 | |
50 | |
|
|
51 | our %COLOR = ( |
|
|
52 | black => 0, |
|
|
53 | white => 1, |
|
|
54 | navy => 2, |
|
|
55 | red => 3, |
|
|
56 | orange => 4, |
|
|
57 | blue => 5, |
|
|
58 | darkorange => 6, |
|
|
59 | green => 7, |
|
|
60 | lightgreen => 8, |
|
|
61 | grey => 9, |
|
|
62 | brown => 10, |
|
|
63 | gold => 11, |
|
|
64 | tan => 12, |
|
|
65 | ); |
|
|
66 | |
47 | END { system "rm", "-rf", $TMPDIR } |
67 | END { system "rm", "-rf", $TMPDIR } |
48 | |
68 | |
49 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
69 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
50 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
70 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
51 | |
71 | |
… | |
… | |
68 | } |
88 | } |
69 | |
89 | |
70 | sub inst_maps($) { |
90 | sub inst_maps($) { |
71 | my (undef, $path) = @_; |
91 | my (undef, $path) = @_; |
72 | |
92 | |
73 | print "installing '$path' to '$DATADIR/maps'\n"; |
93 | print "\nInstalling '$path' to '$DATADIR/maps'\n\n"; |
74 | |
94 | |
75 | if (!-f "$path/regions") { |
95 | if (!-f "$path/regions") { |
76 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
96 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
77 | exit 1 unless $FORCE; |
97 | exit 1 unless $FORCE; |
78 | } |
98 | } |
79 | |
99 | |
80 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
100 | system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
81 | and die "map installation failed.\n"; |
101 | and die "map installation failed.\n"; |
82 | |
102 | |
83 | print "maps installed successfully.\n"; |
103 | print "maps installed successfully.\n"; |
84 | } |
104 | } |
85 | |
105 | |
86 | { |
106 | { |
87 | our %PNG32; |
107 | our %ANIMINFO; |
88 | our %FACEINFO; |
108 | our %FACEINFO; |
|
|
109 | our %RESOURCE; |
89 | our @ARC; |
110 | our @ARC; |
|
|
111 | our %ARC; |
90 | our $TRS; |
112 | our $TRS; |
91 | our $NFILE; |
113 | our $NFILE; |
92 | our %ANIM; |
114 | our $PATH; |
93 | |
115 | |
|
|
116 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
|
|
117 | |
94 | our (@png, @trs, @arc); # files we are interested in |
118 | our (@png, @trs, @arc, @res); # files we are interested in |
95 | |
119 | |
96 | sub commit_png { |
120 | sub commit_png($$$) { |
97 | my ($name, $data) = @_; |
121 | my ($name, $data, $T) = @_; |
98 | |
122 | |
99 | $PNG32{$name} = $data; |
123 | $FACEINFO{$name}{"data$T"} = $data; |
100 | $FACEINFO{$name} ||= {}; |
|
|
101 | } |
124 | } |
102 | |
125 | |
103 | sub process_png { |
126 | sub process_png { |
104 | while (@png) { |
127 | while (@png) { |
105 | my $path = pop @png; |
128 | my ($path, $delete) = @{pop @png}; |
106 | |
129 | |
107 | my $png; |
130 | my $png; |
108 | aio_lstat $path; |
131 | aio_lstat $path; |
109 | my ($size, $mtime) = (stat _)[7,9]; |
132 | my ($size, $mtime) = (stat _)[7,9]; |
110 | |
133 | |
111 | if (0 > aio_load $path, $png) { |
134 | if (0 > aio_load $path, $png) { |
112 | warn "$path: $!, skipping.\n"; |
135 | warn "$path: $!, skipping.\n"; |
113 | next; |
136 | next; |
114 | } |
137 | } |
115 | |
138 | |
|
|
139 | my $stem = $path; |
|
|
140 | my $T; |
|
|
141 | |
|
|
142 | if ($stem =~ s/\.32x32\.png~?$//) { |
|
|
143 | $T = 32; |
|
|
144 | } elsif ($stem =~ s/\.64x64\.png~?$//) { |
|
|
145 | $T = 64; |
|
|
146 | } else { |
|
|
147 | warn "$path: weird filename, skipping.\n"; |
|
|
148 | next; |
|
|
149 | } |
|
|
150 | |
116 | # quickly extract width and height of the (necessarily PNG) image |
151 | # quickly extract width and height of the (necessarily PNG) image |
117 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
152 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
118 | warn "$path: not a recongized png file, skipping.\n"; |
153 | warn "$path: not a recognized png file, skipping.\n"; |
119 | next; |
154 | next; |
120 | } |
155 | } |
121 | |
156 | |
122 | my ($w, $h) = unpack "NN", $1; |
157 | 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 | |
158 | |
132 | if ($w < $T || $h < $T) { |
159 | if ($w < $T || $h < $T) { |
133 | warn "$path: too small ($w $h), skipping.\n"; |
160 | warn "$path: too small ($w $h), skipping.\n"; |
134 | next; |
161 | next; |
135 | } |
162 | } |
… | |
… | |
137 | if ($w % $T || $h % $T) { |
164 | if ($w % $T || $h % $T) { |
138 | warn "$path: weird png size ($w $h), skipping.\n"; |
165 | warn "$path: weird png size ($w $h), skipping.\n"; |
139 | next; |
166 | next; |
140 | } |
167 | } |
141 | |
168 | |
|
|
169 | unless ($path =~ /~$/) { |
|
|
170 | # possibly enlarge |
|
|
171 | if (0 > aio_stat "$stem.64x64.png") { |
|
|
172 | my $other = "$stem.64x64.png~"; |
|
|
173 | |
|
|
174 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
|
|
175 | my $wrap = 0; # for the time being |
|
|
176 | fork_sub { |
|
|
177 | system "convert png:\Q$path\E -depth 8 rgba:-" |
|
|
178 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
|
|
179 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
|
|
180 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
|
|
181 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
182 | die "$other~ has zero size, aborting." unless -s "$other~"; |
|
|
183 | rename "$other~", $other; |
|
|
184 | }; |
|
|
185 | } |
|
|
186 | |
|
|
187 | push @png, [$other, !$CACHE]; |
|
|
188 | } |
|
|
189 | |
|
|
190 | # possibly scale down |
|
|
191 | if (0 > aio_stat "$stem.32x32.png") { |
|
|
192 | my $other = "$stem.32x32.png~"; |
|
|
193 | |
|
|
194 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
|
|
195 | fork_sub { |
|
|
196 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
|
|
197 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
198 | |
|
|
199 | # reduce smoothfaces >10000 bytes |
|
|
200 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
|
|
201 | my $ncolor = 256; |
|
|
202 | while () { |
|
|
203 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
|
|
204 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
|
|
205 | last if 10000 > -s "$other~~"; |
|
|
206 | $ncolor = int $ncolor * 0.9; |
|
|
207 | $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; |
|
|
208 | } |
|
|
209 | |
|
|
210 | printf "reduced %s from %d to %d bytes using %d colours.\n", |
|
|
211 | $other, -s "$other~", -s "$other~~", $ncolor |
|
|
212 | if $VERBOSE >= 2; |
|
|
213 | rename "$other~~", "$other~"; |
|
|
214 | } |
|
|
215 | |
|
|
216 | die "$other~ has zero size, aborting." unless -s "$other~"; |
|
|
217 | rename "$other~", $other; |
|
|
218 | }; |
|
|
219 | } |
|
|
220 | |
|
|
221 | #warn "scaled down $path to $other\n";#d# |
|
|
222 | push @png, [$other, !$CACHE]; |
|
|
223 | } |
|
|
224 | } |
|
|
225 | |
|
|
226 | (my $face = $stem) =~ s/^.*\///; |
|
|
227 | |
|
|
228 | # split all bigfaces, but avoid smoothfaces (*_S) |
142 | if (($w > $T || $h > $T) && $face !~ /_S\./) { |
229 | if (($w > $T || $h > $T) && $face !~ /_S\./) { |
143 | # split |
230 | # split |
144 | my @tile; |
231 | my @tile; |
145 | for my $x (0 .. (int $w / $T) - 1) { |
232 | for my $x (0 .. (int $w / $T) - 1) { |
146 | for my $y (0 .. (int $h / $T) - 1) { |
233 | for my $y (0 .. (int $h / $T) - 1) { |
… | |
… | |
160 | ( |
247 | ( |
161 | "(", |
248 | "(", |
162 | "+clone", |
249 | "+clone", |
163 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
250 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
164 | "+repage", |
251 | "+repage", |
|
|
252 | -quality => "00", |
165 | -write => "png:$_->[2]~", |
253 | -write => "png32:$_->[2]~", |
166 | "+delete", |
254 | "+delete", |
167 | ")", |
255 | ")", |
168 | ) |
256 | ) |
169 | } @todo), |
257 | } @todo), |
170 | "null:"; |
258 | "null:"; |
… | |
… | |
174 | close $convert; |
262 | close $convert; |
175 | |
263 | |
176 | # pass 2, optimise, and rename |
264 | # pass 2, optimise, and rename |
177 | for (@todo) { |
265 | for (@todo) { |
178 | system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; |
266 | system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; |
|
|
267 | die "$_->[2]~ has zero size, aborting." unless -s "$_->[2]~"; |
179 | rename "$_->[2]~", $_->[2]; |
268 | rename "$_->[2]~", $_->[2]; |
180 | } |
269 | } |
181 | }; |
270 | }; |
182 | } |
271 | } |
183 | |
272 | |
… | |
… | |
187 | |
276 | |
188 | if (0 > aio_load $file, $tile) { |
277 | if (0 > aio_load $file, $tile) { |
189 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
278 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
190 | } |
279 | } |
191 | IO::AIO::aio_unlink $file unless $CACHE; |
280 | IO::AIO::aio_unlink $file unless $CACHE; |
192 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile; |
281 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
193 | } |
282 | } |
194 | } else { |
283 | } else { |
195 | # use as-is (either small, use smooth) |
284 | # use as-is (either small, use smooth) |
196 | commit_png $face, $png; |
285 | commit_png $face, $png, $T; |
197 | } |
286 | } |
|
|
287 | |
|
|
288 | aio_unlink $path if $delete; |
198 | } |
289 | } |
199 | } |
290 | } |
200 | |
291 | |
201 | sub process_arc { |
292 | sub process_arc { |
202 | while (@arc) { |
293 | while (@arc) { |
… | |
… | |
206 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
297 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
207 | |
298 | |
208 | my $arc = read_arch "$dir/$file"; |
299 | my $arc = read_arch "$dir/$file"; |
209 | for my $o (values %$arc) { |
300 | for my $o (values %$arc) { |
210 | push @ARC, $o; |
301 | push @ARC, $o; |
|
|
302 | for (my $m = $o; $m; $m = $m->{more}) { |
|
|
303 | $ARC{$m->{_name}} = $m; |
|
|
304 | } |
211 | |
305 | |
212 | $o->{editor_folder} = $dir; |
306 | $o->{editor_folder} = $dir; |
213 | |
307 | |
214 | my $visibility = delete $o->{visibility}; |
308 | my $visibility = delete $o->{visibility}; |
215 | my $magicmap = delete $o->{magicmap}; |
309 | my $magicmap = delete $o->{magicmap}; |
… | |
… | |
226 | my $x = $o->{x} - $dx; |
320 | my $x = $o->{x} - $dx; |
227 | my $y = $o->{y} - $dy; |
321 | my $y = $o->{y} - $dy; |
228 | |
322 | |
229 | my $ext = $x|$y ? "+$x+$y" : ""; |
323 | my $ext = $x|$y ? "+$x+$y" : ""; |
230 | |
324 | |
231 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; |
325 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
232 | |
326 | |
233 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
327 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
234 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
328 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
235 | |
329 | |
236 | my $anim = delete $o->{anim}; |
330 | my $anim = delete $o->{anim}; |
237 | |
331 | |
238 | if ($anim) { |
332 | if ($anim) { |
|
|
333 | # possibly add $ext to the animation name to avoid |
|
|
334 | # the need to specify archnames for all parts |
|
|
335 | # of a multipart archetype. |
239 | $o->{animation} = "$o->{_name}"; |
336 | $o->{animation} = "$o->{_name}"; |
|
|
337 | my $facings = 1; |
|
|
338 | my @frames; |
240 | |
339 | |
241 | for (@$anim) { |
340 | for (@$anim) { |
242 | $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; |
341 | if (/^facings\s+(\d+)/) { |
|
|
342 | $facings = $1*1; |
|
|
343 | } elsif (/^blank.x11$|^empty.x11$/) { |
|
|
344 | push @frames, $_; |
|
|
345 | } else { |
|
|
346 | push @frames, "$_$ext"; |
|
|
347 | } |
243 | } |
348 | } |
244 | |
349 | |
245 | $ANIM{"$o->{_name}$ext"} = |
350 | $ANIMINFO{$o->{animation}} = { |
246 | join "", map "$_\n", |
351 | facings => $facings, |
247 | "anim $o->{_name}", |
352 | frames => \@frames, |
248 | @$anim, |
353 | }; |
249 | "mina"; |
|
|
250 | } |
354 | } |
251 | |
355 | |
252 | for my $face ($o->{face} || (), @{$anim || []}) { |
356 | for my $face ($o->{face} || (), @{$anim || []}) { |
253 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
357 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
254 | |
358 | |
… | |
… | |
257 | $info->{visibility} = $visibility if defined $visibility; |
361 | $info->{visibility} = $visibility if defined $visibility; |
258 | $info->{magicmap} = $magicmap if defined $magicmap; |
362 | $info->{magicmap} = $magicmap if defined $magicmap; |
259 | } |
363 | } |
260 | |
364 | |
261 | if (my $smooth = delete $o->{smoothface}) { |
365 | if (my $smooth = delete $o->{smoothface}) { |
262 | my ($face, $smooth) = split /\s+/, $smooth; |
366 | my %kv =split /\s+/, $smooth; |
263 | # skip empty_S.x11, it seems to server no purpose whatsoever |
367 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
264 | # but increases bandwidth demands and worse. |
368 | while (my ($face, $smooth) = each %kv) { |
265 | unless ($smooth eq "empty_S.x11") { |
|
|
266 | $FACEINFO{$face}{smooth} = $smooth; |
369 | $FACEINFO{$face}{smooth} = $smooth; |
|
|
370 | $FACEINFO{$face}{smoothlevel} = $level; |
267 | } |
371 | } |
268 | } |
372 | } |
269 | } |
373 | } |
270 | } |
374 | } |
271 | } |
375 | } |
… | |
… | |
284 | |
388 | |
285 | $TRS .= $trs; |
389 | $TRS .= $trs; |
286 | } |
390 | } |
287 | } |
391 | } |
288 | |
392 | |
|
|
393 | sub process_res { |
|
|
394 | while (@res) { |
|
|
395 | my ($dir, $file) = @{pop @res}; |
|
|
396 | |
|
|
397 | my $data; |
|
|
398 | aio_load "$dir/$file", $data; |
|
|
399 | |
|
|
400 | my $copyright; |
|
|
401 | aio_load "$dir/copyright", $copyright; |
|
|
402 | |
|
|
403 | $file =~ s/\.res$//; |
|
|
404 | $file =~ /\.([^.]+)$/ |
|
|
405 | or next; |
|
|
406 | |
|
|
407 | my $type = $1; |
|
|
408 | |
|
|
409 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
410 | |
|
|
411 | $RESOURCE{"$dir/$file"} = { |
|
|
412 | type => $1, |
|
|
413 | copyright => $copyright, |
|
|
414 | data => $data, |
|
|
415 | chksum => Digest::MD5::md5 $data, |
|
|
416 | }; |
|
|
417 | } |
|
|
418 | } |
|
|
419 | |
289 | sub find_files; |
420 | sub find_files; |
290 | sub find_files { |
421 | sub find_files { |
291 | my ($path) = @_; |
422 | my ($path) = @_; |
292 | |
423 | |
293 | IO::AIO::aioreq_pri 4; |
424 | IO::AIO::aioreq_pri 4; |
… | |
… | |
297 | find_files "$path/$_" |
428 | find_files "$path/$_" |
298 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
429 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
299 | |
430 | |
300 | for my $file (@$nondirs) { |
431 | for my $file (@$nondirs) { |
301 | if ($file =~ /\.png$/) { |
432 | if ($file =~ /\.png$/) { |
302 | push @png, "$path/$file"; |
433 | push @png, ["$path/$file", 0]; |
303 | } elsif ($file =~ /\.trs$/) { |
434 | } elsif ($file =~ /\.trs$/) { |
304 | push @trs, [$path, $file]; |
435 | push @trs, [$path, $file]; |
305 | } elsif ($file =~ /\.arc$/) { |
436 | } elsif ($file =~ /\.arc$/) { |
306 | push @arc, [$path, $file]; |
437 | push @arc, [$path, $file]; |
|
|
438 | } elsif ($file =~ /\.(ogg|jpg|res)$/) { |
|
|
439 | push @res, [$path, $file]; |
307 | } else { |
440 | } else { |
308 | warn "ignoring $path/$file\n" if $VERBOSE >= 2; |
441 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
309 | } |
442 | } |
310 | } |
443 | } |
311 | }; |
444 | }; |
312 | } |
445 | } |
313 | |
446 | |
314 | sub inst_arch($) { |
447 | sub inst_arch($) { |
315 | my (undef, $path) = @_; |
448 | my (undef, $path) = @_; |
316 | |
449 | |
|
|
450 | $PATH = $path; |
|
|
451 | |
|
|
452 | print "\n", |
317 | print "installing '$path' to '$DATADIR'\n"; |
453 | "Installing '$path' to '$DATADIR'\n", |
|
|
454 | "\n", |
|
|
455 | "This can take a long time if you run this\n", |
|
|
456 | "for the first time or do not use --cache.\n", |
|
|
457 | "\n", |
|
|
458 | "Unless you run verbosely, all following warning\n", |
|
|
459 | "or error messages indicate serious problems.\n", |
|
|
460 | "\n"; |
318 | |
461 | |
319 | if (!-d "$path/treasures") { |
462 | if (!-d "$path/treasures") { |
320 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
463 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
321 | exit 1 unless $FORCE; |
464 | exit 1 unless $FORCE; |
322 | } |
465 | } |
323 | |
466 | |
324 | find_files $path; |
467 | find_files $path; |
325 | IO::AIO::flush; |
468 | IO::AIO::flush; |
326 | |
469 | |
327 | $_->join for ( |
470 | $_->join for ( |
328 | (async \&process_png), (async \&process_png), |
471 | # four png crunchers work fine for my 2x smp machine |
|
|
472 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
329 | (async \&process_trs), (async \&process_trs), |
473 | (async \&process_trs), (async \&process_trs), |
330 | (async \&process_arc), (async \&process_arc), |
474 | (async \&process_arc), (async \&process_arc), |
|
|
475 | (async \&process_res), (async \&process_res), |
331 | ); |
476 | ); |
332 | |
477 | |
333 | { |
478 | { |
334 | open my $fh, ">:utf8", "$DATADIR/animations~" |
479 | # remove path prefix from editor_folder |
335 | or die "$DATADIR/animations~: $!"; |
480 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
336 | print $fh join "", map $ANIM{$_}, sort keys %ANIM |
481 | for values %ARC; |
|
|
482 | |
|
|
483 | # resolve inherit |
|
|
484 | while () { |
|
|
485 | my $progress; |
|
|
486 | my $loop; |
|
|
487 | |
|
|
488 | for my $o (values %ARC) { |
|
|
489 | if (my $other = $o->{inherit}) { |
|
|
490 | if (my $s = $ARC{$other}) { |
|
|
491 | if ($s->{inherit}) { |
|
|
492 | $loop = $s; |
|
|
493 | } else { |
|
|
494 | delete $o->{inherit}; |
|
|
495 | my %s = %$s; |
|
|
496 | delete @s{qw(_name more name name_pl)}; |
|
|
497 | %$o = ( %s, %$o ); |
|
|
498 | ++$progress; |
|
|
499 | } |
|
|
500 | } else { |
|
|
501 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
|
|
502 | delete $ARC{$o->{_name}}; |
|
|
503 | } |
|
|
504 | } |
|
|
505 | } |
|
|
506 | |
|
|
507 | unless ($progress) { |
|
|
508 | die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n" |
|
|
509 | if $loop; |
|
|
510 | |
|
|
511 | last; |
|
|
512 | } |
337 | } |
513 | } |
338 | |
514 | |
339 | { |
515 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
|
|
516 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
|
|
517 | |
340 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
518 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
341 | or die "$DATADIR/archetypes~: $!"; |
519 | or die "$DATADIR/archetypes~: $!"; |
342 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
520 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
343 | print $fh Crossfire::archlist_to_string \@ARC; |
|
|
344 | } |
521 | } |
345 | |
522 | |
346 | { |
523 | { |
347 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
524 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
348 | or die "$DATADIR/treasures~: $!"; |
525 | or die "$DATADIR/treasures~: $!"; |
349 | print $fh $TRS; |
526 | print $fh $TRS; |
350 | } |
527 | } |
351 | |
528 | |
352 | { |
529 | { |
353 | while (my ($k, $v) = each %FACEINFO) { |
530 | 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"; |
531 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
|
|
532 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
|
|
533 | |
|
|
534 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
|
|
535 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
359 | |
536 | |
360 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
537 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
|
|
538 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
|
|
539 | |
|
|
540 | if (my $magicmap = $v->{magicmap}) { |
|
|
541 | $magicmap =~ y/A-Z_\-/a-z/d; |
|
|
542 | $v->{magicmap} = $COLOR{$magicmap}; |
361 | } |
543 | } |
|
|
544 | } |
362 | |
545 | |
363 | open my $fh, ">:perlio", "$DATADIR/faces~" |
546 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
364 | or die "$DATADIR/faces~: $!"; |
547 | or die "$DATADIR/facedata~: $!"; |
365 | |
548 | |
366 | $FACEINFO{""} = { version => 1}; |
549 | print $fh freeze { |
367 | print $fh Storable::nfreeze \%FACEINFO; |
550 | version => 2, |
|
|
551 | faceinfo => \%FACEINFO, |
|
|
552 | animinfo => \%ANIMINFO, |
|
|
553 | resource => \%RESOURCE, |
368 | } |
554 | }; |
|
|
555 | } |
369 | |
556 | |
370 | for (qw(archetypes faces animations treasures)) { |
557 | for (qw(archetypes facedata treasures)) { |
371 | chmod 0644, "$DATADIR/$_~"; |
558 | chmod 0644, "$DATADIR/$_~"; |
372 | rename "$DATADIR/$_~", "$DATADIR/$_" |
559 | rename "$DATADIR/$_~", "$DATADIR/$_" |
373 | or die "$DATADIR/$_: $!"; |
560 | or die "$DATADIR/$_: $!"; |
374 | } |
561 | } |
375 | |
562 | |