mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
hangul ime
This commit is contained in:
@@ -282,7 +282,7 @@ let jongseongDigraphsG = {"\u11A8":"\u11A9", "\u11BA":"\u11AA"}
|
||||
let jongseongDigraphsN = {"\u11BD":"\u11AC", "\u11C2":"\u11AD"}
|
||||
let jongseongDigraphsR = {"\u11A8":"\u11B0", "\u11B7":"\u11B1", "\u11B8":"\u11B2", "\u11BA":"\u11B3", "\u11C0":"\u11B4", "\u11C1":"\u11B5", "\u11C2":"\u11B6"}
|
||||
let jongseongDigraphsB = {"\u11BA":"\u11B9"}
|
||||
let bufAssemble = () => {
|
||||
let bufAssemble = (isPreview) => {
|
||||
if (states.buf[0] === undefined && states.buf[1] === undefined && states.buf[2] === undefined)
|
||||
return ''
|
||||
else if (states.buf[1] === undefined && isHangul(states.buf[0]))
|
||||
@@ -291,32 +291,42 @@ let bufAssemble = () => {
|
||||
return ["\u115F", states.buf[1], states.buf[2]].join('')
|
||||
else if (isHangul(states.buf[2]) && states.buf[0] === undefined && states.buf[1] === undefined )
|
||||
return ["\u115F", "\u1160", states.buf[2]].join('')
|
||||
else if (isChoseong(states.buf[0]) && isJungseong(states.buf[1]) && isJongseong(states.buf[2])) {
|
||||
let i = states.buf[0].charCodeAt(0) - 0x1100
|
||||
let p = states.buf[1].charCodeAt(0) - 0x1161
|
||||
let f = states.buf[2].charCodeAt(0) - 0x11A7
|
||||
return String.fromCodePoint(0xAC00 + (i * 588) + (p * 28) + f)
|
||||
}
|
||||
else if (isChoseong(states.buf[0]) && isJungseong(states.buf[1]) && undefined == states.buf[2]) {
|
||||
let i = states.buf[0].charCodeAt(0) - 0x1100
|
||||
let p = states.buf[1].charCodeAt(0) - 0x1161
|
||||
return String.fromCodePoint(0xAC00 + (i * 588) + (p * 28))
|
||||
}
|
||||
// TODO normalise Hangul IPF to hangul compats but only when NOT in preview mode
|
||||
else
|
||||
return states.buf.join('')
|
||||
}
|
||||
Object.freeze({"n":"세벌식 3-90","states":states,
|
||||
// return: [displayed output, composed output]
|
||||
"accept":(keycodes,shiftin,altgrin)=>{
|
||||
"accept":(headkey,shiftin,altgrin)=>{
|
||||
let layer = 1*shiftin// + 2*altgrin
|
||||
states.code = 1
|
||||
|
||||
let purekeys = keycodes.filter(it => (
|
||||
/*let purekeys = keycodes.filter(it => (
|
||||
inRange(it,7,18) || // numeric
|
||||
inRange(it,29,56) || // alph
|
||||
it == 62 || // space
|
||||
inRange(it,66,76) || // symbols
|
||||
inRange(it,144,163) // numpad
|
||||
))
|
||||
let headkey = purekeys[0]
|
||||
let headkey = purekeys[0]*/
|
||||
|
||||
let s = states.keylayouts[headkey][layer]
|
||||
let bufIndex = isJungseong(s) ? 1 : isJongseong(s) ? 2 : 0
|
||||
|
||||
console.log(`IME accepting keycodes ${keycodes}`)
|
||||
|
||||
if (isHangul(s)) {
|
||||
// ㄲ ㄸ ㅃ ㅆ ㅉ
|
||||
if (0 == bufIndex && isChoseongDigraph(states.buf[0]) && isChoseongDigraph(s)) {
|
||||
// ㄲ ㄸ ㅃ ㅆ ㅉ (only allow when the jung/jongseong is not typed)
|
||||
if (0 == bufIndex && undefined == states.buf[1] && isChoseongDigraph(states.buf[0]) && states.buf[0] == s) {
|
||||
states.buf[0] = choseongDigraphs[s]
|
||||
}
|
||||
// ㅘ ㅙ ㅚ
|
||||
@@ -352,19 +362,19 @@ Object.freeze({"n":"세벌식 3-90","states":states,
|
||||
let sendout = bufAssemble(); reset()
|
||||
states.buf[bufIndex] = s
|
||||
console.log(`sending out: ${sendout}`)
|
||||
return [bufAssemble(), sendout]
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
else {
|
||||
states.buf[bufIndex] = s
|
||||
console.log(`assembling: ${bufAssemble()}`)
|
||||
}
|
||||
|
||||
return [bufAssemble(), ""]
|
||||
return [bufAssemble(1), ""]
|
||||
}
|
||||
else {
|
||||
let sendout = bufAssemble() + s; reset()
|
||||
console.log(`sending out: ${sendout}`)
|
||||
return [bufAssemble(), sendout]
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
},
|
||||
"end":()=>{
|
||||
|
||||
Binary file not shown.
@@ -10,8 +10,8 @@ data class TerrarumKeyLayout(
|
||||
|
||||
data class TerrarumInputMethod(
|
||||
val name: String,
|
||||
// (keycodes, shiftin, altgrin)
|
||||
val acceptChar: (IntArray, Boolean, Boolean) -> Pair<String, String>, // Pair<Display Char, Output Char if any>
|
||||
// (headkey, shiftin, altgrin)
|
||||
val acceptChar: (Int, Boolean, Boolean) -> Pair<String, String>, // Pair<Display Char, Output Char if any>
|
||||
val endCompose: () -> String,
|
||||
val reset: () -> Unit,
|
||||
val composing: () -> Boolean
|
||||
@@ -106,8 +106,8 @@ object IME {
|
||||
val name = jsval.getMember("n").asString()
|
||||
|
||||
|
||||
return TerrarumInputMethod(name, { it, shifted, alted ->
|
||||
val a = jsval.invokeMember("accept", context.eval("js", "'${it.joinToString(",")}'.split(',')"), shifted, alted)
|
||||
return TerrarumInputMethod(name, { headkey, shifted, alted ->
|
||||
val a = jsval.invokeMember("accept", headkey, shifted, alted)
|
||||
a.getArrayElement(0).asString() to a.getArrayElement(1).asString()
|
||||
}, {
|
||||
jsval.invokeMember("end").asString()
|
||||
|
||||
@@ -276,7 +276,8 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
companion object {
|
||||
data class TerrarumKeyboardEvent(
|
||||
val type: Int,
|
||||
val character: String?,
|
||||
val character: String?, // representative key symbol
|
||||
val headkey: Int, // representative keycode
|
||||
val repeatCount: Int,
|
||||
val keycodes: IntArray
|
||||
)
|
||||
@@ -318,11 +319,15 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
else if (shiftin && newKeysym0[1]?.isNotBlank() == true) newKeysym0[1]
|
||||
else newKeysym0[0]
|
||||
|
||||
val headKeyCode = if (keyDiff.size < 1) keys[0] else keyDiff[0]
|
||||
|
||||
if (!keyChanged) {
|
||||
callback(TerrarumKeyboardEvent(KEY_DOWN, keysym, repeatCount, keys))
|
||||
// println("KEY_DOWN '$keysym' ($headKeyCode) $repeatCount; ${keys.joinToString()}")
|
||||
callback(TerrarumKeyboardEvent(KEY_DOWN, keysym, headKeyCode, repeatCount, keys))
|
||||
}
|
||||
else if (newKeysym != null) {
|
||||
callback(TerrarumKeyboardEvent(KEY_DOWN, newKeysym, repeatCount, keys))
|
||||
// println("KEY_DOWC '$newKeysym' ($headKeyCode) $repeatCount; ${keys.joinToString()}")
|
||||
callback(TerrarumKeyboardEvent(KEY_DOWN, newKeysym, headKeyCode, repeatCount, keys))
|
||||
}
|
||||
|
||||
oldKeys = keys // don't put this outside of if-cascade
|
||||
@@ -346,7 +351,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
private fun keysToStr(keymap: TerrarumKeyLayout, keys: IntArray): Array<String?>? {
|
||||
if (keys.size == 0) return null
|
||||
val headkey = keys[0]
|
||||
return if (keymap.symbols!![headkey] == null) null else keymap.symbols!![headkey]
|
||||
return keymap.symbols?.get(headkey)
|
||||
}
|
||||
|
||||
private fun strobeKeys(): IntArray {
|
||||
|
||||
@@ -165,7 +165,7 @@ class UIItemTextLineInput(
|
||||
|
||||
// process keypresses
|
||||
if (isActive) {
|
||||
IngameController.withKeyboardEvent { (_, char, _, keycodes) ->
|
||||
IngameController.withKeyboardEvent { (_, char, headkey, _, keycodes) ->
|
||||
fboUpdateLatch = true
|
||||
forceLitCursor()
|
||||
val ime = getIME()
|
||||
@@ -195,7 +195,7 @@ class UIItemTextLineInput(
|
||||
if (cursorX == 0 || (oldCode !in 0x115F..0x11FF && oldCode !in 0xD7B0..0xD7FF)) break
|
||||
}
|
||||
|
||||
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
|
||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||
tryCursorForward()
|
||||
}
|
||||
}
|
||||
@@ -203,13 +203,13 @@ class UIItemTextLineInput(
|
||||
else if (cursorX > 0 && keycodes.contains(Input.Keys.LEFT)) {
|
||||
// TODO IME endComposing()
|
||||
cursorX -= 1
|
||||
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
|
||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||
tryCursorForward()
|
||||
}
|
||||
else if (cursorX < textbuf.size && keycodes.contains(Input.Keys.RIGHT)) {
|
||||
// TODO IME endComposing()
|
||||
cursorX += 1
|
||||
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
|
||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||
tryCursorBack()
|
||||
}
|
||||
// accept:
|
||||
@@ -220,7 +220,7 @@ class UIItemTextLineInput(
|
||||
val altgrin = keycodes.contains(Input.Keys.ALT_RIGHT)
|
||||
|
||||
val codepoints = if (ime != null) {
|
||||
val newStatus = ime.acceptChar(keycodes, shiftin, altgrin)
|
||||
val newStatus = ime.acceptChar(headkey, shiftin, altgrin)
|
||||
composingView = CodepointSequence(newStatus.first.toCodePoints())
|
||||
|
||||
newStatus.second.toCodePoints()
|
||||
@@ -233,7 +233,7 @@ class UIItemTextLineInput(
|
||||
textbuf.addAll(cursorX, codepoints)
|
||||
|
||||
cursorX += codepoints.size
|
||||
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
|
||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||
|
||||
tryCursorBack()
|
||||
}
|
||||
@@ -302,7 +302,7 @@ class UIItemTextLineInput(
|
||||
textbuf.addAll(cursorX, actuallyInserted)
|
||||
|
||||
cursorX += actuallyInserted.size
|
||||
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
|
||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||
|
||||
tryCursorBack()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user