… | |
… | |
4 | |
4 | |
5 | =cut |
5 | =cut |
6 | |
6 | |
7 | package Crossfire; |
7 | package Crossfire; |
8 | |
8 | |
9 | our $VERSION = '0.9'; |
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 | |
… | |
… | |
33 | JSON::Syck::Dump $_[0] |
33 | JSON::Syck::Dump $_[0] |
34 | } |
34 | } |
35 | |
35 | |
36 | our $LIB = $ENV{CROSSFIRE_LIBDIR}; |
36 | our $LIB = $ENV{CROSSFIRE_LIBDIR}; |
37 | |
37 | |
38 | our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; |
38 | our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" |
|
|
39 | : $ENV{AppData} ? "$ENV{APPDATA}/crossfire" |
|
|
40 | : File::Spec->tmpdir . "/crossfire"; |
39 | |
41 | |
40 | mkdir $VARDIR, 0777; |
42 | mkdir $VARDIR, 0777; |
41 | |
43 | |
42 | sub TILESIZE (){ 32 } |
44 | sub TILESIZE (){ 32 } |
43 | |
45 | |
… | |
… | |
382 | sub read_arch($;$) { |
384 | sub read_arch($;$) { |
383 | my ($path, $toplevel) = @_; |
385 | my ($path, $toplevel) = @_; |
384 | |
386 | |
385 | my %arc; |
387 | my %arc; |
386 | my ($more, $prev); |
388 | my ($more, $prev); |
|
|
389 | my $comment; |
387 | |
390 | |
388 | open my $fh, "<:raw:perlio:utf8", $path |
391 | open my $fh, "<:raw:perlio:utf8", $path |
389 | or Carp::croak "$path: $!"; |
392 | or Carp::croak "$path: $!"; |
390 | |
393 | |
391 | # binmode $fh; |
394 | # binmode $fh; |
… | |
… | |
395 | |
398 | |
396 | while (<$fh>) { |
399 | while (<$fh>) { |
397 | s/\s+$//; |
400 | s/\s+$//; |
398 | if (/^end$/i) { |
401 | if (/^end$/i) { |
399 | last; |
402 | last; |
|
|
403 | |
400 | } elsif (/^arch (\S+)$/i) { |
404 | } elsif (/^arch (\S+)$/i) { |
401 | push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); |
405 | push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); |
|
|
406 | |
402 | } elsif (/^lore$/i) { |
407 | } elsif (/^lore$/i) { |
403 | while (<$fh>) { |
408 | while (<$fh>) { |
404 | last if /^endlore\s*$/i; |
409 | last if /^endlore\s*$/i; |
405 | $arc{lore} .= $_; |
410 | $arc{lore} .= $_; |
406 | } |
411 | } |
… | |
… | |
415 | chomp; |
420 | chomp; |
416 | push @{ $arc{anim} }, $_; |
421 | push @{ $arc{anim} }, $_; |
417 | } |
422 | } |
418 | } elsif (/^(\S+)\s*(.*)$/) { |
423 | } elsif (/^(\S+)\s*(.*)$/) { |
419 | $arc{lc $1} = $2; |
424 | $arc{lc $1} = $2; |
420 | } elsif (/^\s*($|#)/) { |
425 | } elsif (/^\s*#/) { |
|
|
426 | $arc{_comment} .= "$_\n"; |
|
|
427 | |
|
|
428 | } elsif (/^\s*$/) { |
421 | # |
429 | # |
422 | } else { |
430 | } else { |
423 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
431 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
424 | } |
432 | } |
425 | } |
433 | } |
… | |
… | |
431 | s/\s+$//; |
439 | s/\s+$//; |
432 | if (/^more$/i) { |
440 | if (/^more$/i) { |
433 | $more = $prev; |
441 | $more = $prev; |
434 | } elsif (/^object (\S+)$/i) { |
442 | } elsif (/^object (\S+)$/i) { |
435 | my $name = $1; |
443 | my $name = $1; |
436 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name); |
444 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
|
|
445 | undef $comment; |
|
|
446 | delete $arc{_comment} unless length $arc{_comment}; |
437 | $arc->{_atype} = 'object'; |
447 | $arc->{_atype} = 'object'; |
438 | |
448 | |
439 | if ($more) { |
449 | if ($more) { |
440 | $more->{more} = $arc; |
450 | $more->{more} = $arc; |
441 | } else { |
451 | } else { |
… | |
… | |
443 | } |
453 | } |
444 | $prev = $arc; |
454 | $prev = $arc; |
445 | $more = undef; |
455 | $more = undef; |
446 | } elsif (/^arch (\S+)$/i) { |
456 | } elsif (/^arch (\S+)$/i) { |
447 | my $name = $1; |
457 | my $name = $1; |
448 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); |
458 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
|
|
459 | undef $comment; |
|
|
460 | delete $arc{_comment} unless length $arc{_comment}; |
449 | $arc->{_atype} = 'arch'; |
461 | $arc->{_atype} = 'arch'; |
450 | |
462 | |
451 | if ($more) { |
463 | if ($more) { |
452 | $more->{more} = $arc; |
464 | $more->{more} = $arc; |
453 | } else { |
465 | } else { |
… | |
… | |
462 | push @{$toplevel->{lev_array}}, $_+0; |
474 | push @{$toplevel->{lev_array}}, $_+0; |
463 | } |
475 | } |
464 | } else { |
476 | } else { |
465 | $toplevel->{$1} = $2; |
477 | $toplevel->{$1} = $2; |
466 | } |
478 | } |
|
|
479 | } elsif (/^\s*#/) { |
|
|
480 | $comment .= "$_\n"; |
467 | } elsif (/^\s*($|#)/) { |
481 | } elsif (/^\s*($|#)/) { |
468 | # |
482 | # |
469 | } else { |
483 | } else { |
470 | die "$path: unparseable top-level line '$_'"; |
484 | die "$path: unparseable top-level line '$_'"; |
471 | } |
485 | } |
… | |
… | |
491 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
505 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
492 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
506 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
493 | | (delete $a{attack_movement_bits_4_7}); |
507 | | (delete $a{attack_movement_bits_4_7}); |
494 | } |
508 | } |
495 | |
509 | |
|
|
510 | if (my $comment = delete $a{_comment}) { |
|
|
511 | if ($comment =~ /[^\n\s#]/) { |
|
|
512 | $str .= $comment; |
|
|
513 | } |
|
|
514 | } |
|
|
515 | |
496 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
516 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
497 | |
517 | |
498 | my $inv = delete $a{inventory}; |
518 | my $inv = delete $a{inventory}; |
499 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
519 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
500 | my $anim = delete $a{anim}; |
520 | my $anim = delete $a{anim}; |
501 | |
521 | |
502 | my @kv; |
522 | my @kv; |
503 | |
523 | |
… | |
… | |
559 | if $anim; |
579 | if $anim; |
560 | } |
580 | } |
561 | |
581 | |
562 | $str .= "end\n"; |
582 | $str .= "end\n"; |
563 | |
583 | |
564 | if (($a{_atype} eq 'object') && $more) { |
584 | if ($a{_atype} eq 'object') { |
|
|
585 | if ($more) { |
565 | $str .= "\nmore\n"; |
586 | $str .= "more\n"; |
566 | $append->($more) if $more; |
587 | $append->($more) if $more; |
|
|
588 | } else { |
|
|
589 | $str .= "\n"; |
|
|
590 | } |
567 | } |
591 | } |
568 | }; |
592 | }; |
569 | |
593 | |
570 | for (@$arch) { |
594 | for (@$arch) { |
571 | $append->($_); |
595 | $append->($_); |
… | |
… | |
600 | my ($a) = @_; |
624 | my ($a) = @_; |
601 | |
625 | |
602 | my $o = $ARCH{$a->{_name}} |
626 | my $o = $ARCH{$a->{_name}} |
603 | or return; |
627 | or return; |
604 | |
628 | |
605 | my $face = $FACE{$a->{face} || $o->{face} || "blank.111"} |
629 | my $face = $FACE{$a->{face} || $o->{face} || "blank.111"}; |
|
|
630 | unless ($face) { |
|
|
631 | $face = $FACE{"blank.x11"} |
606 | or (warn "no face data found for arch '$a->{_name}'"), return; |
632 | or (warn "no face data found for arch '$a->{_name}'"), return; |
|
|
633 | } |
607 | |
634 | |
608 | if ($face->{w} > 1 || $face->{h} > 1) { |
635 | if ($face->{w} > 1 || $face->{h} > 1) { |
609 | # bigface |
636 | # bigface |
610 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
637 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
611 | |
638 | |