Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sejong25
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Tear of Sejong
sejong25
Commits
d820b053
Commit
d820b053
authored
Jun 27, 2019
by
18신대성
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
이제 글자조합도 잘됨. Input하는거 자체는 완성, enter 눌렀을때 동작만 만들어주면됨
parent
5efe34ff
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
202 additions
and
17 deletions
+202
-17
Input.js
js/Input.js
+202
-17
No files found.
js/Input.js
View file @
d820b053
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment