ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.28 by root, Thu Feb 23 13:15:22 2006 UTC vs.
Revision 1.47 by root, Thu Mar 16 01:42:22 2006 UTC

11use strict; 11use strict;
12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use Storable;
17use File::Spec; 16use File::Spec;
18use List::Util qw(min max); 17use List::Util qw(min max);
19 18use Storable;
20#XXX: The map_* procedures scream for a map-object
21 19
22our @EXPORT = 20our @EXPORT =
23 qw(read_pak read_arch %ARCH TILESIZE $TILE %FACE editor_archs arch_extents); 21 qw(read_pak read_arch %ARCH TILESIZE $TILE %FACE editor_archs arch_extents);
24 22
25our $LIB = $ENV{CROSSFIRE_LIBDIR} 23our $LIB = $ENV{CROSSFIRE_LIBDIR}
48sub MOVE_ALL (){ 0xf } 46sub MOVE_ALL (){ 0xf }
49 47
50sub load_ref($) { 48sub load_ref($) {
51 my ($path) = @_; 49 my ($path) = @_;
52 50
53 open my $fh, ">:raw", "$path~" 51 open my $fh, "<", $path
54 or die "$path~: $!"; 52 or die "$path: $!";
53 binmode $fh;
55 local $/; 54 local $/;
55
56 Storable::thaw <$fh> 56 Storable::thaw <$fh>
57} 57}
58 58
59sub save_ref($$) { 59sub save_ref($$) {
60 my ($ref, $path) = @_; 60 my ($ref, $path) = @_;
61 61
62 open my $fh, ">:raw", "$path~" 62 open my $fh, ">", "$path~"
63 or die "$path~: $!"; 63 or die "$path~: $!";
64 binmode $fh;
64 print $fh Storable::nfreeze $ref; 65 print $fh Storable::freeze $ref;
65 close $fh; 66 close $fh;
66 rename "$path~", $path 67 rename "$path~", $path
67 or die "$path: $!"; 68 or die "$path: $!";
68} 69}
69 70
138 && -M $cache < -M $path 139 && -M $cache < -M $path
139 && load_ref $cache 140 && load_ref $cache
140 } or do { 141 } or do {
141 my %pak; 142 my %pak;
142 143
143 open my $fh, "<:raw", $path 144 open my $fh, "<", $path
144 or Carp::croak "$_[0]: $!"; 145 or Carp::croak "$_[0]: $!";
146 binmode $fh;
145 while (<$fh>) { 147 while (<$fh>) {
146 my ($type, $id, $len, $path) = split; 148 my ($type, $id, $len, $path) = split;
147 $path =~ s/.*\///; 149 $path =~ s/.*\///;
148 read $fh, $pak{$path}, $len; 150 read $fh, $pak{$path}, $len;
149 } 151 }
164 && load_ref $cache 166 && load_ref $cache
165 } or do { 167 } or do {
166 my %arc; 168 my %arc;
167 my ($more, $prev); 169 my ($more, $prev);
168 170
169 open my $fh, "<:raw", $path 171 open my $fh, "<", $path
170 or Carp::croak "$path: $!"; 172 or Carp::croak "$path: $!";
173
174 binmode $fh;
171 175
172 my $parse_block; $parse_block = sub { 176 my $parse_block; $parse_block = sub {
173 my %arc = @_; 177 my %arc = @_;
174 178
175 while (<$fh>) { 179 while (<$fh>) {
259 my ($a) = @_; 263 my ($a) = @_;
260 264
261 my $o = $ARCH{$a->{_name}} 265 my $o = $ARCH{$a->{_name}}
262 or return; 266 or return;
263 267
264 my $face = $FACE{$a->{face} || $o->{face}} 268 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"}
265 or (warn "no face data found for arch '$a->{_name}'"), return; 269 or (warn "no face data found for arch '$a->{_name}'"), return;
266 270
267 if ($face->{w} > 1 || $face->{h} > 1) { 271 if ($face->{w} > 1 || $face->{h} > 1) {
268 # bigface 272 # bigface
269 return (0, 0, $face->{w} - 1, $face->{h} - 1); 273 return (0, 0, $face->{w} - 1, $face->{h} - 1);
301 import 305 import
302 306
303=cut 307=cut
304 308
305sub arch_attr($) { 309sub arch_attr($) {
306 my ($arch) = @_; 310 my ($obj) = @_;
307 311
308 require Crossfire::Data; 312 require Crossfire::Data;
309 313
310 my $attr; 314 my $root;
315
316 my $arch = $ARCH{ $obj->{_name} };
317 my $type = $obj->{type} || $arch->{type};
311 318
312 if ($arch->{type} > 0) { 319 if ($type > 0) {
313 $attr = $Crossfire::Data::ATTR{$arch->{type}+0}; 320 $root = $Crossfire::Data::ATTR{$type};
314 } else { 321 } else {
315 $attr = $Crossfire::Data::TYPE{Misc}; 322 $root = $Crossfire::Data::TYPE{Misc};
316 323
317 type: 324 type:
318 for (@Crossfire::Data::ATTR0) { 325 for (@Crossfire::Data::ATTR0) {
319 my $req = $_->{required} 326 my $req = $_->{required}
320 or die "internal error: ATTR0 without 'required'"; 327 or die "internal error: ATTR0 without 'required'";
321 328
329 keys %$req;
322 while (my ($k, $v) = each %$req) { 330 while (my ($k, $v) = each %$req) {
323 next type 331 next type
324 unless $arch->{$k} == $v; 332 unless $obj->{$k} eq $v || $arch->{$k} eq $v;
325 } 333 }
326 334
327 $attr = $_; 335 $root = $_;
328 } 336 }
337 }
338
339 my $attr = { };
340
341 my @import = ($root);
329 } 342
330
331 $attr || \%Crossfire::Data::DEFAULT_ATTR; 343 unshift @import, \%Crossfire::Data::DEFAULT_ATTR
344 unless $type == 116;
345
346 my (%ignore);
347 my (@section_order, %section, @attr_order);
348
349 while (my $type = shift @import) {
350 push @import, @{$type->{import} || []};
351
352 $attr->{$_} ||= $type->{$_}
353 for qw(name desc use);
354
355 for (@{$type->{ignore} || []}) {
356 $ignore{$_}++ for ref $_ ? @$_ : $_;
357 }
358
359 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) {
360 my ($name, $attr) = @$_;
361 push @section_order, $name;
362 for (@$attr) {
363 my ($k, $v) = @$_;
364 push @attr_order, $k;
365 $section{$name}{$k} ||= $v;
366 }
367 }
368 }
369
370 $attr->{section} = [
371 map !exists $section{$_} ? () : do {
372 my $attr = delete $section{$_};
373
374 [
375 $_,
376 map exists $attr->{$_} && !$ignore{$_}
377 ? [$_ => delete $attr->{$_}] : (),
378 @attr_order
379 ]
380 },
381
382 exists $section{$_} ? [$_ => delete $section{$_}] : (),
383 @section_order
384 ];
385
386 $attr
332} 387}
333 388
334sub arch_edit_sections { 389sub arch_edit_sections {
335# if (edit_type == IGUIConstants.TILE_EDIT_NONE) 390# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
336# edit_type = 0; 391# edit_type = 0;
399 454
400 mkdir $cachedir, 0777; 455 mkdir $cachedir, 0777;
401 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 456 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
402} 457}
403 458
404$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; 459$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire";
405 460
406init $VARDIR; 461init $VARDIR;
407 462
408=head1 AUTHOR 463=head1 AUTHOR
409 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines