… | |
… | |
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 | use Digest::MD5; |
|
|
25 | use Storable; $Storable::canonical = 1; |
25 | |
26 | |
26 | sub usage { |
27 | sub usage { |
27 | warn <<EOF; |
28 | warn <<EOF; |
28 | Usage: cfutil [-v] [-q] [--force] [--cache] |
29 | Usage: cfutil [-v] [-q] [--force] [--cache] |
29 | [--install-arch path] |
30 | [--install-arch path] |
… | |
… | |
67 | } |
68 | } |
68 | |
69 | |
69 | sub inst_maps($) { |
70 | sub inst_maps($) { |
70 | my (undef, $path) = @_; |
71 | my (undef, $path) = @_; |
71 | |
72 | |
72 | print "installing '$path' to '$DATADIR/maps'\n\n"; |
73 | print "installing '$path' to '$DATADIR/maps'\n"; |
73 | |
74 | |
74 | if (!-f "$path/regions") { |
75 | if (!-f "$path/regions") { |
75 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
76 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
76 | exit 1 unless $FORCE; |
77 | exit 1 unless $FORCE; |
77 | } |
78 | } |
78 | |
79 | |
79 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; |
80 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
|
|
81 | and die "map installation failed.\n"; |
|
|
82 | |
|
|
83 | print "maps installed successfully.\n"; |
80 | } |
84 | } |
81 | |
85 | |
82 | { |
86 | { |
83 | our %PNG32; |
87 | our %PNG32; |
84 | our %FACEINFO; |
88 | our %FACEINFO; |
85 | our @ARC; |
89 | our @ARC; |
86 | our $TRS; |
90 | our $TRS; |
87 | our $NFILE; |
91 | our $NFILE; |
88 | our %ANIM; |
92 | our %ANIM; |
89 | our $SMOOTH; |
|
|
90 | |
93 | |
91 | our (@png, @trs, @arc); # files we are interested in |
94 | our (@png, @trs, @arc); # files we are interested in |
92 | |
95 | |
93 | sub commit_png { |
96 | sub commit_png { |
94 | my ($name, $data) = @_; |
97 | my ($name, $data) = @_; |
… | |
… | |
119 | my ($w, $h) = unpack "NN", $1; |
122 | my ($w, $h) = unpack "NN", $1; |
120 | |
123 | |
121 | (my $face = $path) =~ s/^.*\///; |
124 | (my $face = $path) =~ s/^.*\///; |
122 | my $T = 32; |
125 | my $T = 32; |
123 | |
126 | |
124 | unless ($face =~ s/\.base\.(...)\.png$/.$1/) { |
127 | unless ($face =~ s/\.32x32\.png$//) { |
125 | warn "$path: weird filename, skipping.\n"; |
128 | warn "$path: weird filename, skipping.\n"; |
126 | next; |
129 | next; |
127 | } |
130 | } |
128 | |
131 | |
129 | if ($w < $T || $h < $T) { |
132 | if ($w < $T || $h < $T) { |
… | |
… | |
254 | $info->{visibility} = $visibility if defined $visibility; |
257 | $info->{visibility} = $visibility if defined $visibility; |
255 | $info->{magicmap} = $magicmap if defined $magicmap; |
258 | $info->{magicmap} = $magicmap if defined $magicmap; |
256 | } |
259 | } |
257 | |
260 | |
258 | if (my $smooth = delete $o->{smoothface}) { |
261 | if (my $smooth = delete $o->{smoothface}) { |
259 | $SMOOTH .= "$smooth\n"; |
262 | my ($face, $smooth) = split /\s+/, $smooth; |
|
|
263 | # skip empty_S.x11, it seems to server no purpose whatsoever |
|
|
264 | # but increases bandwidth demands and worse. |
|
|
265 | unless ($smooth eq "empty_S.x11") { |
|
|
266 | $FACEINFO{$face}{smooth} = $smooth; |
|
|
267 | } |
260 | } |
268 | } |
261 | } |
269 | } |
262 | } |
270 | } |
263 | } |
271 | } |
264 | } |
272 | } |
… | |
… | |
304 | } |
312 | } |
305 | |
313 | |
306 | sub inst_arch($) { |
314 | sub inst_arch($) { |
307 | my (undef, $path) = @_; |
315 | my (undef, $path) = @_; |
308 | |
316 | |
309 | print "installing '$path' to '$DATADIR'\n\n"; |
317 | print "installing '$path' to '$DATADIR'\n"; |
310 | |
318 | |
311 | if (!-d "$path/treasures") { |
319 | if (!-d "$path/treasures") { |
312 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
320 | warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
313 | exit 1 unless $FORCE; |
321 | exit 1 unless $FORCE; |
314 | } |
322 | } |
… | |
… | |
334 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
342 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
335 | print $fh Crossfire::archlist_to_string \@ARC; |
343 | print $fh Crossfire::archlist_to_string \@ARC; |
336 | } |
344 | } |
337 | |
345 | |
338 | { |
346 | { |
339 | open my $fh, ">:utf8", "$DATADIR/smooth~" |
|
|
340 | or die "$DATADIR/smooth~: $!"; |
|
|
341 | print $fh $SMOOTH; |
|
|
342 | } |
|
|
343 | |
|
|
344 | { |
|
|
345 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
347 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
346 | or die "$DATADIR/treasures~: $!"; |
348 | or die "$DATADIR/treasures~: $!"; |
347 | print $fh $TRS; |
349 | print $fh $TRS; |
348 | } |
350 | } |
349 | |
351 | |
… | |
… | |
359 | } |
361 | } |
360 | |
362 | |
361 | open my $fh, ">:perlio", "$DATADIR/faces~" |
363 | open my $fh, ">:perlio", "$DATADIR/faces~" |
362 | or die "$DATADIR/faces~: $!"; |
364 | or die "$DATADIR/faces~: $!"; |
363 | |
365 | |
|
|
366 | $FACEINFO{""} = { version => 1}; |
364 | print $fh Storable::nfreeze \%FACEINFO; |
367 | print $fh Storable::nfreeze \%FACEINFO; |
365 | } |
368 | } |
366 | |
369 | |
367 | for (qw(archetypes faces animations treasures smooth)) { |
370 | for (qw(archetypes faces animations treasures)) { |
368 | chmod 0644, "$DATADIR/$_~"; |
371 | chmod 0644, "$DATADIR/$_~"; |
369 | rename "$DATADIR/$_~", "$DATADIR/$_"; |
372 | rename "$DATADIR/$_~", "$DATADIR/$_" |
|
|
373 | or die "$DATADIR/$_: $!"; |
370 | } |
374 | } |
|
|
375 | |
|
|
376 | print "archetype data installed successfully.\n"; |
371 | } |
377 | } |
372 | } |
378 | } |
373 | |
379 | |
374 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
380 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
375 | GetOptions ( |
381 | GetOptions ( |