forked from erkyrath/glkote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-demobase.html
218 lines (182 loc) · 5.24 KB
/
sample-demobase.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>GlkOte: Not A Real Game</title>
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="glkote.css" type="text/css">
<link rel="stylesheet" href="dialog.css" type="text/css">
<style type="text/css">
body {
margin: 0px;
height: 100%;
}
#banner {
position: absolute;
top: 0px;
height: 45px;
width: 100%;
background: #DDDDFF;
border-bottom: 4px;
border-top: 0px;
border-left: 0px;
border-right: 0px;
border-color: #E8E8FF;
border-style: solid;
}
#bannertitle {
font-size: 18px;
font-weight: bold;
margin-top: 8px;
margin-left: 16px;
}
#bannerhowto {
text-align: right;
margin-right: 16px;
}
#gameport {
position: absolute;
overflow: hidden;
left: 0px;
right: 0px;
top: 54px;
bottom: 0px;
background: #CCAA88;
margin: 0px;
}
@media screen and (max-device-width: 480px) {
/* This stanza simplifies the layout on small (iPhone-sized) screens.
The top blue banner is removed, so that the gameport can fill the
whole screen. */
#banner {
display: none;
}
#gameport {
top: 0px;
}
}
</style>
<script src="jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="glkote.js" type="text/javascript"></script>
<script src="dialog.js" type="text/javascript"></script>
<script type="text/javascript">
game_generation = 1;
game_metrics = null;
game_streamout = new Array();
prompt = '\n>';
/* Put your game-startup text here.
*/
function startup() {
say('This is an easily-customizable demo of an IF app written in Javascript. You can use it as a starting point for your own IF project (or any web page that wants to accept command-line input and print responses!)\n\nJust customize the startup() function to print your initial text, and customize the respond() function to print a response based on its argument (the player\'s input). Use the say() and say_runon() functions to print game output.\n');
say('Welcome to...');
say('The Game', 'header');
}
/* Put your game-response code here. The val argument is the player's input.
*/
function respond(val) {
say('You typed "' + val + '".');
}
/* Print a line of text. (Or several lines, if the argument contains \n
characters.)
The optional second argument is the text style. The standard glkote.css
file defines all the usual Glk styles: 'normal', 'emphasized' (italics),
'preformatted' (fixed-width), 'subheader' (bold), 'header' (large bold),
'alert', 'note', and 'input'.
If the third argument is true, the text is appended to the previous
line instead of starting a new line.
*/
function say(val, style, runon) {
if (style == undefined)
style = 'normal';
var ls = val.split('\n');
for (ix=0; ix<ls.length; ix++) {
if (runon) {
if (ls[ix])
game_streamout.push({ content: [style, ls[ix]], append: 'true' });
runon = false;
}
else {
if (ls[ix])
game_streamout.push({ content: [style, ls[ix]] });
else
game_streamout.push({ });
}
}
}
/* Print a line of text, appending it to the previous line. This is a
clearer shortcut for say(val, style, true).
*/
function say_runon(val, style) {
say(val, style, true);
}
/* This is the top-level game event hook. It's all set up for a basic
game that accepts line input. */
function game_accept(res) {
if (res.type == 'init') {
game_metrics = res.metrics;
startup();
say(prompt);
}
else if (res.type == 'arrange') {
game_metrics = res.metrics;
}
else if (res.type == 'line') {
say_runon(res.value, 'input');
respond(res.value);
say(prompt);
}
game_select();
}
/* This constructs the game display update and sends it to the display.
It's all set up for a basic game that accepts line input. */
function game_select() {
game_generation = game_generation+1;
var metrics = game_metrics;
var pwidth = metrics.width;
var pheight = metrics.height;
var argw = [
{ id: 1, type: 'buffer', rock: 11,
left: metrics.outspacingx,
top: metrics.outspacingy,
width: pwidth-(2*metrics.outspacingx),
height: pheight-(metrics.outspacingy+metrics.outspacingy) }
];
var argc = [ ];
if (game_streamout.length) {
var obj = { id: 1 };
if (game_streamout.length)
obj.text = game_streamout;
argc.push(obj);
}
var argi = [
{ id: 1, gen: game_generation, type: 'line', maxlen: 200 }
];
var arg = { type:'update', gen:game_generation, windows:argw, content:argc, input:argi };
GlkOte.update(arg);
game_streamout.length = 0;
}
/* The game interface object. */
Game = {
accept: game_accept,
spacing: 0
};
</script>
</head>
<body onLoad="GlkOte.init();">
<div id="banner">
<div id="bannertitle">Not A Real Game</div>
<div id="bannerhowto"><em><a target="_blank" href="sample-help.html">How do I play?</a></em></div>
</div>
<div id="gameport">
<div id="windowport">
<noscript><hr>
<p>You'll need to turn on Javascript in your web browser to play this game.</p>
<hr></noscript>
</div>
<div id="loadingpane">
<img src="waiting.gif" alt="LOADING"><br>
<em> Loading...</em>
</div>
<div id="errorpane" style="display:none;"><div id="errorcontent">...</div></div>
</div>
</body>
</html>