… | |
… | |
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 FreezeThaw qw(freeze thaw)"; |
|
|
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 | thaw <$fh> |
55 | |
|
|
56 | Storable::thaw <$fh> |
65 | } |
57 | } |
66 | |
58 | |
67 | sub save_ref($$) { |
59 | sub 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 | |
317 | sub arch_attr($) { |
309 | sub arch_attr($) { |
318 | my ($arch) = @_; |
310 | my ($obj) = @_; |
319 | |
311 | |
320 | require Crossfire::Data; |
312 | require Crossfire::Data; |
321 | |
313 | |
322 | my $attr; |
314 | my $root; |
|
|
315 | |
|
|
316 | my $arch = $ARCH{ $obj->{_name} }; |
|
|
317 | my $type = $obj->{type} || $arch->{type}; |
323 | |
318 | |
324 | if ($arch->{type} > 0) { |
319 | if ($type > 0) { |
325 | $attr = $Crossfire::Data::ATTR{$arch->{type}+0}; |
320 | $root = $Crossfire::Data::ATTR{$type}; |
326 | } else { |
321 | } else { |
327 | $attr = $Crossfire::Data::TYPE{Misc}; |
322 | $root = $Crossfire::Data::TYPE{Misc}; |
328 | |
323 | |
329 | type: |
324 | type: |
330 | for (@Crossfire::Data::ATTR0) { |
325 | for (@Crossfire::Data::ATTR0) { |
331 | my $req = $_->{required} |
326 | my $req = $_->{required} |
332 | or die "internal error: ATTR0 without 'required'"; |
327 | or die "internal error: ATTR0 without 'required'"; |
333 | |
328 | |
|
|
329 | keys %$req; |
334 | while (my ($k, $v) = each %$req) { |
330 | while (my ($k, $v) = each %$req) { |
335 | next type |
331 | next type |
336 | unless $arch->{$k} == $v; |
332 | unless $obj->{$k} eq $v || $arch->{$k} eq $v; |
337 | } |
333 | } |
338 | |
334 | |
339 | $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; |
340 | } |
362 | } |
|
|
363 | } |
341 | } |
364 | } |
342 | |
365 | |
343 | $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 |
344 | } |
383 | } |
345 | |
384 | |
346 | sub arch_edit_sections { |
385 | sub arch_edit_sections { |
347 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
386 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
348 | # edit_type = 0; |
387 | # edit_type = 0; |