--- deliantra/server/utils/cfutil.in 2007/08/19 09:27:08 1.53 +++ deliantra/server/utils/cfutil.in 2007/12/17 08:03:22 1.63 @@ -16,6 +16,8 @@ use Getopt::Long; use Coro::Event; use AnyEvent; +use YAML::Syck (); +use JSON::XS (); use IO::AIO (); use File::Temp; use Crossfire; @@ -23,7 +25,6 @@ use Coro::AIO; use Coro::Util; use POSIX (); -use Digest::MD5; use Carp; use Coro::Channel; use Coro::Storable; $Storable::canonical = 1; @@ -99,7 +100,10 @@ exit 1 unless $FORCE; } - system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" + system $RSYNC, "-av", "--chmod=u=rwX,go=rX", + "$path/.", "$DATADIR/maps/.", + "--exclude", "CVS", "--exclude", "/world-precomposed", + "--delete", "--delete-excluded" and die "map installation failed.\n"; print "maps installed successfully.\n"; @@ -172,6 +176,16 @@ next; } + (my $base = $stem) =~ s/^.*\///; + + my $fi = $FACEINFO{$base}; + unless ($fi) { + #warn "$path: <$base> not referenced by any archetype, skipping.\n"; + #next; + } + + my $arc = $fi->{arc} || { }; + unless ($path =~ /~$/) { # possibly enlarge if (0 > aio_stat "$stem.64x64.png") { @@ -182,43 +196,59 @@ my $CROP; my $SRC = "png:\Q$path\E"; - # check if this is a wall. ultra-ugly. ultra-ultra-ugly. - if ($path =~ /^(.*\/wall\/.*_)([0-9A-F])(\.x11.*\.png)$/) { - my ($pfx, $dir, $sfx) = ($1, hex $2, $3); - #check for 0..F images to be sure(?) this is a wall - unless (grep { !-e sprintf "%s%X%s", $pfx, $_, $sfx } 0..15) { - # add a 4px border and add other images around it - $CROP = "-shave 8x8 +repage"; - - $w += 8; - $h += 8; - - $SRC = "-size ${w}x${h} xc:transparent"; - $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; - - # 8 surrounding images - for ( - # x y b r0 r1 - [-1, -1, 0, 6], - [ 0, -1, 1, 10, 14], - [+1, -1, 0, 12], - - [-1, 0, 8, 5, 7], - # - [+1, 0, 2, 5, 13], - - [-1, +1, 0, 3], - [ 0, +1, 4, 10, 11], - [+1, +1, 0, 9], - ) { - my ($x, $y, $d, $r0, $r1) = @$_; - $SRC .= sprintf " png:%s%X%s -geometry %+d%+d -composite", - "\Q$pfx", - ($dir & $d) ? $r1 : $r0, - "\Q$sfx", - $x * ($w - 8) + 4, - $y * ($h - 8) + 4; - } + my $is_floor = $arc->{is_floor}; + my $is_wall = 0; + + my ($wall_pfx, $wall_dir, $wall_sfx); + + if ( + !$is_floor + && !$arc->{alive} + && $arc->{move_block} eq "all" + && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/ + ) { + ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3); + + unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) { + $is_wall = 1; + } + } + + if ($is_wall || $is_floor) { + # add a 4px border and add other images around it + $CROP = "-shave 8x8 +repage"; + + $w += 8; + $h += 8; + + $SRC = "-size ${w}x${h} xc:transparent"; + $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; + + # 8 surrounding images + for ( + # x y b r0 r1 + [-1, -1, 0, 6], + [ 0, -1, 1, 10, 14], + [+1, -1, 0, 12], + + [-1, 0, 8, 5, 7], + # + [+1, 0, 2, 5, 13], + + [-1, +1, 0, 3], + [ 0, +1, 4, 10, 11], + [+1, +1, 0, 9], + ) { + my ($x, $y, $d, $r0, $r1) = @$_; + + my $tile = $is_floor ? $path + : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx + : die; + + $SRC .= sprintf " png:%s -geometry %+d%+d -composite", + "\Q$tile", + $x * ($w - 8) + 4, + $y * ($h - 8) + 4; } } @@ -401,20 +431,27 @@ }; } - for my $face ($o->{face} || (), @{$anim || []}) { - next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; + for ($o->{face} || (), @{$anim || []}) { + next if /^facings\s/; + + my $face = $_; + $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates - my $info = $FACEINFO{$face} ||= {}; + my $info = $FACEINFO{$face} ||= { }; + $info->{arc} = $o; + + next if $face =~ /^blank.x11$|^empty.x11$/; - $info->{arc} = $o; $info->{visibility} = $visibility if defined $visibility; $info->{magicmap} = $magicmap if defined $magicmap; } if (my $smooth = delete $o->{smoothface}) { - my %kv =split /\s+/, $smooth; + my %kv = split /\s+/, $smooth; my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support while (my ($face, $smooth) = each %kv) { + $FACEINFO{$smooth}{arc} = $o; + $FACEINFO{$face}{smooth} = $smooth; $FACEINFO{$face}{smoothlevel} = $level; } @@ -464,9 +501,15 @@ my $data; aio_load "$dir/$file", $data; - my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; + my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; - next if $meta && !exists $meta->{$file}; + utf8::decode $dir; + utf8::decode $file; + + # a meta file for resources is now mandatory + unless (exists $meta->{$file}) { + warn "skipping $dir/$file\n" if $VERBOSE >= 3; + } $meta = { %{ $meta->{"" } || {} }, @@ -489,10 +532,17 @@ substr $dir, 0, 1 + length $PATH, ""; + if (my $filter = $meta->{cfutil_filter}) { + if ($filter eq "yaml2json") { + $data = JSON::XS::encode_json YAML::Syck::Load $data; + } else { + warn "$dir/$file: unknown filter $filter, skipping\n"; + } + } + $RESOURCE{"$dir/$file"} = { - type => (delete $meta->{type}) || $type, + type => (exists $meta->{type} ? delete $meta->{type} : $type), data => $data, - chksum => (Digest::MD5::md5 $data), %$meta ? (meta => $meta) : (), }; } @@ -522,10 +572,13 @@ if $file =~ /\.(wav|ogg)$/; } elsif ($dir =~ /^res(?:\/|$)/) { - $c_res->put ([$path, $file, 0]) # FT_FACE - if $file =~ /\.(jpg|png)$/; - $c_res->put ([$path, $file, 7]) # FT_RSRC - if $file =~ /\.(res)$/; + if ($file =~ /\.(jpg|png)$/) { + $c_res->put ([$path, $file, 0]) # FT_FACE + } elsif ($file =~ /\.(res)$/) { + $c_res->put ([$path, $file, 7]) # FT_RSRC + } else { + $c_res->put ([$path, $file, undef]); + } } elsif ($file =~ /\.png$/) { push @c_png, ["$path/$file", 0]; @@ -652,9 +705,6 @@ length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; - $v->{chksum32} = Digest::MD5::md5 $v->{data32}; - $v->{chksum64} = Digest::MD5::md5 $v->{data64}; - if (my $magicmap = $v->{magicmap}) { $magicmap =~ y/A-Z_\-/a-z/d; $v->{magicmap} = $COLOR{$magicmap};