--- deliantra/server/utils/cfutil.in 2007/03/08 15:19:08 1.5 +++ deliantra/server/utils/cfutil.in 2007/03/11 22:36:53 1.9 @@ -21,6 +21,7 @@ use Coro; use Coro::AIO; use POSIX (); +use Digest::MD5; sub usage { warn < $data]; + $PNG32{$name} = $data; + $FACEINFO{$name} ||= {}; } sub process_png { @@ -106,7 +108,7 @@ 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"; next; @@ -149,12 +151,12 @@ fork_sub { open my $convert, "|-", $CONVERT, "png:-", - -negate,#d# (map { ( "(", "+clone", -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), + "+repage", -write => "png:$_->[2]~", "+delete", ")", @@ -201,25 +203,53 @@ 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 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 $anim = delete $o->{anim}) { - $o->{animation} = $o->{_name}; - $ANIM .= join "", map "$_\n", - "anim $o->{_name}", - @$anim, - "mina"; } } } @@ -278,7 +308,7 @@ { open my $fh, ">:utf8", "$DATADIR/animations~" or die "$DATADIR/animations~: $!"; - print $fh $ANIM; + print $fh join "", map $ANIM{$_}, sort keys %ANIM } { @@ -287,18 +317,29 @@ print $fh Crossfire::archlist_to_string \@ARC; } - @PNG = sort { $a->[0] cmp $b->[0] } @PNG; - { - open my $fh, ">:perlio", "$DATADIR/crossfire.0~" - or die "$DATADIR/crossfire.0~: $!"; - printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1] - for 0.. $#PNG; + 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 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; } - rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; - rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; - rename "$DATADIR/animations~" , "$DATADIR/animations"; + for (qw(archetypes faces animations)) { + chmod 0644, "$DATADIR/$_~"; + rename "$DATADIR/$_~", "$DATADIR/$_"; + } die "--install-arch not fully implemented\n"; }