Replace charCode with key
This commit is contained in:
parent
a38c19b9c9
commit
5d769c3989
@ -216,6 +216,7 @@ const vm = new Vue({
|
||||
this.myGuess = this.myGuess.substr(0, this.myGuess.length - 1);
|
||||
this.repaint();
|
||||
} else if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
if (this.myGuess.length === this.wordLength) {
|
||||
client.publish({destination: '/app/guess', body: this.myGuess})
|
||||
this.myGuess = '';
|
||||
@ -224,16 +225,10 @@ const vm = new Vue({
|
||||
}
|
||||
},
|
||||
onCanvasKeypress: function(e) {
|
||||
let charCode = e.charCode;
|
||||
if (isCharacter(charCode)) {
|
||||
if (isCharacterLowercase(charCode)) {
|
||||
charCode = charCode - 32;
|
||||
}
|
||||
const char = String.fromCharCode(charCode);
|
||||
if (this.myGuess.length < this.wordLength) {
|
||||
this.myGuess += char;
|
||||
this.repaint();
|
||||
}
|
||||
const key = e.key.toUpperCase();
|
||||
if (this.myGuess.length < this.wordLength && isCharacter(key)) {
|
||||
this.myGuess += key;
|
||||
this.repaint();
|
||||
}
|
||||
},
|
||||
onChatKeypress: function(e) {
|
||||
@ -469,16 +464,8 @@ function doHttpGet(url, callback) {
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function isCharacter(charCode) {
|
||||
return isCharacterLowercase(charCode) || isCharacterUppercase(charCode);
|
||||
}
|
||||
|
||||
function isCharacterLowercase(charCode) {
|
||||
return charCode >= 97 && charCode <= 122;
|
||||
}
|
||||
|
||||
function isCharacterUppercase(charCode) {
|
||||
return charCode >= 65 && charCode <= 90;
|
||||
function isCharacter(key) {
|
||||
return key >= "A" && key <= "Z";
|
||||
}
|
||||
|
||||
function onChat(message) {
|
||||
|
@ -61,11 +61,12 @@ function start() {
|
||||
function addKeydownListener() {
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Backspace') {
|
||||
e.preventDefault();
|
||||
myGuess = myGuess.substr(0, myGuess.length - 1);
|
||||
repaint();
|
||||
e.preventDefault();
|
||||
}
|
||||
else if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
if (myGuess.length === 5) {
|
||||
client.publish({destination: '/app/practiceGuess', body: myGuess});
|
||||
myGuess = '';
|
||||
@ -78,16 +79,10 @@ function addKeydownListener() {
|
||||
// characters
|
||||
function addKeypressListener() {
|
||||
document.addEventListener('keypress', function(e) {
|
||||
let charCode = e.charCode;
|
||||
if (isCharacter(charCode)) {
|
||||
if (isCharacterLowercase(charCode)) {
|
||||
charCode = charCode - 32;
|
||||
}
|
||||
const char = String.fromCharCode(charCode);
|
||||
if (myGuess.length < 5) {
|
||||
myGuess += char;
|
||||
repaint();
|
||||
}
|
||||
const key = e.key.toUpperCase();
|
||||
if (myGuess.length < 5 && isCharacter(key)) {
|
||||
myGuess += key;
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -181,16 +176,8 @@ function drawHint(xOrigin, yOrigin, progress) {
|
||||
}
|
||||
}
|
||||
|
||||
function isCharacter(charCode) {
|
||||
return isCharacterLowercase(charCode) || isCharacterUppercase(charCode);
|
||||
}
|
||||
|
||||
function isCharacterLowercase(charCode) {
|
||||
return charCode >= 97 && charCode <= 122;
|
||||
}
|
||||
|
||||
function isCharacterUppercase(charCode) {
|
||||
return charCode >= 65 && charCode <= 90;
|
||||
function isCharacter(key) {
|
||||
return key >= "A" && key <= "Z";
|
||||
}
|
||||
|
||||
function repaint() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user