… | |
… | |
19 | use File::Temp; |
19 | use File::Temp; |
20 | use Crossfire; |
20 | use Crossfire; |
21 | use Coro; |
21 | use Coro; |
22 | use Coro::AIO; |
22 | use Coro::AIO; |
23 | use POSIX (); |
23 | use POSIX (); |
|
|
24 | use Digest::MD5; |
24 | |
25 | |
25 | sub usage { |
26 | sub usage { |
26 | warn <<EOF; |
27 | warn <<EOF; |
27 | Usage: cfutil [-v] [-q] [--force] [--cache] |
28 | Usage: cfutil [-v] [-q] [--force] [--cache] |
28 | [--install-arch path] |
29 | [--install-arch path] |
… | |
… | |
77 | |
78 | |
78 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; |
79 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; |
79 | } |
80 | } |
80 | |
81 | |
81 | { |
82 | { |
82 | our @PNG; |
83 | our %PNG32; |
|
|
84 | our %FACEINFO; |
83 | our @ARC; |
85 | our @ARC; |
|
|
86 | our $TRS; |
84 | our $NFILE; |
87 | our $NFILE; |
85 | our @FACE; |
|
|
86 | our $ANIM; |
88 | our %ANIM; |
|
|
89 | our $SMOOTH; |
87 | |
90 | |
88 | our (@png, @trs, @arc); # files we are interested in |
91 | our (@png, @trs, @arc); # files we are interested in |
89 | |
92 | |
90 | sub commit_png { |
93 | sub commit_png { |
91 | my ($name, $data) = @_; |
94 | my ($name, $data) = @_; |
92 | |
95 | |
93 | push @PNG, [$name => $data]; |
96 | $PNG32{$name} = $data; |
|
|
97 | $FACEINFO{$name} ||= {}; |
94 | } |
98 | } |
95 | |
99 | |
96 | sub process_png { |
100 | sub process_png { |
97 | while (@png) { |
101 | while (@png) { |
98 | my $path = pop @png; |
102 | my $path = pop @png; |
… | |
… | |
104 | if (0 > aio_load $path, $png) { |
108 | if (0 > aio_load $path, $png) { |
105 | warn "$path: $!, skipping.\n"; |
109 | warn "$path: $!, skipping.\n"; |
106 | next; |
110 | next; |
107 | } |
111 | } |
108 | |
112 | |
109 | # quickly extratc width and height of the (necessarily PNG) image |
113 | # quickly extract width and height of the (necessarily PNG) image |
110 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
114 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
111 | warn "$path: not a recongized png file, skipping.\n"; |
115 | warn "$path: not a recongized png file, skipping.\n"; |
112 | next; |
116 | next; |
113 | } |
117 | } |
114 | |
118 | |
… | |
… | |
147 | my @todo = grep { $_->[3] <= $mtime } @tile; |
151 | my @todo = grep { $_->[3] <= $mtime } @tile; |
148 | if (@todo) { |
152 | if (@todo) { |
149 | fork_sub { |
153 | fork_sub { |
150 | open my $convert, "|-", $CONVERT, |
154 | open my $convert, "|-", $CONVERT, |
151 | "png:-", |
155 | "png:-", |
152 | -negate,#d# |
|
|
153 | (map { |
156 | (map { |
154 | ( |
157 | ( |
155 | "(", |
158 | "(", |
156 | "+clone", |
159 | "+clone", |
157 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
160 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
|
|
161 | "+repage", |
158 | -write => "png:$_->[2]~", |
162 | -write => "png:$_->[2]~", |
159 | "+delete", |
163 | "+delete", |
160 | ")", |
164 | ")", |
161 | ) |
165 | ) |
162 | } @todo), |
166 | } @todo), |
… | |
… | |
199 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
203 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
200 | |
204 | |
201 | my $arc = read_arch "$dir/$file"; |
205 | my $arc = read_arch "$dir/$file"; |
202 | for my $o (values %$arc) { |
206 | for my $o (values %$arc) { |
203 | push @ARC, $o; |
207 | push @ARC, $o; |
|
|
208 | |
|
|
209 | $o->{editor_folder} = $dir; |
|
|
210 | |
|
|
211 | my $visibility = delete $o->{visibility}; |
|
|
212 | my $magicmap = delete $o->{magicmap}; |
|
|
213 | |
|
|
214 | # find upper left corner :/ |
|
|
215 | # omg, this is sooo broken |
204 | my ($dx, $dy); |
216 | my ($dx, $dy); |
205 | # omg, this is sooo broken |
|
|
206 | for (my $o = $o; $o; $o = $o->{more}) { |
217 | for (my $o = $o; $o; $o = $o->{more}) { |
207 | $dx = $o->{x} if $o->{x} < $dx; |
218 | $dx = $o->{x} if $o->{x} < $dx; |
208 | $dy = $o->{y} if $o->{y} < $dy; |
219 | $dy = $o->{y} if $o->{y} < $dy; |
209 | } |
220 | } |
|
|
221 | |
210 | for (my $o = $o; $o; $o = $o->{more}) { |
222 | for (my $o = $o; $o; $o = $o->{more}) { |
211 | my $x = $o->{x} - $dx; |
223 | my $x = $o->{x} - $dx; |
212 | my $y = $o->{y} - $dy; |
224 | my $y = $o->{y} - $dy; |
213 | if ($x|$y) { |
225 | |
214 | $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; |
226 | my $ext = $x|$y ? "+$x+$y" : ""; |
215 | } |
227 | |
216 | } |
228 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; |
|
|
229 | |
|
|
230 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
|
|
231 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
232 | |
217 | if (my $anim = delete $o->{anim}) { |
233 | my $anim = delete $o->{anim}; |
|
|
234 | |
|
|
235 | if ($anim) { |
218 | $o->{animation} = $o->{_name}; |
236 | $o->{animation} = "$o->{_name}"; |
|
|
237 | |
|
|
238 | for (@$anim) { |
|
|
239 | $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; |
|
|
240 | } |
|
|
241 | |
|
|
242 | $ANIM{"$o->{_name}$ext"} = |
219 | $ANIM .= join "", map "$_\n", |
243 | join "", map "$_\n", |
220 | "anim $o->{_name}", |
244 | "anim $o->{_name}", |
221 | @$anim, |
245 | @$anim, |
222 | "mina"; |
246 | "mina"; |
|
|
247 | } |
|
|
248 | |
|
|
249 | for my $face ($o->{face} || (), @{$anim || []}) { |
|
|
250 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
|
|
251 | |
|
|
252 | my $info = $FACEINFO{$face} ||= {}; |
|
|
253 | |
|
|
254 | $info->{visibility} = $visibility if defined $visibility; |
|
|
255 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
256 | } |
|
|
257 | |
|
|
258 | if (my $smooth = delete $o->{smoothface}) { |
|
|
259 | $SMOOTH .= "$smooth\n"; |
|
|
260 | } |
223 | } |
261 | } |
224 | } |
262 | } |
225 | } |
263 | } |
226 | } |
264 | } |
227 | |
265 | |
228 | sub process_trs { |
266 | sub process_trs { |
229 | while (@trs) { |
267 | while (@trs) { |
230 | my ($dir, $file) = @{pop @trs}; |
268 | my ($dir, $file) = @{pop @trs}; |
|
|
269 | my $path = "$dir/$file"; |
|
|
270 | |
|
|
271 | my $trs; |
|
|
272 | if (0 > aio_load $path, $trs) { |
|
|
273 | warn "$path: $!, skipping.\n"; |
|
|
274 | next; |
|
|
275 | } |
|
|
276 | |
|
|
277 | $TRS .= $trs; |
231 | } |
278 | } |
232 | } |
279 | } |
233 | |
280 | |
234 | sub find_files; |
281 | sub find_files; |
235 | sub find_files { |
282 | sub find_files { |
… | |
… | |
276 | ); |
323 | ); |
277 | |
324 | |
278 | { |
325 | { |
279 | open my $fh, ">:utf8", "$DATADIR/animations~" |
326 | open my $fh, ">:utf8", "$DATADIR/animations~" |
280 | or die "$DATADIR/animations~: $!"; |
327 | or die "$DATADIR/animations~: $!"; |
281 | print $fh $ANIM; |
328 | print $fh join "", map $ANIM{$_}, sort keys %ANIM |
282 | } |
329 | } |
283 | |
330 | |
284 | { |
331 | { |
285 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
332 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
286 | or die "$DATADIR/archetypes~: $!"; |
333 | or die "$DATADIR/archetypes~: $!"; |
|
|
334 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
287 | print $fh Crossfire::archlist_to_string \@ARC; |
335 | print $fh Crossfire::archlist_to_string \@ARC; |
288 | } |
336 | } |
289 | |
337 | |
290 | @PNG = sort { $a->[0] cmp $b->[0] } @PNG; |
338 | { |
291 | |
339 | open my $fh, ">:utf8", "$DATADIR/smooth~" |
|
|
340 | or die "$DATADIR/smooth~: $!"; |
|
|
341 | print $fh $SMOOTH; |
292 | { |
342 | } |
|
|
343 | |
|
|
344 | { |
|
|
345 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
|
|
346 | or die "$DATADIR/treasures~: $!"; |
|
|
347 | print $fh $TRS; |
|
|
348 | } |
|
|
349 | |
|
|
350 | { |
|
|
351 | while (my ($k, $v) = each %FACEINFO) { |
|
|
352 | $v->{data32} ||= delete $PNG32{$k}; |
|
|
353 | } |
|
|
354 | |
|
|
355 | while (my ($k, $v) = each %FACEINFO) { |
|
|
356 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
|
|
357 | |
|
|
358 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
|
|
359 | } |
|
|
360 | |
293 | open my $fh, ">:perlio", "$DATADIR/crossfire.0~" |
361 | open my $fh, ">:perlio", "$DATADIR/faces~" |
294 | or die "$DATADIR/crossfire.0~: $!"; |
362 | or die "$DATADIR/faces~: $!"; |
295 | printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1] |
|
|
296 | for 0.. $#PNG; |
|
|
297 | } |
|
|
298 | |
363 | |
299 | rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; |
364 | print $fh Storable::nfreeze \%FACEINFO; |
300 | rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; |
365 | } |
301 | rename "$DATADIR/animations~" , "$DATADIR/animations"; |
|
|
302 | |
366 | |
303 | die "--install-arch not fully implemented\n"; |
367 | for (qw(archetypes faces animations treasures smooth)) { |
|
|
368 | chmod 0644, "$DATADIR/$_~"; |
|
|
369 | rename "$DATADIR/$_~", "$DATADIR/$_"; |
|
|
370 | } |
304 | } |
371 | } |
305 | } |
372 | } |
306 | |
373 | |
307 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
374 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
308 | GetOptions ( |
375 | GetOptions ( |