version v0.1.3

This commit is contained in:
2016-02-14 04:37:31 +01:00
parent 7dd657471d
commit 45a0e86e74
18 changed files with 366 additions and 83 deletions

View File

@@ -5,17 +5,6 @@
NPGClient.evtHandler = {
keysList: {
F1 : 112,
SPACE : 32,
ESC : 27,
ARROW_UP : 38,
ARROW_DOWN : 40,
ENTER : 13,
DELETE : 46,
BACKSPACE : 8,
},
keyState: {},
//
@@ -23,8 +12,8 @@ NPGClient.evtHandler = {
var self = this;
//
self.keyState = {};
for (k in self.keyList) {
self.keyState[self.keysList[k]] = false;
for (k in NPGClient.KEYS) {
self.keyState[NPGClient[k]] = false;
}
//
document.addEventListener('keydown',function(e) {
@@ -38,14 +27,72 @@ NPGClient.evtHandler = {
},
//
loginValidKey: function(k) {
return (key >= 48 && key <= 90);
isValidKey: function(k) {
return (k >= 48 && k <= 90);
},
//
onKeyDown : function(evt) {
//console.log(evt.keyCode);
onKeyDown: function(evt) {
var self = this;
if (evt.keyCode == NPGClient.KEYS.ESC) {
//self.playerLogout(); // player logout
} else if (evt.keyCode == NPGClient.KEYS.F1) {
//self.sendToMenuPage(); // back to previous page
} else {
switch (NPGClient.PageHandler.currPage) {
case 'login':
self.userLogin(evt);
break;
default:
break;
}
}
},
/*
*
*/
//
userLogin : function (evt) {
//
var self = this;
var oldNameWidth, newNameWidth;
var size = NPGClient.PageHandler.getPageByName('login').ctx.measureText(NPGClient.userName).width;
oldNameWidth = 2.1*size; // corr factor 2.1
switch (evt.keyCode) {
case NPGClient.KEYS.ENTER:
if (NPGClient.SocketIO.isConnected) {
if (NPGClient.userName.length != 0) {
NPGClient.SocketIO.sendMsg('registration', NPGClient.userName);
}
} else {
//self.serverExit();
}
break;
case NPGClient.KEYS.BACKSPACE:
//--- remove a character
evt.preventDefault();
NPGClient.Utils.removeChar();
newNameWidth = NPGClient.PageHandler.getPageByName('login').ctx.measureText(NPGClient.userName).width
// newNameWidth = 2.1*self.ctx.measureText(self.tmpName).width; // corr factor 2.1
// self.cursor.shiftX(newNameWidth - oldNameWidth);
break;
default:
//console.log(evt.keyCode + ' ' + self.isValidKey(evt.keyCode));
//--- add character
if (self.isValidKey(evt.keyCode)) {
//self.cursor.stopBlink;
NPGClient.Utils.addChar(evt.keyCode);
//newNameWidth = 2.1*self.ctx.measureText(self.tmpName).width; // corr factor 2.1
//if (self.validName()) {
// self.cursor.shiftX(newNameWidth - oldNameWidth);
//}
//self.cursor.startBlink;
}
break;
}
},
}