function TypingTextManager() { this.init(); } TypingTextManager.prototype.init = function() { this.contents = []; } TypingTextManager.prototype.getContents = function() { return this.contents; } TypingTextManager.prototype.add = function(arr) { this.contents = this.contents.concat(arr); } TypingTextManager.prototype.slice = function(start, end) { this.contents = this.contents.slice(start, end); } TypingTextManager.prototype.getShuffledArray = function(arr) { return Phaser.ArrayUtils.shuffle(arr); } TypingTextManager.prototype.fillLeftRightBasicKey = function() { var length = this.contents.length; // console.log(length); for(var i = length - 1; i > -1; i--) { var char = this.contents[i]; // console.log(char); if(this.isKoreanConsonant(char)) { this.contents.splice(i + 1, 0, "ㅓ"); } else if(this.isKoreanVowel(char)) { this.contents.splice(i, 0, "ㄹ"); } else if(this.isEnglishLeftHand(char)) { this.contents.splice(i + 1, 0, "j"); } else if(this.isEnglishRightHand(char)) { this.contents.splice(i, 0, "f"); } } } TypingTextManager.prototype.isKoreanConsonant = function(char) { if(char.length != 1) return false; if(TypingTextManager.KOREAN_LETTER_CHO.indexOf(char) > -1) return true; else if(TypingTextManager.KOREAN_LETTER_JONG.indexOf(char) > -1) return; return false; } TypingTextManager.prototype.isKoreanVowel = function(char) { if(char.length != 1) return false; if(TypingTextManager.KOREAN_LETTER_JUNG.indexOf(char) > -1) return true; return false; } TypingTextManager.prototype.isEnglishLeftHand = function(char) { if(char.length != 1) return false; if(TypingTextManager.ENGLISH_LETTER_LEFT.indexOf(char) > -1) return true; return false; } TypingTextManager.prototype.isEnglishRightHand = function(char) { if(char.length != 1) return false; if(TypingTextManager.ENGLISH_LETTER_RIGHT.indexOf(char) > -1) return true; return false; } TypingTextManager.prototype.makePracticeContents = function(arr, repeatCount) { this.init(); this.add(arr); for(var i = 0; i < repeatCount; i++) { this.add(this.getShuffledArray(arr)); } this.fillLeftRightBasicKey(); } TypingTextManager.prototype.makeTestContents = function(arr) { this.init(); this.add(this.getShuffledArray(arr)); } TypingTextManager.prototype.makeExaminationContents = function(arr) { this.init(); // getExaminationArray : slice too long sentence by proper words and last space // this.add(arr); for(var i = 0; i < arr.length; i++) { var sentence = arr[i]; if(sentence.length == 0) continue; if(sentence.length > TypingTextManager.SENTENCE_MAX_CHARACTER) this.add(this.makeShortSentences(sentence)); else this.add(sentence); } } TypingTextManager.prototype.makeShortSentences = function(sentence) { var words = sentence.split(" "); var wordCount = words.length; var shortSentences = []; var sentenceIndex = 0; shortSentences[sentenceIndex] = ""; // console.log(sentence); // console.log(words); for(var i = 0; i < wordCount; i++) { // console.log(words[i]); // console.log(shortSentences[sentenceIndex].length); // console.log(words[i]); if(shortSentences[sentenceIndex].length + words[i].length < TypingTextManager.SENTENCE_MAX_CHARACTER) if(i < wordCount - 1) shortSentences[sentenceIndex] = shortSentences[sentenceIndex].concat(words[i], " "); else // last word shortSentences[sentenceIndex] = shortSentences[sentenceIndex].concat(words[i]); else { sentenceIndex++; if(i < wordCount - 1) shortSentences[sentenceIndex] = words[i] + " "; else // last word shortSentences[sentenceIndex] = words[i]; } } return shortSentences; } TypingTextManager.shuffledArray = function(arr) { return Phaser.ArrayUtils.shuffle(arr); } TypingTextManager.KOREAN_LETTER_CHO = [ "ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" ]; TypingTextManager.KOREAN_LETTER_JUNG = [ "ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ" ]; TypingTextManager.KOREAN_LETTER_JONG = [ "", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" ]; TypingTextManager.ENGLISH_LETTER_LEFT = [ "q", "w", "e", "r", "t", "a", "s", "d", "f", "g", "z", "x", "c", "v", "b" ]; TypingTextManager.ENGLISH_LETTER_RIGHT = [ "y", "u", "i", "o", "p", "h", "j", "k", "l", "n", "m" ]; TypingTextManager.SENTENCE_MAX_CHARACTER = 35; // 27;