… | |
… | |
16 | use List::Util qw(min max); |
16 | use List::Util qw(min max); |
17 | |
17 | |
18 | use Crossfire; |
18 | use Crossfire; |
19 | use Crossfire::MapWidget; |
19 | use Crossfire::MapWidget; |
20 | use File::Spec::Functions; |
20 | use File::Spec::Functions; |
|
|
21 | use File::Basename; |
|
|
22 | use File::Path; |
|
|
23 | use HTTP::Request::Common; |
21 | use Cwd 'abs_path'; |
24 | use Cwd 'abs_path'; |
|
|
25 | use strict; |
22 | |
26 | |
23 | our @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 pseudohtml2txt); |
27 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb |
|
|
28 | fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall |
|
|
29 | stack_find arch_is_wall arch_is_monster add_table_widget quick_msg |
|
|
30 | def arch_is_exit map2abs exit_paths pseudohtml2txt arch_is_connector); |
24 | |
31 | |
25 | sub pseudohtml2txt { |
32 | sub pseudohtml2txt { |
26 | my ($html) = @_; |
33 | my ($html) = @_; |
27 | |
34 | |
28 | $html =~ s/<br\s*?\/?>/\n/gsi; |
35 | $html =~ s/<br\s*?\/?>/\n/gsi; |
29 | $html =~ s/<b>(.*?)<\/b>/_\1_/gsi; |
36 | $html =~ s/<b>(.*?)<\/b>/_\1_/gsi; |
|
|
37 | $html =~ s/<li>/\n* /gi; |
|
|
38 | $html =~ s/<\/?\s*li>//gi; |
|
|
39 | $html =~ s/<\/?\s*ul>//gi; |
|
|
40 | $html =~ s/>/>/g; |
|
|
41 | $html =~ s/</</g; |
30 | $html |
42 | $html |
31 | } |
43 | } |
32 | |
44 | |
33 | sub exit_paths { |
45 | sub exit_paths { |
34 | my ($mappath, $map1path, $map2path) = @_; |
46 | my ($mappath, $map1path, $map2path) = @_; |
… | |
… | |
60 | } |
72 | } |
61 | |
73 | |
62 | sub map2abs { |
74 | sub map2abs { |
63 | my ($dest, $mape) = @_; |
75 | my ($dest, $mape) = @_; |
64 | |
76 | |
|
|
77 | #$dest = abs_path $dest; |
65 | my $dir; |
78 | my $dir; |
66 | if (File::Spec->file_name_is_absolute($dest)) { |
79 | if (File::Spec->file_name_is_absolute($dest)) { |
67 | $dir = catdir ($::CFG->{MAPDIR}, $dest); |
80 | $dir = catdir ($::MAPDIR, $dest); |
68 | } else { |
81 | } else { |
69 | my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
82 | my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
70 | $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
83 | $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
71 | } |
84 | } |
72 | return $dir; |
85 | return $dir; |
… | |
… | |
107 | |
120 | |
108 | sub fill_pb_from_arch { |
121 | sub fill_pb_from_arch { |
109 | my ($pb, $a) = @_; |
122 | my ($pb, $a) = @_; |
110 | |
123 | |
111 | my $o = $Crossfire::ARCH{$a->{_name}}; |
124 | my $o = $Crossfire::ARCH{$a->{_name}}; |
112 | my $face = $Crossfire::FACE{$a->{face} || $o->{face} || "blank.111"} |
125 | my $face = $Crossfire::FACE{$a->{face} || $o->{face} || "blank.111"}; |
|
|
126 | unless ($face) { |
|
|
127 | $face = $Crossfire::FACE{"blank.x11"} |
113 | or warn "no gfx found for arch '$a->{_name}' at ($x|$y)\n"; |
128 | or warn "no gfx found for arch '$a->{_name}'\n"; |
|
|
129 | } |
114 | |
130 | |
115 | $face or return; |
131 | $face or return; |
116 | |
132 | |
117 | $pb->fill (0x00000000); |
133 | $pb->fill (0x00000000); |
118 | $TILE->composite ($pb, |
134 | $TILE->composite ($pb, |
… | |
… | |
147 | } |
163 | } |
148 | |
164 | |
149 | sub arch_is_floor { |
165 | sub arch_is_floor { |
150 | my ($a) = @_; |
166 | my ($a) = @_; |
151 | my $ar = Crossfire::arch_attr $a; |
167 | my $ar = Crossfire::arch_attr $a; |
|
|
168 | return ( |
152 | return (substr $ar->{name}, 0, 5) eq 'Floor'; |
169 | (substr $ar->{name}, 0, 5) eq 'Floor' |
153 | #return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |
170 | or (substr $ar->{name}, 0, 10) eq 'Shop Floor' |
|
|
171 | ) |
|
|
172 | } |
|
|
173 | |
|
|
174 | sub arch_is_connector { |
|
|
175 | my ($a) = @_; |
|
|
176 | my $ar = Crossfire::arch_attr $a; |
|
|
177 | my $has_connect_field = 0; |
|
|
178 | |
|
|
179 | TOP: for (@{$ar->{section}}) { |
|
|
180 | my $name = shift @$_; |
|
|
181 | my @r = @$_; |
|
|
182 | if ($name eq 'general') { |
|
|
183 | for (@r) { |
|
|
184 | my ($k, $s) = ($_->[0], $_->[1]); |
|
|
185 | if ($k eq 'connected' && $s->{name} eq 'connection') { |
|
|
186 | $has_connect_field = 1; |
|
|
187 | last TOP; |
|
|
188 | } |
|
|
189 | } |
|
|
190 | last TOP; |
|
|
191 | } |
|
|
192 | } |
|
|
193 | |
|
|
194 | return $has_connect_field; |
154 | } |
195 | } |
155 | |
196 | |
156 | sub arch_is_wall { |
197 | sub arch_is_wall { |
157 | my ($a) = @_; |
198 | my ($a) = @_; |
158 | my $ar = Crossfire::arch_attr $a; |
199 | my $ar = Crossfire::arch_attr $a; |
… | |
… | |
317 | } |
358 | } |
318 | |
359 | |
319 | return \@outstack; |
360 | return \@outstack; |
320 | } |
361 | } |
321 | |
362 | |
|
|
363 | sub upload { |
|
|
364 | my ($login, $password, $srcrep, $path, $rev, $mapdata) = @_; |
|
|
365 | require LWP::UserAgent; |
|
|
366 | my $ua = LWP::UserAgent->new ( |
|
|
367 | agent => "gcrossedit", |
|
|
368 | keep_alive => 1, |
|
|
369 | env_proxy => 1, |
|
|
370 | timeout => 30, |
|
|
371 | ); |
|
|
372 | require HTTP::Request::Common; |
|
|
373 | |
|
|
374 | my $res = $ua->post ( |
|
|
375 | $ENV{CFPLUS_UPLOAD}, |
|
|
376 | Content_Type => 'multipart/form-data', |
|
|
377 | Content => [ |
|
|
378 | path => $path, |
|
|
379 | mapdir => $srcrep, |
|
|
380 | map => $mapdata, |
|
|
381 | revision => $rev, |
|
|
382 | cf_login => $login, #ENV{CFPLUS_LOGIN}, |
|
|
383 | cf_password => $password, #ENV{CFPLUS_PASSWORD}, |
|
|
384 | comment => "", |
|
|
385 | ] |
|
|
386 | ); |
|
|
387 | |
|
|
388 | if ($res->is_error) { |
|
|
389 | # fatal condition |
|
|
390 | warn $res->status_line; |
|
|
391 | } else { |
|
|
392 | # script replies are marked as {{..}} |
|
|
393 | my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g; |
|
|
394 | warn map "$_\n", @msgs; |
|
|
395 | } |
|
|
396 | } |
|
|
397 | |
322 | =head1 AUTHOR |
398 | =head1 AUTHOR |
323 | |
399 | |
324 | Marc Lehmann <schmorp@schmorp.de> |
400 | Marc Lehmann <schmorp@schmorp.de> |
325 | http://home.schmorp.de/ |
401 | http://home.schmorp.de/ |
326 | |
402 | |