Simplify guest selection and handle disconnections
This commit is contained in:
parent
315db97abb
commit
d022ab9aa4
2 changed files with 17 additions and 12 deletions
|
@ -22,7 +22,6 @@
|
|||
<form id="room" class="off">
|
||||
<ul class="players">
|
||||
</ul>
|
||||
<input type="number" hidden name="guest"/>
|
||||
<input type="submit" name="invite" value="Invite to a game" disabled/>
|
||||
</form>
|
||||
<p id="debug"></p>
|
||||
|
|
28
www/room.js
28
www/room.js
|
@ -10,7 +10,7 @@ function Room(domElem, lib) {
|
|||
var playersList = domElem.getElementsByClassName('players')[0];
|
||||
domElem.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
lib.send({tag: "Invitation", to: parseInt(domElem.guest.value)})
|
||||
lib.send({tag: "Invitation", to: session.selected})
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -63,6 +63,8 @@ function Room(domElem, lib) {
|
|||
var player = players[key];
|
||||
if(key == session.key) {
|
||||
off();
|
||||
} else if(key == session.selected) {
|
||||
reset();
|
||||
}
|
||||
if(player != undefined) {
|
||||
playersList.removeChild(player.dom);
|
||||
|
@ -85,25 +87,29 @@ function Room(domElem, lib) {
|
|||
function off() {
|
||||
domElem.className = "off";
|
||||
session.loggedIn = false;
|
||||
reset();
|
||||
}
|
||||
|
||||
function select(key) {
|
||||
if(key == domElem.guest.value) {
|
||||
unselect(players[key].dom);
|
||||
if(key === session.selected) {
|
||||
unselect(key);
|
||||
} else {
|
||||
if(session.selected) {
|
||||
unselect(session.selected);
|
||||
}
|
||||
reset();
|
||||
players[key].dom.className = "selected";
|
||||
session.selected = players[key].dom;
|
||||
domElem.guest.value = key;
|
||||
session.selected = key;
|
||||
domElem.invite.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function unselect(dom) {
|
||||
dom.className = "";
|
||||
domElem.guest.value = "";
|
||||
function reset() {
|
||||
if(session.selected) {
|
||||
unselect(session.selected);
|
||||
}
|
||||
}
|
||||
|
||||
function unselect(key) {
|
||||
players[key].dom.className = "";
|
||||
session.selected = null;
|
||||
domElem.invite.disabled = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue