Mercurial > hg > rlgwebd
comparison 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 |
comparison
equal
deleted
inserted
replaced
185:bbfda4a4eb7f | 186:674e8899703b |
---|---|
28 /* The session id assigned by the server. */ | 28 /* The session id assigned by the server. */ |
29 connect: false, | 29 connect: false, |
30 /* Login name and key are now in sessionStorage. */ | 30 /* Login name and key are now in sessionStorage. */ |
31 /* Whether the game is being played or just watched. */ | 31 /* Whether the game is being played or just watched. */ |
32 playing: false, | 32 playing: false, |
33 /* If watching, the name of the player. */ | |
34 playername: null, | |
35 /* Whether the Stop button was pushed. */ | |
36 leaving: false, | |
33 /* WebSocket for communication */ | 37 /* WebSocket for communication */ |
34 sock: null | 38 sock: null |
35 }; | 39 }; |
36 | 40 |
37 /* The interval ID for checking the status of current games. */ | 41 /* The interval ID for checking the status of current games. */ |
654 termemu.resize(msgObject.h, msgObject.w); | 658 termemu.resize(msgObject.h, msgObject.w); |
655 termemu.reset(); | 659 termemu.reset(); |
656 termemu.toAltBuf(); | 660 termemu.toAltBuf(); |
657 var pname = msgObject.p; | 661 var pname = msgObject.p; |
658 var gname = games[msgObject.g].name; | 662 var gname = games[msgObject.g].name; |
663 session.playername = pname; | |
659 message("You are now watching " + pname + " play " + gname + "."); | 664 message("You are now watching " + pname + " play " + gname + "."); |
660 } | 665 } |
661 else if (msgObject.t == 'd') { | 666 else if (msgObject.t == 'd') { |
662 writeData(msgObject.d); | 667 writeData(msgObject.d); |
663 } | 668 } |
723 | 728 |
724 function gameover() { | 729 function gameover() { |
725 if (!session.connect) | 730 if (!session.connect) |
726 return; | 731 return; |
727 /* TODO IFACE2 If the end was unexpected, tell player the game was saved. */ | 732 /* TODO IFACE2 If the end was unexpected, tell player the game was saved. */ |
728 if (session.playing) | 733 if (session.playing) { |
729 message("Finished playing."); | 734 message("Finished playing."); |
730 else | 735 } |
731 message("Finished watching."); | 736 else { |
737 if (session.leaving) { | |
738 /* Client-initiated: the user stopped watching. */ | |
739 message("Finished watching " + session.playername + "."); | |
740 } | |
741 else { | |
742 /* Server-initiated: end of game. */ | |
743 message(session.playername + " has finished playing."); | |
744 } | |
745 session.playername = null; | |
746 } | |
732 session.connect = false; | 747 session.connect = false; |
733 session.playing = false; | 748 session.playing = false; |
749 session.leaving = false; | |
734 termemu.toNormBuf(); | 750 termemu.toNormBuf(); |
735 if ("lcred" in sessionStorage) | 751 if ("lcred" in sessionStorage) |
736 setmode("choose"); | 752 setmode("choose"); |
737 else | 753 else |
738 setmode("login"); | 754 setmode("login"); |
743 sessionStorage.removeItem("lcred"); | 759 sessionStorage.removeItem("lcred"); |
744 sessionStorage.removeItem("lname"); | 760 sessionStorage.removeItem("lname"); |
745 setmode("login"); | 761 setmode("login"); |
746 } | 762 } |
747 | 763 |
748 /* TODO determine whether this is needed */ | |
749 function stop() { | 764 function stop() { |
750 if (!session.connect) | 765 if (!session.connect) |
751 return; | 766 return; |
752 if (session.sock) { | 767 if (session.sock) { |
768 session.leaving = true; | |
753 session.sock.close(); | 769 session.sock.close(); |
754 return; | 770 return; |
755 } | 771 } |
756 } | 772 } |
757 | 773 |