chiark / gitweb /
New front end! To complement the webification of my puzzles via Java
[sgt-puzzles.git] / html / jspage.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 open my $footerfile, "<", shift @ARGV or die "footer: open: $!\n";
7 my $footer = "";
8 $footer .= $_ while <$footerfile>;
9 close $footerfile;
10
11 for my $arg (@ARGV) {
12     $arg =~ /(.*\/)?([^\/]+)\.html$/ or die;
13     my $filename = $2;
14     open my $gamefile, "<", $arg or die "$arg: open: $!\n";
15     my $unfinished = 0;
16     my $docname = $filename;
17     chomp(my $puzzlename = <$gamefile>);
18     while ($puzzlename =~ s/^([^:=]+)(=([^:]+))?://) {
19         if ($1 eq "unfinished") {
20             $unfinished = 1;
21         } elsif ($1 eq "docname") {
22             $docname = $3;
23         } else {
24             die "$arg: unknown keyword '$1'\n";
25         }
26     }
27     my $instructions = "";
28     $instructions .= $_ while <$gamefile>;
29     close $gamefile;
30
31     open my $outpage, ">", "${filename}.html";
32
33     my $unfinishedtitlefragment = $unfinished ? "an unfinished puzzle " : "";
34     my $unfinishedheading = $unfinished ? "<h2 align=center>an unfinished puzzle</h2>\n" : "";
35     my $unfinishedpara;
36     my $links;
37     if ($unfinished) {
38         $unfinishedpara = <<EOF;
39 <p>
40 You have found your way to a page containing an <em>unfinished</em>
41 puzzle in my collection, not linked from the <a href="../">main
42 puzzles page</a>. Don't be surprised if things are hard to understand
43 or don't work as you expect.
44 EOF
45         $links = <<EOF;
46 <p align="center">
47 <a href="../">Back to main puzzles page</a> (which does not link to this)
48 EOF
49     } else {
50         $unfinishedpara = "";
51         $links = <<EOF;
52 <p align="center">
53 <a href="../doc/${docname}.html#${docname}">Full instructions</a>
54 |
55 <a href="../">Back to main puzzles page</a>
56 EOF
57     }
58
59     print $outpage <<EOF;
60 <html>
61 <head>
62 <meta http-equiv="Content-Type" content="text/html; charset=ASCII" />
63 <title>${puzzlename}, ${unfinishedtitlefragment}from Simon Tatham's Portable Puzzle Collection</title>
64 <script type="text/javascript" src="${filename}.js"></script>
65 </head>
66 <body onLoad="initPuzzle();">
67 <h1 align=center>${puzzlename}</h1>
68 ${unfinishedheading}
69 <h2 align=center>from Simon Tatham's Portable Puzzle Collection</h2>
70
71 ${unfinishedpara}
72
73 <hr>
74 <p align=center>
75   <input type="button" id="new" value="New game">
76   <input type="button" id="restart" value="Restart game">
77   <input type="button" id="undo" value="Undo move">
78   <input type="button" id="redo" value="Redo move">
79   <input type="button" id="solve" value="Solve game">
80   <input type="button" id="specific" value="Enter game ID">
81   <input type="button" id="random" value="Enter random seed">
82   <select id="gametype"></select>
83 </p>
84 <p align=center>
85   <table cellpadding="0" cellspacing="0">
86     <tr>
87       <td>
88         <canvas id="puzzlecanvas" width="1" height="1" tabindex="1">
89       </td>
90     <tr>
91       <td id="statusbarholder">
92       </td>
93     </tr>
94   </table>
95 </p>
96 <p align=center>
97   Link to this puzzle:
98   <a id="permalink-desc">by game ID</a>
99   <a id="permalink-seed">by random seed</a>
100 </p>
101 <hr>
102
103 ${instructions}
104
105 ${links}
106
107 ${footer}
108 </body>
109 </html>
110 EOF
111
112     close $outpage;
113 }