Add: TypingTextManager
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
class TypingTextManager {
|
||||
|
||||
constructor() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.contents = [];
|
||||
}
|
||||
|
||||
getContents() {
|
||||
return this.contents;
|
||||
}
|
||||
|
||||
add(arr) {
|
||||
this.contents = this.contents.concat(arr);
|
||||
}
|
||||
|
||||
slice(start, end) {
|
||||
this.contents = this.contents.slice(start, end);
|
||||
}
|
||||
|
||||
getShuffledArray(arr) {
|
||||
return Phaser.ArrayUtils.shuffle(arr);
|
||||
}
|
||||
|
||||
|
||||
makePracticeContents(arr, repeatCount) {
|
||||
this.init();
|
||||
this.add(arr);
|
||||
for(let i = 0; i < repeatCount; i++) {
|
||||
this.add(this.getShuffledArray(arr));
|
||||
}
|
||||
}
|
||||
|
||||
makeTestContents(arr) {
|
||||
this.init();
|
||||
this.add(this.getShuffledArray(arr));
|
||||
}
|
||||
};
|
||||
@@ -117,71 +117,23 @@ class TypingPractice {
|
||||
}
|
||||
|
||||
initTypingData() {
|
||||
this.typingContents = this.getTypingPracticeContents();
|
||||
console.log(this.typingContents);
|
||||
let randomContents = Phaser.ArrayUtils.shuffle(this.typingContents);
|
||||
console.log(randomContents);
|
||||
this.wordCountForStage = TypingPractice.WORD_COUNT_FOR_STAGE;
|
||||
if(isDebugMode())
|
||||
this.wordCountForStage = 3;
|
||||
this.typingRandomContents = randomContents.slice(1, this.wordCountForStage + 1); // start Num, end Num (not index)
|
||||
console.log(this.typingRandomContents);
|
||||
this.typingContentLength = this.typingContents.length;
|
||||
let typingTextMan = new TypingTextManager();
|
||||
|
||||
let typingPracticeContents = this.loadPracticeContent();
|
||||
// console.log(typingPracticeContents);
|
||||
typingTextMan.makePracticeContents(typingPracticeContents, 1);
|
||||
this.typingRandomContents = typingTextMan.getContents();
|
||||
// console.log(this.typingRandomContents);
|
||||
this.typingContentLength = this.typingRandomContents.length;
|
||||
this.typingIndex = 0;
|
||||
|
||||
|
||||
|
||||
this.isTyping = false;
|
||||
// this.timeTypingStart = 0;
|
||||
// this.timeTypingEnd = 0;
|
||||
|
||||
this.typingLetterCountTotal = 0;
|
||||
this.typingRecordTotal = 0;
|
||||
}
|
||||
|
||||
|
||||
getTypingPracticeContents() {
|
||||
let TypingPracticeContents = this.loadPracticeContent();
|
||||
// console.log('playingStageData.language : ' + playingStageData.language);
|
||||
// console.log('playingStageData.level : ' + playingStageData.level);
|
||||
// console.log('TypingPracticeContents : ' + TypingPracticeContents);
|
||||
|
||||
// this.typingRecordForLines = [];
|
||||
// this.typingElapsedTime = [];
|
||||
// for(let i = 0; i < TypingPracticeContents.length; i++) {
|
||||
// this.typingRecordForLines[i] = 0;
|
||||
// this.typingElapsedTime[i] = 0;
|
||||
// }
|
||||
|
||||
return TypingPracticeContents;
|
||||
}
|
||||
|
||||
loadTemporaryContent() {
|
||||
testContent = [
|
||||
"ㅃ",
|
||||
"ㅂ",
|
||||
"ㅈ",
|
||||
"ㅉ",
|
||||
"ㄸ",
|
||||
"ㄷ",
|
||||
"ㄱ",
|
||||
"ㄲ",
|
||||
"ㅅ"
|
||||
];
|
||||
// testContent = [
|
||||
// "a",
|
||||
// "s",
|
||||
// "d",
|
||||
// "f",
|
||||
// "j",
|
||||
// "k",
|
||||
// "l",
|
||||
// ";",
|
||||
// "'"
|
||||
// ];
|
||||
return testContent;
|
||||
}
|
||||
|
||||
loadPracticeContent() {
|
||||
let appName = "";
|
||||
if(isTypingTestStage())
|
||||
@@ -257,16 +209,8 @@ class TypingPractice {
|
||||
this.textTypingContentsDone.text = "";
|
||||
else
|
||||
this.textTypingContentsDone.text = this.typingRandomContents[doneIndex];
|
||||
// for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
|
||||
// let doneIndex = this.typingIndex - i - 1;
|
||||
// if(doneIndex < 0) {
|
||||
// this.textTypingContentsDone.text = "";
|
||||
// } else {
|
||||
// this.textTypingContentsDone.text = this.typingRandomContents[doneIndex];
|
||||
// }
|
||||
// }
|
||||
|
||||
if(this.typingIndex === this.wordCountForStage) {
|
||||
if(this.typingIndex === this.typingContentLength) {
|
||||
this.textTypingContent.text = "";
|
||||
return;
|
||||
}
|
||||
@@ -278,21 +222,8 @@ class TypingPractice {
|
||||
this.textTypingContentPreview.text = "";
|
||||
else
|
||||
this.textTypingContentPreview.text = this.typingRandomContents[previewIndex];
|
||||
// for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
|
||||
// let previewIndex = this.typingIndex + i + 1;
|
||||
// if(previewIndex < this.typingRandomContents.length)
|
||||
// this.textTypingContentPreview.text = this.typingRandomContents[previewIndex];
|
||||
// else
|
||||
// this.textTypingContentPreview.text = "";
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
resetTypingContent() {
|
||||
this.textTypingContent.clearColors();
|
||||
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_RIGHT, 0);
|
||||
}
|
||||
*/
|
||||
|
||||
getKeyCode(text) {
|
||||
return this.keyMapper.getKeyIDOfText(text);
|
||||
@@ -318,110 +249,15 @@ class TypingPractice {
|
||||
let inputContent = event.key;
|
||||
let typingContent = this.typingRandomContents[this.typingIndex];
|
||||
|
||||
// if(this.getKeyCode(inputContent) === this.getKeyCode(typingContent)
|
||||
// && this.getShiftTypeOfText(inputContent) === this.getShiftTypeOfText(typingContent)) {
|
||||
// console.log("correct key");
|
||||
// }
|
||||
|
||||
// if(shiftKey.isDown)
|
||||
// console.log(this.shiftKey);
|
||||
if(this.isKeyPressed(inputContent, typingContent)) {
|
||||
this.playNextContent();
|
||||
|
||||
if(this.typingIndex === this.wordCountForStage) {
|
||||
if(this.typingIndex === this.typingContentLength) {
|
||||
this.goResult();
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(event.keyCode == Phaser.Keyboard.ENTER) {
|
||||
// console.log("### enter ###");
|
||||
let inputContent = this.inputTextContent.canvasInput.value();
|
||||
let typingContent = this.typingRandomContents[this.typingIndex];
|
||||
|
||||
if(inputContent == typingContent) {
|
||||
this.calculateTypingRecord(typingContent);
|
||||
this.playNextContent();
|
||||
|
||||
if(this.typingIndex == this.wordCountForStage)
|
||||
this.goResult();
|
||||
// this.state.start('TypingPracticeResult');
|
||||
}
|
||||
}
|
||||
else {
|
||||
// console.log(this.inputTextContent.canvasInput.value());
|
||||
if(this.isTyping == false) {
|
||||
// console.log(event);
|
||||
this.setTimeTypingStart();
|
||||
}
|
||||
|
||||
this.showTypingContentHighlight();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
showTypingContentHighlight() {
|
||||
let typingContent = this.typingRandomContents[this.typingIndex];
|
||||
let inputContent = this.inputTextContent.canvasInput.value();
|
||||
|
||||
this.textTypingContent.clearColors();
|
||||
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_RIGHT, 0);
|
||||
|
||||
if(typingContent == null)
|
||||
return;
|
||||
|
||||
let typingContentLength = typingContent.length;
|
||||
for(let i = 0; i < typingContentLength; i++) {
|
||||
// console.log("typingContent.charAt(i) : " + typingContent.charAt(i));
|
||||
// console.log("inputContent.charAt(i) : " + inputContent.charAt(i));
|
||||
|
||||
if(typingContent.charAt(i) != inputContent.charAt(i)) {
|
||||
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_WRONG, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
calculateTypingRecord(typingContent) {
|
||||
// console.log('입력 단어 : ' + this.typingRandomContents[this.typingIndex]);
|
||||
|
||||
this.isTyping = false;
|
||||
this.timeTypingEnd = game.time.elapsedSince(0);
|
||||
// console.log('this.timeTypingEnd : ' + this.timeTypingEnd);
|
||||
|
||||
let elapsedTimeMS = this.timeTypingEnd - this.timeTypingStart;
|
||||
// console.log('elapsedTimeMS : ' + elapsedTimeMS);
|
||||
|
||||
let typingContentLength = StringUtil.getUnicodeAlphabetCount(typingContent);
|
||||
// console.log('typingContentLength : ' + typingContentLength);
|
||||
let typingContentPlusEnterCount = typingContentLength + TypingPractice.TYPING_COUNT_PLUS_ENTER;
|
||||
|
||||
let typingRecord = (typingContentPlusEnterCount + TypingPractice.TYPING_COUNT_PLUS_ENTER) * 60000 / elapsedTimeMS;
|
||||
|
||||
// this.typingElapsedTime[this.typingIndex] = elapsedTimeMS;
|
||||
this.typingLetterCountTotal += typingContentPlusEnterCount;
|
||||
// this.typingRecordForLines[this.typingIndex] = typingRecord;
|
||||
// console.log(this.typingRecordForLines[this.typingIndex]);
|
||||
|
||||
// let typingElapsedTimeTotal = 0;
|
||||
// for(let i = 0; i <= this.typingIndex; i++) {
|
||||
// // console.log('i : ' + i + ' - time : ' + this.typingElapsedTime[i]);
|
||||
// typingElapsedTimeTotal += this.typingElapsedTime[i];
|
||||
// }
|
||||
// this.typingRecordTotal = this.typingLetterCountTotal * 60000 / typingElapsedTimeTotal;
|
||||
// console.log(this.typingLetterCountTotal);
|
||||
// console.log(typingElapsedTimeTotal);
|
||||
// console.log(typingRecordTotal);
|
||||
|
||||
// console.log('-------------- total --------------');
|
||||
// console.log('typingLetterCountTotal : ' + this.typingLetterCountTotal);
|
||||
// console.log('typingElapsedTimeTotal : ' + typingElapsedTimeTotal);
|
||||
// console.log('typingRecordTotal : ' + typingRecordTotal);
|
||||
// console.log('-----------------------------------');
|
||||
}
|
||||
*/
|
||||
|
||||
playNextContent() {
|
||||
this.typingIndex++;
|
||||
@@ -431,25 +267,9 @@ class TypingPractice {
|
||||
}
|
||||
|
||||
showPlayingWordNumber() {
|
||||
this.contentProgressText.print(this.typingIndex + 1, this.wordCountForStage);
|
||||
this.contentProgressText.print(this.typingIndex + 1, this.typingContentLength);
|
||||
}
|
||||
|
||||
/*
|
||||
setTimeTypingStart() {
|
||||
this.timeTypingStart = game.time.elapsedSince(0);
|
||||
let timeGap = this.timeTypingStart - this.timeTypingEnd;
|
||||
|
||||
if(timeGap < 50)
|
||||
return;
|
||||
|
||||
this.isTyping = true;
|
||||
// console.log('last End : ' + this.timeTypingEnd);
|
||||
// console.log('this.timeTypingStart : ' + this.timeTypingStart);
|
||||
|
||||
// console.log('time gap : ' + (this.timeTypingStart - this.timeTypingEnd));
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -462,6 +282,4 @@ TypingPractice.OFFSET_RIGHT_ALIGN = 10;
|
||||
TypingPractice.WORD_COUNT_FOR_STAGE = 10;
|
||||
|
||||
TypingPractice.COLOR_CONTENT_WRONG = "#aaaaaa";
|
||||
TypingPractice.COLOR_CONTENT_RIGHT = "#ffff4d";
|
||||
|
||||
|
||||
TypingPractice.COLOR_CONTENT_RIGHT = "#ffff4d";
|
||||
@@ -238,7 +238,7 @@ class KeyMapper {
|
||||
|
||||
if(keyData.englishKey !== null && keyData.englishKey.shiftText === text)
|
||||
return true;
|
||||
else if(keyData.koreanKey !== null && keyData.koreanKey.shiftText === text)
|
||||
else if(keyData.koreanKey !== null && keyData.koreanKey.shiftText === text && keyData.koreanKey.normalText !== text)
|
||||
return true;
|
||||
else if(keyData.functionKey !== null && keyData.functionKey.shiftText === text)
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user