Add start routine in session module picking the correct message and add an explicit loggedIn private boolean, rename the getter
This commit is contained in:
parent
0b834b4876
commit
403ee2da92
3 changed files with 20 additions and 7 deletions
|
@ -36,7 +36,7 @@ function Login(modules) {
|
||||||
function initDOMEvents() {
|
function initDOMEvents() {
|
||||||
root.addEventListener('submit', function(e) {
|
root.addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if(modules.session.loggedIn()) {
|
if(modules.session.isLoggedIn()) {
|
||||||
modules.messaging.send({tag: "Invitation", to: them});
|
modules.messaging.send({tag: "Invitation", to: them});
|
||||||
} else {
|
} else {
|
||||||
modules.session.start(root.you.value);
|
modules.session.start(root.you.value);
|
||||||
|
@ -100,7 +100,7 @@ function Login(modules) {
|
||||||
|
|
||||||
function refreshPlayers() {
|
function refreshPlayers() {
|
||||||
modules.dom.clear(players);
|
modules.dom.clear(players);
|
||||||
if(modules.session.loggedIn()) {
|
if(modules.session.isLoggedIn()) {
|
||||||
refreshThem();
|
refreshThem();
|
||||||
} else {
|
} else {
|
||||||
refreshYou();
|
refreshYou();
|
||||||
|
@ -151,7 +151,7 @@ function Login(modules) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setMode() {
|
function setMode() {
|
||||||
var loggedIn = modules.session.loggedIn()
|
var loggedIn = modules.session.isLoggedIn()
|
||||||
root.join.disabled = loggedIn;
|
root.join.disabled = loggedIn;
|
||||||
root.invite.disabled = !loggedIn;
|
root.invite.disabled = !loggedIn;
|
||||||
if(loggedIn) {
|
if(loggedIn) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ function Room(modules) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function filter(name) {
|
function filter(name) {
|
||||||
if(modules.session.loggedIn()) {
|
if(modules.session.isLoggedIn()) {
|
||||||
var keep = function(player) {
|
var keep = function(player) {
|
||||||
return player.name.match(name) && !modules.session.is(player.key) && player.alone;
|
return player.name.match(name) && !modules.session.is(player.key) && player.alone;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
function Session(modules) {
|
function Session(modules) {
|
||||||
var key = null;
|
var key = null;
|
||||||
var name = null;
|
var name = null;
|
||||||
|
var loggedIn = false;
|
||||||
|
|
||||||
modules.messaging.addEventListener(["Welcome"], function(o) {
|
modules.messaging.addEventListener(["Welcome"], function(o) {
|
||||||
key = o.key;
|
key = o.key;
|
||||||
|
modules.save.set('player.id', key);
|
||||||
});
|
});
|
||||||
|
|
||||||
modules.messaging.addEventListener(["Relay", "LogIn"], function(o) {
|
modules.messaging.addEventListener(["Relay", "LogIn"], function(o) {
|
||||||
|
@ -15,7 +17,8 @@ function Session(modules) {
|
||||||
return {
|
return {
|
||||||
is: is,
|
is: is,
|
||||||
getKey: getKey,
|
getKey: getKey,
|
||||||
loggedIn: loggedIn
|
loggedIn: loggedIn,
|
||||||
|
start: start
|
||||||
};
|
};
|
||||||
|
|
||||||
function is(sessionKey) {
|
function is(sessionKey) {
|
||||||
|
@ -26,7 +29,17 @@ function Session(modules) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loggedIn() {
|
function isLoggedIn() {
|
||||||
return name != undefined;
|
return loggedIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
function start(name) {
|
||||||
|
var myID = modules.save.get('player.id');
|
||||||
|
if(myID != undefined) {
|
||||||
|
modules.messaging.send({tag: 'Tadaima', myID: myID, name: name});
|
||||||
|
} else {
|
||||||
|
modules.messaging.send({tag: 'Hello', name: name});
|
||||||
|
}
|
||||||
|
modules.save.set('player.name', name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue