--- deliantra/server/utils/cfutil.in 2007/03/07 20:30:18 1.4 +++ deliantra/server/utils/cfutil.in 2007/03/11 02:12:45 1.6 @@ -21,6 +21,7 @@ use Coro; use Coro::AIO; use POSIX (); +use Digest::MD5; 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 +121,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\./) { @@ -197,17 +202,52 @@ my $arc = read_arch "$dir/$file"; for my $o (values %$arc) { push @ARC, $o; - my ($dx, $dy); + + 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; - if ($x|$y) { - $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; + + my $ext = $x|$y ? "+$x+$y" : ""; + + $o->{face} .= $ext; + + 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}$ext"; + + for (@$anim) { + $_ .= $ext unless /^facings\s/; + } + + $ANIM{"$o->{_name}$ext"} = + join "", map "$_\n", + "anim $o->{_name}$ext", + @$anim, + "mina"; + } + + for my $face ($o->{face} || (), @{$anim || []}) { + next if /^facings\s/; + + my $info = $FACEINFO{$face} ||= {}; + + $info->{visibility} = $visibility if defined $visibility; + $info->{magicmap} = $magicmap if defined $magicmap; } } } @@ -264,11 +304,41 @@ (async \&process_arc), (async \&process_arc), ); - open my $archetypes, ">:utf8", "$DATADIR/archetypes~" - or die "$DATADIR/archetypes~: $!"; - print $archetypes Crossfire::archlist_to_string \@ARC; - close $archetypes; - rename "$DATADIR/archetypes~", "$DATADIR/archetypes"; + { + 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~: $!"; + print $fh Crossfire::archlist_to_string \@ARC; + } + + { + while (my ($k, $v) = each %FACEINFO) { + $v->{data32} ||= delete $PNG32{$k}; + } + + while (my ($k, $v) = each %FACEINFO) { + exists $v->{data32} or warn "$k: face has no png32. this will crash the server.\n"; + + $v->{chksum32} = Digest::MD5::md5 $v->{data32}; + } + + open my $fh, ">:perlio", "$DATADIR/faces~" + or die "$DATADIR/faces~: $!"; + + print $fh Storable::nfreeze \%FACEINFO; + + #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO; + } + + for (qw(archetypes faces animations)) { + chmod 0644, "$DATADIR/$_~"; + rename "$DATADIR/$_~", "$DATADIR/$_"; + } die "--install-arch not fully implemented\n"; }