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.6 by root, Fri Nov 18 12:34:13 2005 UTC

9 9
10my $arch; 10my $arch;
11 11
12umask 022; 12umask 022;
13 13
14our $VERSION = '1.0';
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", 54 "a:hover { text-color: red; }\n",
51 "a:visited { text-color: #008; }\n", 55 "a:visited { text-color: #008; }\n",
71 "-->\n</style>", 75 "-->\n</style>",
72 "</head>", 76 "</head>",
73 "<body>"; 77 "<body>";
74 78
75 print "<table id='nav'>", 79 print "<table id='nav'>",
76 "<tr><td rowspan='3'><span style='font-height: 20pt; font-style: bold;'>"; 80 "<tr valign='center'><td rowspan='3' style='padding-right: 3em'>",
81 "Crossfire Map<br/>",
82 "<span style='font-size: 18pt'>";
77 print "<a href='/'>/</a> "; 83 print "<a href='/'>/</a> ";
78 for (0 .. $#path - 1) { 84 for (0 .. $#path - 1) {
79 print "<a href='/", (join "/", @path[0..$_]), "/'>$path[$_]</a> / "; 85 print "<a href='/", (join "/", @path[0..$_]), "/'>$path[$_]</a> / ";
80 } 86 }
81 87
82 my @tile = map { 88 my @tile = map {
83 $meta->{info}{"tile_path_$_"} 89 $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>" 90 ? "<a href='$meta->{info}{\"tile_path_$_\"}.html'><img style='border: 2px solid blue;' src='$meta->{info}{\"tile_path_$_\"}.jpg'/></a>"
85 : "" 91 : ""
86 } 1..4; 92 } 1..4;
93 #"}"# vim misparses without this comment
87 94
88 print "$path[-1] "; 95 print "$path[-1]",
89 print "</span></td>", 96 "</span>",
97 "<p style='font-size: 8pt;'><a href='/about.txt'>[more about cfmaps.schmorp.de]</a></p>",
98 "</td>",
90 "<td/><td>$tile[0]</td><td/></tr>", 99 "<td/><td>$tile[0]</td><td/></tr>",
91 "<tr><td>$tile[3]</td>"; 100 "<tr><td>$tile[3]</td>",
92 print "<td><img id='thumb' src='@path[-1].jpg'/></td>", 101 "<td><img id='thumb' src='@path[-1].jpg'/></td>",
93 "<td>$tile[1]</td>", 102 "<td>$tile[1]</td>",
94 "<tr><td/><td>$tile[2]</td><td/></tr>"; 103 "<tr><td/><td>$tile[2]</td><td/></tr>",
95 print "</table>"; 104 "</table>";
96 105
97 my $W1 = $W + 600; 106 my $W1 = $W + 600;
98 107
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; '>", 108 print "<p class='m' style='white-space: pre; width=auto; '>",
101 escape_html $meta->{info}{msg}, 109 escape_html $meta->{info}{msg},
102 "</p>"; 110 "</p>";
103 111
104 print "<table id='map'>"; 112 print "<table id='map'>";
105 113
106 my %ignore = map +($_ => 1), qw(_name x y); 114 my %ignore = map +($_ => 1), qw(name _name x y);
107 115
108 for my $y (0.. $meta->{height} - 1) { 116 for my $y (0.. $meta->{height} - 1) {
109 print "<tr>"; 117 print "<tr>";
110 for my $x (0.. $meta->{width} - 1) { 118 for my $x (0.. $meta->{width} - 1) {
111 print "<td>"; 119 print "<td>";
112 if (my $as = $meta->{map}[$x][$y]) { 120 if (my $as = $meta->{map}[$x][$y]) {
113 print "<span><div>($x|$y)<ul>"; 121 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 122
121 if (($o->{type} == 66 || $o->{type} == 41) && $_ eq "slaying") { # door, teleporter 123 sub print_archs {
122 $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1 124 print "<ul>";
123 if $v eq "/!"; # random map 125 for my $a (@{$_[0]}) {
126 my $o = $arch->{$a->{_name}};
127 my $aname = escape_html $a->{_name};
128 my $name = escape_html $a->{name} || $o->{name};
129 print "<li><a href='/archetypes.html#", (lc $a->{_name}), "'>$aname \"$name\"</a>\n";
130 for (sort keys %$a) {
131 next if $ignore{$_};
132 my $v = escape_html $a->{$_};
124 133
134 if (($o->{type} == 66 || $o->{type} == 41) && $_ eq "slaying") { # door, teleporter
135 $a->{msg} =~ /^final_map\s*(\S+)\s*$/m, $v = $1
136 if $v eq "/!"; # random map
137
125 print "slaying => <a href='$v.html'>$v</a>\n"; 138 print "slaying => <a href='$v.html'>$v</a>\n";
139 } elsif ($_ eq "other_arch") {
140 print "$_ => <a href='/archetypes.html#", (lc $a->{$_}), "'>$v</a>\n";
141 } elsif ($_ eq "inventory") {
142 print "inventory =>\n";
143 print_archs ($a->{$_});
126 } elsif ($_ eq "msg") { 144 } elsif ($_ eq "msg") {
127 print "<p class='m'>$v</p>"; 145 print "<p class='m'>$v</p>";
128 } else { 146 } else {
129 print "$_ => $v\n"; 147 print "$_ => $v\n";
148 }
130 } 149 }
131 } 150 }
151 print "</ul>";
132 } 152 }
153
154 print_archs $as;
133 print "</ul></div></span>"; 155 print "</div></span>";
134 } 156 }
135 print "</td>"; 157 print "</td>";
136 } 158 }
137 print "</tr>"; 159 print "</tr>";
138 } 160 }
139 161
162 print "</table></p><hr/><p style='font-size: 6pt'>created by <b>cfmap2html</b> version $VERSION</p>",
140 print "</table></p><p style='height: 600px;'/></body></html>"; 163 "<p style='height: 600px;'/></body></html>";
141 164
142 close $fh; 165 close $fh;
143 166
144 system "gzip", "-7f", "$path.html"; 167 system "gzip", "-7f", "$path.html";
145} 168}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines