ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.112 by root, Thu Jun 21 00:07:54 2007 UTC vs.
Revision 1.118 by root, Wed Dec 5 11:39:26 2007 UTC

4 4
5=cut 5=cut
6 6
7package Crossfire; 7package Crossfire;
8 8
9our $VERSION = '1.0'; 9our $VERSION = '1.13';
10 10
11use strict; 11use strict;
12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
22 *ARCH $TILE *FACE *FACEDATA 22 *ARCH $TILE *FACE *FACEDATA
23 TILESIZE CACHESTRIDE 23 TILESIZE CACHESTRIDE
24 editor_archs arch_extents 24 editor_archs arch_extents
25); 25);
26 26
27use JSON::XS qw(from_json to_json); 27use JSON::XS qw(decode_json encode_json);
28 28
29our $LIB = $ENV{CROSSFIRE_LIBDIR}; 29our $LIB = $ENV{CROSSFIRE_LIBDIR};
30 30
31our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" 31our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire"
32 : $ENV{AppData} ? "$ENV{APPDATA}/crossfire" 32 : $ENV{AppData} ? "$ENV{APPDATA}/crossfire"
475} 475}
476 476
477sub attr_thaw($) { 477sub attr_thaw($) {
478 my ($ob) = @_; 478 my ($ob) = @_;
479 479
480 $ob->{attach} = from_json $ob->{attach} 480 $ob->{attach} = decode_json $ob->{attach}
481 if exists $ob->{attach}; 481 if exists $ob->{attach};
482 482
483 $ob 483 $ob
484} 484}
485 485
486sub attr_freeze($) { 486sub attr_freeze($) {
487 my ($ob) = @_; 487 my ($ob) = @_;
488 488
489 $ob->{attach} = Crossfire::to_json $ob->{attach} 489 $ob->{attach} = Crossfire::encode_json $ob->{attach}
490 if exists $ob->{attach}; 490 if exists $ob->{attach};
491 491
492 $ob 492 $ob
493} 493}
494 494
808 808
809 my (%ignore); 809 my (%ignore);
810 my (@section_order, %section, @attr_order); 810 my (@section_order, %section, @attr_order);
811 811
812 while (my $type = shift @import) { 812 while (my $type = shift @import) {
813 push @import,
814 grep $_,
815 map $Crossfire::Data::TYPE{$_},
813 push @import, @{$type->{import} || []}; 816 @{$type->{import} || []};
814 817
815 $attr->{$_} ||= $type->{$_} 818 $attr->{$_} ||= $type->{$_}
816 for qw(name desc use); 819 for qw(name desc use);
817 820
818 for (@{$type->{ignore} || []}) { 821 for (@{$type->{ignore} || []}) {
943=cut 946=cut
944 947
945sub load_tilecache() { 948sub load_tilecache() {
946 require Gtk2; 949 require Gtk2;
947 950
948 if (-e "$LIB/facedata") { # Crossfire TRT faces
949 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache, 951 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
950 sub { 952 sub {
951 my %cache; 953 my %cache;
952 my $facedata = Storable::retrieve "$LIB/facedata"; 954 my $facedata = Storable::retrieve "$LIB/facedata";
953 955
954 $facedata->{version} == 2 956 $facedata->{version} == 2
955 or die "$LIB/facedata: version mismatch, cannot proceed."; 957 or die "$LIB/facedata: version mismatch, cannot proceed.";
956 958
957 my $faces = $facedata->{faceinfo}; 959 my $faces = $facedata->{faceinfo};
958 my $idx = 0; 960 my $idx = 0;
959 961
960 for (sort keys %$faces) { 962 for (sort keys %$faces) {
961 my ($face, $info) = ($_, $faces->{$_}); 963 my ($face, $info) = ($_, $faces->{$_});
962 964
963 my $pb = new Gtk2::Gdk::PixbufLoader; 965 my $pb = new Gtk2::Gdk::PixbufLoader;
964 $pb->write ($info->{data32}); 966 $pb->write ($info->{data32});
965 $pb->close; 967 $pb->close;
966 my $pb = $pb->get_pixbuf; 968 my $pb = $pb->get_pixbuf;
967 969
968 my $tile = $cache{$face} = { 970 my $tile = $cache{$face} = {
969 pb => $pb, 971 pb => $pb,
970 idx => $idx, 972 idx => $idx,
971 w => int $pb->get_width / TILESIZE, 973 w => int $pb->get_width / TILESIZE,
972 h => int $pb->get_height / TILESIZE, 974 h => int $pb->get_height / TILESIZE,
973 }; 975 };
974 976
975 $idx += $tile->{w} * $tile->{h}; 977 $idx += $tile->{w} * $tile->{h};
976 } 978 }
977 979
978 construct_tilecache_pb $idx, \%cache; 980 construct_tilecache_pb $idx, \%cache;
979 981
980 \%cache 982 \%cache
981 }; 983 };
982
983 *FACEDATA = Storable::retrieve "$LIB/facedata";
984
985 } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version
986 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache,
987 sub {
988 my $tile = read_pak "$LIB/crossfire.0";
989
990 my %cache;
991
992 my $idx = 0;
993
994 for my $name (sort keys %$tile) {
995 my $pb = new Gtk2::Gdk::PixbufLoader;
996 $pb->write ($tile->{$name});
997 $pb->close;
998 my $pb = $pb->get_pixbuf;
999
1000 my $tile = $cache{$name} = {
1001 pb => $pb,
1002 idx => $idx,
1003 w => int $pb->get_width / TILESIZE,
1004 h => int $pb->get_height / TILESIZE,
1005 };
1006
1007 $idx += $tile->{w} * $tile->{h};
1008 }
1009
1010 construct_tilecache_pb $idx, \%cache;
1011
1012 \%cache
1013 };
1014
1015 *FACEDATA = { };
1016 }
1017} 984}
1018 985
1019=head1 AUTHOR 986=head1 AUTHOR
1020 987
1021 Marc Lehmann <schmorp@schmorp.de> 988 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines