Fix: show highlight key (incomplete)

This commit is contained in:
2019-05-15 22:31:43 +09:00
parent 9d0c9770c2
commit f57a7bc9f3
4 changed files with 92 additions and 21 deletions
+87 -17
View File
@@ -378,13 +378,15 @@ var TypingTest = {
},
checkTypingContents: function(event) {
// var inputContent = this.inputTextContent.canvasInput.value().trim();
var inputContent = this.inputTextContent.canvasInput.value();
var typingContent = this.typingRandomContents[this.typingIndex];
if(event.keyCode == Phaser.Keyboard.ENTER ||
event.keyCode == Phaser.Keyboard.SPACEBAR) {
// console.log("### enter ###");
var inputContent = this.inputTextContent.canvasInput.value().trim();
var typingContent = this.typingRandomContents[this.typingIndex];
console.log("inputContent : " + inputContent);
console.log("typingContent : " + typingContent);
// console.log("inputContent : " + inputContent);
// console.log("typingContent : " + typingContent);
if(inputContent === typingContent) {
this.calculateTypingRecord(typingContent);
@@ -394,23 +396,27 @@ var TypingTest = {
this.gameOver();
// this.goResult();
// this.state.start('TypingTestResult');
}
}
else {
// console.log(this.inputTextContent.canvasInput.value());
if(this.isTyping == false) {
// console.log(event);
this.setTimeTypingStart();
}
this.showTypingContentHighlight();
return;
}
}
// console.log(this.inputTextContent.canvasInput.value());
if(this.isTyping == false) {
// console.log(event);
this.setTimeTypingStart();
}
this.showTypingContentHighlight(inputContent, typingContent);
this.hideHighlightKey(this.highlightKey);
this.highlightKey = this.getHighlioghtKey(inputContent, typingContent);
console.log(this.highlightKey);
this.showHighlightKey(this.highlightKey);
this.moveHands(this.highlightKey);
},
showTypingContentHighlight: function() {
var typingContent = this.typingRandomContents[this.typingIndex];
var inputContent = this.inputTextContent.canvasInput.value();
showTypingContentHighlight: function(inputContent, typingContent) {
this.textTypingContent.clearColors();
this.textTypingContent.addColor(TypingTest.COLOR_CONTENT_RIGHT, 0);
@@ -429,6 +435,70 @@ var TypingTest = {
}
},
getHighlioghtKey: function(inputContent, typingContent) {
var inputLength = inputContent.length;
var typingtLength = typingContent.length;
var misspelledIndex = -1;
for(var i = 0; i < inputLength; i++) {
if(inputContent[i] != typingContent[i]) {
misspelledIndex = i;
break;
}
}
if(misspelledIndex > -1)
return "Backspace";
return "a";
},
hideHighlightKey: function(highlightKey) {
// var prevText = this.typingRandomContents[this.typingIndex];
if(highlightKey === undefined)
return;
this.keyboard.hideHighlight(highlightKey);
},
showHighlightKey: function(highlightKey) {
// var typingText = this.typingRandomContents[this.typingIndex];
if(highlightKey === undefined)
return;
this.keyboard.showHighlight(highlightKey, this.leftHand, this.rightHand);
},
moveHands: function(highlightKey) {
// var typingText = this.typingRandomContents[this.typingIndex];
if(highlightKey === undefined)
return;
var key = this.keyboard.getKeyOfText(highlightKey);
var handSide = key.handSide;
if(handSide === KeyButton.LEFT_HAND) {
this.leftHand.moveTo(key);
if(this.keyMapper.isShiftText(highlightKey)) {
var shiftRightKey = this.keyboard.getKey("ShiftRight");
shiftRightKey.showHighlight();
this.rightHand.moveTo(shiftRightKey);
} else {
this.rightHand.moveToDefaultPosition();
}
} else {
this.rightHand.moveTo(key);
if(this.keyMapper.isShiftText(highlightKey)) {
var shiftLeftKey = this.keyboard.getKey("ShiftLeft");
shiftLeftKey.showHighlight();
this.leftHand.moveTo(shiftLeftKey);
} else {
this.leftHand.moveToDefaultPosition();
}
}
},
calculateTypingRecord: function(typingContent) {
// console.log('입력 단어 : ' + this.typingRandomContents[this.typingIndex]);