ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/utils/cfutil.in
(Generate patch)

Comparing deliantra/server/utils/cfutil.in (file contents):
Revision 1.24 by root, Thu Apr 12 14:18:06 2007 UTC vs.
Revision 1.30 by root, Sat Apr 21 11:55:36 2007 UTC

20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5; 24use Digest::MD5;
25use Storable; $Storable::canonical = 1; 25use Coro::Storable; $Storable::canonical = 1;
26 26
27sub usage { 27sub usage {
28 warn <<EOF; 28 warn <<EOF;
29Usage: cfutil [-v] [-q] [--force] [--cache] 29Usage: cfutil [-v] [-q] [--force] [--cache]
30 [--install-arch path] 30 [--install-arch path]
68} 68}
69 69
70sub inst_maps($) { 70sub inst_maps($) {
71 my (undef, $path) = @_; 71 my (undef, $path) = @_;
72 72
73 print "installing '$path' to '$DATADIR/maps'\n"; 73 print "\nInstalling '$path' to '$DATADIR/maps'\n\n";
74 74
75 if (!-f "$path/regions") { 75 if (!-f "$path/regions") {
76 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";
77 exit 1 unless $FORCE; 77 exit 1 unless $FORCE;
78 } 78 }
85 85
86{ 86{
87 our %ANIMINFO; 87 our %ANIMINFO;
88 our %FACEINFO; 88 our %FACEINFO;
89 our @ARC; 89 our @ARC;
90 our %ARC;
90 our $TRS; 91 our $TRS;
91 our $NFILE; 92 our $NFILE;
92 93
93 our $QUANTIZE = "+dither -colorspace RGB -colors 256"; 94 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
94 95
256 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 257 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
257 258
258 my $arc = read_arch "$dir/$file"; 259 my $arc = read_arch "$dir/$file";
259 for my $o (values %$arc) { 260 for my $o (values %$arc) {
260 push @ARC, $o; 261 push @ARC, $o;
262 for (my $m = $o; $m; $m = $m->{more}) {
263 $ARC{$m->{_name}} = $m;
264 }
261 265
262 $o->{editor_folder} = $dir; 266 $o->{editor_folder} = $dir;
263 267
264 my $visibility = delete $o->{visibility}; 268 my $visibility = delete $o->{visibility};
265 my $magicmap = delete $o->{magicmap}; 269 my $magicmap = delete $o->{magicmap};
276 my $x = $o->{x} - $dx; 280 my $x = $o->{x} - $dx;
277 my $y = $o->{y} - $dy; 281 my $y = $o->{y} - $dy;
278 282
279 my $ext = $x|$y ? "+$x+$y" : ""; 283 my $ext = $x|$y ? "+$x+$y" : "";
280 284
281 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; 285 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
282 286
283 my $visibility = delete $o->{visibility} if exists $o->{visibility}; 287 my $visibility = delete $o->{visibility} if exists $o->{visibility};
284 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 288 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
285 289
286 my $anim = delete $o->{anim}; 290 my $anim = delete $o->{anim};
372 } 376 }
373 377
374 sub inst_arch($) { 378 sub inst_arch($) {
375 my (undef, $path) = @_; 379 my (undef, $path) = @_;
376 380
381 print "\n",
377 print "installing '$path' to '$DATADIR'\n", 382 "Installing '$path' to '$DATADIR'\n",
383 "\n",
378 "(this can take a long time if you run this\n", 384 "This can take a long time if you run this\n",
379 "for the first time or do not use --cache).\n"; 385 "for the first time or do not use --cache.\n",
386 "\n",
387 "Unless you run verbosely, all following warning\n",
388 "or error messages indicate serious problems.\n",
389 "\n";
380 390
381 if (!-d "$path/treasures") { 391 if (!-d "$path/treasures") {
382 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 392 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n";
383 exit 1 unless $FORCE; 393 exit 1 unless $FORCE;
384 } 394 }
392 (async \&process_trs), (async \&process_trs), 402 (async \&process_trs), (async \&process_trs),
393 (async \&process_arc), (async \&process_arc), 403 (async \&process_arc), (async \&process_arc),
394 ); 404 );
395 405
396 { 406 {
407 # remove path prefix from editor_folder
408 substr $_->{editor_folder}, 0, 1 + length $path, ""
409 for values %ARC;
410
411 # resolve inherit
412 while () {
413 my $progress;
414 my $loop;
415
416 for my $o (values %ARC) {
417 if (my $other = $o->{inherit}) {
418 if (my $s = $ARC{$other}) {
419 if ($s->{inherit}) {
420 $loop = $s;
421 } else {
422 delete $o->{inherit};
423 my %s = %$s;
424 delete @s{qw(_name more name name_pl)};
425 %$o = ( %s, %$o );
426 ++$progress;
427 }
428 } else {
429 warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n";
430 delete $ARC{$o->{_name}};
431 }
432 }
433 }
434
435 unless ($progress) {
436 die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n"
437 if $loop;
438
439 last;
440 }
441 }
442
397 open my $fh, ">:utf8", "$DATADIR/archetypes~" 443 open my $fh, ">:utf8", "$DATADIR/archetypes~"
398 or die "$DATADIR/archetypes~: $!"; 444 or die "$DATADIR/archetypes~: $!";
399 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; 445 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC];
400 print $fh Crossfire::archlist_to_string \@ARC;
401 } 446 }
402 447
403 { 448 {
404 open my $fh, ">:utf8", "$DATADIR/treasures~" 449 open my $fh, ">:utf8", "$DATADIR/treasures~"
405 or die "$DATADIR/treasures~: $!"; 450 or die "$DATADIR/treasures~: $!";
419 } 464 }
420 465
421 open my $fh, ">:perlio", "$DATADIR/facedata~" 466 open my $fh, ">:perlio", "$DATADIR/facedata~"
422 or die "$DATADIR/facedata~: $!"; 467 or die "$DATADIR/facedata~: $!";
423 468
424 print $fh Storable::nfreeze { 469 print $fh freeze {
425 version => 2, 470 version => 2,
426 faceinfo => \%FACEINFO, 471 faceinfo => \%FACEINFO,
427 animinfo => \%ANIMINFO, 472 animinfo => \%ANIMINFO,
428 }; 473 };
429 } 474 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines