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.31 by root, Thu Feb 23 15:01:43 2006 UTC vs.
Revision 1.49 by root, Thu Mar 16 22:10:25 2006 UTC

13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use File::Spec; 16use File::Spec;
17use List::Util qw(min max); 17use List::Util qw(min max);
18 18use Storable;
19#XXX: The map_* procedures scream for a map-object
20 19
21our @EXPORT = 20our @EXPORT =
22 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);
23 22
24our $LIB = $ENV{CROSSFIRE_LIBDIR} 23our $LIB = $ENV{CROSSFIRE_LIBDIR}
44sub MOVE_FLY_HIGH (){ 0x4 } 43sub MOVE_FLY_HIGH (){ 0x4 }
45sub MOVE_FLYING (){ 0x6 } 44sub MOVE_FLYING (){ 0x6 }
46sub MOVE_SWIM (){ 0x8 } 45sub MOVE_SWIM (){ 0x8 }
47sub MOVE_ALL (){ 0xf } 46sub MOVE_ALL (){ 0xf }
48 47
49BEGIN {
50 if ($^O eq "MSWin32") {
51 eval "use FreezeThaw qw(freeze thaw)";
52 } else {
53 eval "use Storable qw(freeze thaw)";
54 }
55}
56
57sub load_ref($) { 48sub load_ref($) {
58 my ($path) = @_; 49 my ($path) = @_;
59 50
60 open my $fh, "<", $path 51 open my $fh, "<", $path
61 or die "$path: $!"; 52 or die "$path: $!";
62 binmode $fh; 53 binmode $fh;
63 local $/; 54 local $/;
64 thaw <$fh> 55
56 Storable::thaw <$fh>
65} 57}
66 58
67sub save_ref($$) { 59sub save_ref($$) {
68 my ($ref, $path) = @_; 60 my ($ref, $path) = @_;
69 61
70 open my $fh, ">", "$path~" 62 open my $fh, ">", "$path~"
71 or die "$path~: $!"; 63 or die "$path~: $!";
72 binmode $fh; 64 binmode $fh;
73 print $fh freeze $ref; 65 print $fh Storable::freeze $ref;
74 close $fh; 66 close $fh;
75 rename "$path~", $path 67 rename "$path~", $path
76 or die "$path: $!"; 68 or die "$path: $!";
77} 69}
78 70
271 my ($a) = @_; 263 my ($a) = @_;
272 264
273 my $o = $ARCH{$a->{_name}} 265 my $o = $ARCH{$a->{_name}}
274 or return; 266 or return;
275 267
276 my $face = $FACE{$a->{face} || $o->{face}} 268 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"}
277 or (warn "no face data found for arch '$a->{_name}'"), return; 269 or (warn "no face data found for arch '$a->{_name}'"), return;
278 270
279 if ($face->{w} > 1 || $face->{h} > 1) { 271 if ($face->{w} > 1 || $face->{h} > 1) {
280 # bigface 272 # bigface
281 return (0, 0, $face->{w} - 1, $face->{h} - 1); 273 return (0, 0, $face->{w} - 1, $face->{h} - 1);
313 import 305 import
314 306
315=cut 307=cut
316 308
317sub arch_attr($) { 309sub arch_attr($) {
318 my ($arch) = @_; 310 my ($obj) = @_;
319 311
320 require Crossfire::Data; 312 require Crossfire::Data;
321 313
314 my $root;
322 my $attr; 315 my $attr = { };
316
317 my $arch = $ARCH{ $obj->{_name} };
318 my $type = $obj->{type} || $arch->{type};
323 319
324 if ($arch->{type} > 0) { 320 if ($type > 0) {
325 $attr = $Crossfire::Data::ATTR{$arch->{type}+0}; 321 $root = $Crossfire::Data::ATTR{$type};
326 } else { 322 } else {
327 $attr = $Crossfire::Data::TYPE{Misc}; 323 $root = $Crossfire::Data::TYPE{Misc};
328 324
329 type: 325 type:
330 for (@Crossfire::Data::ATTR0) { 326 for (@Crossfire::Data::ATTR0) {
331 my $req = $_->{required} 327 my $req = $_->{required}
332 or die "internal error: ATTR0 without 'required'"; 328 or die "internal error: ATTR0 without 'required'";
333 329
330 keys %$req;
334 while (my ($k, $v) = each %$req) { 331 while (my ($k, $v) = each %$req) {
335 next type 332 next type
336 unless $arch->{$k} == $v; 333 unless $obj->{$k} == $v || $arch->{$k} == $v;
337 } 334 }
338 335
339 $attr = $_; 336 $root = $_;
340 } 337 }
338 }
339
340 my @import = ($root);
341 } 341
342
343 $attr || \%Crossfire::Data::DEFAULT_ATTR; 342 unshift @import, \%Crossfire::Data::DEFAULT_ATTR
343 unless $type == 116;
344
345 my (%ignore);
346 my (@section_order, %section, @attr_order);
347
348 while (my $type = shift @import) {
349 push @import, @{$type->{import} || []};
350
351 $attr->{$_} ||= $type->{$_}
352 for qw(name desc use);
353
354 for (@{$type->{ignore} || []}) {
355 $ignore{$_}++ for ref $_ ? @$_ : $_;
356 }
357
358 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) {
359 my ($name, $attr) = @$_;
360 push @section_order, $name;
361 for (@$attr) {
362 my ($k, $v) = @$_;
363 push @attr_order, $k;
364 $section{$name}{$k} ||= $v;
365 }
366 }
367 }
368
369 $attr->{section} = [
370 map !exists $section{$_} ? () : do {
371 my $attr = delete $section{$_};
372
373 [
374 $_,
375 map exists $attr->{$_} && !$ignore{$_}
376 ? [$_ => delete $attr->{$_}] : (),
377 @attr_order
378 ]
379 },
380
381 exists $section{$_} ? [$_ => delete $section{$_}] : (),
382 @section_order
383 ];
384
385 $attr
344} 386}
345 387
346sub arch_edit_sections { 388sub arch_edit_sections {
347# if (edit_type == IGUIConstants.TILE_EDIT_NONE) 389# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
348# edit_type = 0; 390# edit_type = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines