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.82 by root, Sat Apr 3 22:30:21 2010 UTC vs.
Revision 1.91 by root, Tue Oct 5 23:52:52 2010 UTC

20# <http://www.gnu.org/licenses/>. 20# <http://www.gnu.org/licenses/>.
21# 21#
22# The authors can be reached via e-mail to <support@deliantra.net> 22# The authors can be reached via e-mail to <support@deliantra.net>
23# 23#
24 24
25use strict; 25use common::sense;
26 26
27my $prefix = "@prefix@"; 27my $prefix = "@prefix@";
28my $exec_prefix = "@exec_prefix@"; 28my $exec_prefix = "@exec_prefix@";
29my $datarootdir = "@datarootdir@"; 29my $datarootdir = "@datarootdir@";
30my $DATADIR = "@datadir@/@PACKAGE@"; 30my $DATADIR = "@datadir@/@PACKAGE@";
74my $VERBOSE = 1; 74my $VERBOSE = 1;
75my $CACHE = 0; 75my $CACHE = 0;
76my $FORCE; 76my $FORCE;
77my $TMPDIR = "/tmp/cfutil$$~"; 77my $TMPDIR = "/tmp/cfutil$$~";
78my $TMPFILE = "aaaa0"; 78my $TMPFILE = "aaaa0";
79my @COMMIT;
79 80
80our %COLOR = ( 81our %COLOR = (
81 black => 0, 82 black => 0,
82 white => 1, 83 white => 1,
83 navy => 2, 84 navy => 2,
155 and die "map installation failed.\n"; 156 and die "map installation failed.\n";
156 157
157 print "maps installed successfully.\n"; 158 print "maps installed successfully.\n";
158} 159}
159 160
161our %WALL_SUFFIX = (
162 "0" => "⬤",
163 "1_3" => "╸",
164 "1_4" => "╺",
165 "2_1_2" => "━",
166
167 "1_2" => "╹",
168 "2_2_4" => "┛",
169 "2_2_1" => "┗",
170 "3_1" => "┻",
171
172 "1_1" => "╻",
173 "2_2_3" => "┓",
174 "2_2_2" => "┏",
175 "3_3" => "┳",
176
177 "2_1_1" => "┃",
178 "3_4" => "┫",
179 "3_2" => "┣",
180 "4" => "╋",
181);
182
183sub autoglyph {
184 my ($stem, $face) = @_;
185
186 if ($stem =~ /^wall\/|Nimwall/) {
187 while (my ($k, $v) = each %WALL_SUFFIX) {
188 return $v if $stem =~ /_$k.x11/;
189 }
190
191 "+"
192
193 } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) {
194 "."
195
196 } elsif ($stem =~ /^player\//) {
197 "\@"
198
199 } else {
200 substr $stem, 0, 1
201 }
202}
203
160{ 204{
161 our %ANIMINFO; 205 our %ANIMINFO;
162 our %FACEINFO; 206 our %FACEINFO;
163 our %RESOURCE; 207 our %RESOURCE;
164 our @ARC; 208 our @ARC;
173 our $c_trs = new Coro::Channel; 217 our $c_trs = new Coro::Channel;
174 our $c_res = new Coro::Channel; 218 our $c_res = new Coro::Channel;
175 219
176 our @c_png; 220 our @c_png;
177 221
178 sub commit_png($$$) { 222 sub commit_png($$$$) {
179 my ($name, $data, $T) = @_; 223 my ($stem, $name, $data, $T) = @_;
180 224
225 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH;
181 $FACEINFO{$name}{"data$T"} = $data; 226 $FACEINFO{$name}{"data$T"} = $data;
182 } 227 }
183 228
184 sub process_png { 229 sub process_png {
185 while (@c_png) { 230 while (@c_png) {
403 448
404 if (0 > aio_load $file, $tile) { 449 if (0 > aio_load $file, $tile) {
405 die "$path: unable to read tile +$x+$y, aborting.\n"; 450 die "$path: unable to read tile +$x+$y, aborting.\n";
406 } 451 }
407 IO::AIO::aio_unlink $file unless $CACHE; 452 IO::AIO::aio_unlink $file unless $CACHE;
408 commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; 453 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T;
409 } 454 }
410 } else { 455 } else {
411 # use as-is (either small, use smooth) 456 # use as-is (either small, use smooth)
412 commit_png $face, $png, $T; 457 commit_png $stem, $face, $png, $T;
413 } 458 }
414 459
415 aio_unlink $path if $delete; 460 aio_unlink $path if $delete;
416 } 461 }
417 } 462 }
432 477
433 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge 478 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge
434 479
435 my $visibility = delete $o->{visibility}; 480 my $visibility = delete $o->{visibility};
436 my $magicmap = delete $o->{magicmap}; 481 my $magicmap = delete $o->{magicmap};
482 my $glyph = delete $o->{glyph};
437 483
438 # find upper left corner :/ 484 # find upper left corner :/
439 # omg, this is sooo broken 485 # omg, this is sooo broken
440 my ($dx, $dy); 486 my ($dx, $dy);
441 for (my $o = $o; $o; $o = $o->{more}) { 487 for (my $o = $o; $o; $o = $o->{more}) {
451 497
452 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; 498 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
453 499
454 $visibility = delete $o->{visibility} if exists $o->{visibility}; 500 $visibility = delete $o->{visibility} if exists $o->{visibility};
455 $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 501 $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
502 $glyph = delete $o->{glyph} if exists $o->{glyph};
456 503
457 my $anim = delete $o->{anim}; 504 my $anim = delete $o->{anim};
458 505
459 if ($anim) { 506 if ($anim) {
460 # possibly add $ext to the animation name to avoid 507 # possibly add $ext to the animation name to avoid
491 538
492 next if $face =~ /^blank.x11$|^empty.x11$/; 539 next if $face =~ /^blank.x11$|^empty.x11$/;
493 540
494 $info->{visibility} = $visibility if defined $visibility; 541 $info->{visibility} = $visibility if defined $visibility;
495 $info->{magicmap} = $magicmap if defined $magicmap; 542 $info->{magicmap} = $magicmap if defined $magicmap;
543 $info->{glyph} = $glyph if defined $glyph;
496 } 544 }
497 545
498 if (my $smooth = delete $o->{smoothface}) { 546 if (my $smooth = delete $o->{smoothface}) {
499 my %kv = split /\s+/, $smooth; 547 my %kv = split /\s+/, $smooth;
500 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 548 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
569 if ($meta->{license} =~ s/^#//) { 617 if ($meta->{license} =~ s/^#//) {
570 $meta->{license} = ({ 618 $meta->{license} = ({
571 "pd" => "Public Domain", 619 "pd" => "Public Domain",
572 "gpl" => "GNU General Public License, version 3.0 or any later", 620 "gpl" => "GNU General Public License, version 3.0 or any later",
573 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", 621 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
622 "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/",
574 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", 623 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/",
575 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", 624 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
576 })->{$meta->{license}} 625 })->{$meta->{license}}
577 || warn "$dir/$file: license tag '$meta->{license}' not found."; 626 || warn "$dir/$file: license tag '$meta->{license}' not found.";
627 }
628
629 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
630 ($meta->{author} = $1) =~ s/_/ /g;
578 } 631 }
579 632
580 $file =~ s/\.res$//; 633 $file =~ s/\.res$//;
581 $file =~ s/\.(ogg|wav|jpg|png)$//; 634 $file =~ s/\.(ogg|wav|jpg|png)$//;
582 635
795 if (my $magicmap = $v->{magicmap}) { 848 if (my $magicmap = $v->{magicmap}) {
796 $magicmap =~ y/A-Z_\-/a-z/d; 849 $magicmap =~ y/A-Z_\-/a-z/d;
797 $v->{magicmap} = $COLOR{$magicmap}; 850 $v->{magicmap} = $COLOR{$magicmap};
798 } 851 }
799 852
853 my $stem = delete $v->{stem};
854 $v->{glyph} //= autoglyph $stem, $v;
855 $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph};
856
800 delete $v->{arc}; 857 delete $v->{arc};
801 } 858 }
802 859
803 print "processing resources...\n" if $VERBOSE; 860 print "processing resources...\n" if $VERBOSE;
804 my $enc = JSON::XS->new->utf8->canonical->relaxed; 861 my $enc = JSON::XS->new->utf8->canonical->relaxed;
805 while (my ($k, $v) = each %RESOURCE) { 862 while (my ($k, $v) = each %RESOURCE) {
806 863
864 if ($v->{meta} && $v->{meta}{datadir}) {
865 delete $RESOURCE{$k};
866
867 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
868
869 printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE;
870 open my $fh, ">:raw", "$DATADIR/$k~"
871 or die "$DATADIR/$k~: $!";
872 syswrite $fh, $v->{data};
873 push @COMMIT, $k;
874
875 } else {
807 if ($v->{type} & 1) { 876 if ($v->{type} & 1) {
808 # prepend meta info 877 # prepend meta info
809 878
810 my $meta = $enc->encode ({ 879 my $meta = $enc->encode ({
811 name => $k, 880 name => $k,
812 %{ $v->{meta} || {} }, 881 %{ $v->{meta} || {} },
813 }); 882 });
814 883
815 $v->{data} = pack "(w/a*)*", $meta, $v->{data}; 884 $v->{data} = pack "(w/a*)*", $meta, $v->{data};
816 } 885 }
817 886
818 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 887 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
888 }
819 } 889 }
820 890
821 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 891 printf "writing facedata (%d faces, %d anims, %d resources)...\n",
822 scalar keys %FACEINFO, 892 scalar keys %FACEINFO,
823 scalar keys %ANIMINFO, 893 scalar keys %ANIMINFO,
836 906
837 } 907 }
838 908
839 print "committing files...\n" if $VERBOSE; 909 print "committing files...\n" if $VERBOSE;
840 910
841 for (qw(archetypes facedata treasures)) { 911 for (qw(archetypes facedata treasures), @COMMIT) {
842 chmod 0644, "$DATADIR/$_~"; 912 chmod 0644, "$DATADIR/$_~";
843 rename "$DATADIR/$_~", "$DATADIR/$_" 913 rename "$DATADIR/$_~", "$DATADIR/$_"
844 or die "$DATADIR/$_: $!"; 914 or die "$DATADIR/$_: $!";
845 } 915 }
846 916

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines