… | |
… | |
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 | use Storable; |
18 | use Storable; |
19 | |
|
|
20 | #XXX: The map_* procedures scream for a map-object |
|
|
21 | |
19 | |
22 | our @EXPORT = |
20 | our @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 | |
25 | our $LIB = $ENV{CROSSFIRE_LIBDIR} |
23 | our $LIB = $ENV{CROSSFIRE_LIBDIR} |
… | |
… | |
311 | sub arch_attr($) { |
309 | sub arch_attr($) { |
312 | my ($arch) = @_; |
310 | my ($arch) = @_; |
313 | |
311 | |
314 | require Crossfire::Data; |
312 | require Crossfire::Data; |
315 | |
313 | |
316 | my $attr; |
314 | my $root; |
317 | |
315 | |
318 | if ($arch->{type} > 0) { |
316 | if ($arch->{type} > 0) { |
319 | $attr = $Crossfire::Data::ATTR{$arch->{type}+0}; |
317 | $root = $Crossfire::Data::ATTR{$arch->{type}+0}; |
320 | } else { |
318 | } else { |
321 | $attr = $Crossfire::Data::TYPE{Misc}; |
319 | $root = $Crossfire::Data::TYPE{Misc}; |
322 | |
320 | |
323 | type: |
321 | type: |
324 | for (@Crossfire::Data::ATTR0) { |
322 | for (@Crossfire::Data::ATTR0) { |
325 | my $req = $_->{required} |
323 | my $req = $_->{required} |
326 | or die "internal error: ATTR0 without 'required'"; |
324 | or die "internal error: ATTR0 without 'required'"; |
… | |
… | |
329 | while (my ($k, $v) = each %$req) { |
327 | while (my ($k, $v) = each %$req) { |
330 | next type |
328 | next type |
331 | unless $arch->{$k} == $v; |
329 | unless $arch->{$k} == $v; |
332 | } |
330 | } |
333 | |
331 | |
334 | $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; |
335 | } |
359 | } |
|
|
360 | } |
336 | } |
361 | } |
337 | |
362 | |
338 | $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->{$_} && !$ignore{$_} |
|
|
370 | ? [$_ => delete $attr->{$_}] : (), |
|
|
371 | @attr_order |
|
|
372 | ] |
|
|
373 | }, |
|
|
374 | |
|
|
375 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
|
|
376 | @section_order |
|
|
377 | ]; |
|
|
378 | |
|
|
379 | use PApp::Util; |
|
|
380 | warn PApp::Util::dumpval $attr; |
|
|
381 | |
|
|
382 | $attr |
339 | } |
383 | } |
340 | |
384 | |
341 | sub arch_edit_sections { |
385 | sub arch_edit_sections { |
342 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
386 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
343 | # edit_type = 0; |
387 | # edit_type = 0; |