2018-05-11 12:31:53 +02:00
|
|
|
function Session(modules) {
|
|
|
|
var key = null;
|
2019-12-08 23:01:24 +01:00
|
|
|
var playerKey = null;
|
2018-05-11 12:31:53 +02:00
|
|
|
var name = null;
|
2019-11-24 22:54:46 +01:00
|
|
|
var loggedIn = false;
|
2018-05-11 12:31:53 +02:00
|
|
|
|
|
|
|
modules.messaging.addEventListener(["Welcome"], function(o) {
|
2019-12-08 23:01:24 +01:00
|
|
|
playerKey = o.key;
|
|
|
|
modules.save.set('player.id', o.key);
|
2018-05-11 12:31:53 +02:00
|
|
|
});
|
|
|
|
|
2019-12-08 23:01:24 +01:00
|
|
|
modules.messaging.addEventListener(["LogIn"], function(o) {
|
2018-05-11 12:31:53 +02:00
|
|
|
if(is(o.from)) {
|
2019-12-08 23:01:24 +01:00
|
|
|
name = o.as;
|
2018-05-11 12:31:53 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
is: is,
|
2018-05-12 15:32:00 +02:00
|
|
|
getKey: getKey,
|
2019-12-08 23:01:24 +01:00
|
|
|
isLoggedIn: isLoggedIn,
|
2019-11-24 22:54:46 +01:00
|
|
|
start: start
|
2018-05-11 12:31:53 +02:00
|
|
|
};
|
|
|
|
|
2019-12-08 23:01:24 +01:00
|
|
|
function is(somePlayerKey) {
|
|
|
|
return playerKey == somePlayerKey;
|
2018-05-11 12:31:53 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 15:32:00 +02:00
|
|
|
function getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2019-11-24 22:54:46 +01:00
|
|
|
function isLoggedIn() {
|
|
|
|
return loggedIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
function start(name) {
|
|
|
|
var myID = modules.save.get('player.id');
|
|
|
|
if(myID != undefined) {
|
|
|
|
modules.messaging.send({tag: 'Tadaima', myID: myID, name: name});
|
2019-12-08 23:01:24 +01:00
|
|
|
playerKey = myID;
|
2019-11-24 22:54:46 +01:00
|
|
|
} else {
|
|
|
|
modules.messaging.send({tag: 'Hello', name: name});
|
|
|
|
}
|
|
|
|
modules.save.set('player.name', name);
|
2018-05-11 12:31:53 +02:00
|
|
|
}
|
|
|
|
}
|