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.30 by root, Thu Feb 23 14:54:44 2006 UTC vs.
Revision 1.46 by root, Thu Mar 16 01:34:01 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, "<:raw", "$path~" 51 open my $fh, "<", $path
61 or die "$path~: $!"; 52 or die "$path: $!";
53 binmode $fh;
62 local $/; 54 local $/;
63 thaw <$fh> 55
56 Storable::thaw <$fh>
64} 57}
65 58
66sub save_ref($$) { 59sub save_ref($$) {
67 my ($ref, $path) = @_; 60 my ($ref, $path) = @_;
68 61
69 open my $fh, ">:raw", "$path~" 62 open my $fh, ">", "$path~"
70 or die "$path~: $!"; 63 or die "$path~: $!";
71 my $ref = freeze $ref; 64 binmode $fh;
72 print $fh $ref; 65 print $fh Storable::freeze $ref;
73 close $fh; 66 close $fh;
74 rename "$path~", $path 67 rename "$path~", $path
75 or die "$path: $!"; 68 or die "$path: $!";
76} 69}
77 70
146 && -M $cache < -M $path 139 && -M $cache < -M $path
147 && load_ref $cache 140 && load_ref $cache
148 } or do { 141 } or do {
149 my %pak; 142 my %pak;
150 143
151 open my $fh, "<:raw", $path 144 open my $fh, "<", $path
152 or Carp::croak "$_[0]: $!"; 145 or Carp::croak "$_[0]: $!";
146 binmode $fh;
153 while (<$fh>) { 147 while (<$fh>) {
154 my ($type, $id, $len, $path) = split; 148 my ($type, $id, $len, $path) = split;
155 $path =~ s/.*\///; 149 $path =~ s/.*\///;
156 read $fh, $pak{$path}, $len; 150 read $fh, $pak{$path}, $len;
157 } 151 }
172 && load_ref $cache 166 && load_ref $cache
173 } or do { 167 } or do {
174 my %arc; 168 my %arc;
175 my ($more, $prev); 169 my ($more, $prev);
176 170
177 open my $fh, "<:raw", $path 171 open my $fh, "<", $path
178 or Carp::croak "$path: $!"; 172 or Carp::croak "$path: $!";
173
174 binmode $fh;
179 175
180 my $parse_block; $parse_block = sub { 176 my $parse_block; $parse_block = sub {
181 my %arc = @_; 177 my %arc = @_;
182 178
183 while (<$fh>) { 179 while (<$fh>) {
267 my ($a) = @_; 263 my ($a) = @_;
268 264
269 my $o = $ARCH{$a->{_name}} 265 my $o = $ARCH{$a->{_name}}
270 or return; 266 or return;
271 267
272 my $face = $FACE{$a->{face} || $o->{face}} 268 my $face = $FACE{$a->{face} || $o->{face} || "blank.111"}
273 or (warn "no face data found for arch '$a->{_name}'"), return; 269 or (warn "no face data found for arch '$a->{_name}'"), return;
274 270
275 if ($face->{w} > 1 || $face->{h} > 1) { 271 if ($face->{w} > 1 || $face->{h} > 1) {
276 # bigface 272 # bigface
277 return (0, 0, $face->{w} - 1, $face->{h} - 1); 273 return (0, 0, $face->{w} - 1, $face->{h} - 1);
309 import 305 import
310 306
311=cut 307=cut
312 308
313sub arch_attr($) { 309sub arch_attr($) {
314 my ($arch) = @_; 310 my ($obj) = @_;
315 311
316 require Crossfire::Data; 312 require Crossfire::Data;
317 313
318 my $attr; 314 my $root;
315
316 my $arch = $ARCH{ $obj->{_name} };
317 my $type = $obj->{type} || $arch->{type};
319 318
320 if ($arch->{type} > 0) { 319 if ($type > 0) {
321 $attr = $Crossfire::Data::ATTR{$arch->{type}+0}; 320 $root = $Crossfire::Data::ATTR{$type};
322 } else { 321 } else {
323 $attr = $Crossfire::Data::TYPE{Misc}; 322 $root = $Crossfire::Data::TYPE{Misc};
324 323
325 type: 324 type:
326 for (@Crossfire::Data::ATTR0) { 325 for (@Crossfire::Data::ATTR0) {
327 my $req = $_->{required} 326 my $req = $_->{required}
328 or die "internal error: ATTR0 without 'required'"; 327 or die "internal error: ATTR0 without 'required'";
329 328
329 keys %$req;
330 while (my ($k, $v) = each %$req) { 330 while (my ($k, $v) = each %$req) {
331 next type 331 next type
332 unless $arch->{$k} == $v; 332 unless $obj->{$k} eq $v || $arch->{$k} eq $v;
333 } 333 }
334 334
335 $attr = $_; 335 $root = $_;
336 }
337 }
338
339 my $attr = { };
340
341 my @import = (\%Crossfire::Data::DEFAULT_ATTR, $root);
342 my (%ignore);
343 my (@section_order, %section, @attr_order);
344
345 while (my $type = shift @import) {
346 push @import, @{$type->{import} || []};
347
348 $attr->{$_} ||= $type->{$_}
349 for qw(name desc use);
350
351 for (@{$type->{ignore} || []}) {
352 $ignore{$_}++ for ref $_ ? @$_ : $_;
353 }
354
355 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) {
356 my ($name, $attr) = @$_;
357 push @section_order, $name;
358 for (@$attr) {
359 my ($k, $v) = @$_;
360 push @attr_order, $k;
361 $section{$name}{$k} ||= $v;
336 } 362 }
363 }
337 } 364 }
338 365
339 $attr || \%Crossfire::Data::DEFAULT_ATTR; 366 $attr->{section} = [
367 map !exists $section{$_} ? () : do {
368 my $attr = delete $section{$_};
369
370 [
371 $_,
372 map exists $attr->{$_} && !$ignore{$_}
373 ? [$_ => delete $attr->{$_}] : (),
374 @attr_order
375 ]
376 },
377
378 exists $section{$_} ? [$_ => delete $section{$_}] : (),
379 @section_order
380 ];
381
382 $attr
340} 383}
341 384
342sub arch_edit_sections { 385sub arch_edit_sections {
343# if (edit_type == IGUIConstants.TILE_EDIT_NONE) 386# if (edit_type == IGUIConstants.TILE_EDIT_NONE)
344# edit_type = 0; 387# edit_type = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines