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

Comparing deliantra/gde/GCE/Util.pm (file contents):
Revision 1.4 by elmex, Sun Mar 12 23:32:58 2006 UTC vs.
Revision 1.13 by elmex, Sat Apr 1 18:45:05 2006 UTC

15use Storable; 15use Storable;
16use List::Util qw(min max); 16use List::Util qw(min max);
17 17
18use Crossfire; 18use Crossfire;
19use Crossfire::MapWidget; 19use Crossfire::MapWidget;
20use File::Spec::Functions;
21use Cwd 'abs_path';
20 22
21our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall stack_find arch_is_wall arch_is_monster add_table_widget); 23our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall stack_find arch_is_wall arch_is_monster add_table_widget quick_msg def arch_is_exit map2abs exit_paths);
24
25sub exit_paths {
26 my ($mappath, $map1path, $map2path) = @_;
27 $mappath = abs_path $mappath;
28 $map1path = abs_path $map1path;
29 $map2path = abs_path $map2path;
30
31 if ( (substr $map1path, 0, length $mappath) eq $mappath
32 and (substr $map2path, 0, length $mappath) eq $mappath) {
33 substr $map1path, 0, length $mappath, '';
34 substr $map2path, 0, length $mappath, '';
35
36 my ($v1, $d1, $f1) = File::Spec->splitpath ($map1path);
37 my ($v2, $d2, $f2) = File::Spec->splitpath ($map2path);
38
39 my @di1 = File::Spec->splitdir ($d1);
40 my @di2 = File::Spec->splitdir ($d2);
41
42 if ((defined $di1[1]) and (defined $di2[1]) and $di1[1] eq $di2[1]) {
43 my $m1 = File::Spec->abs2rel ($map1path, File::Spec->catdir (@di2));
44 my $m2 = File::Spec->abs2rel ($map2path, File::Spec->catdir (@di1));
45 return ($m1, $m2);
46 } else {
47 return ($map1path, $map2path);
48 }
49 } else {
50 return ('', '');
51 }
52}
53
54sub map2abs {
55 my ($dest, $mape) = @_;
56
57 my $dir;
58 if (File::Spec->file_name_is_absolute($dest)) {
59 $dir = catdir ($::CFG->{MAPDIR}, $dest);
60 } else {
61 my ($v, $p, $f) = File::Spec->splitpath ($mape->{path});
62 $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p));
63 }
64 return $dir;
65}
66
67sub def($$) {
68 return defined ($_[0]) ? $_[0] : $_[1];
69}
70
71sub quick_msg {
72 my $wid = shift;
73 my $msg;
74 my $win = $::MAINWIN;
75 if (ref $wid) {
76 $win = $wid;
77 $msg = shift;
78 } else {
79 $msg = $wid;
80 }
81 my $dia = Gtk2::Dialog->new ('Message', $win, 'destroy-with-parent', 'gtk-ok' => 'none');
82
83 my $lbl = Gtk2::Label->new ($msg);
84 $dia->vbox->add ($lbl);
85 $dia->signal_connect (response => sub { $_[0]->destroy });
86
87 unless (defined $_[0]) {
88 Glib::Timeout->add (1000, sub { $dia->destroy; 0 });
89 }
90
91 $dia->show_all;
92}
22 93
23sub new_arch_pb { 94sub new_arch_pb {
24 # this is awful, is this really the best way? 95 # this is awful, is this really the best way?
25 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; 96 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
26 return $pb; 97 return $pb;
27} 98}
28 99
29sub fill_pb_from_arch { 100sub fill_pb_from_arch {
30 my ($pb, $arch) = @_; 101 my ($pb, $a) = @_;
102
103 my $o = $Crossfire::ARCH{$a->{_name}};
104 my $face = $Crossfire::FACE{$a->{face} || $o->{face} || "blank.111"}
105 or warn "no gfx found for arch '$a->{_name}' at ($x|$y)\n";
106
107 $face or return;
31 108
32 $pb->fill (0x00000000); 109 $pb->fill (0x00000000);
33 $TILE->composite ($pb, 110 $TILE->composite ($pb,
34 0, 0, 111 0, 0,
35 TILESIZE, TILESIZE, 112 TILESIZE, TILESIZE,
36 - ($arch->{_face} % 64) * TILESIZE, - TILESIZE * int $arch->{_face} / 64, 113 - ($face->{idx} % 64) * TILESIZE, - TILESIZE * int $face->{idx} / 64,
37 1, 1, 'nearest', 255 114 1, 1, 'nearest', 255
38 ); 115 );
39} 116}
40 117
41sub classify_arch_layer { 118sub classify_arch_layer {
53 130
54 return 'between'; 131 return 'between';
55 } 132 }
56} 133}
57 134
135sub arch_is_exit {
136 my ($a) = @_;
137 my $type = $Crossfire::ARCH{$a->{_name}}->{type};
138 return $type eq '66' || $type eq '41';
139}
140
58sub arch_is_floor { 141sub arch_is_floor {
59 my ($a) = @_; 142 my ($a) = @_;
143 my $ar = Crossfire::arch_attr $a;
144 return (substr $ar->{name}, 0, 5) eq 'Floor';
60 return $Crossfire::ARCH{$a->{_name}}->{is_floor}; 145#return $Crossfire::ARCH{$a->{_name}}->{is_floor};
61} 146}
62 147
63sub arch_is_wall { 148sub arch_is_wall {
64 my ($a) = @_; 149 my ($a) = @_;
150 my $ar = Crossfire::arch_attr $a;
151 return $ar->{name} eq 'Wall';
65 return $Crossfire::ARCH{$a->{_name}}->{no_pass}; 152#return $Crossfire::ARCH{$a->{_name}}->{no_pass};
66} 153}
67 154
68sub arch_is_monster { 155sub arch_is_monster {
69 my ($a) = @_; 156 my ($a) = @_;
70 my $arch = $Crossfire::ARCH{$a->{_name}}; 157 my $arch = $Crossfire::ARCH{$a->{_name}};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines