Fix: checkTypingContents duplicated execution bug
This commit is contained in:
@@ -16,7 +16,8 @@ var TypingTest = {
|
|||||||
|
|
||||||
game.stage.backgroundColor = '#4d4d4d';
|
game.stage.backgroundColor = '#4d4d4d';
|
||||||
|
|
||||||
// keyboard shortcut
|
/*
|
||||||
|
// keyboard shortcut - useless. this.keyboard is chargning for ESC event
|
||||||
this.keyboardShortcut = new KeyboardShortcut();
|
this.keyboardShortcut = new KeyboardShortcut();
|
||||||
this.keyboardShortcut.addCallback(
|
this.keyboardShortcut.addCallback(
|
||||||
Phaser.KeyCode.ESC, // keyCode
|
Phaser.KeyCode.ESC, // keyCode
|
||||||
@@ -24,6 +25,7 @@ var TypingTest = {
|
|||||||
(function() { this.back(); }).bind(this), // keyUpHandler
|
(function() { this.back(); }).bind(this), // keyUpHandler
|
||||||
"keyboard_test" // callerClassName
|
"keyboard_test" // callerClassName
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
// top ui
|
// top ui
|
||||||
var screenTopUI = new ScreenTopUI();
|
var screenTopUI = new ScreenTopUI();
|
||||||
@@ -125,17 +127,9 @@ var TypingTest = {
|
|||||||
Phaser.KeyCode.ESC, // keyCode
|
Phaser.KeyCode.ESC, // keyCode
|
||||||
null, // keyDownHandler
|
null, // keyDownHandler
|
||||||
(function() { this.back(); }).bind(this), // keyUpHandler
|
(function() { this.back(); }).bind(this), // keyUpHandler
|
||||||
"typing_practice" // callerClassName
|
"keyboard_test" // callerClassName
|
||||||
);
|
);
|
||||||
|
|
||||||
game.input.keyboard.processKeyPress = (function(event) {
|
|
||||||
if(self.isOnStage === false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
self.checkTypingContents(event);
|
|
||||||
});
|
|
||||||
this.shiftKey = game.input.keyboard.addKey(Phaser.Keyboard.SHIFT);
|
|
||||||
|
|
||||||
// hands
|
// hands
|
||||||
this.leftHand = new LeftHand(this.keyMapper);
|
this.leftHand = new LeftHand(this.keyMapper);
|
||||||
this.rightHand = new RightHand(this.keyMapper);
|
this.rightHand = new RightHand(this.keyMapper);
|
||||||
@@ -379,15 +373,14 @@ var TypingTest = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
checkTypingContents: function(event) {
|
checkTypingContents: function(event) {
|
||||||
// var inputContent = this.inputTextContent.canvasInput.value().trim();
|
var inputContent = this.inputTextContent.canvasInput.value().trim();
|
||||||
var inputContent = this.inputTextContent.canvasInput.value();
|
|
||||||
var typingContent = this.typingRandomContents[this.typingIndex];
|
var typingContent = this.typingRandomContents[this.typingIndex];
|
||||||
|
|
||||||
if(event.keyCode == Phaser.Keyboard.ENTER ||
|
if(event.keyCode == Phaser.Keyboard.ENTER ||
|
||||||
event.keyCode == Phaser.Keyboard.SPACEBAR) {
|
event.keyCode == Phaser.Keyboard.SPACEBAR) {
|
||||||
// console.log("### enter ###");
|
console.log("### enter ###");
|
||||||
// console.log("inputContent : " + inputContent);
|
console.log("inputContent : " + inputContent);
|
||||||
// console.log("typingContent : " + typingContent);
|
console.log("typingContent : " + typingContent);
|
||||||
|
|
||||||
if(inputContent === typingContent) {
|
if(inputContent === typingContent) {
|
||||||
this.calculateTypingRecord(typingContent);
|
this.calculateTypingRecord(typingContent);
|
||||||
@@ -400,7 +393,6 @@ var TypingTest = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(this.inputTextContent.canvasInput.value());
|
|
||||||
if(this.isTyping == false) {
|
if(this.isTyping == false) {
|
||||||
// console.log(event);
|
// console.log(event);
|
||||||
this.setTimeTypingStart();
|
this.setTimeTypingStart();
|
||||||
@@ -447,9 +439,6 @@ var TypingTest = {
|
|||||||
var typingLength = typingContent.length;
|
var typingLength = typingContent.length;
|
||||||
// console.log("inputLength : " + inputLength + " / " + inputContent);
|
// console.log("inputLength : " + inputLength + " / " + inputContent);
|
||||||
// console.log("typingLength : " + typingLength + " / " + typingContent);
|
// console.log("typingLength : " + typingLength + " / " + typingContent);
|
||||||
if(inputLength == typingLength)
|
|
||||||
return undefined;
|
|
||||||
|
|
||||||
var misspelledIndex = -1;
|
var misspelledIndex = -1;
|
||||||
for(var i = 0; i < inputLength; i++) {
|
for(var i = 0; i < inputLength; i++) {
|
||||||
if(inputContent[i] != typingContent[i]) {
|
if(inputContent[i] != typingContent[i]) {
|
||||||
@@ -462,7 +451,9 @@ var TypingTest = {
|
|||||||
if(isEnglishTypingApp()) {
|
if(isEnglishTypingApp()) {
|
||||||
// console.log("===== english");
|
// console.log("===== english");
|
||||||
// console.log("misspelledIndex : " + misspelledIndex);
|
// console.log("misspelledIndex : " + misspelledIndex);
|
||||||
if(misspelledIndex == -1)
|
if(inputLength == typingLength)
|
||||||
|
highlightKey = "Enter";
|
||||||
|
else if(misspelledIndex == -1)
|
||||||
highlightKey = typingContent[inputLength];
|
highlightKey = typingContent[inputLength];
|
||||||
else if(misspelledIndex > -1)
|
else if(misspelledIndex > -1)
|
||||||
highlightKey = "Backspace";
|
highlightKey = "Backspace";
|
||||||
|
|||||||
Reference in New Issue
Block a user