1 | #!@PERL@ |
1 | #!@PERL@ |
2 | |
2 | |
3 | use strict; |
3 | # |
|
|
4 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
5 | # |
|
|
6 | # Copyright (©) 2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
7 | # |
|
|
8 | # Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | # the terms of the Affero GNU General Public License as published by the |
|
|
10 | # Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | # option) any later version. |
|
|
12 | # |
|
|
13 | # This program is distributed in the hope that it will be useful, |
|
|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | # GNU General Public License for more details. |
|
|
17 | # |
|
|
18 | # You should have received a copy of the Affero GNU General Public License |
|
|
19 | # and the GNU General Public License along with this program. If not, see |
|
|
20 | # <http://www.gnu.org/licenses/>. |
|
|
21 | # |
|
|
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
|
|
23 | # |
|
|
24 | |
|
|
25 | use common::sense; |
4 | |
26 | |
5 | my $prefix = "@prefix@"; |
27 | my $prefix = "@prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
7 | my $datarootdir = "@datarootdir@"; |
29 | my $datarootdir = "@datarootdir@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
30 | my $DATADIR = "@datadir@/@PACKAGE@"; |
… | |
… | |
12 | my $OPTIPNG = "@OPTIPNG@"; |
34 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
35 | my $RSYNC = "@RSYNC@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
36 | my $PNGNQ = "@PNGNQ@"; |
15 | |
37 | |
16 | use Getopt::Long; |
38 | use Getopt::Long; |
|
|
39 | use File::Temp; |
|
|
40 | use POSIX (); |
|
|
41 | use Carp; |
|
|
42 | |
17 | use Coro::Event; |
43 | use Coro::EV; |
18 | use AnyEvent; |
44 | use AnyEvent; |
|
|
45 | use YAML::XS (); |
|
|
46 | use JSON::XS (); |
19 | use IO::AIO (); |
47 | use IO::AIO (); |
20 | use File::Temp; |
48 | use Digest::MD5 (); |
21 | use Crossfire; |
49 | |
22 | use Coro; |
50 | use Coro 5.12; |
23 | use Coro::AIO; |
51 | use Coro::AIO; |
24 | use POSIX (); |
52 | use Coro::Util; |
25 | use Digest::MD5; |
53 | use Coro::Channel; |
26 | use Carp; |
|
|
27 | use Coro::Storable; $Storable::canonical = 1; |
54 | use Coro::Storable; $Storable::canonical = 1; |
28 | |
55 | |
|
|
56 | use Deliantra; |
|
|
57 | |
29 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
58 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
|
|
59 | |
|
|
60 | sub WRITE_FACEINFO() { 0 } |
30 | |
61 | |
31 | sub usage { |
62 | sub usage { |
32 | warn <<EOF; |
63 | warn <<EOF; |
33 | Usage: cfutil [-v] [-q] [--force] [--cache] |
64 | Usage: cfutil [-v] [-q] [--force] [--cache] |
34 | [--install-arch path] |
65 | [--install-arch path] |
… | |
… | |
45 | my $VERBOSE = 1; |
76 | my $VERBOSE = 1; |
46 | my $CACHE = 0; |
77 | my $CACHE = 0; |
47 | my $FORCE; |
78 | my $FORCE; |
48 | my $TMPDIR = "/tmp/cfutil$$~"; |
79 | my $TMPDIR = "/tmp/cfutil$$~"; |
49 | my $TMPFILE = "aaaa0"; |
80 | my $TMPFILE = "aaaa0"; |
|
|
81 | my @COMMIT; |
50 | |
82 | |
51 | our %COLOR = ( |
83 | our %COLOR = ( |
|
|
84 | # original cf colours |
52 | black => 0, |
85 | black => 0, |
53 | white => 1, |
86 | white => 1, |
54 | navy => 2, |
87 | navy => 2, # "dark blue" |
55 | red => 3, |
88 | red => 3, |
56 | orange => 4, |
89 | orange => 4, |
57 | blue => 5, |
90 | blue => 5, # "light blue" |
58 | darkorange => 6, |
91 | darkorange => 6, |
59 | green => 7, |
92 | green => 7, |
60 | lightgreen => 8, |
93 | lightgreen => 8, |
61 | grey => 9, |
94 | grey => 9, |
|
|
95 | brown => 10, # "yellow" |
|
|
96 | gold => 11, # "light yellow" |
|
|
97 | tan => 12, # yellowish gray |
|
|
98 | |
|
|
99 | # new for deliantra |
62 | brown => 10, |
100 | none => 13, |
|
|
101 | |
|
|
102 | # compatibility to existing archetypes |
|
|
103 | lightblue => 5, |
63 | gold => 11, |
104 | gray => 9, |
|
|
105 | yellow => 11, |
64 | tan => 12, |
106 | khaki => 12, |
65 | ); |
107 | ); |
66 | |
108 | |
67 | END { system "rm", "-rf", $TMPDIR } |
109 | END { system "rm", "-rf", $TMPDIR } |
68 | |
110 | |
69 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
111 | my $s_INT = EV::signal INT => sub { exit 1 }; |
70 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
112 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
|
|
113 | |
|
|
114 | our %hash; |
|
|
115 | |
|
|
116 | # here we could try to avoid collisions and reduce chksum size further |
|
|
117 | sub make_hash($\$\$;$) { |
|
|
118 | my ($id, $dataref, $hashref, $clen) = @_; |
|
|
119 | |
|
|
120 | my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
|
|
121 | |
|
|
122 | if (exists $hash{$hash}) { |
|
|
123 | # hash collision, but some files are simply identical |
|
|
124 | if (${$hash{$hash}[1]} ne $$dataref) { |
|
|
125 | warn "hash collision $hash{$hash}[0] vs. $id\n"; |
|
|
126 | exit 1; |
|
|
127 | } else { |
|
|
128 | print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
|
|
129 | } |
|
|
130 | } |
|
|
131 | $hash{$hash} = [$id, $dataref, $hashref]; |
|
|
132 | |
|
|
133 | $$hashref = $hash; |
|
|
134 | } |
71 | |
135 | |
72 | mkdir $TMPDIR, 0700 |
136 | mkdir $TMPDIR, 0700 |
73 | or die "$TMPDIR: $!"; |
137 | or die "$TMPDIR: $!"; |
74 | |
138 | |
75 | sub fork_sub(&) { |
139 | sub fork_sub(&) { |
… | |
… | |
95 | if (!-f "$path/regions") { |
159 | if (!-f "$path/regions") { |
96 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
160 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
97 | exit 1 unless $FORCE; |
161 | exit 1 unless $FORCE; |
98 | } |
162 | } |
99 | |
163 | |
100 | system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
164 | system $RSYNC, "-av", "--chmod=u=rwX,go=rX", |
|
|
165 | "$path/.", "$DATADIR/maps/.", |
|
|
166 | "--exclude", "CVS", "--exclude", "/world-precomposed", |
|
|
167 | "--delete", "--delete-excluded" |
101 | and die "map installation failed.\n"; |
168 | and die "map installation failed.\n"; |
102 | |
169 | |
103 | print "maps installed successfully.\n"; |
170 | print "maps installed successfully.\n"; |
|
|
171 | } |
|
|
172 | |
|
|
173 | { |
|
|
174 | no utf8; # == values are utf-8 encoded |
|
|
175 | |
|
|
176 | our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋); |
|
|
177 | |
|
|
178 | # used to create crude text glyphs for text-based clients |
|
|
179 | sub autoglyph { |
|
|
180 | my ($stem, $face) = @_; |
|
|
181 | |
|
|
182 | if ($stem =~ /^wall\/|Nimwall/) { |
|
|
183 | return $WALL_SUFFIX[hex $1] |
|
|
184 | if $stem =~ /(_[0-9A-F]).x11/; |
|
|
185 | |
|
|
186 | "█" |
|
|
187 | |
|
|
188 | } elsif ($stem =~ /^traps\//) { |
|
|
189 | "☠" |
|
|
190 | |
|
|
191 | } elsif ($stem =~ /^armour\/shield/) { |
|
|
192 | "Ø" |
|
|
193 | |
|
|
194 | } elsif ($stem =~ /^armour\//) { |
|
|
195 | "A" |
|
|
196 | |
|
|
197 | } elsif ($stem =~ /^weapon\//) { |
|
|
198 | "†" |
|
|
199 | |
|
|
200 | } elsif ($stem =~ /^readable\//) { |
|
|
201 | "✉" |
|
|
202 | |
|
|
203 | } elsif ($stem =~ /^river\//) { |
|
|
204 | "~" |
|
|
205 | |
|
|
206 | } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
|
|
207 | "·" |
|
|
208 | |
|
|
209 | } elsif ($stem =~ /^spells\//) { |
|
|
210 | "!" |
|
|
211 | |
|
|
212 | } elsif ($stem =~ /^exit\//) { |
|
|
213 | "⎆" |
|
|
214 | |
|
|
215 | } elsif ($stem =~ /^construct\//) { |
|
|
216 | "⌂" |
|
|
217 | |
|
|
218 | } elsif ($stem =~ /^player\//) { |
|
|
219 | "\@" |
|
|
220 | |
|
|
221 | } elsif ($stem =~ /^(?:monster|misc|class|connect|gods|indoor|inorganic|mining|music|skills).*\/(.)/) { |
|
|
222 | $1 |
|
|
223 | |
|
|
224 | } else { |
|
|
225 | substr $stem, 0, 1 |
|
|
226 | } |
|
|
227 | } |
104 | } |
228 | } |
105 | |
229 | |
106 | { |
230 | { |
107 | our %ANIMINFO; |
231 | our %ANIMINFO; |
108 | our %FACEINFO; |
232 | our %FACEINFO; |
… | |
… | |
113 | our $NFILE; |
237 | our $NFILE; |
114 | our $PATH; |
238 | our $PATH; |
115 | |
239 | |
116 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
240 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
117 | |
241 | |
118 | our (@png, @trs, @arc, @res); # files we are interested in |
242 | our $c_arc = new Coro::Channel; |
|
|
243 | our $c_any = new Coro::Channel; |
119 | |
244 | |
|
|
245 | our @c_png; |
|
|
246 | |
120 | sub commit_png($$$) { |
247 | sub commit_png($$$$) { |
121 | my ($name, $data, $T) = @_; |
248 | my ($stem, $name, $data, $T) = @_; |
122 | |
249 | |
|
|
250 | $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; |
123 | $FACEINFO{$name}{"data$T"} = $data; |
251 | $FACEINFO{$name}{"data$T"} = $data; |
124 | } |
252 | } |
125 | |
253 | |
126 | sub process_png { |
254 | sub process_png { |
127 | while (@png) { |
255 | while (@c_png) { |
128 | my ($path, $delete) = @{pop @png}; |
256 | my ($path, $delete) = @{pop @c_png}; |
129 | |
257 | |
130 | my $png; |
258 | my $png; |
131 | aio_lstat $path; |
259 | aio_lstat $path; |
132 | my ($size, $mtime) = (stat _)[7,9]; |
260 | my ($size, $mtime) = (stat _)[7,9]; |
133 | |
261 | |
… | |
… | |
164 | if ($w % $T || $h % $T) { |
292 | if ($w % $T || $h % $T) { |
165 | warn "$path: weird png size ($w $h), skipping.\n"; |
293 | warn "$path: weird png size ($w $h), skipping.\n"; |
166 | next; |
294 | next; |
167 | } |
295 | } |
168 | |
296 | |
|
|
297 | (my $base = $stem) =~ s/^.*\///; |
|
|
298 | |
|
|
299 | my $fi = $FACEINFO{$base}; |
|
|
300 | unless ($fi) { |
|
|
301 | #warn "$path: <$base> not referenced by any archetype, skipping.\n"; |
|
|
302 | #next; |
|
|
303 | } |
|
|
304 | |
|
|
305 | my $arc = $fi->{arc} || { }; |
|
|
306 | |
169 | unless ($path =~ /~$/) { |
307 | unless ($path =~ /~$/) { |
170 | # possibly enlarge |
308 | # possibly enlarge |
171 | if (0 > aio_stat "$stem.64x64.png") { |
309 | if (0 > aio_stat "$stem.64x64.png") { |
172 | my $other = "$stem.64x64.png~"; |
310 | my $other = "$stem.64x64.png~"; |
173 | |
311 | |
174 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
312 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
175 | my $wrap = 0; # for the time being |
|
|
176 | fork_sub { |
313 | fork_sub { |
|
|
314 | my $CROP; |
|
|
315 | my $SRC = "png:\Q$path\E"; |
|
|
316 | |
|
|
317 | my $is_floor = $arc->{is_floor}; |
|
|
318 | my $is_wall = 0; |
|
|
319 | |
|
|
320 | my ($wall_pfx, $wall_dir, $wall_sfx); |
|
|
321 | |
|
|
322 | if ( |
|
|
323 | !$is_floor |
|
|
324 | && !$arc->{alive} |
|
|
325 | && $arc->{move_block} eq "all" |
|
|
326 | && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/ |
|
|
327 | ) { |
|
|
328 | ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3); |
|
|
329 | |
|
|
330 | unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) { |
|
|
331 | $is_wall = 1; |
|
|
332 | } |
|
|
333 | } |
|
|
334 | |
|
|
335 | if ($is_wall || $is_floor) { |
|
|
336 | # add a 4px border and add other images around it |
|
|
337 | $CROP = "-shave 8x8 +repage"; |
|
|
338 | |
|
|
339 | $w += 8; |
|
|
340 | $h += 8; |
|
|
341 | |
|
|
342 | $SRC = "-size ${w}x${h} xc:transparent"; |
|
|
343 | $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; |
|
|
344 | |
|
|
345 | # 8 surrounding images |
|
|
346 | for ( |
|
|
347 | # x y b r0 r1 |
|
|
348 | [-1, -1, 0, 6], |
|
|
349 | [ 0, -1, 1, 10, 14], |
|
|
350 | [+1, -1, 0, 12], |
|
|
351 | |
|
|
352 | [-1, 0, 8, 5, 7], |
|
|
353 | # |
|
|
354 | [+1, 0, 2, 5, 13], |
|
|
355 | |
|
|
356 | [-1, +1, 0, 3], |
|
|
357 | [ 0, +1, 4, 10, 11], |
|
|
358 | [+1, +1, 0, 9], |
|
|
359 | ) { |
|
|
360 | my ($x, $y, $d, $r0, $r1) = @$_; |
|
|
361 | |
|
|
362 | my $tile = $is_floor ? $path |
|
|
363 | : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx |
|
|
364 | : die; |
|
|
365 | |
|
|
366 | $SRC .= sprintf " png:%s -geometry %+d%+d -composite", |
|
|
367 | "\Q$tile", |
|
|
368 | $x * ($w - 8) + 4, |
|
|
369 | $y * ($h - 8) + 4; |
|
|
370 | } |
|
|
371 | } |
|
|
372 | |
177 | system "convert png:\Q$path\E -depth 8 rgba:-" |
373 | system "convert -depth 8 $SRC rgba:-" |
178 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
374 | . "| $exec_prefix/bin/cfhq2xa $w $h 0" |
179 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
375 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~" |
180 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
376 | and die "convert/cfhq2xa pipeline error: status $? ($!)"; |
181 | system $OPTIPNG, "-i0", "-q", "$other~"; |
377 | system $OPTIPNG, "-i0", "-q", "$other~"; |
182 | die "$other~ has zero size, aborting." unless -s "$other~"; |
378 | die "$other~ has zero size, aborting." unless -s "$other~"; |
183 | rename "$other~", $other; |
379 | rename "$other~", $other; |
184 | }; |
380 | }; |
185 | } |
381 | } |
186 | |
382 | |
187 | push @png, [$other, !$CACHE]; |
383 | push @c_png, [$other, !$CACHE]; |
188 | } |
384 | } |
189 | |
385 | |
190 | # possibly scale down |
386 | # possibly scale down |
191 | if (0 > aio_stat "$stem.32x32.png") { |
387 | if (0 > aio_stat "$stem.32x32.png") { |
192 | my $other = "$stem.32x32.png~"; |
388 | my $other = "$stem.32x32.png~"; |
… | |
… | |
195 | fork_sub { |
391 | fork_sub { |
196 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
392 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
197 | system $OPTIPNG, "-i0", "-q", "$other~"; |
393 | system $OPTIPNG, "-i0", "-q", "$other~"; |
198 | |
394 | |
199 | # reduce smoothfaces >10000 bytes |
395 | # reduce smoothfaces >10000 bytes |
|
|
396 | # obsolete, no longer required |
200 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
397 | if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { |
201 | my $ncolor = 256; |
398 | my $ncolor = 256; |
202 | while () { |
399 | while () { |
203 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
400 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
204 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
401 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
205 | last if 10000 > -s "$other~~"; |
402 | last if 10000 > -s "$other~~"; |
… | |
… | |
217 | rename "$other~", $other; |
414 | rename "$other~", $other; |
218 | }; |
415 | }; |
219 | } |
416 | } |
220 | |
417 | |
221 | #warn "scaled down $path to $other\n";#d# |
418 | #warn "scaled down $path to $other\n";#d# |
222 | push @png, [$other, !$CACHE]; |
419 | push @c_png, [$other, !$CACHE]; |
223 | } |
420 | } |
224 | } |
421 | } |
225 | |
422 | |
226 | (my $face = $stem) =~ s/^.*\///; |
423 | (my $face = $stem) =~ s/^.*\///; |
227 | |
424 | |
… | |
… | |
276 | |
473 | |
277 | if (0 > aio_load $file, $tile) { |
474 | if (0 > aio_load $file, $tile) { |
278 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
475 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
279 | } |
476 | } |
280 | IO::AIO::aio_unlink $file unless $CACHE; |
477 | IO::AIO::aio_unlink $file unless $CACHE; |
281 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
478 | commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
282 | } |
479 | } |
283 | } else { |
480 | } else { |
284 | # use as-is (either small, use smooth) |
481 | # use as-is (either small, use smooth) |
285 | commit_png $face, $png, $T; |
482 | commit_png $stem, $face, $png, $T; |
286 | } |
483 | } |
287 | |
484 | |
288 | aio_unlink $path if $delete; |
485 | aio_unlink $path if $delete; |
289 | } |
486 | } |
290 | } |
487 | } |
291 | |
488 | |
|
|
489 | sub process_faceinfo { |
|
|
490 | my ($dir, $file) = @_; |
|
|
491 | my $path = "$dir/$file"; |
|
|
492 | |
|
|
493 | my $data; |
|
|
494 | if (0 > aio_load $path, $data) { |
|
|
495 | warn "$path: $!, skipping.\n"; |
|
|
496 | return; |
|
|
497 | } |
|
|
498 | |
|
|
499 | for (split /\n/, $data) { |
|
|
500 | my ($face, $visibility, $fg, $bg, $glyph) = split /\s+/; |
|
|
501 | |
|
|
502 | $glyph =~ s/^?(?=.)//; # remove "autoglyph" flag |
|
|
503 | |
|
|
504 | (my $fgi = $COLOR{$fg}) |
|
|
505 | // warn "WARNING: $path: $face specifies unknown foreground colour '$fg'.\n"; |
|
|
506 | (my $bgi = $COLOR{$bg}) |
|
|
507 | // warn "WARNING: $path: $face specifies unknown background colour '$bg'.\n"; |
|
|
508 | |
|
|
509 | my $fi = $FACEINFO{$face} ||= { }; |
|
|
510 | $fi->{visibility} = $visibility * 1; |
|
|
511 | $fi->{magicmap} = $fgi; # foreground colour becomes magicmap |
|
|
512 | $fi->{glyph} = (chr $fgi) . (chr $bgi) . $glyph; |
|
|
513 | # bg not used except for text clients |
|
|
514 | } |
|
|
515 | } |
|
|
516 | |
292 | sub process_arc { |
517 | sub process_arc { |
293 | while (@arc) { |
518 | while (my ($dir, $file) = @{ $c_arc->get }) { |
294 | my ($dir, $file) = @{pop @arc}; |
|
|
295 | |
|
|
296 | my $arc; |
519 | my $arc; |
297 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
520 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
298 | |
521 | |
299 | my $arc = read_arch "$dir/$file"; |
522 | my $arc = read_arch "$dir/$file"; |
300 | for my $o (values %$arc) { |
523 | for my $o (values %$arc) { |
301 | push @ARC, $o; |
524 | push @ARC, $o; |
302 | for (my $m = $o; $m; $m = $m->{more}) { |
525 | for (my $m = $o; $m; $m = $m->{more}) { |
303 | $ARC{$m->{_name}} = $m; |
526 | $ARC{$m->{_name}} = $m; |
304 | } |
527 | } |
305 | |
528 | |
306 | $o->{editor_folder} = $dir; |
529 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
307 | |
|
|
308 | my $visibility = delete $o->{visibility}; |
|
|
309 | my $magicmap = delete $o->{magicmap}; |
|
|
310 | |
530 | |
311 | # find upper left corner :/ |
531 | # find upper left corner :/ |
312 | # omg, this is sooo broken |
532 | # omg, this is sooo broken |
313 | my ($dx, $dy); |
533 | my ($dx, $dy); |
314 | for (my $o = $o; $o; $o = $o->{more}) { |
534 | for (my $o = $o; $o; $o = $o->{more}) { |
… | |
… | |
321 | my $y = $o->{y} - $dy; |
541 | my $y = $o->{y} - $dy; |
322 | |
542 | |
323 | my $ext = $x|$y ? "+$x+$y" : ""; |
543 | my $ext = $x|$y ? "+$x+$y" : ""; |
324 | |
544 | |
325 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
545 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
326 | |
|
|
327 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
|
|
328 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
329 | |
546 | |
330 | my $anim = delete $o->{anim}; |
547 | my $anim = delete $o->{anim}; |
331 | |
548 | |
332 | if ($anim) { |
549 | if ($anim) { |
333 | # possibly add $ext to the animation name to avoid |
550 | # possibly add $ext to the animation name to avoid |
… | |
… | |
351 | facings => $facings, |
568 | facings => $facings, |
352 | frames => \@frames, |
569 | frames => \@frames, |
353 | }; |
570 | }; |
354 | } |
571 | } |
355 | |
572 | |
356 | for my $face ($o->{face} || (), @{$anim || []}) { |
573 | for ($o->{face} || (), @{$anim || []}) { |
357 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
574 | next if /^facings\s/; |
358 | |
575 | |
|
|
576 | my $face = $_; |
|
|
577 | $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates |
|
|
578 | |
359 | my $info = $FACEINFO{$face} ||= {}; |
579 | my $info = $FACEINFO{$face} ||= { }; |
|
|
580 | $info->{arc} = $o; |
360 | |
581 | |
361 | $info->{visibility} = $visibility if defined $visibility; |
582 | next if $face =~ /^blank.x11$|^empty.x11$/; |
362 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
363 | } |
583 | } |
364 | |
584 | |
365 | if (my $smooth = delete $o->{smoothface}) { |
585 | if (my $smooth = delete $o->{smoothface}) { |
366 | my %kv =split /\s+/, $smooth; |
586 | my %kv = split /\s+/, $smooth; |
367 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
587 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
368 | while (my ($face, $smooth) = each %kv) { |
588 | while (my ($face, $smooth) = each %kv) { |
|
|
589 | $FACEINFO{$smooth}{arc} = $o; |
|
|
590 | |
369 | $FACEINFO{$face}{smooth} = $smooth; |
591 | $FACEINFO{$face}{smooth} = $smooth; |
370 | $FACEINFO{$face}{smoothlevel} = $level; |
592 | $FACEINFO{$face}{smoothlevel} = $level; |
371 | } |
593 | } |
372 | } |
594 | } |
373 | } |
595 | } |
374 | } |
596 | } |
375 | } |
597 | } |
376 | } |
598 | } |
377 | |
599 | |
378 | sub process_trs { |
600 | sub process_trs { |
379 | while (@trs) { |
|
|
380 | my ($dir, $file) = @{pop @trs}; |
601 | my ($dir, $file) = @_; |
381 | my $path = "$dir/$file"; |
602 | my $path = "$dir/$file"; |
382 | |
603 | |
383 | my $trs; |
604 | my $trs; |
384 | if (0 > aio_load $path, $trs) { |
605 | if (0 > aio_load $path, $trs) { |
385 | warn "$path: $!, skipping.\n"; |
606 | warn "$path: $!, skipping.\n"; |
386 | next; |
607 | return; |
387 | } |
608 | } |
388 | |
609 | |
389 | $TRS .= $trs; |
610 | $TRS .= $trs; |
390 | } |
|
|
391 | } |
611 | } |
392 | |
612 | |
393 | my %FILECACHE; |
613 | my %FILECACHE; |
394 | |
614 | |
395 | sub load_cached($;$) { |
615 | sub load_cached($;$) { |
396 | unless (exists $FILECACHE{$_[0]}) { |
616 | unless (exists $FILECACHE{$_[0]}) { |
397 | my $data; |
617 | my $data; |
398 | if (0 < aio_load $_[0], $data) { |
618 | if (0 < aio_load $_[0], $data) { |
|
|
619 | if ($_[1]) { |
399 | $data = $_[1]->($data) |
620 | $data = eval { $_[1]->($data) }; |
400 | if $_[1]; |
621 | warn "$_[0]: $@" if $@; |
|
|
622 | } |
401 | } |
623 | } |
402 | |
624 | |
403 | $FILECACHE{$_[0]} = $data; |
625 | $FILECACHE{$_[0]} = $data; |
404 | } |
626 | } |
405 | |
627 | |
406 | $FILECACHE{$_[0]} |
628 | $FILECACHE{$_[0]} |
407 | } |
629 | } |
408 | |
630 | |
409 | sub process_res { |
631 | sub process_res { |
410 | while (@res) { |
|
|
411 | my ($dir, $file, $type) = @{pop @res}; |
632 | my ($dir, $file, $type) = @_; |
412 | |
633 | |
413 | my $data; |
634 | my $data; |
414 | aio_load "$dir/$file", $data; |
635 | aio_load "$dir/$file", $data; |
415 | |
636 | |
416 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
637 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
417 | |
638 | |
|
|
639 | utf8::decode $dir; |
|
|
640 | utf8::decode $file; |
|
|
641 | |
|
|
642 | # a meta file for resources is now mandatory |
|
|
643 | unless (exists $meta->{$file}) { |
|
|
644 | warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
|
|
645 | return; |
|
|
646 | } |
|
|
647 | |
|
|
648 | $meta = { |
|
|
649 | %{ $meta->{"" } || {} }, |
|
|
650 | %{ $meta->{$file} || {} }, |
|
|
651 | }; |
|
|
652 | |
|
|
653 | if ($meta->{license} =~ s/^#//) { |
|
|
654 | $meta->{license} = ({ |
|
|
655 | "pd" => "Public Domain", |
|
|
656 | "gpl" => "GNU General Public License, version 3.0 or any later", |
|
|
657 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
658 | "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
|
|
659 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
|
|
660 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
|
|
661 | })->{$meta->{license}} |
|
|
662 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
|
|
663 | } |
|
|
664 | |
|
|
665 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
|
|
666 | ($meta->{author} = $1) =~ s/_/ /g; |
|
|
667 | } |
|
|
668 | |
418 | $file =~ s/\.res$//; |
669 | $file =~ s/\.res$//; |
419 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
670 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
420 | |
671 | |
421 | substr $dir, 0, 1 + length $PATH, ""; |
672 | substr $dir, 0, 1 + length $PATH, ""; |
422 | |
673 | |
423 | $meta = { |
674 | if (my $filter = $meta->{cfutil_filter}) { |
424 | %{ $meta->{"" } || {} }, |
675 | if ($filter eq "yaml2json") { |
425 | %{ $meta->{$file} || {} }, |
676 | $data = JSON::XS::encode_json YAML::XS::Load $data; |
|
|
677 | } elsif ($filter eq "json2json") { |
|
|
678 | $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
|
|
679 | } elsif ($filter eq "perl2json") { |
|
|
680 | $data = eval $data; die if $@; |
|
|
681 | $data = JSON::XS::encode_json $data; |
|
|
682 | } else { |
|
|
683 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
426 | }; |
684 | } |
|
|
685 | } |
427 | |
686 | |
428 | $RESOURCE{"$dir/$file"} = { |
687 | $RESOURCE{"$dir/$file"} = { |
429 | type => (delete $meta->{type}) || $type, |
688 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
430 | data => $data, |
689 | data => $data, |
431 | chksum => (Digest::MD5::md5 $data), |
|
|
432 | %$meta ? (meta => $meta) : (), |
690 | %$meta ? (meta => $meta) : (), |
433 | }; |
691 | }; |
|
|
692 | } |
|
|
693 | |
|
|
694 | sub process_any { |
|
|
695 | while (my ($func, @args) = @{ $c_any->get }) { |
|
|
696 | $func->(@args); |
434 | } |
697 | } |
435 | } |
698 | } |
436 | |
699 | |
437 | sub find_files; |
700 | sub find_files; |
438 | sub find_files { |
701 | sub find_files { |
439 | my ($path) = @_; |
702 | my ($path) = @_; |
440 | |
703 | |
|
|
704 | my $grp = IO::AIO::aio_group; |
|
|
705 | |
|
|
706 | my $scandir; $scandir = sub { |
|
|
707 | my ($path) = @_; |
|
|
708 | |
441 | IO::AIO::aioreq_pri 4; |
709 | IO::AIO::aioreq_pri 4; |
442 | IO::AIO::aio_scandir $path, 4, sub { |
710 | add $grp IO::AIO::aio_scandir $path, 4, sub { |
443 | my ($dirs, $nondirs) = @_; |
711 | my ($dirs, $nondirs) = @_; |
444 | |
712 | |
445 | find_files "$path/$_" |
713 | $scandir->("$path/$_") |
446 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
714 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
447 | |
715 | |
448 | my $dir = $path; |
716 | my $dir = $path; |
449 | substr $dir, 0, 1 + length $PATH, ""; |
717 | substr $dir, 0, 1 + length $PATH, ""; |
450 | |
718 | |
451 | for my $file (@$nondirs) { |
719 | for my $file (@$nondirs) { |
452 | if ($dir =~ /^music(?:\/|$)/) { |
720 | if ($dir =~ /^music(?:\/|$)/) { |
453 | push @res, [$path, $file, 3] # FT_MUSIC |
721 | $c_any->put ([\&process_res, $path, $file, 3]) # FT_MUSIC |
454 | if $file =~ /\.(ogg)$/; |
722 | if $file =~ /\.(ogg)$/; |
455 | |
723 | |
456 | } elsif ($dir =~ /^sounds(?:\/|$)/) { |
724 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
457 | push @res, [$path, $file, 5] # FT_SOUND |
725 | $c_any->put ([\&process_res, $path, $file, 5]) # FT_SOUND |
458 | if $file =~ /\.(wav|ogg)$/; |
726 | if $file =~ /\.(wav|ogg)$/; |
459 | |
727 | |
460 | } elsif ($dir =~ /^res(?:\/|$)/) { |
728 | } elsif ($dir =~ /^res(?:\/|$)/) { |
461 | push @res, [$path, $file, 0] # FT_FACE |
|
|
462 | if $file =~ /\.(jpg|png)$/; |
729 | if ($file =~ /\.(jpg|png)$/) { |
463 | push @res, [$path, $file, 7] # FT_RSRC |
730 | $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE |
464 | if $file =~ /\.(res)$/; |
731 | } elsif ($file =~ /\.(res)$/) { |
|
|
732 | $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC |
|
|
733 | } else { |
|
|
734 | $c_any->put ([\&process_res, $path, $file, undef]); |
|
|
735 | } |
465 | |
736 | |
466 | } elsif ($file =~ /\.png$/) { |
737 | } elsif ($file =~ /\.png$/) { |
467 | push @png, ["$path/$file", 0]; |
738 | push @c_png, ["$path/$file", 0]; |
468 | |
739 | |
|
|
740 | } elsif ($file =~ /\.faceinfo$/) { |
|
|
741 | $c_any->put ([\&process_faceinfo, $path, $file]); |
|
|
742 | |
469 | } elsif ($file =~ /\.trs$/) { |
743 | } elsif ($file =~ /\.trs$/) { |
470 | push @trs, [$path, $file]; |
744 | $c_any->put ([\&process_trs, $path, $file]); |
471 | |
745 | |
472 | } elsif ($file =~ /\.arc$/) { |
746 | } elsif ($file =~ /\.arc$/) { |
473 | push @arc, [$path, $file]; |
747 | $c_arc->put ([$path, $file]); |
474 | |
748 | |
475 | } else { |
749 | } else { |
476 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
750 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
477 | } |
751 | } |
|
|
752 | } |
478 | } |
753 | }; |
479 | }; |
754 | }; |
|
|
755 | |
|
|
756 | $scandir->($path); |
|
|
757 | aio_wait $grp; |
|
|
758 | } |
|
|
759 | |
|
|
760 | sub generate_plurals { |
|
|
761 | # use Lingua::EN::Inflect (); |
|
|
762 | # Lingua::EN::Inflect::classical; |
|
|
763 | # Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy |
|
|
764 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
|
|
765 | # |
|
|
766 | # for my $a (@ARC) { |
|
|
767 | # my $name = $a->{name} || $a->{_name}; |
|
|
768 | # |
|
|
769 | # next unless $a->{name_pl}; |
|
|
770 | # next if $a->{invisible}; |
|
|
771 | # next if $a->{is_floor}; |
|
|
772 | # next if $a->{no_pick}; |
|
|
773 | # |
|
|
774 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
|
|
775 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
|
|
776 | # ? $name |
|
|
777 | # : Lingua::EN::Inflect::PL $name; |
|
|
778 | # |
|
|
779 | # if ($pl ne $a->{name_pl}) { |
|
|
780 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
|
|
781 | # } |
|
|
782 | # } |
480 | } |
783 | } |
481 | |
784 | |
482 | sub inst_arch($) { |
785 | sub inst_arch($) { |
483 | my (undef, $path) = @_; |
786 | my (undef, $path) = @_; |
484 | |
787 | |
… | |
… | |
497 | if (!-d "$path/treasures") { |
800 | if (!-d "$path/treasures") { |
498 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
801 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
499 | exit 1 unless $FORCE; |
802 | exit 1 unless $FORCE; |
500 | } |
803 | } |
501 | |
804 | |
|
|
805 | print "start file scan, arc, any processing...\n" if $VERBOSE; |
|
|
806 | |
|
|
807 | my @a_arc = map +(async \&process_arc), 1..2; |
|
|
808 | my @a_any = map +(async \&process_any), 1..4; |
|
|
809 | |
502 | find_files $path; |
810 | find_files $path; |
503 | IO::AIO::flush; |
|
|
504 | |
811 | |
505 | $_->join for ( |
812 | $c_arc->shutdown; |
|
|
813 | $c_any->shutdown; |
|
|
814 | |
|
|
815 | $_->join for @a_arc; # need to parse all archetypes before png processing |
|
|
816 | |
|
|
817 | print "end arc, start png processing...\n" if $VERBOSE; |
|
|
818 | |
506 | # four png crunchers work fine for my 2x smp machine |
819 | # eight png crunchers work fine for my 4x smp machine |
507 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
820 | my @a_png = map +(async \&process_png), 1..8; |
508 | (async \&process_trs), (async \&process_trs), |
|
|
509 | (async \&process_arc), (async \&process_arc), |
|
|
510 | (async \&process_res), (async \&process_res), |
|
|
511 | ); |
|
|
512 | |
821 | |
|
|
822 | print "end any processing...\n" if $VERBOSE; |
|
|
823 | $_->join for @a_any; |
|
|
824 | |
|
|
825 | print "end png processing...\n" if $VERBOSE; |
|
|
826 | $_->join for @a_png; |
|
|
827 | |
|
|
828 | print "scanning done, processing results...\n" if $VERBOSE; |
513 | { |
829 | { |
514 | # remove path prefix from editor_folder |
830 | # remove path prefix from editor_folder |
|
|
831 | $_->{editor_folder} =~ /^\x00/ |
515 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
832 | and substr $_->{editor_folder}, 0, 2 + length $path, "" |
516 | for values %ARC; |
833 | for values %ARC; |
517 | |
834 | |
|
|
835 | print "resolving inheritance tree...\n" if $VERBOSE; |
518 | # resolve inherit |
836 | # resolve inherit |
519 | while () { |
837 | while () { |
520 | my $progress; |
838 | my $progress; |
521 | my $loop; |
839 | my $loop; |
522 | |
840 | |
523 | for my $o (values %ARC) { |
841 | for my $o (values %ARC) { |
524 | if (my $other = $o->{inherit}) { |
842 | for my $other (split /,/, $o->{inherit}) { |
525 | if (my $s = $ARC{$other}) { |
843 | if (my $s = $ARC{$other}) { |
526 | if ($s->{inherit}) { |
844 | if ($s->{inherit}) { |
527 | $loop = $s; |
845 | $loop = $s; |
528 | } else { |
846 | } else { |
529 | delete $o->{inherit}; |
847 | delete $o->{inherit}; |
… | |
… | |
531 | delete @s{qw(_name more name name_pl)}; |
849 | delete @s{qw(_name more name name_pl)}; |
532 | %$o = ( %s, %$o ); |
850 | %$o = ( %s, %$o ); |
533 | ++$progress; |
851 | ++$progress; |
534 | } |
852 | } |
535 | } else { |
853 | } else { |
536 | warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
854 | warn "WARNING: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
537 | delete $ARC{$o->{_name}}; |
855 | delete $ARC{$o->{_name}}; |
538 | } |
856 | } |
539 | } |
857 | } |
540 | } |
858 | } |
541 | |
859 | |
… | |
… | |
548 | } |
866 | } |
549 | |
867 | |
550 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
868 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
551 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
869 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
552 | |
870 | |
|
|
871 | print "generating plurals...\n" if $VERBOSE; |
|
|
872 | generate_plurals; |
|
|
873 | |
|
|
874 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
553 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
875 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
554 | or die "$DATADIR/archetypes~: $!"; |
876 | or die "$DATADIR/archetypes~: $!"; |
555 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
877 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
|
|
878 | } |
|
|
879 | |
|
|
880 | if (WRITE_FACEINFO) { |
|
|
881 | my @table; |
|
|
882 | for my $face (sort keys %FACEINFO) { |
|
|
883 | my $v = $FACEINFO{$face}; |
|
|
884 | (my $xf = $face) =~ s/\+\d+\+\d+$//; |
|
|
885 | |
|
|
886 | $v->{magicmap} //= $FACEINFO{$xf}{magicmap}; |
|
|
887 | $v->{glyph} //= $FACEINFO{$xf}{glyph}; |
|
|
888 | |
|
|
889 | $v->{magicmap} =~ y/A-Z_\-/a-z/d; |
|
|
890 | |
|
|
891 | delete $v->{glyph} if $v->{glyph} =~ /^\?./; |
|
|
892 | |
|
|
893 | my $stem = $v->{stem}; |
|
|
894 | $v->{glyph} = $v->{glyph} // ("?" . (autoglyph $stem, $v)); |
|
|
895 | |
|
|
896 | push @table, [$face, $v->{visibility} || 0, $v->{magicmap} || "none", "none ", $v->{glyph}]; |
|
|
897 | } |
|
|
898 | use Text::Table; |
|
|
899 | my $tb = new Text::Table undef, { align => "num" }, undef, undef, undef; |
|
|
900 | $tb->load (@table); |
|
|
901 | open my $fh, ">:raw", "default.faceinfo"or die; |
|
|
902 | print $fh $tb; |
|
|
903 | print "default.faceinfo written, exiting.\n"; |
|
|
904 | exit 77; |
556 | } |
905 | } |
557 | |
906 | |
558 | { |
907 | { |
|
|
908 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
559 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
909 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
560 | or die "$DATADIR/treasures~: $!"; |
910 | or die "$DATADIR/treasures~: $!"; |
561 | print $fh $TRS; |
911 | print $fh $TRS; |
562 | } |
912 | } |
563 | |
913 | |
564 | { |
914 | { |
|
|
915 | print "processing facedata...\n" if $VERBOSE; |
565 | while (my ($k, $v) = each %FACEINFO) { |
916 | while (my ($k, $v) = each %FACEINFO) { |
566 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
917 | length $v->{data32} or warn "WARNING: face '$k' has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
567 | length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; |
918 | length $v->{data64} or warn "WARNING: face '$k' has no png64. this will not work very well.\n"; |
568 | |
919 | |
|
|
920 | make_hash $k, $v->{data32}, $v->{hash32}; |
|
|
921 | make_hash $k, $v->{data64}, $v->{hash64}; |
|
|
922 | |
569 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
923 | #length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
570 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
924 | #length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n"; |
571 | |
925 | |
572 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
926 | exists $v->{visibility} |
573 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
927 | or warn "WARNING: face '$k' has no visibility info, missing faceinfo entry?\n"; |
574 | |
928 | |
575 | if (my $magicmap = $v->{magicmap}) { |
929 | my $stem = delete $v->{stem}; |
576 | $magicmap =~ y/A-Z_\-/a-z/d; |
930 | $v->{glyph} // warn "WARNING: face '$k' has glyph, cannot autoglyph at the moment."; |
577 | $v->{magicmap} = $COLOR{$magicmap}; |
931 | #$v->{glyph} //= autoglyph $stem, $v; |
|
|
932 | |
|
|
933 | delete $v->{arc}; |
|
|
934 | } |
|
|
935 | |
|
|
936 | print "processing resources...\n" if $VERBOSE; |
|
|
937 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
|
|
938 | while (my ($k, $v) = each %RESOURCE) { |
|
|
939 | |
|
|
940 | if ($v->{meta} && $v->{meta}{datadir}) { |
|
|
941 | delete $RESOURCE{$k}; |
|
|
942 | |
|
|
943 | $k =~ s/^res\/// or die "$k: datadir files must be in res/"; |
|
|
944 | |
|
|
945 | printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE; |
|
|
946 | open my $fh, ">:raw", "$DATADIR/$k~" |
|
|
947 | or die "$DATADIR/$k~: $!"; |
|
|
948 | syswrite $fh, $v->{data}; |
|
|
949 | push @COMMIT, $k; |
|
|
950 | |
|
|
951 | } else { |
|
|
952 | if ($v->{type} & 1) { |
|
|
953 | # prepend meta info |
|
|
954 | |
|
|
955 | my $meta = $enc->encode ({ |
|
|
956 | name => $k, |
|
|
957 | %{ $v->{meta} || {} }, |
|
|
958 | }); |
|
|
959 | |
|
|
960 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
578 | } |
961 | } |
|
|
962 | |
|
|
963 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
579 | } |
964 | } |
|
|
965 | } |
|
|
966 | |
|
|
967 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
|
|
968 | scalar keys %FACEINFO, |
|
|
969 | scalar keys %ANIMINFO, |
|
|
970 | scalar keys %RESOURCE |
|
|
971 | if $VERBOSE; |
580 | |
972 | |
581 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
973 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
582 | or die "$DATADIR/facedata~: $!"; |
974 | or die "$DATADIR/facedata~: $!"; |
583 | |
975 | |
584 | print $fh freeze { |
976 | print $fh nfreeze { |
585 | version => 2, |
977 | version => 2, |
586 | faceinfo => \%FACEINFO, |
978 | faceinfo => \%FACEINFO, |
587 | animinfo => \%ANIMINFO, |
979 | animinfo => \%ANIMINFO, |
588 | resource => \%RESOURCE, |
980 | resource => \%RESOURCE, |
589 | }; |
981 | }; |
590 | } |
|
|
591 | |
982 | |
|
|
983 | } |
|
|
984 | |
|
|
985 | print "committing files...\n" if $VERBOSE; |
|
|
986 | |
592 | for (qw(archetypes facedata treasures)) { |
987 | for (qw(archetypes facedata treasures), @COMMIT) { |
593 | chmod 0644, "$DATADIR/$_~"; |
988 | chmod 0644, "$DATADIR/$_~"; |
594 | rename "$DATADIR/$_~", "$DATADIR/$_" |
989 | rename "$DATADIR/$_~", "$DATADIR/$_" |
595 | or die "$DATADIR/$_: $!"; |
990 | or die "$DATADIR/$_: $!"; |
596 | } |
991 | } |
597 | |
992 | |