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.4 by root, Wed Mar 7 20:30:18 2007 UTC vs.
Revision 1.12 by root, Mon Mar 12 17:26:41 2007 UTC

19use File::Temp; 19use File::Temp;
20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5;
24 25
25sub usage { 26sub usage {
26 warn <<EOF; 27 warn <<EOF;
27Usage: cfutil [-v] [-q] [--force] [--cache] 28Usage: cfutil [-v] [-q] [--force] [--cache]
28 [--install-arch path] 29 [--install-arch path]
77 78
78 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; 79 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded";
79} 80}
80 81
81{ 82{
82 our @PNG; 83 our %PNG32;
84 our %FACEINFO;
83 our @ARC; 85 our @ARC;
86 our $TRS;
84 our $NFILE; 87 our $NFILE;
88 our %ANIM;
89 our $SMOOTH;
85 90
86 our (@png, @trs, @arc); # files we are interested in 91 our (@png, @trs, @arc); # files we are interested in
87 92
88 sub commit_png { 93 sub commit_png {
89 my ($name, $data) = @_; 94 my ($name, $data) = @_;
90 #warn "$name: commited\n"; 95
96 $PNG32{$name} = $data;
97 $FACEINFO{$name} ||= {};
91 } 98 }
92 99
93 sub process_png { 100 sub process_png {
94 while (@png) { 101 while (@png) {
95 my $path = pop @png; 102 my $path = pop @png;
98 aio_lstat $path; 105 aio_lstat $path;
99 my ($size, $mtime) = (stat _)[7,9]; 106 my ($size, $mtime) = (stat _)[7,9];
100 107
101 if (0 > aio_load $path, $png) { 108 if (0 > aio_load $path, $png) {
102 warn "$path: $!, skipping.\n"; 109 warn "$path: $!, skipping.\n";
103 return; 110 next;
104 } 111 }
105 112
106 # quickly extratc width and height of the (necessarily PNG) image 113 # quickly extract width and height of the (necessarily PNG) image
107 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 114 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
108 warn "$path: not a recongized png file, skipping.\n"; 115 warn "$path: not a recongized png file, skipping.\n";
109 return; 116 next;
110 } 117 }
111 118
112 my ($w, $h) = unpack "NN", $1; 119 my ($w, $h) = unpack "NN", $1;
113 120
114 (my $face = $path) =~ s/^.*\///; 121 (my $face = $path) =~ s/^.*\///;
115 my $T = 32; 122 my $T = 32;
116 123
117 unless ($face =~ s/\.base\.(...)\.png$/.$1/) { 124 unless ($face =~ s/\.base\.(...)\.png$/.$1/) {
118 warn "$path: weird filename, skipping.\n"; 125 warn "$path: weird filename, skipping.\n";
119 return; 126 next;
120 } 127 }
121 128
122 if ($w < $T || $h < $T) { 129 if ($w < $T || $h < $T) {
123 warn "$path: too small ($w $h), skipping.\n"; 130 warn "$path: too small ($w $h), skipping.\n";
124 return; 131 next;
125 } 132 }
126 133
127 if ($w % $T || $h % $T) { 134 if ($w % $T || $h % $T) {
128 warn "$path: weird png size ($w $h), skipping.\n"; 135 warn "$path: weird png size ($w $h), skipping.\n";
129 return; 136 next;
130 } 137 }
131 138
132 if (($w > $T || $h > $T) && $face !~ /_S\./) { 139 if (($w > $T || $h > $T) && $face !~ /_S\./) {
133 # split 140 # split
134 my @tile; 141 my @tile;
149 (map { 156 (map {
150 ( 157 (
151 "(", 158 "(",
152 "+clone", 159 "+clone",
153 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 160 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
161 "+repage",
154 -write => "png:$_->[2]~", 162 -write => "png:$_->[2]~",
155 "+delete", 163 "+delete",
156 ")", 164 ")",
157 ) 165 )
158 } @todo), 166 } @todo),
195 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 203 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
196 204
197 my $arc = read_arch "$dir/$file"; 205 my $arc = read_arch "$dir/$file";
198 for my $o (values %$arc) { 206 for my $o (values %$arc) {
199 push @ARC, $o; 207 push @ARC, $o;
208
209 $o->{editor_folder} = $dir;
210
211 my $visibility = delete $o->{visibility};
212 my $magicmap = delete $o->{magicmap};
213
214 # find upper left corner :/
215 # omg, this is sooo broken
200 my ($dx, $dy); 216 my ($dx, $dy);
201 # omg, this is sooo broken
202 for (my $o = $o; $o; $o = $o->{more}) { 217 for (my $o = $o; $o; $o = $o->{more}) {
203 $dx = $o->{x} if $o->{x} < $dx; 218 $dx = $o->{x} if $o->{x} < $dx;
204 $dy = $o->{y} if $o->{y} < $dy; 219 $dy = $o->{y} if $o->{y} < $dy;
205 } 220 }
221
206 for (my $o = $o; $o; $o = $o->{more}) { 222 for (my $o = $o; $o; $o = $o->{more}) {
207 my $x = $o->{x} - $dx; 223 my $x = $o->{x} - $dx;
208 my $y = $o->{y} - $dy; 224 my $y = $o->{y} - $dy;
225
226 my $ext = $x|$y ? "+$x+$y" : "";
227
228 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/;
229
230 my $visibility = delete $o->{visibility} if exists $o->{visibility};
231 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
232
233 my $anim = delete $o->{anim};
234
209 if ($x|$y) { 235 if ($anim) {
210 $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; 236 $o->{animation} = "$o->{_name}";
237
238 for (@$anim) {
239 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/;
240 }
241
242 $ANIM{"$o->{_name}$ext"} =
243 join "", map "$_\n",
244 "anim $o->{_name}",
245 @$anim,
246 "mina";
247 }
248
249 for my $face ($o->{face} || (), @{$anim || []}) {
250 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
251
252 my $info = $FACEINFO{$face} ||= {};
253
254 $info->{visibility} = $visibility if defined $visibility;
255 $info->{magicmap} = $magicmap if defined $magicmap;
256 }
257
258 if (my $smooth = delete $o->{smoothface}) {
259 $SMOOTH .= "$smooth\n";
211 } 260 }
212 } 261 }
213 } 262 }
214 } 263 }
215 } 264 }
216 265
217 sub process_trs { 266 sub process_trs {
218 while (@trs) { 267 while (@trs) {
219 my ($dir, $file) = @{pop @trs}; 268 my ($dir, $file) = @{pop @trs};
269 my $path = "$dir/$file";
270
271 my $trs;
272 if (0 > aio_load $path, $trs) {
273 warn "$path: $!, skipping.\n";
274 next;
275 }
276
277 $TRS .= $trs;
220 } 278 }
221 } 279 }
222 280
223 sub find_files; 281 sub find_files;
224 sub find_files { 282 sub find_files {
262 (async \&process_png), (async \&process_png), 320 (async \&process_png), (async \&process_png),
263 (async \&process_trs), (async \&process_trs), 321 (async \&process_trs), (async \&process_trs),
264 (async \&process_arc), (async \&process_arc), 322 (async \&process_arc), (async \&process_arc),
265 ); 323 );
266 324
325 {
326 open my $fh, ">:utf8", "$DATADIR/animations~"
327 or die "$DATADIR/animations~: $!";
328 print $fh join "", map $ANIM{$_}, sort keys %ANIM
329 }
330
331 {
267 open my $archetypes, ">:utf8", "$DATADIR/archetypes~" 332 open my $fh, ">:utf8", "$DATADIR/archetypes~"
268 or die "$DATADIR/archetypes~: $!"; 333 or die "$DATADIR/archetypes~: $!";
334 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC;
269 print $archetypes Crossfire::archlist_to_string \@ARC; 335 print $fh Crossfire::archlist_to_string \@ARC;
270 close $archetypes; 336 }
271 rename "$DATADIR/archetypes~", "$DATADIR/archetypes";
272 337
273 die "--install-arch not fully implemented\n"; 338 {
339 open my $fh, ">:utf8", "$DATADIR/smooth~"
340 or die "$DATADIR/smooth~: $!";
341 print $fh $SMOOTH;
342 }
343
344 {
345 open my $fh, ">:utf8", "$DATADIR/treasures~"
346 or die "$DATADIR/treasures~: $!";
347 print $fh $TRS;
348 }
349
350 {
351 while (my ($k, $v) = each %FACEINFO) {
352 $v->{data32} ||= delete $PNG32{$k};
353 }
354
355 while (my ($k, $v) = each %FACEINFO) {
356 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
357
358 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
359 }
360
361 open my $fh, ">:perlio", "$DATADIR/faces~"
362 or die "$DATADIR/faces~: $!";
363
364 print $fh Storable::nfreeze \%FACEINFO;
365 }
366
367 for (qw(archetypes faces animations treasures smooth)) {
368 chmod 0644, "$DATADIR/$_~";
369 rename "$DATADIR/$_~", "$DATADIR/$_";
370 }
274 } 371 }
275} 372}
276 373
277Getopt::Long::Configure ("bundling", "no_ignore_case"); 374Getopt::Long::Configure ("bundling", "no_ignore_case");
278GetOptions ( 375GetOptions (

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines