ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cfmaps/cfmap2html
(Generate patch)

Comparing cfmaps/cfmap2html (file contents):
Revision 1.4 by root, Fri Nov 18 11:15:53 2005 UTC vs.
Revision 1.9 by root, Sun Nov 20 00:58:57 2005 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
3# cfmap2html - convert crossfire maps to html
4# Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de>
5#
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
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with gvpe; if not, write to the Free Software
18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2 19
3use Storable; 20use Storable;
4 21
5my $LIBDIR = $ENV{CROSSFIRE_LIBDIR} 22my $LIBDIR = $ENV{CROSSFIRE_LIBDIR}
6 or die "\$CROSSFIRE_LIBDIR must be set\n"; 23 or die "\$CROSSFIRE_LIBDIR must be set\n";
9 26
10my $arch; 27my $arch;
11 28
12umask 022; 29umask 022;
13 30
31our $VERSION = '1.04';
32
14sub escape_html($) { 33sub escape_html($) {
15 local $_ = shift; 34 local $_ = shift;
16 s/([<>&])/sprintf "&#%d;", ord $1/ge; 35 s/([<>&])/sprintf "&#%d;", ord $1/ge;
17 $_ 36 $_
18} 37}
19 38
20for my $path (@ARGV) { 39for my $path (@ARGV) {
21 print "$path\n"; 40# print STDERR "$path\n";
22 41
23 if (!-e "$path.png" 42 if (!-e "$path.png"
24 || !-e "$path.pst" 43 || !-e "$path.pst"
25 || -M "$path.pst" > -M $path 44 || -M "$path.pst" > -M $path
26 || -M "$path.png" > -M $path) { 45 || -M "$path.png" > -M $path) {
43 my (@path) = split /\//, $path; 62 my (@path) = split /\//, $path;
44 63
45 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">", 64 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">",
46 "<html>", 65 "<html>",
47 "<head>", 66 "<head>",
48 "<title>$path</title>", 67 "<title>Crossfire Map \"$path\"</title>",
49 "<style type='text/css'><!--\n", 68 "<style type='text/css'><!--\n",
50 "body { background: white; text-color: black; }\n", 69 "body { background: white; color: black; }\n",
51 "a { text-color: blue; }\n", 70 "a { color: blue; }\n",
52 "a:hover { text-color: red; }\n", 71 "a:hover { color: #800; }\n",
72 "a:active { color: #f00; }\n",
53 "a:visited { text-color: #008; }\n", 73 "a:visited { color: #008; }\n",
74 "img { display: block; }\n",
54 75
55 "#nav { border-spacing: 0px; margin: 10px; padding: 0px; }\n", 76 ".nav { border-spacing: 0px; margin: 10px; padding: 0px; }\n",
56 "#nav td { margin: 0px; padding: 0px; border: 0px; }\n", 77 ".nav td { margin: 0px; padding: 0px; border: 0px; }\n",
57 "#thumb { border: 2px solid yellow; width: $meta->{width}px; height: $meta->{height}px; padding: 0px; }\n", 78 ".thumb { border: 3px solid yellow; width: $meta->{width}px; height: $meta->{height}px; padding: 0px; }\n",
79 ".tile { border: 3px solid blue; }\n",
80 ".tile:hover { border: 3px solid yellow; }\n",
58 81
59 "#map { table-layout: fixed; width: ${W}px; height: ${H}px; border: 2px solid #777; border-spacing: 0px; ", 82 ".map { table-layout: fixed; width: ${W}px; height: ${H}px; border: 2px solid #777; border-spacing: 0px; ",
60 "background-image: url($path[-1].png); background-position: 0px 0px; background-repeat: no-repeat; background-attachment: relative; }\n", 83 "background-image: url($path[-1].png); background-position: 0px 0px; background-repeat: no-repeat; }\n",
61 "#map tr { width: ${W}px; height: ${T}px; border-style: none; margin: 0px; padding: 0px; }\n", 84 ".map tr { width: ${W}px; height: ${T}px; border-style: none; margin: 0px; padding: 0px; }\n",
62 85
63 "#map td { width: ${T}px; height: ${T}px; border-style: none; margin: 0px; padding: 0px; }\n", 86 ".map td { width: ${T}px; height: ${T}px; border-style: none; margin: 0px; padding: 0px; }\n",
64 "#map td:hover { border: 3px solid yellow; border-style: ridge; }\n", 87 ".map td:hover { border: 3px solid yellow; border-style: ridge; }\n",
65 88
66 "#map span { position: relative; }\n", 89 ".map span { position: relative; }\n",
67 90
68 "#map div { display: none; position: absolute; min-width: 40em; ", 91 ".map div { display: none; position: absolute; min-width: 40em; ",
69 "font-size: 8pt; border: 0px; background: #eee; border: 3px solid yellow; border-style: ridge; padding: 4px; }\n", 92 "font-size: 8pt; border: 0px; background: #eee; border: 3px solid yellow; border-style: ridge; padding: 4px; }\n",
70 "#map td:hover div { display: block; position: absolute; z-index: 1; top: -1px; left: ${T}px; white-space: pre; }\n", 93 ".map td:hover div { display: block; position: absolute; z-index: 1; top: -1px; left: ${T}px; white-space: pre; }\n",
71 94
72 "p.m { white-space: pre; margin-left: 2em; background: #ddd; padding: 2px; border: 1px solid black; }\n", 95 "p.m { white-space: pre; margin-left: 2em; background: #ddd; padding: 2px; border: 1px solid black; }\n",
73 "-->\n</style>", 96 "-->\n</style>",
74 "</head>", 97 "</head>",
75 "<body>"; 98 "<body>";
76 99
77 print "<table id='nav'>", 100 print "<table class='nav'>",
78 "<tr><td rowspan='3'><h1>"; 101 "<tr style='vertical-align: middle;'><td rowspan='3' style='padding-right: 3em'>",
102 "Crossfire Map<br/>",
103 "<span style='font-size: 18pt'>";
79 print "<a href='/'>/</a> "; 104 print "<a href='/'>/</a> ";
80 for (0 .. $#path - 1) { 105 for (0 .. $#path - 1) {
81 print "<a href='/", (join "/", @path[0..$_]), "/'>$path[$_]</a> / "; 106 print "<a href='/", (join "/", @path[0..$_]), "/'>$path[$_]</a> / ";
82 } 107 }
83 108
84 my @tile = map { 109 my @tile = map {
85 $meta->{info}{"tile_path_$_"} 110 $meta->{info}{"tile_path_$_"}
86 ? "<a href='$meta->{info}{\"tile_path_$_\"}.html'><img style='border: 2px solid blue;' src='$meta->{info}{\"tile_path_$_\"}.jpg'/></a>" 111 ? "<a href='$meta->{info}{\"tile_path_$_\"}.html'><img class='tile' src='$meta->{info}{\"tile_path_$_\"}.jpg' alt='tile_path_$_'/></a>"
87 : "" 112 : ""
88 } 1..4; 113 } 1..4;
114 #"}"# vim misparses without this comment
89 115
90 print "$path[-1] "; 116 print "$path[-1]",
91 print "</h1></td>", 117 "</span>",
118 "<p style='font-size: 8pt;'><a href='/about.txt'>[more about cfmaps.schmorp.de]</a></p>",
119 "</td>",
92 "<td/><td>$tile[0]</td><td/></tr>", 120 "<td/><td>$tile[0]</td><td/></tr>",
93 "<tr><td>$tile[3]</td>"; 121 "<tr><td>$tile[3]</td>",
94 print "<td><img id='thumb' src='@path[-1].jpg'/></td>", 122 "<td><img class='thumb' src='@path[-1].jpg' alt='map thumbnail'/></td>",
95 "<td>$tile[1]</td>", 123 "<td>$tile[1]</td></tr>",
96 "<tr><td/><td>$tile[2]</td><td/></tr>"; 124 "<tr><td/><td>$tile[2]</td><td/></tr>",
97 print "</table>"; 125 "</table>";
98 126
99 my $W1 = $W + 600; 127 my $W1 = $W + 600;
100 128
101 print "<p style='width: ${W1}px'><a href='/about.txt'>[about cfmaps.schmorp.de]</a></p>";
102 print "<p class='m' style='white-space: pre; width=auto; '>", 129 print "<p class='m' style='white-space: pre; width: auto; '>",
103 escape_html $meta->{info}{msg}, 130 escape_html $meta->{info}{msg},
104 "</p>"; 131 "</p>";
105 132
106 print "<table id='map'>"; 133 print "<table class='map'>";
107 134
108 my %ignore = map +($_ => 1), qw(_name x y); 135 my %ignore = map +($_ => 1), qw(name _name x y);
109 136
110 for my $y (0.. $meta->{height} - 1) { 137 for my $y (0.. $meta->{height} - 1) {
111 print "<tr>"; 138 print "<tr>";
112 for my $x (0.. $meta->{width} - 1) { 139 for my $x (0.. $meta->{width} - 1) {
113 print "<td>"; 140 print "<td>";
114 if (my $as = $meta->{map}[$x][$y]) { 141 if (my $as = $meta->{map}[$x][$y]) {
115 print "<span><div>($x|$y)<ul>"; 142 print "<span><div>($x|$y)";
116 for my $a (@$as) {
117 my $o = $arch->{$a->{_name}};
118 print "<li>\"$o->{name}\" ($a->{_name})\n";
119 for (sort keys %$a) {
120 next if $ignore{$_};
121 my $v = escape_html $a->{$_};
122 143
123 if (($o->{type} == 66 || $o->{type} == 41) && $_ eq "slaying") { # door, teleporter 144 sub print_archs {
124 $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1 145 print "<ul>";
125 if $v eq "/!"; # random map 146 for my $a (@{$_[0]}) {
147 my $o = $arch->{$a->{_name}};
148 my $type = $a->{type} || $o->{type};
149 my $aname = escape_html $a->{_name};
150 my $name = escape_html $a->{name} || $o->{name};
126 151
152 print "<li><a href='/archetypes.html#", (lc $a->{_name}), "'>$aname \"$name\"</a>\n";
153 for (sort keys %$a) {
154 next if $ignore{$_};
155 my $v = escape_html $a->{$_};
156
157 if (($type == 66 || $type == 41) && $_ eq "slaying") { # door, teleporter
158 $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1
159 if $v eq "/!"; # random map
160
127 print "slaying => <a href='$v.html'>$v</a>\n"; 161 print "slaying => <a href='$v.html'>$v</a>\n";
162 } elsif ($_ eq "other_arch") {
163 print "$_ => <a href='/archetypes.html#", (lc $a->{$_}), "'>$v</a>\n";
164 } elsif ($_ eq "inventory") {
165 print "inventory =>\n";
166 print_archs ($a->{$_});
128 } elsif ($_ eq "msg") { 167 } elsif ($_ eq "msg") {
129 print "<p class='m'>$v</p>"; 168 print "<p class='m'>$v</p>";
130 } else { 169 } else {
131 print "$_ => $v\n"; 170 print "$_ => $v\n";
171 }
132 } 172 }
173 print "</li>";
133 } 174 }
175 print "</ul>";
134 } 176 }
177
178 print_archs $as;
135 print "</ul></div></span>"; 179 print "</div></span>";
136 } 180 }
137 print "</td>"; 181 print "</td>";
138 } 182 }
139 print "</tr>"; 183 print "</tr>";
140 } 184 }
141 185
142 print "</table></p><p style='height: 600px;'/></body></html>"; 186 my $W2 = $W + 600;
187
188 print "</table><hr/><p style='font-size: 8pt'>created by <b>cfmap2html</b> version $VERSION</p>",
189 "<p style='width: ${W2}px; height: 600px;'/></body></html>";
143 190
144 close $fh; 191 close $fh;
145 192
146 system "gzip", "-7f", "$path.html"; 193 system "gzip", "-7f", "$path.html";
147} 194}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines