1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | # cfmap2html - convert crossfire maps to html |
3 | # cfmap2html - convert deliantra maps to html |
4 | # Copyright (C) 2005,2007 Marc Lehmann <cfmaps@schmorp.de> |
4 | # Copyright (C) 2005,2007,2008,2009 Marc Lehmann <cfmaps@schmorp.de> |
5 | # |
5 | # |
6 | # CFMAP2HTML is free software; you can redistribute it and/or modify |
6 | # CFMAP2HTML is free software; you can redistribute it and/or modify |
7 | # it under the terms of the GNU General Public License as published by |
7 | # it under the terms of the GNU General Public License as published by |
8 | # the Free Software Foundation; either version 2 of the License, or |
8 | # the Free Software Foundation; either version 2 of the License, or |
9 | # (at your option) any later version. |
9 | # (at your option) any later version. |
… | |
… | |
15 | # |
15 | # |
16 | # You should have received a copy of the GNU General Public License |
16 | # You should have received a copy of the GNU General Public License |
17 | # along with cfmaps; if not, write to the Free Software |
17 | # along with cfmaps; if not, write to the Free Software |
18 | # Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | # Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | |
19 | |
20 | our $VERSION = '2.1'; |
20 | our $VERSION = '2.201'; |
21 | |
21 | |
22 | use strict; |
22 | use strict; |
23 | |
23 | |
24 | use List::Util qw(min max); |
24 | use List::Util qw(min max); |
25 | use Crossfire 1.0; |
25 | use Deliantra; |
26 | |
26 | |
27 | my $T = 32; |
27 | my $T = 32; |
28 | |
28 | |
29 | sub escape_html($) { |
29 | sub escape_html($) { |
30 | local $_ = shift; |
30 | local $_ = shift; |
… | |
… | |
40 | |
40 | |
41 | if (!-e "$base.png" |
41 | if (!-e "$base.png" |
42 | || -M "$base.png" > -M "$base.map") { |
42 | || -M "$base.png" > -M "$base.map") { |
43 | # regenerate png and metainfo |
43 | # regenerate png and metainfo |
44 | push @cfmap2png, $path; |
44 | push @cfmap2png, $path; |
|
|
45 | # force xhtml file to be remade as well |
|
|
46 | utime 1, 1, "$base.xhtml"; |
45 | } |
47 | } |
46 | } |
48 | } |
47 | |
49 | |
48 | system "cfmap2png", @cfmap2png |
50 | system "cfmap2png", @cfmap2png |
49 | if @cfmap2png; |
51 | if @cfmap2png; |
|
|
52 | |
|
|
53 | Deliantra::load_archetypes; |
50 | |
54 | |
51 | for my $path (@ARGV) { |
55 | for my $path (@ARGV) { |
52 | (my $base = $path) =~ s/\.map//; |
56 | (my $base = $path) =~ s/\.map//; |
53 | if (!-e "$base.xhtml" |
57 | if (!-e "$base.xhtml" |
54 | || -M "$base.xhtml" > -M "$base.map") { |
58 | || -M "$base.xhtml" > -M "$base.map") { |
55 | |
59 | |
56 | Crossfire::load_archetypes |
|
|
57 | unless %ARCH; |
|
|
58 | |
|
|
59 | my $meta = read_arch "$base.map"; |
60 | my $meta = eval { read_arch "$base.map" } |
|
|
61 | or next; |
60 | my $arch = $meta->{arch}; |
62 | my $arch = $meta->{arch}; |
61 | |
63 | |
62 | open my $fh, ">:utf8", "$base.xhtml" |
64 | open my $fh, ">:utf8", "$base.xhtml" |
63 | or die "$base.xhtml: $!"; |
65 | or die "$base.xhtml: $!"; |
64 | |
66 | |
… | |
… | |
109 | : "" |
111 | : "" |
110 | } 1..4; |
112 | } 1..4; |
111 | |
113 | |
112 | print "$path[-1]", |
114 | print "$path[-1]", |
113 | "</span>", |
115 | "</span>", |
114 | "<p class='about'><a href='/about.txt'>[more about cfmaps.schmorp.de]</a></p>", |
116 | "<p class='about'><a href='/about.txt'>[more about maps.deliantra.net]</a></p>", |
115 | "</td>", |
117 | "</td>", |
116 | "<td/><td>$tile[0]</td><td/></tr>", |
118 | "<td/><td>$tile[0]</td><td/></tr>", |
117 | "<tr><td>$tile[3]</td>", |
119 | "<tr><td>$tile[3]</td>", |
118 | "<td><img class='thumb' src='@path[-1].jpg' width='$W' height='$H' alt='map thumbnail'/></td>", |
120 | "<td><img class='thumb' src='@path[-1].jpg' width='$W' height='$H' alt='map thumbnail'/></td>", |
119 | "<td>$tile[1]</td></tr>", |
121 | "<td>$tile[1]</td></tr>", |
… | |
… | |
124 | |
126 | |
125 | print "<p class='m'>", |
127 | print "<p class='m'>", |
126 | escape_html delete $info->{msg}, |
128 | escape_html delete $info->{msg}, |
127 | "</p>"; |
129 | "</p>"; |
128 | |
130 | |
|
|
131 | if (open my $fh, "<", "$base.png.err") { |
|
|
132 | local $/; |
129 | print "<p class='i'><table>", |
133 | print "<p class='m'>", |
|
|
134 | (escape_html scalar <$fh>), |
|
|
135 | "</p>"; |
|
|
136 | } |
|
|
137 | |
|
|
138 | print "<table class='i'>", |
130 | (map "<tr><td>" . (escape_html $_) . "</td><td>" . (escape_html $info->{$_}) . "</td></tr>", |
139 | (map "<tr><td>" . (escape_html $_) . "</td><td>" . (escape_html $info->{$_}) . "</td></tr>", |
131 | grep !/^_/, keys %$info), |
140 | grep !/^_/, keys %$info), |
132 | "</table></p>"; |
141 | "</table>", |
|
|
142 | "<p />"; |
133 | |
143 | |
134 | print "<table class='map'>"; |
144 | print "<table class='map'>"; |
135 | |
145 | |
136 | my %ignore = map +($_ => 1), qw(name _name _atype x y); |
146 | my %ignore = map +($_ => 1), qw(name _name _atype x y); |
137 | my %is_exit = map +($_ => 1), 41, 57, 66; |
147 | my %is_exit = map +($_ => 1), 41, 57, 66; |
… | |
… | |
140 | print "<tr>"; |
150 | print "<tr>"; |
141 | for my $x (0.. $W - 1) { |
151 | for my $x (0.. $W - 1) { |
142 | if (my $as = $map[$x][$y]) { |
152 | if (my $as = $map[$x][$y]) { |
143 | my @class; |
153 | my @class; |
144 | |
154 | |
145 | push @class, "fishy" if grep $_->{invisible} || $_->{face} || exists $_->{no_pass} || exists $_->{no_pick}, @$as; |
155 | push @class, "fishy" if grep exists $_->{invisible} || exists $_->{face} |
|
|
156 | || exists $_->{move_block} || exists $_->{move_allow} |
|
|
157 | || exists $_->{no_pick}, @$as; |
146 | push @class, "exit" if grep $is_exit{$ARCH{$_->{_name}}{type}} && $_->{slaying}, @$as; |
158 | push @class, "exit" if grep $is_exit{$ARCH{$_->{_name}}{type}} && $_->{slaying}, @$as; |
147 | push @class, "dialog" if grep $_->{msg} =~ /^\@match/m, @$as; |
159 | push @class, "dialog" if grep $_->{msg} =~ /^\@match/m, @$as; |
148 | |
160 | |
149 | print "<td", (@class ? " class='" . (join " ", @class) . "'" : ""), ">"; |
161 | print "<td", (@class ? " class='" . (join " ", @class) . "'" : ""), ">"; |
150 | print "<div>"; |
162 | print "<div>"; |
… | |
… | |
155 | |
167 | |
156 | print "<div>($x|$y)"; |
168 | print "<div>($x|$y)"; |
157 | |
169 | |
158 | sub print_archs { |
170 | sub print_archs { |
159 | print "<ul>"; |
171 | print "<ul>"; |
160 | for my $a (@{$_[0]}) { |
172 | for my $a (reverse @{$_[0]}) { |
161 | my $o = $ARCH{$a->{_name}}; |
173 | my $o = $ARCH{$a->{_name}}; |
162 | my $type = $a->{type} || $o->{type}; |
174 | my $type = $a->{type} || $o->{type}; |
163 | my $aname = escape_html $a->{_name}; |
175 | my $aname = escape_html $a->{_name}; |
164 | my $name = escape_html $a->{name} || $o->{name}; |
176 | my $name = escape_html $a->{name} || $o->{name}; |
165 | |
177 | |
… | |
… | |
170 | |
182 | |
171 | if ($_ eq "slaying" && $is_exit{$type}) { # door, teleporter, player_changer |
183 | if ($_ eq "slaying" && $is_exit{$type}) { # door, teleporter, player_changer |
172 | $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1 |
184 | $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1 |
173 | if $v eq "/!"; # random map |
185 | if $v eq "/!"; # random map |
174 | |
186 | |
|
|
187 | if ($v =~ s/^\*//) { |
|
|
188 | print "slaying => <a href='/search?t=$v'>*$v</a>\n"; |
|
|
189 | } else { |
175 | print "slaying => <a href='$v.xhtml'>$v</a>\n"; |
190 | print "slaying => <a href='$v.xhtml'>$v</a>\n"; |
|
|
191 | } |
176 | } elsif ($_ eq "other_arch") { |
192 | } elsif ($_ eq "other_arch") { |
177 | print "$_ => <a href='/a/$a->{$_}'>$v</a>\n"; |
193 | print "$_ => <a href='/a/$a->{$_}'>$v</a>\n"; |
178 | } elsif ($_ eq "inventory") { |
194 | } elsif ($_ eq "inventory") { |
179 | print "inventory =>\n"; |
195 | print "inventory =>\n"; |
180 | print_archs ($a->{$_}); |
196 | print_archs ($a->{$_}); |