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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines