--- deliantra/server/utils/cfutil.in 2007/03/07 18:04:44 1.3 +++ deliantra/server/utils/cfutil.in 2007/03/14 16:23:26 1.17 @@ -21,6 +21,8 @@ use Coro; use Coro::AIO; use POSIX (); +use Digest::MD5; +use Storable; $Storable::canonical = 1; sub usage { warn < aio_load $path, $png) { warn "$path: $!, skipping.\n"; - return; + next; } - # quickly extratc width and height of the (necessarily PNG) image + # quickly extract width and height of the (necessarily PNG) image unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { warn "$path: not a recongized png file, skipping.\n"; - return; + next; } my ($w, $h) = unpack "NN", $1; @@ -116,17 +126,17 @@ unless ($face =~ s/\.base\.(...)\.png$/.$1/) { warn "$path: weird filename, skipping.\n"; - return; + next; } if ($w < $T || $h < $T) { warn "$path: too small ($w $h), skipping.\n"; - return; + next; } if ($w % $T || $h % $T) { warn "$path: weird png size ($w $h), skipping.\n"; - return; + next; } if (($w > $T || $h > $T) && $face !~ /_S\./) { @@ -151,6 +161,7 @@ "(", "+clone", -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), + "+repage", -write => "png:$_->[2]~", "+delete", ")", @@ -193,13 +204,85 @@ my $arc; aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ + my $arc = read_arch "$dir/$file"; + for my $o (values %$arc) { + push @ARC, $o; + + $o->{editor_folder} = $dir; + + my $visibility = delete $o->{visibility}; + my $magicmap = delete $o->{magicmap}; + + # find upper left corner :/ + # omg, this is sooo broken + my ($dx, $dy); + for (my $o = $o; $o; $o = $o->{more}) { + $dx = $o->{x} if $o->{x} < $dx; + $dy = $o->{y} if $o->{y} < $dy; + } + + for (my $o = $o; $o; $o = $o->{more}) { + my $x = $o->{x} - $dx; + my $y = $o->{y} - $dy; + + my $ext = $x|$y ? "+$x+$y" : ""; + + $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; + + my $visibility = delete $o->{visibility} if exists $o->{visibility}; + my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; + + my $anim = delete $o->{anim}; + + if ($anim) { + $o->{animation} = "$o->{_name}"; + + for (@$anim) { + $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; + } + + $ANIM{"$o->{_name}$ext"} = + join "", map "$_\n", + "anim $o->{_name}", + @$anim, + "mina"; + } + + for my $face ($o->{face} || (), @{$anim || []}) { + next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; + + my $info = $FACEINFO{$face} ||= {}; + + $info->{visibility} = $visibility if defined $visibility; + $info->{magicmap} = $magicmap if defined $magicmap; + } + + if (my $smooth = delete $o->{smoothface}) { + my ($face, $smooth) = split /\s+/, $smooth; + # skip empty_S.x11, it seems to server no purpose whatsoever + # but increases bandwidth demands and worse. + unless ($smooth eq "empty_S.x11") { + $FACEINFO{$face}{smooth} = $smooth; + } + } + } + } } } sub process_trs { while (@trs) { my ($dir, $file) = @{pop @trs}; + my $path = "$dir/$file"; + + my $trs; + if (0 > aio_load $path, $trs) { + warn "$path: $!, skipping.\n"; + next; + } + + $TRS .= $trs; } } @@ -231,7 +314,7 @@ sub inst_arch($) { my (undef, $path) = @_; - print "installing '$path' to '$DATADIR'\n\n"; + print "installing '$path' to '$DATADIR'\n"; if (!-d "$path/treasures") { warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; @@ -247,7 +330,50 @@ (async \&process_arc), (async \&process_arc), ); - die "--install-arch not yet implemented\n"; + { + open my $fh, ">:utf8", "$DATADIR/animations~" + or die "$DATADIR/animations~: $!"; + print $fh join "", map $ANIM{$_}, sort keys %ANIM + } + + { + open my $fh, ">:utf8", "$DATADIR/archetypes~" + or die "$DATADIR/archetypes~: $!"; + substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; + print $fh Crossfire::archlist_to_string \@ARC; + } + + { + open my $fh, ">:utf8", "$DATADIR/treasures~" + or die "$DATADIR/treasures~: $!"; + print $fh $TRS; + } + + { + while (my ($k, $v) = each %FACEINFO) { + $v->{data32} ||= delete $PNG32{$k}; + } + + while (my ($k, $v) = each %FACEINFO) { + length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; + + $v->{chksum32} = Digest::MD5::md5 $v->{data32}; + } + + open my $fh, ">:perlio", "$DATADIR/faces~" + or die "$DATADIR/faces~: $!"; + + $FACEINFO{""} = { version => 1}; + print $fh Storable::nfreeze \%FACEINFO; + } + + for (qw(archetypes faces animations treasures)) { + chmod 0644, "$DATADIR/$_~"; + rename "$DATADIR/$_~", "$DATADIR/$_" + or die "$DATADIR/$_: $!"; + } + + print "archetype data installed successfully.\n"; } }