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