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

Comparing cfmaps/cfmap2html (file contents):
Revision 1.2 by root, Fri Nov 18 06:57:15 2005 UTC vs.
Revision 1.8 by root, Fri Nov 18 23:43:12 2005 UTC

9 9
10my $arch; 10my $arch;
11 11
12umask 022; 12umask 022;
13 13
14our $VERSION = '1.02';
15
14sub escape_html($) { 16sub escape_html($) {
15 local $_ = shift; 17 local $_ = shift;
16 s/([<>&])/sprintf "&#%d;", ord $1/ge; 18 s/([<>&])/sprintf "&#%d;", ord $1/ge;
17 $_ 19 $_
18} 20}
19 21
20for my $path (@ARGV) { 22for my $path (@ARGV) {
23# print STDERR "$path\n";
24
21 if (!-e "$path.png" 25 if (!-e "$path.png"
22 || !-e "$path.pst" 26 || !-e "$path.pst"
23 || -M "$path.pst" > -M $path 27 || -M "$path.pst" > -M $path
24 || -M "$path.png" > -M $path) { 28 || -M "$path.png" > -M $path) {
25 # regenerate png and metainfo 29 # regenerate png and metainfo
41 my (@path) = split /\//, $path; 45 my (@path) = split /\//, $path;
42 46
43 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">", 47 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">",
44 "<html>", 48 "<html>",
45 "<head>", 49 "<head>",
46 "<title>$path</title>", 50 "<title>Crossfire Map \"$path\"</title>",
47 "<style type='text/css'><!--\n", 51 "<style type='text/css'><!--\n",
48 "body { background: white; text-color: black; }\n", 52 "body { background: white; text-color: black; }\n",
49 "a { text-color: blue; }\n", 53 "a { text-color: blue; }\n",
50 "a:hover { text-color: red; }\n",
51 "a:visited { text-color: #008; }\n", 54 "a:visited { text-color: #008; }\n",
55 "img { display: block; }\n",
52 56
53 "#nav { border-spacing: 0px; margin: 10px; padding: 0px; }\n", 57 "#nav { border-spacing: 0px; margin: 10px; padding: 0px; }\n",
54 "#nav td { margin: 0px; padding: 0px; border: 0px; }\n", 58 "#nav td { margin: 0px; padding: 0px; border: 0px; }\n",
55 "#thumb { border: 2px solid yellow; width: $meta->{width}px; height: $meta->{height}px; padding: 0px; }\n", 59 "#thumb { border: 3px solid yellow; width: $meta->{width}px; height: $meta->{height}px; padding: 0px; }\n",
60 ".tile { border: 3px solid blue; }\n",
61 ".tile:hover { border: 3px solid yellow; }\n",
56 62
57 "#map { table-layout: fixed; width: ${W}px; height: ${H}px; border: 2px solid #777; border-spacing: 0px; ", 63 "#map { table-layout: fixed; width: ${W}px; height: ${H}px; border: 2px solid #777; border-spacing: 0px; ",
58 "background-image: url($path[-1].png); background-position: 0px 0px; background-repeat: no-repeat; background-attachment: relative; }\n", 64 "background-image: url($path[-1].png); background-position: 0px 0px; background-repeat: no-repeat; background-attachment: relative; }\n",
59 "#map tr { width: ${W}px; height: ${T}px; border-style: none; margin: 0px; padding: 0px; }\n", 65 "#map tr { width: ${W}px; height: ${T}px; border-style: none; margin: 0px; padding: 0px; }\n",
60 66
71 "-->\n</style>", 77 "-->\n</style>",
72 "</head>", 78 "</head>",
73 "<body>"; 79 "<body>";
74 80
75 print "<table id='nav'>", 81 print "<table id='nav'>",
76 "<tr><td rowspan='3'><span style='font-height: 20pt; font-style: bold;'>"; 82 "<tr valign='center'><td rowspan='3' style='padding-right: 3em'>",
83 "Crossfire Map<br/>",
84 "<span style='font-size: 18pt'>";
77 print "<a href='/'>/</a> "; 85 print "<a href='/'>/</a> ";
78 for (0 .. $#path - 1) { 86 for (0 .. $#path - 1) {
79 print "<a href='/", (join "/", @path[0..$_]), "/'>$path[$_]</a> / "; 87 print "<a href='/", (join "/", @path[0..$_]), "/'>$path[$_]</a> / ";
80 } 88 }
81 89
82 my @tile = map { 90 my @tile = map {
83 $meta->{info}{"tile_path_$_"} 91 $meta->{info}{"tile_path_$_"}
84 ? "<a href='$meta->{info}{\"tile_path_$_\"}.html'><img style='border: 2px solid blue;' src='$meta->{info}{\"tile_path_$_\"}.jpg'/></a>" 92 ? "<a href='$meta->{info}{\"tile_path_$_\"}.html'><img class='tile' src='$meta->{info}{\"tile_path_$_\"}.jpg'/></a>"
85 : "" 93 : ""
86 } 1..4; 94 } 1..4;
95 #"}"# vim misparses without this comment
87 96
88 print "$path[-1] "; 97 print "$path[-1]",
89 print "</span></td>", 98 "</span>",
99 "<p style='font-size: 8pt;'><a href='/about.txt'>[more about cfmaps.schmorp.de]</a></p>",
100 "</td>",
90 "<td/><td>$tile[0]</td><td/></tr>", 101 "<td/><td>$tile[0]</td><td/></tr>",
91 "<tr><td>$tile[3]</td>"; 102 "<tr><td>$tile[3]</td>",
92 print "<td><img id='thumb' src='@path[-1].jpg'/></td>", 103 "<td><img id='thumb' src='@path[-1].jpg'/></td>",
93 "<td>$tile[1]</td>", 104 "<td>$tile[1]</td>",
94 "<tr><td/><td>$tile[2]</td><td/></tr>"; 105 "<tr><td/><td>$tile[2]</td><td/></tr>",
95 print "</table>"; 106 "</table>";
96 107
97 my $W1 = $W + 600; 108 my $W1 = $W + 600;
98 109
99 print "<p style='width: ${W1}px'><a href='/about.txt'>[about cfmaps.schmorp.de]</a></p>";
100 print "<p class='m' style='white-space: pre; width=auto; '>", 110 print "<p class='m' style='white-space: pre; width=auto; '>",
101 escape_html $meta->{info}{msg}, 111 escape_html $meta->{info}{msg},
102 "</p>"; 112 "</p>";
103 113
104 print "<table id='map'>"; 114 print "<table id='map'>";
105 115
106 my %ignore = map +($_ => 1), qw(_name x y); 116 my %ignore = map +($_ => 1), qw(name _name x y);
107 117
108 for my $y (0.. $meta->{height} - 1) { 118 for my $y (0.. $meta->{height} - 1) {
109 print "<tr>"; 119 print "<tr>";
110 for my $x (0.. $meta->{width} - 1) { 120 for my $x (0.. $meta->{width} - 1) {
111 print "<td>"; 121 print "<td>";
112 if (my $as = $meta->{map}[$x][$y]) { 122 if (my $as = $meta->{map}[$x][$y]) {
113 print "<span><div>($x|$y)<ul>"; 123 print "<span><div>($x|$y)";
114 for my $a (@$as) {
115 my $o = $arch->{$a->{_name}};
116 print "<li>\"$o->{name}\" ($a->{_name})\n";
117 for (sort keys %$a) {
118 next if $ignore{$_};
119 my $v = escape_html $a->{$_};
120 124
121 if (($o->{type} == 66 || $o->{type} == 41) && $_ eq "slaying") { # door, teleporter 125 sub print_archs {
122 $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1 126 print "<ul>";
123 if $v eq "/!"; # random map 127 for my $a (@{$_[0]}) {
128 my $o = $arch->{$a->{_name}};
129 my $aname = escape_html $a->{_name};
130 my $name = escape_html $a->{name} || $o->{name};
131 print "<li><a href='/archetypes.html#", (lc $a->{_name}), "'>$aname \"$name\"</a>\n";
132 for (sort keys %$a) {
133 next if $ignore{$_};
134 my $v = escape_html $a->{$_};
124 135
136 if (($o->{type} == 66 || $o->{type} == 41) && $_ eq "slaying") { # door, teleporter
137 $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1
138 if $v eq "/!"; # random map
139
125 print "slaying => <a href='$v.html'>$v</a>\n"; 140 print "slaying => <a href='$v.html'>$v</a>\n";
141 } elsif ($_ eq "other_arch") {
142 print "$_ => <a href='/archetypes.html#", (lc $a->{$_}), "'>$v</a>\n";
143 } elsif ($_ eq "inventory") {
144 print "inventory =>\n";
145 print_archs ($a->{$_});
126 } elsif ($_ eq "msg") { 146 } elsif ($_ eq "msg") {
127 print "<p class='m'>$v</p>"; 147 print "<p class='m'>$v</p>";
128 } else { 148 } else {
129 print "$_ => $v\n"; 149 print "$_ => $v\n";
150 }
130 } 151 }
131 } 152 }
153 print "</ul>";
132 } 154 }
155
156 print_archs $as;
133 print "</ul></div></span>"; 157 print "</div></span>";
134 } 158 }
135 print "</td>"; 159 print "</td>";
136 } 160 }
137 print "</tr>"; 161 print "</tr>";
138 } 162 }
139 163
140 print "</table></p><p style='height: 600px;'/></body></html>"; 164 my $W2 = $W + 600;
165
166 print "</table></p><hr/><p style='font-size: 8pt'>created by <b>cfmap2html</b> version $VERSION</p>",
167 "<p style='width: ${W2}px; height: 600px;'/></body></html>";
141 168
142 close $fh; 169 close $fh;
143 170
144 system "gzip", "-7f", "$path.html"; 171 system "gzip", "-7f", "$path.html";
145} 172}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines