Add: total tdd
This commit is contained in:
@@ -52,7 +52,10 @@ class TypingPractice {
|
||||
|
||||
|
||||
this.keyMapper = new KeyMapper();
|
||||
new Keyboard(this.keyMapper);
|
||||
if(sessionStorageManager.playingAppName.indexOf("korean") > 0)
|
||||
new Keyboard(this.keyMapper, Keyboard.KOREAN);
|
||||
else
|
||||
new Keyboard(this.keyMapper, Keyboard.ENGLISH);
|
||||
|
||||
game.input.keyboard.processKeyPress = () => {
|
||||
self.checkTypingContents(event);
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
class KeyData {
|
||||
|
||||
constructor() {
|
||||
this.functionKey = null;
|
||||
this.englishKey = null;
|
||||
this.koreanKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
class KeyTextData {
|
||||
|
||||
constructor(normalText, shiftText) {
|
||||
@@ -7,6 +16,8 @@ class KeyTextData {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class KeyMapper {
|
||||
|
||||
constructor() {
|
||||
@@ -20,112 +31,143 @@ class KeyMapper {
|
||||
|
||||
|
||||
registerFunctionKey() {
|
||||
this.registerKeyTextData("Backquote", "`", "~");
|
||||
this.registerKeyTextData("Digit1", "1", "!");
|
||||
this.registerKeyTextData("Digit2", "2", "@");
|
||||
this.registerKeyTextData("Digit3", "3", "#");
|
||||
this.registerKeyTextData("Digit4", "4", "$");
|
||||
this.registerKeyTextData("Digit5", "5", "%");
|
||||
this.registerKeyTextData("Digit6", "6", "^");
|
||||
this.registerKeyTextData("Digit7", "7", "&");
|
||||
this.registerKeyTextData("Digit8", "8", "*");
|
||||
this.registerKeyTextData("Digit9", "9", "(");
|
||||
this.registerKeyTextData("Digit0", "0", ")");
|
||||
this.registerKeyTextData("Minus", "-", "_");
|
||||
this.registerKeyTextData("Equal", "=", "+");
|
||||
this.registerKeyTextData("Backspace", "backspace", "backspace");
|
||||
this.registerFunctionKeyTextData("Backquote", "`", "~");
|
||||
this.registerFunctionKeyTextData("Digit1", "1", "!");
|
||||
this.registerFunctionKeyTextData("Digit2", "2", "@");
|
||||
this.registerFunctionKeyTextData("Digit3", "3", "#");
|
||||
this.registerFunctionKeyTextData("Digit4", "4", "$");
|
||||
this.registerFunctionKeyTextData("Digit5", "5", "%");
|
||||
this.registerFunctionKeyTextData("Digit6", "6", "^");
|
||||
this.registerFunctionKeyTextData("Digit7", "7", "&");
|
||||
this.registerFunctionKeyTextData("Digit8", "8", "*");
|
||||
this.registerFunctionKeyTextData("Digit9", "9", "(");
|
||||
this.registerFunctionKeyTextData("Digit0", "0", ")");
|
||||
this.registerFunctionKeyTextData("Minus", "-", "_");
|
||||
this.registerFunctionKeyTextData("Equal", "=", "+");
|
||||
this.registerFunctionKeyTextData("Backspace", "backspace", "backspace");
|
||||
|
||||
this.registerKeyTextData("Tab", "tab", "tab");
|
||||
this.registerKeyTextData("BracketLeft", "[", "{");
|
||||
this.registerKeyTextData("BracketRight", "]", "}");
|
||||
this.registerKeyTextData("Backslash", "\\", "|");
|
||||
this.registerFunctionKeyTextData("Tab", "tab", "tab");
|
||||
this.registerFunctionKeyTextData("BracketLeft", "[", "{");
|
||||
this.registerFunctionKeyTextData("BracketRight", "]", "}");
|
||||
this.registerFunctionKeyTextData("Backslash", "\\", "|");
|
||||
|
||||
this.registerKeyTextData("CapsLock", "caps lock", "caps lock");
|
||||
this.registerKeyTextData("Semicolon", ";", ":");
|
||||
this.registerKeyTextData("Quote", "'", "\"");
|
||||
this.registerKeyTextData("Enter", "enter", "enter");
|
||||
this.registerFunctionKeyTextData("CapsLock", "caps lock", "caps lock");
|
||||
this.registerFunctionKeyTextData("Semicolon", ";", ":");
|
||||
this.registerFunctionKeyTextData("Quote", "'", "\"");
|
||||
this.registerFunctionKeyTextData("Enter", "enter", "enter");
|
||||
|
||||
this.registerKeyTextData("ShiftLeft", "left_shift", "left_shift");
|
||||
this.registerKeyTextData("ShiftRight", "right_shift", "right_shift");
|
||||
this.registerKeyTextData("Comma", ",", "<");
|
||||
this.registerKeyTextData("Period", ".", ">");
|
||||
this.registerKeyTextData("Slash", "/", "?");
|
||||
this.registerFunctionKeyTextData("ShiftLeft", "left_shift", "left_shift");
|
||||
this.registerFunctionKeyTextData("ShiftRight", "right_shift", "right_shift");
|
||||
this.registerFunctionKeyTextData("Comma", ",", "<");
|
||||
this.registerFunctionKeyTextData("Period", ".", ">");
|
||||
this.registerFunctionKeyTextData("Slash", "/", "?");
|
||||
|
||||
this.registerKeyTextData("ControlLeft", "ctrl", "ctrl");
|
||||
this.registerKeyTextData("window", "window", "window");
|
||||
this.registerKeyTextData("AltLeft", "alt", "alt");
|
||||
this.registerKeyTextData("chinese", "한자", "한자");
|
||||
this.registerKeyTextData("Space", "space", "space");
|
||||
this.registerKeyTextData("korean_english", "한/영", "한/영");
|
||||
this.registerKeyTextData("AltRight", "alt", "alt");
|
||||
this.registerKeyTextData("ControlRight", "ctrl", "ctrl");
|
||||
this.registerFunctionKeyTextData("ControlLeft", "ctrl", "ctrl");
|
||||
this.registerFunctionKeyTextData("window", "window", "window");
|
||||
this.registerFunctionKeyTextData("AltLeft", "alt", "alt");
|
||||
this.registerFunctionKeyTextData("Chinese", "한자", "한자");
|
||||
this.registerFunctionKeyTextData("Space", "space", "space");
|
||||
this.registerFunctionKeyTextData("KoreanEnglish", "한/영", "한/영");
|
||||
this.registerFunctionKeyTextData("AltRight", "alt", "alt");
|
||||
this.registerFunctionKeyTextData("ControlRight", "ctrl", "ctrl");
|
||||
}
|
||||
|
||||
registerEnglishKey() {
|
||||
this.registerKeyTextData("KeyQ", "q", "Q");
|
||||
this.registerKeyTextData("KeyW", "w", "W");
|
||||
this.registerKeyTextData("KeyE", "e", "E");
|
||||
this.registerKeyTextData("KeyR", "r", "R");
|
||||
this.registerKeyTextData("KeyT", "t", "T");
|
||||
this.registerKeyTextData("KeyY", "y", "Y");
|
||||
this.registerKeyTextData("KeyU", "u", "U");
|
||||
this.registerKeyTextData("KeyI", "i", "I");
|
||||
this.registerKeyTextData("KeyO", "o", "O");
|
||||
this.registerKeyTextData("KeyP", "p", "P");
|
||||
this.registerEnglishKeyTextData("KeyQ", "q", "Q");
|
||||
this.registerEnglishKeyTextData("KeyW", "w", "W");
|
||||
this.registerEnglishKeyTextData("KeyE", "e", "E");
|
||||
this.registerEnglishKeyTextData("KeyR", "r", "R");
|
||||
this.registerEnglishKeyTextData("KeyT", "t", "T");
|
||||
this.registerEnglishKeyTextData("KeyY", "y", "Y");
|
||||
this.registerEnglishKeyTextData("KeyU", "u", "U");
|
||||
this.registerEnglishKeyTextData("KeyI", "i", "I");
|
||||
this.registerEnglishKeyTextData("KeyO", "o", "O");
|
||||
this.registerEnglishKeyTextData("KeyP", "p", "P");
|
||||
|
||||
this.registerKeyTextData("KeyA", "a", "A");
|
||||
this.registerKeyTextData("KeyS", "s", "S");
|
||||
this.registerKeyTextData("KeyD", "d", "D");
|
||||
this.registerKeyTextData("KeyF", "f", "F");
|
||||
this.registerKeyTextData("KeyG", "g", "G");
|
||||
this.registerKeyTextData("KeyH", "h", "H");
|
||||
this.registerKeyTextData("KeyJ", "j", "J");
|
||||
this.registerKeyTextData("KeyK", "k", "K");
|
||||
this.registerKeyTextData("KeyL", "l", "L");
|
||||
this.registerEnglishKeyTextData("KeyA", "a", "A");
|
||||
this.registerEnglishKeyTextData("KeyS", "s", "S");
|
||||
this.registerEnglishKeyTextData("KeyD", "d", "D");
|
||||
this.registerEnglishKeyTextData("KeyF", "f", "F");
|
||||
this.registerEnglishKeyTextData("KeyG", "g", "G");
|
||||
this.registerEnglishKeyTextData("KeyH", "h", "H");
|
||||
this.registerEnglishKeyTextData("KeyJ", "j", "J");
|
||||
this.registerEnglishKeyTextData("KeyK", "k", "K");
|
||||
this.registerEnglishKeyTextData("KeyL", "l", "L");
|
||||
|
||||
this.registerKeyTextData("KeyZ", "z", "Z");
|
||||
this.registerKeyTextData("KeyX", "x", "X");
|
||||
this.registerKeyTextData("KeyC", "c", "C");
|
||||
this.registerKeyTextData("KeyV", "v", "V");
|
||||
this.registerKeyTextData("KeyB", "b", "B");
|
||||
this.registerKeyTextData("KeyN", "n", "N");
|
||||
this.registerKeyTextData("KeyM", "m", "M");
|
||||
this.registerEnglishKeyTextData("KeyZ", "z", "Z");
|
||||
this.registerEnglishKeyTextData("KeyX", "x", "X");
|
||||
this.registerEnglishKeyTextData("KeyC", "c", "C");
|
||||
this.registerEnglishKeyTextData("KeyV", "v", "V");
|
||||
this.registerEnglishKeyTextData("KeyB", "b", "B");
|
||||
this.registerEnglishKeyTextData("KeyN", "n", "N");
|
||||
this.registerEnglishKeyTextData("KeyM", "m", "M");
|
||||
}
|
||||
|
||||
registerKoreanKey() {
|
||||
this.registerKeyTextData("KeyQ", "ㅂ", "ㅃ");
|
||||
this.registerKeyTextData("KeyW", "ㅈ", "ㅉ");
|
||||
this.registerKeyTextData("KeyE", "ㄷ", "ㄸ");
|
||||
this.registerKeyTextData("KeyR", "ㄱ", "ㄲ");
|
||||
this.registerKeyTextData("KeyT", "ㅅ", "ㅆ");
|
||||
this.registerKeyTextData("KeyY", "ㅛ", "ㅛ");
|
||||
this.registerKeyTextData("KeyU", "ㅕ", "ㅕ");
|
||||
this.registerKeyTextData("KeyI", "ㅑ", "ㅑ");
|
||||
this.registerKeyTextData("KeyO", "ㅐ", "ㅒ");
|
||||
this.registerKeyTextData("KeyP", "ㅔ", "ㅖ");
|
||||
this.registerKoreanKeyTextData("KeyQ", "ㅂ", "ㅃ");
|
||||
this.registerKoreanKeyTextData("KeyW", "ㅈ", "ㅉ");
|
||||
this.registerKoreanKeyTextData("KeyE", "ㄷ", "ㄸ");
|
||||
this.registerKoreanKeyTextData("KeyR", "ㄱ", "ㄲ");
|
||||
this.registerKoreanKeyTextData("KeyT", "ㅅ", "ㅆ");
|
||||
this.registerKoreanKeyTextData("KeyY", "ㅛ", "ㅛ");
|
||||
this.registerKoreanKeyTextData("KeyU", "ㅕ", "ㅕ");
|
||||
this.registerKoreanKeyTextData("KeyI", "ㅑ", "ㅑ");
|
||||
this.registerKoreanKeyTextData("KeyO", "ㅐ", "ㅒ");
|
||||
this.registerKoreanKeyTextData("KeyP", "ㅔ", "ㅖ");
|
||||
|
||||
this.registerKeyTextData("KeyA", "ㅁ", "ㅁ");
|
||||
this.registerKeyTextData("KeyS", "ㄴ", "ㄴ");
|
||||
this.registerKeyTextData("KeyD", "ㅇ", "ㅇ");
|
||||
this.registerKeyTextData("KeyF", "ㄹ", "ㄹ");
|
||||
this.registerKeyTextData("KeyG", "ㅎ", "ㅎ");
|
||||
this.registerKeyTextData("KeyH", "ㅗ", "ㅗ");
|
||||
this.registerKeyTextData("KeyJ", "ㅓ", "ㅓ");
|
||||
this.registerKeyTextData("KeyK", "ㅏ", "ㅏ");
|
||||
this.registerKeyTextData("KeyL", "ㅣ", "ㅣ");
|
||||
this.registerKoreanKeyTextData("KeyA", "ㅁ", "ㅁ");
|
||||
this.registerKoreanKeyTextData("KeyS", "ㄴ", "ㄴ");
|
||||
this.registerKoreanKeyTextData("KeyD", "ㅇ", "ㅇ");
|
||||
this.registerKoreanKeyTextData("KeyF", "ㄹ", "ㄹ");
|
||||
this.registerKoreanKeyTextData("KeyG", "ㅎ", "ㅎ");
|
||||
this.registerKoreanKeyTextData("KeyH", "ㅗ", "ㅗ");
|
||||
this.registerKoreanKeyTextData("KeyJ", "ㅓ", "ㅓ");
|
||||
this.registerKoreanKeyTextData("KeyK", "ㅏ", "ㅏ");
|
||||
this.registerKoreanKeyTextData("KeyL", "ㅣ", "ㅣ");
|
||||
|
||||
this.registerKeyTextData("KeyZ", "ㅋ", "ㅋ");
|
||||
this.registerKeyTextData("KeyX", "ㅌ", "ㅌ");
|
||||
this.registerKeyTextData("KeyC", "ㅊ", "ㅊ");
|
||||
this.registerKeyTextData("KeyV", "ㅍ", "ㅍ");
|
||||
this.registerKeyTextData("KeyB", "ㅠ", "ㅠ");
|
||||
this.registerKeyTextData("KeyN", "ㅜ", "ㅜ");
|
||||
this.registerKeyTextData("KeyM", "ㅡ", "ㅡ");
|
||||
this.registerKoreanKeyTextData("KeyZ", "ㅋ", "ㅋ");
|
||||
this.registerKoreanKeyTextData("KeyX", "ㅌ", "ㅌ");
|
||||
this.registerKoreanKeyTextData("KeyC", "ㅊ", "ㅊ");
|
||||
this.registerKoreanKeyTextData("KeyV", "ㅍ", "ㅍ");
|
||||
this.registerKoreanKeyTextData("KeyB", "ㅠ", "ㅠ");
|
||||
this.registerKoreanKeyTextData("KeyN", "ㅜ", "ㅜ");
|
||||
this.registerKoreanKeyTextData("KeyM", "ㅡ", "ㅡ");
|
||||
}
|
||||
|
||||
|
||||
registerKeyTextData(keyID, normalText, shiftText) {
|
||||
this.keyboardKeyMap[keyID] = new KeyTextData(normalText, shiftText);
|
||||
registerFunctionKeyTextData(keyID, normalText, shiftText) {
|
||||
if(this.keyboardKeyMap[keyID] === undefined) {
|
||||
this.keyboardKeyMap[keyID] = new KeyData();
|
||||
}
|
||||
this.keyboardKeyMap[keyID].functionKey = new KeyTextData(normalText, shiftText);
|
||||
|
||||
if(this.inputKeyMap[keyID] === undefined)
|
||||
this.inputKeyMap[keyID] = keyID;
|
||||
if(this.inputKeyMap[normalText] === undefined)
|
||||
this.inputKeyMap[normalText] = keyID;
|
||||
if(this.inputKeyMap[shiftText] === undefined)
|
||||
this.inputKeyMap[shiftText] = keyID;
|
||||
}
|
||||
|
||||
registerEnglishKeyTextData(keyID, normalText, shiftText) {
|
||||
if(this.keyboardKeyMap[keyID] === undefined) {
|
||||
this.keyboardKeyMap[keyID] = new KeyData();
|
||||
}
|
||||
this.keyboardKeyMap[keyID].englishKey = new KeyTextData(normalText, shiftText);
|
||||
|
||||
if(this.inputKeyMap[keyID] === undefined)
|
||||
this.inputKeyMap[keyID] = keyID;
|
||||
if(this.inputKeyMap[normalText] === undefined)
|
||||
this.inputKeyMap[normalText] = keyID;
|
||||
if(this.inputKeyMap[shiftText] === undefined)
|
||||
this.inputKeyMap[shiftText] = keyID;
|
||||
}
|
||||
|
||||
registerKoreanKeyTextData(keyID, normalText, shiftText) {
|
||||
if(this.keyboardKeyMap[keyID] === undefined) {
|
||||
this.keyboardKeyMap[keyID] = new KeyData();
|
||||
}
|
||||
this.keyboardKeyMap[keyID].koreanKey = new KeyTextData(normalText, shiftText);
|
||||
|
||||
if(this.inputKeyMap[keyID] === undefined)
|
||||
this.inputKeyMap[keyID] = keyID;
|
||||
@@ -136,20 +178,52 @@ class KeyMapper {
|
||||
}
|
||||
|
||||
|
||||
getNormalText(keyID) {
|
||||
getNormalText(keyID, language) {
|
||||
if(this.keyboardKeyMap[keyID] === undefined) {
|
||||
console.log(keyID);
|
||||
return "?";
|
||||
}
|
||||
return this.keyboardKeyMap[keyID].normalText;
|
||||
|
||||
// console.log(keyID);
|
||||
// console.log(language);
|
||||
// console.log(this.keyboardKeyMap[keyID]);
|
||||
let keyData = this.keyboardKeyMap[keyID];
|
||||
if(language === Keyboard.ENGLISH && keyData.englishKey !== null) {
|
||||
return keyData.englishKey.normalText;
|
||||
}
|
||||
else if(language === Keyboard.KOREAN && keyData.koreanKey !== null) {
|
||||
return keyData.koreanKey.normalText;
|
||||
}
|
||||
else if(keyData.functionKey !== undefined) {
|
||||
return keyData.functionKey.normalText;
|
||||
}
|
||||
else {
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
getShiftText(keyID) {
|
||||
getShiftText(keyID, language) {
|
||||
if(this.keyboardKeyMap[keyID] === undefined) {
|
||||
console.log(keyID);
|
||||
return "?";
|
||||
}
|
||||
return this.keyboardKeyMap[keyID].shiftText;
|
||||
|
||||
// console.log(keyID);
|
||||
// console.log(language);
|
||||
// console.log(this.keyboardKeyMap[keyID]);
|
||||
let keyData = this.keyboardKeyMap[keyID];
|
||||
if(language === Keyboard.ENGLISH && keyData.englishKey !== null) {
|
||||
return keyData.englishKey.shiftText;
|
||||
}
|
||||
else if(language === Keyboard.KOREAN && keyData.koreanKey !== null) {
|
||||
return keyData.koreanKey.shiftText;
|
||||
}
|
||||
else if(keyData.functionKey !== undefined) {
|
||||
return keyData.functionKey.shiftText;
|
||||
}
|
||||
else {
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,12 +234,16 @@ class KeyMapper {
|
||||
|
||||
isShiftText(text) {
|
||||
let keyID = this.getKeyIDOfText(text);
|
||||
let keyTextData = this.keyboardKeyMap[keyID];
|
||||
let keyData = this.keyboardKeyMap[keyID];
|
||||
|
||||
if(keyTextData.normalText === text)
|
||||
return false;
|
||||
if(keyData.englishKey !== null && keyData.englishKey.shiftText === text)
|
||||
return true;
|
||||
else if(keyData.koreanKey !== null && keyData.koreanKey.shiftText === text)
|
||||
return true;
|
||||
else if(keyData.functionKey !== null && keyData.functionKey.shiftText === text)
|
||||
return true;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class Keyboard {
|
||||
|
||||
constructor(keyMapper) {
|
||||
constructor(keyMapper, language) {
|
||||
this.keyMapper = keyMapper;
|
||||
this.language = language;
|
||||
|
||||
this.keyIndex = 0;
|
||||
this.keyDataList = [];
|
||||
@@ -129,8 +130,8 @@ class Keyboard {
|
||||
|
||||
|
||||
addFunctionKeyData(keyID, handSide, fingerType, x, y, width, height, type) {
|
||||
let normalText = this.keyMapper.getNormalText(keyID);
|
||||
let shiftText = this.keyMapper.getShiftText(keyID);
|
||||
let normalText = this.keyMapper.getNormalText(keyID, this.language);
|
||||
let shiftText = this.keyMapper.getShiftText(keyID, this.language);
|
||||
|
||||
let newKey = this.makeKeyDataObject(
|
||||
keyID,
|
||||
@@ -146,8 +147,8 @@ class Keyboard {
|
||||
|
||||
addNextFunctionKeyData(keyID, handSide, fingerType, width, height, type) {
|
||||
let prevKey = this.keyDataList[this.keyIndex - 1];
|
||||
let normalText = this.keyMapper.getNormalText(keyID);
|
||||
let shiftText = this.keyMapper.getShiftText(keyID);
|
||||
let normalText = this.keyMapper.getNormalText(keyID, this.language);
|
||||
let shiftText = this.keyMapper.getShiftText(keyID, this.language);
|
||||
|
||||
let newKey = this.makeKeyDataObject(
|
||||
keyID,
|
||||
@@ -165,8 +166,8 @@ class Keyboard {
|
||||
|
||||
addNextNormalKeyData(keyID, handSide, fingerType) {
|
||||
let prevKey = this.keyDataList[this.keyIndex - 1];
|
||||
let normalText = this.keyMapper.getNormalText(keyID);
|
||||
let shiftText = this.keyMapper.getShiftText(keyID);
|
||||
let normalText = this.keyMapper.getNormalText(keyID, this.language);
|
||||
let shiftText = this.keyMapper.getShiftText(keyID, this.language);
|
||||
|
||||
let newKey = this.makeNextNormalKeyDataObject(
|
||||
keyID,
|
||||
@@ -329,7 +330,7 @@ class Keyboard {
|
||||
KeyButton.LEFT_FUNCTION_KEY
|
||||
);
|
||||
this.addNextFunctionKeyData(
|
||||
"chinese",
|
||||
"Chinese",
|
||||
KeyButton.LEFT_HAND,
|
||||
KeyButton.NONE_FINGER,
|
||||
Keyboard.CHINESE_KEY_WIDTH_PX,
|
||||
@@ -345,7 +346,7 @@ class Keyboard {
|
||||
KeyButton.CENTER_FUNCTION_KEY
|
||||
);
|
||||
this.addNextFunctionKeyData(
|
||||
"korean_english",
|
||||
"KoreanEnglish",
|
||||
KeyButton.RIGHT_HAND,
|
||||
KeyButton.NONE_FINGER,
|
||||
Keyboard.KOREAN_ENGLISH_KEY_WIDTH_PX,
|
||||
@@ -373,6 +374,9 @@ class Keyboard {
|
||||
}
|
||||
|
||||
|
||||
Keyboard.ENGLISH = "english";
|
||||
Keyboard.KOREAN = "korean";
|
||||
|
||||
Keyboard.DEFAULT_KEY_SIZE_PX = 46;
|
||||
Keyboard.BACKSPACE_KEY_WIDTH_PX = Keyboard.DEFAULT_KEY_SIZE_PX * 1.5;
|
||||
Keyboard.TAB_KEY_WIDTH_PX = Keyboard.DEFAULT_KEY_SIZE_PX * 1.5;
|
||||
|
||||
Reference in New Issue
Block a user