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