2019-12-11 22:03:16 +01:00
|
|
|
Screen.Login = function(modules) {
|
2019-12-14 18:26:24 +01:00
|
|
|
var form = modules.ui.connectedForm('login');
|
2019-12-11 22:03:16 +01:00
|
|
|
init();
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
initDOMEvents();
|
|
|
|
initMessageHandlers();
|
|
|
|
var name = modules.save.get('player.name');
|
|
|
|
if(name != undefined && name.length > 0) {
|
2019-12-14 18:26:24 +01:00
|
|
|
form.you.value = name;
|
|
|
|
modules.ui.enableForm('login', true);
|
2019-12-11 22:03:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initDOMEvents() {
|
2019-12-14 18:26:24 +01:00
|
|
|
form.addEventListener('submit', function(e) {
|
2019-12-11 22:03:16 +01:00
|
|
|
e.preventDefault();
|
2019-12-14 18:26:24 +01:00
|
|
|
modules.session.start(form.you.value);
|
2019-12-11 22:03:16 +01:00
|
|
|
});
|
2019-12-14 18:26:24 +01:00
|
|
|
|
|
|
|
form.you.addEventListener("input", validate);
|
2019-12-11 22:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function initMessageHandlers() {
|
|
|
|
modules.messaging.addEventListener(["LogIn"], function(o) {
|
2019-12-14 18:26:24 +01:00
|
|
|
if(modules.session.is(o.from)) {
|
|
|
|
modules.screen.select('hall');
|
|
|
|
}
|
2019-12-11 22:03:16 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-14 18:26:24 +01:00
|
|
|
function validate(e) {
|
|
|
|
modules.ui.enableForm('login', e.target.value != "")
|
2019-12-11 22:03:16 +01:00
|
|
|
}
|
|
|
|
}
|