… | |
… | |
4 | |
4 | |
5 | =cut |
5 | =cut |
6 | |
6 | |
7 | package Crossfire; |
7 | package Crossfire; |
8 | |
8 | |
9 | our $VERSION = '0.92'; |
9 | our $VERSION = '0.96'; |
10 | |
10 | |
11 | use strict; |
11 | use strict; |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
… | |
… | |
384 | sub read_arch($;$) { |
384 | sub read_arch($;$) { |
385 | my ($path, $toplevel) = @_; |
385 | my ($path, $toplevel) = @_; |
386 | |
386 | |
387 | my %arc; |
387 | my %arc; |
388 | my ($more, $prev); |
388 | my ($more, $prev); |
|
|
389 | my $comment; |
389 | |
390 | |
390 | open my $fh, "<:raw:perlio:utf8", $path |
391 | open my $fh, "<:raw:perlio:utf8", $path |
391 | or Carp::croak "$path: $!"; |
392 | or Carp::croak "$path: $!"; |
392 | |
393 | |
393 | # binmode $fh; |
394 | # binmode $fh; |
… | |
… | |
397 | |
398 | |
398 | while (<$fh>) { |
399 | while (<$fh>) { |
399 | s/\s+$//; |
400 | s/\s+$//; |
400 | if (/^end$/i) { |
401 | if (/^end$/i) { |
401 | last; |
402 | last; |
|
|
403 | |
402 | } elsif (/^arch (\S+)$/i) { |
404 | } elsif (/^arch (\S+)$/i) { |
403 | push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); |
405 | push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); |
|
|
406 | |
404 | } elsif (/^lore$/i) { |
407 | } elsif (/^lore$/i) { |
405 | while (<$fh>) { |
408 | while (<$fh>) { |
406 | last if /^endlore\s*$/i; |
409 | last if /^endlore\s*$/i; |
407 | $arc{lore} .= $_; |
410 | $arc{lore} .= $_; |
408 | } |
411 | } |
… | |
… | |
417 | chomp; |
420 | chomp; |
418 | push @{ $arc{anim} }, $_; |
421 | push @{ $arc{anim} }, $_; |
419 | } |
422 | } |
420 | } elsif (/^(\S+)\s*(.*)$/) { |
423 | } elsif (/^(\S+)\s*(.*)$/) { |
421 | $arc{lc $1} = $2; |
424 | $arc{lc $1} = $2; |
422 | } elsif (/^\s*($|#)/) { |
425 | } elsif (/^\s*#/) { |
|
|
426 | $arc{_comment} .= $_; |
|
|
427 | |
|
|
428 | } elsif (/^\s*$/) { |
423 | # |
429 | # |
424 | } else { |
430 | } else { |
425 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
431 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
426 | } |
432 | } |
427 | } |
433 | } |
… | |
… | |
431 | |
437 | |
432 | while (<$fh>) { |
438 | while (<$fh>) { |
433 | s/\s+$//; |
439 | s/\s+$//; |
434 | if (/^more$/i) { |
440 | if (/^more$/i) { |
435 | $more = $prev; |
441 | $more = $prev; |
|
|
442 | } elsif (/^\s*#/) { |
|
|
443 | $comment .= $_; |
436 | } elsif (/^object (\S+)$/i) { |
444 | } elsif (/^object (\S+)$/i) { |
437 | my $name = $1; |
445 | my $name = $1; |
438 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name); |
446 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
|
|
447 | delete $arc{_comment} unless length $arc{_comment}; |
439 | $arc->{_atype} = 'object'; |
448 | $arc->{_atype} = 'object'; |
440 | |
449 | |
441 | if ($more) { |
450 | if ($more) { |
442 | $more->{more} = $arc; |
451 | $more->{more} = $arc; |
443 | } else { |
452 | } else { |
… | |
… | |
445 | } |
454 | } |
446 | $prev = $arc; |
455 | $prev = $arc; |
447 | $more = undef; |
456 | $more = undef; |
448 | } elsif (/^arch (\S+)$/i) { |
457 | } elsif (/^arch (\S+)$/i) { |
449 | my $name = $1; |
458 | my $name = $1; |
450 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); |
459 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
|
|
460 | delete $arc{_comment} unless length $arc{_comment}; |
451 | $arc->{_atype} = 'arch'; |
461 | $arc->{_atype} = 'arch'; |
452 | |
462 | |
453 | if ($more) { |
463 | if ($more) { |
454 | $more->{more} = $arc; |
464 | $more->{more} = $arc; |
455 | } else { |
465 | } else { |
… | |
… | |
602 | my ($a) = @_; |
612 | my ($a) = @_; |
603 | |
613 | |
604 | my $o = $ARCH{$a->{_name}} |
614 | my $o = $ARCH{$a->{_name}} |
605 | or return; |
615 | or return; |
606 | |
616 | |
607 | my $face = $FACE{$a->{face} || $o->{face} || "blank.111"} |
617 | my $face = $FACE{$a->{face} || $o->{face} || "blank.111"}; |
|
|
618 | unless ($face) { |
|
|
619 | $face = $FACE{"blank.x11"} |
608 | or (warn "no face data found for arch '$a->{_name}'"), return; |
620 | or (warn "no face data found for arch '$a->{_name}'"), return; |
|
|
621 | } |
609 | |
622 | |
610 | if ($face->{w} > 1 || $face->{h} > 1) { |
623 | if ($face->{w} > 1 || $face->{h} > 1) { |
611 | # bigface |
624 | # bigface |
612 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
625 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
613 | |
626 | |