… | |
… | |
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; |
84 | our $NFILE; |
86 | our $NFILE; |
85 | our @FACE; |
|
|
86 | our $ANIM; |
87 | our %ANIM; |
87 | |
88 | |
88 | our (@png, @trs, @arc); # files we are interested in |
89 | our (@png, @trs, @arc); # files we are interested in |
89 | |
90 | |
90 | sub commit_png { |
91 | sub commit_png { |
91 | my ($name, $data) = @_; |
92 | my ($name, $data) = @_; |
92 | |
93 | |
93 | push @PNG, [$name => $data]; |
94 | $PNG32{$name} = $data; |
|
|
95 | $FACEINFO{$name} ||= {}; |
94 | } |
96 | } |
95 | |
97 | |
96 | sub process_png { |
98 | sub process_png { |
97 | while (@png) { |
99 | while (@png) { |
98 | my $path = pop @png; |
100 | my $path = pop @png; |
… | |
… | |
104 | if (0 > aio_load $path, $png) { |
106 | if (0 > aio_load $path, $png) { |
105 | warn "$path: $!, skipping.\n"; |
107 | warn "$path: $!, skipping.\n"; |
106 | next; |
108 | next; |
107 | } |
109 | } |
108 | |
110 | |
109 | # quickly extratc width and height of the (necessarily PNG) image |
111 | # quickly extract width and height of the (necessarily PNG) image |
110 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
112 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
111 | warn "$path: not a recongized png file, skipping.\n"; |
113 | warn "$path: not a recongized png file, skipping.\n"; |
112 | next; |
114 | next; |
113 | } |
115 | } |
114 | |
116 | |
… | |
… | |
147 | my @todo = grep { $_->[3] <= $mtime } @tile; |
149 | my @todo = grep { $_->[3] <= $mtime } @tile; |
148 | if (@todo) { |
150 | if (@todo) { |
149 | fork_sub { |
151 | fork_sub { |
150 | open my $convert, "|-", $CONVERT, |
152 | open my $convert, "|-", $CONVERT, |
151 | "png:-", |
153 | "png:-", |
152 | -negate,#d# |
|
|
153 | (map { |
154 | (map { |
154 | ( |
155 | ( |
155 | "(", |
156 | "(", |
156 | "+clone", |
157 | "+clone", |
157 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
158 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
|
|
159 | "+repage", |
158 | -write => "png:$_->[2]~", |
160 | -write => "png:$_->[2]~", |
159 | "+delete", |
161 | "+delete", |
160 | ")", |
162 | ")", |
161 | ) |
163 | ) |
162 | } @todo), |
164 | } @todo), |
… | |
… | |
199 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
201 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
200 | |
202 | |
201 | my $arc = read_arch "$dir/$file"; |
203 | my $arc = read_arch "$dir/$file"; |
202 | for my $o (values %$arc) { |
204 | for my $o (values %$arc) { |
203 | push @ARC, $o; |
205 | push @ARC, $o; |
|
|
206 | |
|
|
207 | my $visibility = delete $o->{visibility}; |
|
|
208 | my $magicmap = delete $o->{magicmap}; |
|
|
209 | |
|
|
210 | # find upper left corner :/ |
|
|
211 | # omg, this is sooo broken |
204 | my ($dx, $dy); |
212 | my ($dx, $dy); |
205 | # omg, this is sooo broken |
|
|
206 | for (my $o = $o; $o; $o = $o->{more}) { |
213 | for (my $o = $o; $o; $o = $o->{more}) { |
207 | $dx = $o->{x} if $o->{x} < $dx; |
214 | $dx = $o->{x} if $o->{x} < $dx; |
208 | $dy = $o->{y} if $o->{y} < $dy; |
215 | $dy = $o->{y} if $o->{y} < $dy; |
209 | } |
216 | } |
|
|
217 | |
210 | for (my $o = $o; $o; $o = $o->{more}) { |
218 | for (my $o = $o; $o; $o = $o->{more}) { |
211 | my $x = $o->{x} - $dx; |
219 | my $x = $o->{x} - $dx; |
212 | my $y = $o->{y} - $dy; |
220 | my $y = $o->{y} - $dy; |
|
|
221 | |
|
|
222 | my $ext = $x|$y ? "+$x+$y" : ""; |
|
|
223 | |
|
|
224 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; |
|
|
225 | |
|
|
226 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
|
|
227 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
228 | |
|
|
229 | my $anim = delete $o->{anim}; |
|
|
230 | |
213 | if ($x|$y) { |
231 | if ($anim) { |
214 | $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; |
232 | $o->{animation} = "$o->{_name}"; |
|
|
233 | |
|
|
234 | for (@$anim) { |
|
|
235 | $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; |
|
|
236 | } |
|
|
237 | |
|
|
238 | $ANIM{"$o->{_name}$ext"} = |
|
|
239 | join "", map "$_\n", |
|
|
240 | "anim $o->{_name}", |
|
|
241 | @$anim, |
|
|
242 | "mina"; |
215 | } |
243 | } |
|
|
244 | |
|
|
245 | for my $face ($o->{face} || (), @{$anim || []}) { |
|
|
246 | next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; |
|
|
247 | |
|
|
248 | my $info = $FACEINFO{$face} ||= {}; |
|
|
249 | |
|
|
250 | $info->{visibility} = $visibility if defined $visibility; |
|
|
251 | $info->{magicmap} = $magicmap if defined $magicmap; |
216 | } |
252 | } |
217 | if (my $anim = delete $o->{anim}) { |
|
|
218 | $o->{animation} = $o->{_name}; |
|
|
219 | $ANIM .= join "", map "$_\n", |
|
|
220 | "anim $o->{_name}", |
|
|
221 | @$anim, |
|
|
222 | "mina"; |
|
|
223 | } |
253 | } |
224 | } |
254 | } |
225 | } |
255 | } |
226 | } |
256 | } |
227 | |
257 | |
… | |
… | |
276 | ); |
306 | ); |
277 | |
307 | |
278 | { |
308 | { |
279 | open my $fh, ">:utf8", "$DATADIR/animations~" |
309 | open my $fh, ">:utf8", "$DATADIR/animations~" |
280 | or die "$DATADIR/animations~: $!"; |
310 | or die "$DATADIR/animations~: $!"; |
281 | print $fh $ANIM; |
311 | print $fh join "", map $ANIM{$_}, sort keys %ANIM |
282 | } |
312 | } |
283 | |
313 | |
284 | { |
314 | { |
285 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
315 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
286 | or die "$DATADIR/archetypes~: $!"; |
316 | or die "$DATADIR/archetypes~: $!"; |
287 | print $fh Crossfire::archlist_to_string \@ARC; |
317 | print $fh Crossfire::archlist_to_string \@ARC; |
288 | } |
318 | } |
289 | |
319 | |
290 | @PNG = sort { $a->[0] cmp $b->[0] } @PNG; |
|
|
291 | |
|
|
292 | { |
320 | { |
|
|
321 | while (my ($k, $v) = each %FACEINFO) { |
|
|
322 | $v->{data32} ||= delete $PNG32{$k}; |
|
|
323 | } |
|
|
324 | |
|
|
325 | while (my ($k, $v) = each %FACEINFO) { |
|
|
326 | length $v->{data32} or warn "$k: face has no png32. this will crash the server.\n"; |
|
|
327 | |
|
|
328 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
|
|
329 | } |
|
|
330 | |
293 | open my $fh, ">:perlio", "$DATADIR/crossfire.0~" |
331 | open my $fh, ">:perlio", "$DATADIR/faces~" |
294 | or die "$DATADIR/crossfire.0~: $!"; |
332 | 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 | |
333 | |
299 | rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; |
334 | print $fh Storable::nfreeze \%FACEINFO; |
300 | rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; |
335 | |
301 | rename "$DATADIR/animations~" , "$DATADIR/animations"; |
336 | #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO; |
|
|
337 | } |
|
|
338 | |
|
|
339 | for (qw(archetypes faces animations)) { |
|
|
340 | chmod 0644, "$DATADIR/$_~"; |
|
|
341 | rename "$DATADIR/$_~", "$DATADIR/$_"; |
|
|
342 | } |
302 | |
343 | |
303 | die "--install-arch not fully implemented\n"; |
344 | die "--install-arch not fully implemented\n"; |
304 | } |
345 | } |
305 | } |
346 | } |
306 | |
347 | |