Mercurial > hg > rlgwebd
annotate rlgterm.js @ 186:674e8899703b
Client: improve messages at the end of watching a game.
The messages differentiate between the user stopping watching and the
watched game coming to an end.
| author | John "Elwin" Edwards | 
|---|---|
| date | Tue, 20 Jan 2015 16:06:12 -0500 | 
| parents | bf518a00190b | 
| children | 12a733792e0b | 
| 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 | 
| 
44
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
3 /* Data on the available games. */ | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
4 var games = { | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
5 "rogue3": { | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
6 "name": "Rogue V3", | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
7 "uname": "rogue3" | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
8 }, | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
9 "rogue4": { | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
10 "name": "Rogue V4", | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
11 "uname": "rogue4" | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
12 }, | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
13 "rogue5": { | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
14 "name": "Rogue V5", | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
15 "uname": "rogue5" | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
16 }, | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
17 "srogue": { | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
18 "name": "Super-Rogue", | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
19 "uname": "srogue" | 
| 
120
 
54979d35611a
Add support for Advanced Rogue 5.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
118 
diff
changeset
 | 
20 }, | 
| 
 
54979d35611a
Add support for Advanced Rogue 5.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
118 
diff
changeset
 | 
21 "arogue5": { | 
| 
 
54979d35611a
Add support for Advanced Rogue 5.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
118 
diff
changeset
 | 
22 "name": "Advanced Rogue 5", | 
| 
 
54979d35611a
Add support for Advanced Rogue 5.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
118 
diff
changeset
 | 
23 "uname": "arogue5" | 
| 
44
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
24 } | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
25 }; | 
| 
 
b848cb50cd69
rlgterm.js: present game options to the player.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
41 
diff
changeset
 | 
26 | 
| 
59
 
00b985b8ba6a
RLG-Web client: implement watching.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
58 
diff
changeset
 | 
27 var session = { | 
| 
 
00b985b8ba6a
RLG-Web client: implement watching.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
58 
diff
changeset
 | 
28 /* The session id assigned by the server. */ | 
| 159 | 29 connect: false, | 
| 
127
 
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
120 
diff
changeset
 | 
30 /* Login name and key are now in sessionStorage. */ | 
| 
59
 
00b985b8ba6a
RLG-Web client: implement watching.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
58 
diff
changeset
 | 
31 /* Whether the game is being played or just watched. */ | 
| 
100
 
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
97 
diff
changeset
 | 
32 playing: false, | 
| 
186
 
674e8899703b
Client: improve messages at the end of watching a game.
 
John "Elwin" Edwards 
parents: 
176 
diff
changeset
 | 
33 /* If watching, the name of the player. */ | 
| 
 
674e8899703b
Client: improve messages at the end of watching a game.
 
John "Elwin" Edwards 
parents: 
176 
diff
changeset
 | 
34 playername: null, | 
| 
 
674e8899703b
Client: improve messages at the end of watching a game.
 
John "Elwin" Edwards 
parents: 
176 
diff
changeset
 | 
35 /* Whether the Stop button was pushed. */ | 
| 
 
674e8899703b
Client: improve messages at the end of watching a game.
 
John "Elwin" Edwards 
parents: 
176 
diff
changeset
 | 
36 leaving: false, | 
| 
100
 
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
97 
diff
changeset
 | 
37 /* WebSocket for communication */ | 
| 
 
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
97 
diff
changeset
 | 
38 sock: null | 
| 
59
 
00b985b8ba6a
RLG-Web client: implement watching.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
58 
diff
changeset
 | 
39 }; | 
| 
39
 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
38 
diff
changeset
 | 
40 | 
| 
73
 
d084610a89b5
Automatically update the lists of current games and actions.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
70 
diff
changeset
 | 
41 /* The interval ID for checking the status of current games. */ | 
| 
 
d084610a89b5
Automatically update the lists of current games and actions.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
70 
diff
changeset
 | 
42 var statInterval = null; | 
| 
 
d084610a89b5
Automatically update the lists of current games and actions.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
70 
diff
changeset
 | 
43 /* How frequently to check. */ | 
| 
 
d084610a89b5
Automatically update the lists of current games and actions.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
70 
diff
changeset
 | 
44 var statDelta = 8000; | 
| 
105
 
a9371002aecc
RLG-Web client: use WebSockets for game lists.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
101 
diff
changeset
 | 
45 /* A WebSocket to listen for status events. */ | 
| 
 
a9371002aecc
RLG-Web client: use WebSockets for game lists.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
101 
diff
changeset
 | 
46 var statsock = null; | 
| 
163
 
0f6da35b27a0
RLGWebD: overhaul the list of current games.
 
John "Elwin" Edwards 
parents: 
161 
diff
changeset
 | 
47 /* List of currently active games. */ | 
| 
 
0f6da35b27a0
RLGWebD: overhaul the list of current games.
 
John "Elwin" Edwards 
parents: 
161 
diff
changeset
 | 
48 var currentList = []; | 
| 
 
0f6da35b27a0
RLGWebD: overhaul the list of current games.
 
John "Elwin" Edwards 
parents: 
161 
diff
changeset
 | 
49 /* Last time the list was updated. */ | 
| 
 
0f6da35b27a0
RLGWebD: overhaul the list of current games.
 
John "Elwin" Edwards 
parents: 
161 
diff
changeset
 | 
50 var currentTS = null; | 
| 
73
 
d084610a89b5
Automatically update the lists of current games and actions.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents: 
70 
diff
changeset
 | 
51 | 
| 
0
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
52 function writeData(hexstr) { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
53 var codenum; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
54 var codes = []; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
55 var nc; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
56 var u8wait = 0; /* Stores bits from previous bytes of multibyte sequences. */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
57 var expect = 0; /* The number of 10------ bytes expected. */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
58 /* UTF-8 translation. */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
59 for (var i = 0; i < hexstr.length; i += 2) { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
60 nc = Number("0x" + hexstr.substr(i, 2)); | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
61 if (nc < 0x7F) { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
62 /* 0------- */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
63 codes.push(nc); | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
64 /* Any incomplete sequence will be discarded. */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
65 u8wait = 0; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
66 expect = 0; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
67 } | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
68 else if (nc < 0xC0) { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
69 /* 10------ : part of a multibyte sequence */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
70 if (expect > 0) { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
71 u8wait <<= 6; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
72 u8wait += (nc & 0x3F); | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
73 expect--; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
74 if (expect == 0) { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
75 codes.push(u8wait); | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
76 u8wait = 0; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
77 } | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
78 } | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
79 else { | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
80 /* Assume an initial byte was missed. */ | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
81 u8wait = 0; | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
82 } | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
83 } | 
| 
 
bd412f63ce0d
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:   | 
