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