Commit d820b053 authored by 18신대성's avatar 18신대성

이제 글자조합도 잘됨. Input하는거 자체는 완성, enter 눌렀을때 동작만 만들어주면됨

parent 5efe34ff
...@@ -4,6 +4,7 @@ Input.input = []; ...@@ -4,6 +4,7 @@ Input.input = [];
Input.convInput = ""; // converted input Input.convInput = ""; // converted input
Input.isShifted = false; Input.isShifted = false;
Input.pressCount = 0;
Input.reset = function() Input.reset = function()
{ {
...@@ -59,8 +60,187 @@ Input.convert = function() ...@@ -59,8 +60,187 @@ Input.convert = function()
if (this.input[i] >= ''.charCodeAt(0)) vowels.push(krInput.length - 1); // 모음일 경우 if (this.input[i] >= ''.charCodeAt(0)) vowels.push(krInput.length - 1); // 모음일 경우
} }
} }
this.convInput = krInput;
console.log(vowels); console.log(vowels);
this.convInput = "";
let vowelIdx = 0;
if (vowelIdx === vowels.length) this.convInput = krInput; // 모음이 없을때
else // 모음이 존재할때
{
for (let i = 0; i <= vowels[vowelIdx] - 2; i++) this.convInput += krInput[i];
while (vowelIdx < vowels.length)
{
if (krInput[vowels[vowelIdx] - 1] >= ''.charCodeAt(0)) // 모음 앞에 모음이 있을때
{
this.convInput += krInput[vowels[vowelIdx]];
vowelIdx++;
}
else // 모음 앞에 자음이 있을때
{
var first = this.convertToFirst(krInput[vowels[vowelIdx] - 1]);
var middle = krInput[vowels[vowelIdx]];
var last = 0;
if (vowelIdx + 1 >= vowels.length) // 다음 모음이 없을때
{
if (vowels[vowelIdx] + 1 < krInput.length) // 다음 자음이 존재할 때
{
if (vowels[vowelIdx] + 2 < krInput.length) // 다다음 자음이 존재할때
{
var combLast = this.combineLast(krInput[vowels[vowelIdx] + 1], krInput[vowels[vowelIdx] + 2]);
if (combLast != null) // 뒤의 두 자음을 합칠수 있을 때
{
last = combLast;
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
for (var i = vowels[vowelIdx] + 3; i < krInput.length; i++) this.convInput += krInput[i];
vowelIdx++;
}
else // 뒤의 두 자음을 합칠수 없을때
{
last = this.convertToLast(krInput[vowels[vowelIdx] + 1]);
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
for (var i = vowels[vowelIdx] + 2; i < krInput.length; i++) this.convInput += krInput[i];
vowelIdx++;
}
}
else // 다다음 자음이 없을때
{
last = this.convertToLast(krInput[vowels[vowelIdx] + 1]);
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
vowelIdx++;
}
}
else // 다음 글자가 없을때
{
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
vowelIdx++;
}
}
else // 다음 모음이 있을때
{
if (vowels[vowelIdx + 1] - vowels[vowelIdx] <= 2) // 다음 모음 사이에 자음이 0개거나 1개
{
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
vowelIdx++;
}
else if (vowels[vowelIdx + 1] - vowels[vowelIdx] === 3) // 다음 모음 사이에 자음이 2개
{
last = this.convertToLast(krInput[vowels[vowelIdx] + 1]);
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
vowelIdx++;
}
else // 다음 모음 사이에 자음이 3개 이상
{
var combLast = this.combineLast(krInput[vowels[vowelIdx] + 1], krInput[vowels[vowelIdx] + 2]);
if (combLast != null) // 뒤의 두 자음을 합칠수 있을 때
{
last = combLast;
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
for (var i = vowels[vowelIdx] + 3; i < vowels[vowelIdx + 1] - 1; i++) this.convInput += krInput[i];
vowelIdx++;
}
else // 뒤의 두 자음을 합칠수 없을때
{
last = this.convertToLast(krInput[vowels[vowelIdx] + 1]);
this.convInput += String.fromCharCode(this.convertToCharCode(first, middle, last));
for (var i = vowels[vowelIdx] + 2; i < vowels[vowelIdx + 1] - 1; i++) this.convInput += krInput[i];
vowelIdx++;
}
}
}
}
}
}
console.log('__________');
}
Input.convertToLast = function(word)
{
let output = 0;
switch(word)
{
case '': output = 1; break;
case '': output = 2; break;
case '': output = 4; break;
case '': output = 7; break;
case '': output = 8; break;
case '': output = 16; break;
case '': output = 17; break;
case '': output = 19; break;
case '': output = 20; break;
case '': output = 21; break;
case '': output = 22; break;
case '': output = 23; break;
case '': output = 24; break;
case '': output = 25; break;
case '': output = 26; break;
case '': output = 27; break;
default: break;
}
return output;
}
Input.convertToCharCode = function(first, middle, last)
{
// 'last' must be code of last words
console.log(first + ' ' + (middle.charCodeAt(0) - ''.charCodeAt(0)) + ' ' + last );
var returnCode = 0xac00 + 28 * 21 * first + 28 * (middle.charCodeAt(0) - ''.charCodeAt(0)) + last;
console.log(returnCode);
return returnCode;
}
Input.combineLast = function(left, right)
{
if (right.charCodeAt(0) <= ''.charCodeAt(0))
{
let output = null;
switch(left + ',' + right)
{
case 'ㄱ,ㅅ': output = 3; break;
case 'ㄴ,ㅈ': output = 5; break;
case 'ㄴ,ㅎ': output = 6; break;
case 'ㄹ,ㄱ': output = 9; break;
case 'ㄹ,ㅁ': output = 10; break;
case 'ㄹ,ㅂ': output = 11; break;
case 'ㄹ,ㅅ': output = 12; break;
case 'ㄹ,ㅌ': output = 13; break;
case 'ㄹ,ㅍ': output = 14; break;
case 'ㄹ,ㅎ': output = 15; break;
case 'ㅂ,ㅅ': output = 18; break;
default: break;
}
return output;
}
else return null;
}
// 나중에 바꿀 계획 있음
Input.convertToFirst = function(word)
{
let output = 0;
switch(word)
{
case '': output = 0; break;
case '': output = 1; break;
case '': output = 2; break;
case '': output = 3; break;
case '': output = 4; break;
case '': output = 5; break;
case '': output = 6; break;
case '': output = 7; break;
case '': output = 8; break;
case '': output = 9; break;
case '': output = 10; break;
case '': output = 11; break;
case '': output = 12; break;
case '': output = 13; break;
case '': output = 14; break;
case '': output = 15; break;
case '': output = 16; break;
case '': output = 17; break;
case '': output = 18; break;
default: break;
}
return output;
} }
Input.inputField = Input.inputField =
...@@ -70,6 +250,7 @@ Input.inputField = ...@@ -70,6 +250,7 @@ Input.inputField =
this.background = scene.add.sprite(400, 500, 'inputFieldBackground').setScale(0.2); this.background = scene.add.sprite(400, 500, 'inputFieldBackground').setScale(0.2);
this.text = scene.add.text(400, 500, "안녕하세요", {font: '15pt 궁서'}).setOrigin(0.5, 0.5).setColor('#000000'); this.text = scene.add.text(400, 500, "안녕하세요", {font: '15pt 궁서'}).setOrigin(0.5, 0.5).setColor('#000000');
scene.input.keyboard.on('keyup', function() {Input.pressCount--})
scene.input.keyboard.on('keydown-SHIFT', function() {Input.isShifted = true}); scene.input.keyboard.on('keydown-SHIFT', function() {Input.isShifted = true});
scene.input.keyboard.on('keyup-SHIFT', function() {Input.isShifted = false}); scene.input.keyboard.on('keyup-SHIFT', function() {Input.isShifted = false});
scene.input.keyboard.on('keydown-DELETE', function() {Input.reset()}); scene.input.keyboard.on('keydown-DELETE', function() {Input.reset()});
...@@ -126,6 +307,8 @@ Input.inputField = ...@@ -126,6 +307,8 @@ Input.inputField =
Input.pushInput = function(inputKey) Input.pushInput = function(inputKey)
{ {
if (this.pressCount < 3)
{
let output; let output;
if (Input.isShifted) if (Input.isShifted)
{ {
...@@ -146,4 +329,6 @@ Input.pushInput = function(inputKey) ...@@ -146,4 +329,6 @@ Input.pushInput = function(inputKey)
console.log(Input.input); console.log(Input.input);
Input.convert(); Input.convert();
Input.inputField.text.setText(Input.convInput); Input.inputField.text.setText(Input.convInput);
this.pressCount++;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment