From 16850f6eb0814fba8cc91b5c17edbac90cc9be87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Wed, 28 Aug 2019 10:51:49 +0900 Subject: [PATCH] Fix: typing record (completed) --- src/game/lib/util/string_util.js | 6 ++- src/game/typing/examination/game.js | 66 +++++++++++++++++------------ 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/game/lib/util/string_util.js b/src/game/lib/util/string_util.js index 8088250..f8dc0b4 100644 --- a/src/game/lib/util/string_util.js +++ b/src/game/lib/util/string_util.js @@ -193,12 +193,14 @@ StringUtil.getUnicodeAlphabetCount = function(text) { var count = 0; var textLen = text.length for(var i = 0; i < textLen; i++) { - if(StringUtil.isKoreanAlphabet(text[i])) - count += StringUtil.getUnicodeKoreanAlphabetCount(text[i]); + var unicodeLetter = text[i]; + if(StringUtil.isKoreanAlphabet(unicodeLetter)) + count += StringUtil.getUnicodeKoreanAlphabetCount(unicodeLetter); else count++; } + // console.log(unicodeLetter + " count : " + count); return count; }; diff --git a/src/game/typing/examination/game.js b/src/game/typing/examination/game.js index ff9b890..119f47f 100644 --- a/src/game/typing/examination/game.js +++ b/src/game/typing/examination/game.js @@ -340,7 +340,9 @@ TypingExamination.prototype.initTypingData = function() { this.typingRecordTotal = 0; this.correctLetterCountInLine = 0; - this.correctLetterCountInAllLines = 0; + this.correctUnicodeLetterCountInAllLines = 0; + + this.animalLevelID = -1; } @@ -505,24 +507,30 @@ TypingExamination.prototype.onKeyUp = function(event) { this.highlightTypingContent(notTrimmedInputContent, notTrimmedTypingContent); - // get correct letter count - // if the count > this.correctLetterCountInLine + 1 (2 more at onece), it's abusing (reset input text) - // if the count = this.correctLetterCountInLine + 1 - // this.correctLetterCountInLine++ - // this.correctLetterCountForAllLines++ - // update this.textTypingRecord.text with this.correctLetterCountForAllLines - var correctLetterCount = this.getCorrectLetterCount(trimmedInputContent, trimmedTypingContent); - if(correctLetterCount > this.correctLetterCountInLine + 1) { - var abusingAmount = correctLetterCount - this.correctLetterCountInLine; - console.log("abusing!!! " + abusingAmount); - } else { - if(correctLetterCount === this.correctLetterCountInLine + 1) { + var correctLetterCount = this.getCorrectLetterCount(notTrimmedInputContent, notTrimmedTypingContent); + if(correctLetterCount === this.correctLetterCountInLine + 1) { + this.correctLetterCountInLine++; + + var correctLetter = notTrimmedInputContent[this.correctLetterCountInLine - 1]; + var unicodeLetterCount = StringUtil.getUnicodeAlphabetCount(correctLetter); + this.correctUnicodeLetterCountInAllLines += unicodeLetterCount; + // console.log(this.correctUnicodeLetterCountInAllLines + " : '" + correctLetter + "'"); + } else if(correctLetterCount > this.correctLetterCountInLine) { + var count = correctLetterCount - this.correctLetterCountInLine; + // console.log("*** missed onKeyUp event - begin : " + count); + for(var i = 0; i < count; i++) { this.correctLetterCountInLine++; - var correctLetter = trimmedTypingContent[correctLetterCount - 1]; + + var correctLetter = notTrimmedInputContent[this.correctLetterCountInLine - 1]; var unicodeLetterCount = StringUtil.getUnicodeAlphabetCount(correctLetter); - this.correctLetterCountInAllLines += unicodeLetterCount; + this.correctUnicodeLetterCountInAllLines += unicodeLetterCount; + // console.log(this.correctUnicodeLetterCountInAllLines + " : '" + correctLetter + "'"); } + // console.log("*** missed onKeyUp event - end"); + } else { + // console.log("combinationing letter for " + " (" + notTrimmedInputContent[correctLetterCount] + "), correctLetterCount : " + correctLetterCount); } + this.updateTypingRecord(); if(event.keyCode == Phaser.Keyboard.ENTER) @@ -542,7 +550,8 @@ TypingExamination.prototype.onKeyEnter = function(trimmedInputContent, trimmedTy // console.log("input completed"); // this.calculateTypingRecord(notTrimmedTypingContent); - this.correctLetterCountInAllLines++; + this.correctUnicodeLetterCountInAllLines++; + // console.log(this.correctUnicodeLetterCountInAllLines + " : Enter"); this.correctLetterCountInLine = 0; // update this.textTypingRecord.text with this.correctLetterCountForAllLines this.updateTypingRecord(); @@ -555,6 +564,8 @@ TypingExamination.prototype.onKeyEnter = function(trimmedInputContent, trimmedTy return; } + // console.log("\n"); + // console.log("\n"); this.playNextContent(); return; } @@ -594,24 +605,27 @@ TypingExamination.prototype.highlightTypingContent = function(notTrimmedInputCon TypingExamination.prototype.updateTypingRecord = function() { - this.typingRecordTotal = this.correctLetterCountInAllLines * TimeUtil.MINUTE_SEC / this.realtimeStageTimer.getElapsedTime(); + this.typingRecordTotal = this.correctUnicodeLetterCountInAllLines * TimeUtil.MINUTE_SEC / this.realtimeStageTimer.getElapsedTime(); // console.log("---"); - // console.log(this.correctLetterCountInAllLines); + // console.log(this.correctUnicodeLetterCountInAllLines); // console.log(this.realtimeStageTimer.getElapsedTime()); // console.log(typingRecord); var typingRecordInteger = Math.floor(this.typingRecordTotal); this.averageTypingSpeedText.print(typingRecordInteger); var animalLevelID = Animal.animalLevelIDByRecord(typingRecordInteger, Animal.TYPE_EXAM); - this.animalRecordList.activate(animalLevelID); - this.animalRecordList.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); + if(animalLevelID !== this.animalLevelID) { + this.animalLevelID = animalLevelID; + this.animalRecordList.activate(animalLevelID); + this.animalRecordList.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); + } } -TypingExamination.prototype.getCorrectLetterCount = function(trimmedInputContent, trimmedTypingContent) { - var typingContentLength = trimmedTypingContent.length; +TypingExamination.prototype.getCorrectLetterCount = function(inputContent, typingContent) { + var typingContentLength = inputContent.length; for(var i = 0; i < typingContentLength; i++) { - var typingChar = trimmedTypingContent.charAt(i); - var inputChar = trimmedInputContent.charAt(i); + var typingChar = inputContent.charAt(i); + var inputChar = typingContent.charAt(i); // console.log("typingChar : " + typingChar); // console.log("inputChar : " + inputChar); @@ -620,8 +634,8 @@ TypingExamination.prototype.getCorrectLetterCount = function(trimmedInputContent // return 0; if(typingChar !== inputChar) { - // console.log("trimmedInputContent.charAt(" + i + ") : " + trimmedInputContent.charCodeAt(i).toString(16) + ", " + inputChar); - // console.log("trimmedTypingContent.charAt(" + i + ") : " + trimmedTypingContent.charCodeAt(i).toString(16) + ", " + typingChar); + // console.log("typingContent.charAt(" + i + ") : " + typingContent.charCodeAt(i).toString(16) + ", " + inputChar); + // console.log("inputContent.charAt(" + i + ") : " + inputContent.charCodeAt(i).toString(16) + ", " + typingChar); return i; }