Mercurial > hg > rlgwebd
annotate rlgterm.js @ 78:06375a159188
Try to guess a good text size.
When starting, resize the fonts if there isn't room for the terminal,
or if there is a lot of empty space.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Sat, 23 Jun 2012 19:13:34 -0700 |
parents | f8bb37f48d58 |
children | e04c8bf6d4da |
rev | line source |
---|---|
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
1 /* rlgterm.js: Roguelike Gallery's driver for termemu.js */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
2 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
3 // A state machine that keeps track of polling the server. |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
4 var ajaxstate = { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
5 state: 0, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
6 timerID: null, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
7 clear: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
8 if (this.timerID != null) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
9 window.clearTimeout(this.timerID); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
10 this.timerID = null; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
11 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
12 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
13 set: function (ms) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
14 this.clear(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
15 this.timerID = window.setTimeout(getData, ms); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
16 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
17 gotdata: function () { |
35
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
18 this.set(1000); |
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
19 this.state = 1; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
20 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
21 gotnothing: function () { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
22 if (this.state == 0) { |
35
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
23 this.set(1000); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
24 this.state = 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
25 } |
38
b06a14876645
RLG-Web: reduce polling further.
John "Elwin" Edwards <elwin@sdf.org>
parents:
35
diff
changeset
|
26 else if (this.state < 4) { |
35
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
27 this.set(4000); |
38
b06a14876645
RLG-Web: reduce polling further.
John "Elwin" Edwards <elwin@sdf.org>
parents:
35
diff
changeset
|
28 this.state++; |
b06a14876645
RLG-Web: reduce polling further.
John "Elwin" Edwards <elwin@sdf.org>
parents:
35
diff
changeset
|
29 } |
63
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
30 else if (session.playing) { |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
31 if (this.state < 8) { |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
32 this.set(15000); |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
33 this.state++; |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
34 } |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
35 else { |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
36 /* It's been over a minute. Stop polling. */ |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
37 this.clear(); |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
38 } |
38
b06a14876645
RLG-Web: reduce polling further.
John "Elwin" Edwards <elwin@sdf.org>
parents:
35
diff
changeset
|
39 } |
b06a14876645
RLG-Web: reduce polling further.
John "Elwin" Edwards <elwin@sdf.org>
parents:
35
diff
changeset
|
40 else { |
63
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
41 /* If watching, it can't stop polling entirely, because there |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
42 * are no POST events to start it up again. */ |
a077f9f84052
RLG-Web client: adjust polling for watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
61
diff
changeset
|
43 this.set(10000); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
44 } |
35
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
45 }, |
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
46 posted: function (wasdata) { |
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
47 if (wasdata) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
48 this.set(1000); |
35
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
49 this.state = 1; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
50 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
51 else { |
35
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
52 this.set(200); |
f15efa4818b4
rglterm.js: reduce the server polling.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
53 this.state = 0; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
54 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
55 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
56 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
57 |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
58 /* Data on the available games. */ |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
59 var games = { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
60 "rogue3": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
61 "name": "Rogue V3", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
62 "uname": "rogue3" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
63 }, |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
64 "rogue4": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
65 "name": "Rogue V4", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
66 "uname": "rogue4" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
67 }, |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
68 "rogue5": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
69 "name": "Rogue V5", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
70 "uname": "rogue5" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
71 }, |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
72 "srogue": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
73 "name": "Super-Rogue", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
74 "uname": "srogue" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
75 } |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
76 }; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
77 |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
78 var session = { |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
79 /* The session id assigned by the server. */ |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
80 id: null, |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
81 /* Login name and key */ |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
82 lname: null, |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org> |