mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
pickaxes are faster in general
This commit is contained in:
@@ -1,477 +0,0 @@
|
||||
let states = {"keylayouts":[[""],[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["0",")"],
|
||||
["1","!"],
|
||||
["2","@"],
|
||||
["3","#"],
|
||||
["4","$"],
|
||||
["5","%"],
|
||||
["6","^"],
|
||||
["7","&"],
|
||||
["8","*"],
|
||||
["9","("],
|
||||
["*"],
|
||||
["#"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["ㅁ"],
|
||||
["ㅠ"],
|
||||
["ㅊ"],
|
||||
["ㅇ"],
|
||||
["ㄷ","ㄸ"],
|
||||
["ㄹ"],
|
||||
["ㅎ"],
|
||||
["ㅗ"],
|
||||
["ㅑ"],
|
||||
["ㅓ","·"],
|
||||
["ㅏ","ㆍ"],// A & ARAE-A
|
||||
["ㅣ","|"],
|
||||
["ㅡ","…"],
|
||||
["ㅜ"],
|
||||
["ㅐ","ㅒ"],
|
||||
["ㅔ","ㅖ"],
|
||||
["ㅂ","ㅃ"],
|
||||
["ㄱ","ㄲ"],
|
||||
["ㄴ"],
|
||||
["ㅅ","ㅆ"],
|
||||
["ㅕ"],
|
||||
["ㅍ"],
|
||||
["ㅈ","ㅉ"],
|
||||
["ㅌ","¤"],
|
||||
["ㅛ"],
|
||||
["ㅋ"],
|
||||
[",","<"],
|
||||
[".",">"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[" "],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\n"],
|
||||
["\x08"],
|
||||
["`","~"],
|
||||
["-","_"],
|
||||
["=","+"],
|
||||
["[","{"],
|
||||
["]","}"],
|
||||
["\\","₩"],
|
||||
["ㅆ",":"],
|
||||
["'",'"'],
|
||||
["/","?"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["0"],
|
||||
["1"],
|
||||
["2"],
|
||||
["3"],
|
||||
["4"],
|
||||
["5"],
|
||||
["6"],
|
||||
["7"],
|
||||
["8"],
|
||||
["9"],
|
||||
["/"],
|
||||
["*"],
|
||||
["-"],
|
||||
["+"],
|
||||
["."],
|
||||
["."],
|
||||
["\n"],
|
||||
["="],
|
||||
["("],
|
||||
[")"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined]
|
||||
],
|
||||
"code":0,
|
||||
"buf":[]}
|
||||
let reset = () => {
|
||||
states.code = 0
|
||||
states.buf = []
|
||||
}
|
||||
let inRange = (s,a,b) => (a <= s && s <= b)
|
||||
let isHangul = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x3131, 0x318E)
|
||||
let isConsonant = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x3131, 0x314E)
|
||||
let isVowel = (s) => s !== undefined && (inRange(s.charCodeAt(0), 0x314F, 0x3163) || inRange(s.charCodeAt(0), 0x318D, 0x318E))
|
||||
let isVowelSuper = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x318D, 0x318E)
|
||||
let isJongseongConsonant = (s) => s !== undefined && (inRange(s.charCodeAt(0), 0x3131, 0x314E) && !([0x3138, 0x3143, 0x3149].includes(s.charCodeAt(0))))
|
||||
let isJungseongDigraph1 = (s) => s !== undefined && ([0x3157, 0x315C].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphO = (s) => s !== undefined && ([0x314F, 0x3150, 0x3163].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphU = (s) => s !== undefined && ([0x3153, 0x3154, 0x3163].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphEU = (s) => s !== undefined && ([0x3163].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphAA = (s) => s !== undefined && ([0x3163].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphG = (s) => s !== undefined && ([0x3145].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphN = (s) => s !== undefined && ([0x3148, 0x314E].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphR = (s) => s !== undefined && ([0x3131, 0x3141, 0x3142, 0x3145, 0x314C, 0x314D, 0x314E].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphB = (s) => s !== undefined && ([0x3145].includes(s.charCodeAt(0)))
|
||||
let jungseongDigraphsO = {"\u314F":"\u3158", "\u3150":"\u3159", "\u3163":"\u315A"}
|
||||
let jungseongDigraphsU = {"\u3153":"\u315D", "\u3154":"\u315E", "\u3163":"\u315F"}
|
||||
let jungseongDigraphsEU = {"\u3163":"\u3162"}
|
||||
let jungseongDigraphsAA = {"\u3163":"\u318E"}
|
||||
let jongseongDigraphsG = {"\u3145":"\u3133"}
|
||||
let jongseongDigraphsN = {"\u3148":"\u3135", "\u314E":"\u3136"}
|
||||
let jongseongDigraphsR = {"\u3131":"\u313A", "\u3141":"\u313B", "\u3142":"\u313C", "\u3145":"\u313D", "\u314C":"\u313E", "\u314D":"\u313F", "\u314E":"\u3140"}
|
||||
let jongseongDigraphsB = {"\u3145":"\u3144"}
|
||||
let isThisCharJongseongDigraph = (s) => s !== undefined && ([0x3133, 0x3135, 0x3136, 0x313A, 0x313B, 0x313C, 0x313D, 0x313E, 0x313F, 0x3140, 0x3144].includes(s.charCodeAt(0)))
|
||||
let isThisCharJungseongDigraph = (s) => s !== undefined && ([0x3158, 0x3159, 0x315A, 0x315D, 0x315E, 0x315F, 0x3162, 0x318E].includes(s.charCodeAt(0)))
|
||||
let choseongTable = {"\u3131":0,"\u3132":1,"\u3134":2,"\u3137":3,"\u3138":4,"\u3139":5,"\u3141":6,"\u3142":7,"\u3143":8,"\u3145":9,"\u3146":10,"\u3147":11,"\u3148":12,"\u3149":13,"\u314A":14,"\u314B":15,"\u314C":16,"\u314D":17,"\u314E":18}
|
||||
let jongseongTable = {"\u3131":0,"\u3132":1,"\u3133":2,"\u3134":3,"\u3135":4,"\u3136":5,"\u3137":6,"\u3139":7,"\u313A":8,"\u313B":9,"\u313C":10,"\u313D":11,"\u313E":12,"\u313F":13,"\u3140":14,"\u3141":15,"\u3142":16,"\u3144":17,"\u3145":18,"\u3146":19,"\u3147":20,"\u3148":21,"\u314A":22,"\u314B":23,"\u314C":24,"\u314D":25,"\u314E":26}
|
||||
let detachJongseongDigraph = {
|
||||
"\u3133":["\u3131","\u3145"],
|
||||
"\u3135":["\u3134","\u3148"],
|
||||
"\u3136":["\u3134","\u314E"],
|
||||
"\u313A":["\u3139","\u3131"],
|
||||
"\u313B":["\u3139","\u3141"],
|
||||
"\u313C":["\u3139","\u3142"],
|
||||
"\u313D":["\u3139","\u3145"],
|
||||
"\u313E":["\u3139","\u314C"],
|
||||
"\u313F":["\u3139","\u314D"],
|
||||
"\u3140":["\u3139","\u314E"],
|
||||
"\u3144":["\u3142","\u3145"]
|
||||
}
|
||||
let detachJungseongDigraph = {
|
||||
"\u3158":["\u3157","\u314F"],
|
||||
"\u3159":["\u3157","\u3150"],
|
||||
"\u315A":["\u3157","\u314E"],
|
||||
"\u315D":["\u315C","\u3153"],
|
||||
"\u315E":["\u315C","\u3154"],
|
||||
"\u315F":["\u315C","\u3163"],
|
||||
"\u3162":["\u3161","\u3163"],
|
||||
"\u318E":["\u318D","\u3163"]
|
||||
}
|
||||
let bufAssemble = (isPreview) => {
|
||||
// nothing on the buffer
|
||||
if (states.buf[0] === undefined && states.buf[1] === undefined && states.buf[2] === undefined)
|
||||
return ''
|
||||
// Hangul: I P F
|
||||
else if (!isVowelSuper(states.buf[1]) && isConsonant(states.buf[0]) && isVowel(states.buf[1]) && isConsonant(states.buf[2])) {
|
||||
let i = choseongTable[states.buf[0]]
|
||||
let p = states.buf[1].charCodeAt(0) - 0x314F
|
||||
let f = jongseongTable[states.buf[2]] + 1
|
||||
return String.fromCodePoint(0xAC00 + (i * 588) + (p * 28) + f)
|
||||
}
|
||||
// Hangul: I P x
|
||||
else if (!isVowelSuper(states.buf[1]) && isConsonant(states.buf[0]) && isVowel(states.buf[1]) && undefined == states.buf[2]) {
|
||||
let i = choseongTable[states.buf[0]]
|
||||
let p = states.buf[1].charCodeAt(0) - 0x314F
|
||||
return String.fromCodePoint(0xAC00 + (i * 588) + (p * 28))
|
||||
}
|
||||
else if (isVowelSuper(states.buf[1]) && isConsonant(states.buf[0]) && isConsonant(states.buf[2])) {
|
||||
let i = choseongTable[states.buf[0]]
|
||||
let p = (states.buf[1].charCodeAt(0) - 0x318D) * 3
|
||||
let f = jongseongTable[states.buf[2]] + 1
|
||||
return String.fromCodePoint(0x1100 + i, 0x119E + p, 0x11A7 + f)
|
||||
}
|
||||
else if (isVowelSuper(states.buf[1]) && isConsonant(states.buf[0])) {
|
||||
let i = choseongTable[states.buf[0]]
|
||||
let p = (states.buf[1].charCodeAt(0) - 0x318D) * 3
|
||||
return String.fromCodePoint(0x1100 + i, 0x119E + p)
|
||||
}
|
||||
else
|
||||
return states.buf.join('')
|
||||
}
|
||||
//let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
|
||||
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `${buf[i]}`).join(' ')
|
||||
return Object.freeze({"n":"두벌식 수정 표준","v":"one","c":"CuriousTo\uA75Bvald","m":"candidates",
|
||||
"t":states.keylayouts.map(it => [it[0],it[1]]),
|
||||
// return: [displayed output, composed output]
|
||||
"accept":(headkey,shiftin,altgrin)=>{
|
||||
let layer = 1*shiftin// + 2*altgrin
|
||||
states.code = 1
|
||||
|
||||
/*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 s = states.keylayouts[headkey][layer]
|
||||
|
||||
if (isHangul(s)) {
|
||||
let bufIndex = (isJongseongConsonant(s) && isConsonant(states.buf[0]) && undefined !== states.buf[1]) ? 2 :
|
||||
(isVowel(s) && isConsonant(states.buf[0])) ? 1 : 0
|
||||
let vowelCollision = isVowel(states.buf[1]) && isVowel(s)
|
||||
let hasJongseongAlready = (states.buf[2] !== undefined)
|
||||
|
||||
// console.log(`accepting hangul '${s}' at buf[${bufIndex}] (vowelCollision = ${vowelCollision})`)
|
||||
|
||||
// ㅘ ㅙ ㅚ
|
||||
if (!hasJongseongAlready && 1 == bufIndex && "\u3157" == states.buf[1] && isJungseongDigraphO(s)) {
|
||||
states.buf[1] = jungseongDigraphsO[s]
|
||||
}
|
||||
// ㅝ ㅞ ㅟ
|
||||
else if (!hasJongseongAlready && 1 == bufIndex && "\u315C" == states.buf[1] && isJungseongDigraphU(s)) {
|
||||
states.buf[1] = jungseongDigraphsU[s]
|
||||
}
|
||||
// ㅢ
|
||||
else if (!hasJongseongAlready && 1 == bufIndex && "\u3161" == states.buf[1] && isJungseongDigraphEU(s)) {
|
||||
states.buf[1] = jungseongDigraphsEU[s]
|
||||
}
|
||||
// ㆎ
|
||||
else if (!hasJongseongAlready && 1 == bufIndex && "\u318D" == states.buf[1] && isJungseongDigraphAA(s)) {
|
||||
states.buf[1] = jungseongDigraphsAA[s]
|
||||
}
|
||||
// ㄳ
|
||||
else if (2 == bufIndex && "\u3131" == states.buf[2] && isJongseongDigraphG(s)) {
|
||||
states.buf[2] = jongseongDigraphsG[s]
|
||||
}
|
||||
// ㄵ ㄶ
|
||||
else if (2 == bufIndex && "\u3134" == states.buf[2] && isJongseongDigraphN(s)) {
|
||||
states.buf[2] = jongseongDigraphsN[s]
|
||||
}
|
||||
// ㄺ ㄻ ㄼ ㄽ ㄾ ㄿ ㅀ
|
||||
else if (2 == bufIndex && "\u3139" == states.buf[2] && isJongseongDigraphR(s)) {
|
||||
states.buf[2] = jongseongDigraphsR[s]
|
||||
}
|
||||
// ㅄ
|
||||
else if (2 == bufIndex && "\u3142" == states.buf[2] && isJongseongDigraphB(s)) {
|
||||
states.buf[2] = jongseongDigraphsB[s]
|
||||
}
|
||||
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
|
||||
else if (states.buf[bufIndex] !== undefined) {
|
||||
let oldbufstr = bufDebugStringify(states.buf)
|
||||
let sendout = ''
|
||||
if (vowelCollision && isThisCharJongseongDigraph(states.buf[2])) {
|
||||
let digraphs = detachJongseongDigraph[states.buf[2]]
|
||||
let newbuf = [digraphs[1], s]
|
||||
states.buf = [states.buf[0], states.buf[1], digraphs[0]]
|
||||
sendout = bufAssemble()
|
||||
states.buf = newbuf
|
||||
}
|
||||
else if (vowelCollision) {
|
||||
let newbuf = [states.buf[2], s]
|
||||
states.buf = [states.buf[0], states.buf[1]]
|
||||
sendout = bufAssemble()
|
||||
states.buf = newbuf
|
||||
}
|
||||
else {
|
||||
sendout = bufAssemble()
|
||||
reset()
|
||||
if (bufIndex == 2)
|
||||
states.buf[0] = s
|
||||
else
|
||||
states.buf[bufIndex] = s
|
||||
}
|
||||
let newbufstr = bufDebugStringify(states.buf)
|
||||
// console.log(`sending out: ${oldbufstr} -> ${sendout} ; ${newbufstr}`)
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
else {
|
||||
states.buf[bufIndex] = s
|
||||
// console.log(`assembling: ${bufDebugStringify(states.buf)} -> ${bufAssemble()}`)
|
||||
}
|
||||
|
||||
return [bufAssemble(1), ""]
|
||||
}
|
||||
else {
|
||||
// console.log(`accepting char '${s}'`)
|
||||
let oldbufstr = bufDebugStringify(states.buf)
|
||||
let sendout = bufAssemble() + (s || ''); reset()
|
||||
// console.log(`sending out: ${oldbufstr} -> ${sendout}`)
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
},
|
||||
"backspace":()=>{
|
||||
// disassemble jung/jongseong digraphs
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let last = states.buf.pop()
|
||||
|
||||
if (last !== undefined) {
|
||||
// detach jongseong
|
||||
if (isThisCharJongseongDigraph(last))
|
||||
states.buf[2] = detachJongseongDigraph[last][0]
|
||||
// detach jungseong
|
||||
else if (isThisCharJungseongDigraph(last))
|
||||
states.buf[1] = detachJungseongDigraph[last][0]
|
||||
}
|
||||
|
||||
if (states.buf.length == 0) reset()
|
||||
|
||||
// let newbufstr = bufDebugStringify(states.buf)
|
||||
// console.log(`popping assembly: ${oldbufstr} -> ${newbufstr}`)
|
||||
|
||||
return bufAssemble(1)
|
||||
},
|
||||
"end":()=>{
|
||||
// console.log(`end composing`)
|
||||
let ret = bufAssemble()
|
||||
reset()
|
||||
return ret
|
||||
},
|
||||
"reset":()=>{ reset() },
|
||||
"composing":()=>(states.code!=0)
|
||||
})
|
||||
@@ -1,479 +0,0 @@
|
||||
let states = {"keylayouts":[[""],[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\u110F",")"],
|
||||
["\u11C2","\u11BD"],
|
||||
["\u11BB","@"],
|
||||
["\u11B8","#"],
|
||||
["\u116D","$"],
|
||||
["\u1172","%"],
|
||||
["\u1163","^"],
|
||||
["\u1168","&"],
|
||||
["\u1174","*"],
|
||||
["\u116E","("],
|
||||
["*"],
|
||||
["#"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\u11BC","\u11AE"],
|
||||
["\u116E","!"],
|
||||
["\u1166","\u11B1"],
|
||||
["\u1175","\u11B0"],
|
||||
["\u1167","\u11BF"],
|
||||
["\u1161","\u11A9"],
|
||||
["\u1173","/"],
|
||||
["\u1102","'"],
|
||||
["\u1106","8"],
|
||||
["\u110B","4"],
|
||||
["\u1100","5"],
|
||||
["\u110C","6"],
|
||||
["\u1112","1"],
|
||||
["\u1109","0"],
|
||||
["\u110E","9"],
|
||||
["\u1111",">"],
|
||||
["\u11BA","\u11C1"],
|
||||
["\u1162","\u1164"],
|
||||
["\u11AB","\u11AD"],
|
||||
["\u1165",";"],
|
||||
["\u1103","7"],
|
||||
["\u1169","\u11B6"],
|
||||
["\u11AF","\u11C0"],
|
||||
["\u11A8","\u11B9"],
|
||||
["\u1105","<"],
|
||||
["\u11B7","\u11BE"],
|
||||
[",","2"],
|
||||
[".","3"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[" "],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\n"],
|
||||
["\x08"],
|
||||
["¤","~"],
|
||||
["-","_"],
|
||||
["=","+"],
|
||||
["[","{"],
|
||||
["]","}"],
|
||||
["\\","₩"],
|
||||
["\u1107",":"],
|
||||
["\u1110",'"'],
|
||||
["\u1169","?"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["0"],
|
||||
["1"],
|
||||
["2"],
|
||||
["3"],
|
||||
["4"],
|
||||
["5"],
|
||||
["6"],
|
||||
["7"],
|
||||
["8"],
|
||||
["9"],
|
||||
["/"],
|
||||
["*"],
|
||||
["-"],
|
||||
["+"],
|
||||
["."],
|
||||
["."],
|
||||
["\n"],
|
||||
["="],
|
||||
["("],
|
||||
[")"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined]
|
||||
],
|
||||
"code":0,
|
||||
"buf":[]}
|
||||
let reset = () => {
|
||||
states.code = 0
|
||||
states.buf = []
|
||||
}
|
||||
let inRange = (s,a,b) => (a <= s && s <= b)
|
||||
let isHangul = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x1100, 0x11C2)
|
||||
let isChoseong = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x1100, 0x1112)
|
||||
let isJungseong = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x1161, 0x1175)
|
||||
let isJongseong = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x11A8, 0x11C2)
|
||||
let isChoseongDigraph = (s) => s !== undefined && ([0x1100, 0x1103, 0x1107, 0x1109, 0x110C].includes(s.charCodeAt(0)))
|
||||
let isThisCharChoseongDigraph = (s) => s !== undefined && ([0x1101, 0x1104, 0x1108, 0x110A, 0x110D].includes(s.charCodeAt(0)))
|
||||
let isThisCharJungseongDigraph = (s) => s !== undefined && ([0x116A, 0x116B, 0x116C, 0x116F, 0x1170, 0x1171, 0x1174].includes(s.charCodeAt(0)))
|
||||
let isThisCharJongseongDigraph = (s) => s !== undefined && ([0x11A9, 0x11AA, 0x11AC, 0x11AD, 0x11B0, 0x11B1, 0x11B2, 0x11B3, 0x11B4, 0x11B5, 0x11B6, 0x11B9].includes(s.charCodeAt(0))) // ㅆ is an exception!
|
||||
let isJungseongDigraphO = (s) => s !== undefined && ([0x1161, 0x1162, 0x1175].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphU = (s) => s !== undefined && ([0x1165, 0x1166, 0x1175].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphEU = (s) => s !== undefined && ([0x1175].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphG = (s) => s !== undefined && ([0x11A8, 0x11BA].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphN = (s) => s !== undefined && ([0x11BD, 0x11C2].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphR = (s) => s !== undefined && ([0x11A8, 0x11B7, 0x11B8, 0x11BA, 0x11C0, 0x11C1, 0x11C2].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphB = (s) => s !== undefined && ([0x11BA].includes(s.charCodeAt(0)))
|
||||
let choseongDigraphs = {"\u1100":"\u1101", "\u1103":"\u1104", "\u1107":"\u1108", "\u1109":"\u110A", "\u110C":"\u110D"}
|
||||
let jungseongDigraphsO = {"\u1161":"\u116A", "\u1162":"\u116B", "\u1175":"\u116C"}
|
||||
let jungseongDigraphsU = {"\u1165":"\u116F", "\u1166":"\u1170", "\u1175":"\u1171"}
|
||||
let jungseongDigraphsEU = {"\u1175":"\u1174"}
|
||||
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 detachChoseongDigraph = {
|
||||
"\u1101":["\u1100","\u1100"],
|
||||
"\u1104":["\u1103","\u1103"],
|
||||
"\u1108":["\u1107","\u1107"],
|
||||
"\u110A":["\u1109","\u1109"],
|
||||
"\u110D":["\u110C","\u110C"]
|
||||
}
|
||||
let detachJungseongDigraph = {
|
||||
"\u116A":["\u1169","\u1161"],
|
||||
"\u116B":["\u1169","\u1162"],
|
||||
"\u116C":["\u1169","\u1175"],
|
||||
"\u116F":["\u116E","\u1165"],
|
||||
"\u1170":["\u116E","\u1166"],
|
||||
"\u1171":["\u116E","\u1175"],
|
||||
"\u1174":["\u1173","\u1175"]
|
||||
}
|
||||
let detachJongseongDigraph = {
|
||||
"\u11A9":["\u11A8","\u11A8"],
|
||||
"\u11AA":["\u11A8","\u11BA"],
|
||||
"\u11AC":["\u11AB","\u11BD"],
|
||||
"\u11AD":["\u11AB","\u11C2"],
|
||||
"\u11B0":["\u11AF","\u11A8"],
|
||||
"\u11B1":["\u11AF","\u11B7"],
|
||||
"\u11B2":["\u11AF","\u11B8"],
|
||||
"\u11B3":["\u11AF","\u11BA"],
|
||||
"\u11B4":["\u11AF","\u11C0"],
|
||||
"\u11B5":["\u11AF","\u11C1"],
|
||||
"\u11B6":["\u11AF","\u11C2"],
|
||||
"\u11B9":["\u11B8","\u11BA"],
|
||||
"\u11BB":["\u11BA","\u11BA"]
|
||||
}
|
||||
let normaliseLUT = {
|
||||
// Hangul Jamo Initials → Hangul Compatibility Jamo
|
||||
"\u1100":"\u3131","\u1101":"\u3132","\u1102":"\u3134","\u1103":"\u3137","\u1104":"\u3138",
|
||||
"\u1105":"\u3139","\u1106":"\u3141","\u1107":"\u3142","\u1108":"\u3143","\u1109":"\u3145",
|
||||
"\u110A":"\u3146","\u110B":"\u3147","\u110C":"\u3148","\u110D":"\u3149","\u110E":"\u314A",
|
||||
"\u110F":"\u314B","\u1110":"\u314C","\u1111":"\u314D","\u1112":"\u314E",
|
||||
// Hangul Jamo Peaks → Hangul Compatibility Jamo
|
||||
"\u1161":"\u314F","\u1162":"\u3150","\u1163":"\u3151","\u1164":"\u3152","\u1165":"\u3153",
|
||||
"\u1166":"\u3154","\u1167":"\u3155","\u1168":"\u3156","\u1169":"\u3157","\u116A":"\u3158",
|
||||
"\u116B":"\u3159","\u116C":"\u315A","\u116D":"\u315B","\u116E":"\u315C","\u116F":"\u315D",
|
||||
"\u1170":"\u315E","\u1171":"\u315F","\u1172":"\u3160","\u1173":"\u3161","\u1174":"\u3162",
|
||||
"\u1175":"\u3163",
|
||||
// Hangul Jamo Finals → Hangul Compatibility Jamo
|
||||
"\u11A8":"\u3131","\u11A9":"\u3132","\u11AA":"\u3133","\u11AB":"\u3134","\u11AC":"\u3135",
|
||||
"\u11AD":"\u3136","\u11AE":"\u3137","\u11AF":"\u3139","\u11B0":"\u313A","\u11B1":"\u313B",
|
||||
"\u11B2":"\u313C","\u11B3":"\u313D","\u11B4":"\u313E","\u11B5":"\u313F","\u11B6":"\u3140",
|
||||
"\u11B7":"\u3141","\u11B8":"\u3142","\u11B9":"\u3144","\u11BA":"\u3145","\u11BB":"\u3146",
|
||||
"\u11BC":"\u3147","\u11BD":"\u3148","\u11BE":"\u314A","\u11BF":"\u314B","\u11C0":"\u314C",
|
||||
"\u11C1":"\u314D","\u11C2":"\u314E"
|
||||
}
|
||||
let normaliseBuf = (it) => normaliseLUT[it] || it
|
||||
let bufAssemble = (isPreview) => {
|
||||
// nothing on the buffer
|
||||
if (states.buf[0] === undefined && states.buf[1] === undefined && states.buf[2] === undefined)
|
||||
return ''
|
||||
// Hangul: I x F
|
||||
else if (isPreview && states.buf[1] === undefined && isHangul(states.buf[0]))
|
||||
return [states.buf[0], "\u1160", states.buf[2]].join('')
|
||||
// Hangul: x P F
|
||||
else if (isPreview && states.buf[0] === undefined && isHangul(states.buf[1]))
|
||||
return ["\u115F", states.buf[1], states.buf[2]].join('')
|
||||
// Hangul: x x F
|
||||
else if (isPreview && isHangul(states.buf[2]) && states.buf[0] === undefined && states.buf[1] === undefined )
|
||||
return ["\u115F", "\u1160", states.buf[2]].join('')
|
||||
// Hangul: I P F
|
||||
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)
|
||||
}
|
||||
// Hangul: I P
|
||||
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))
|
||||
}
|
||||
// Normalise unterminated hangul assembly
|
||||
else if (!isPreview)
|
||||
return states.buf.map(it => normaliseBuf(it)).join('')
|
||||
else
|
||||
return states.buf.join('')
|
||||
}
|
||||
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
|
||||
return Object.freeze({"n":"세벌식 3-90","v":"one","c":"CuriousTo\uA75Bvald","m":"candidates",
|
||||
"t":states.keylayouts.map(it => [it[0],it[1]]),
|
||||
// return: [displayed output, composed output]
|
||||
"accept":(headkey,shiftin,altgrin)=>{
|
||||
let layer = 1*shiftin// + 2*altgrin
|
||||
states.code = 1
|
||||
|
||||
/*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 s = states.keylayouts[headkey][layer]
|
||||
let bufIndex = isJungseong(s) ? 1 : isJongseong(s) ? 2 : 0
|
||||
|
||||
if (isHangul(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]
|
||||
}
|
||||
// ㅘ ㅙ ㅚ
|
||||
else if (1 == bufIndex && "\u1169" == states.buf[1] && isJungseongDigraphO(s)) {
|
||||
states.buf[1] = jungseongDigraphsO[s]
|
||||
}
|
||||
// ㅝ ㅞ ㅟ
|
||||
else if (1 == bufIndex && "\u116E" == states.buf[1] && isJungseongDigraphU(s)) {
|
||||
states.buf[1] = jungseongDigraphsU[s]
|
||||
}
|
||||
// ㅢ
|
||||
else if (1 == bufIndex && "\u1173" == states.buf[1] && isJungseongDigraphEU(s)) {
|
||||
states.buf[1] = jungseongDigraphsEU[s]
|
||||
}
|
||||
// ㄲ ㄳ
|
||||
else if (2 == bufIndex && "\u11A8" == states.buf[2] && isJongseongDigraphG(s)) {
|
||||
states.buf[2] = jongseongDigraphsG[s]
|
||||
}
|
||||
// ㄵ ㄶ
|
||||
else if (2 == bufIndex && "\u11AB" == states.buf[2] && isJongseongDigraphN(s)) {
|
||||
states.buf[2] = jongseongDigraphsN[s]
|
||||
}
|
||||
// ㄺ ㄻ ㄼ ㄽ ㄾ ㄿ ㅀ
|
||||
else if (2 == bufIndex && "\u11AF" == states.buf[2] && isJongseongDigraphR(s)) {
|
||||
states.buf[2] = jongseongDigraphsR[s]
|
||||
}
|
||||
// ㅄ
|
||||
else if (2 == bufIndex && "\u11B8" == states.buf[2] && isJongseongDigraphB(s)) {
|
||||
states.buf[2] = jongseongDigraphsB[s]
|
||||
}
|
||||
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
|
||||
else if (states.buf[bufIndex] !== undefined) {
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let sendout = bufAssemble(); reset()
|
||||
states.buf[bufIndex] = s
|
||||
// let newbufstr = bufDebugStringify(states.buf)
|
||||
// console.log(`sending out: ${oldbufstr} -> ${sendout} ; ${newbufstr}`)
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
else {
|
||||
states.buf[bufIndex] = s
|
||||
// console.log(`assembling: ${bufDebugStringify(states.buf)} -> ${bufAssemble()}`)
|
||||
}
|
||||
|
||||
return [bufAssemble(1), ""]
|
||||
}
|
||||
else {
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let sendout = bufAssemble() + (s || ''); reset()
|
||||
// console.log(`sending out: ${oldbufstr} -> ${sendout}`)
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
},
|
||||
"backspace":()=>{
|
||||
// disassemble jung/jongseong digraphs
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let last = states.buf.pop()
|
||||
|
||||
if (last !== undefined) {
|
||||
// detach jongseong
|
||||
if (isThisCharJongseongDigraph(last))
|
||||
states.buf[2] = detachJongseongDigraph[last][0]
|
||||
// detach jungseong
|
||||
else if (isThisCharJungseongDigraph(last))
|
||||
states.buf[1] = detachJungseongDigraph[last][0]
|
||||
// detach choseong
|
||||
else if (isThisCharChoseongDigraph(last))
|
||||
states.buf[0] = detachChoseongDigraph[last][0]
|
||||
}
|
||||
|
||||
if (states.buf.length == 0) reset()
|
||||
|
||||
// let newbufstr = bufDebugStringify(states.buf)
|
||||
// console.log(`popping assembly: ${oldbufstr} -> ${newbufstr}`)
|
||||
|
||||
return bufAssemble(1)
|
||||
},
|
||||
"end":()=>{
|
||||
// console.log(`end composing`)
|
||||
let ret = bufAssemble()
|
||||
reset()
|
||||
return ret
|
||||
},
|
||||
"reset":()=>{ reset() },
|
||||
"composing":()=>(states.code!=0)
|
||||
})
|
||||
@@ -1,510 +0,0 @@
|
||||
let states = {"keylayouts":[[""],[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["0",")"],
|
||||
["1","!"],
|
||||
["2","@"],
|
||||
["3","#"],
|
||||
["4","$"],
|
||||
["5","%"],
|
||||
["6","^"],
|
||||
["7","&"],
|
||||
["8","*"],
|
||||
["9","("],
|
||||
["*"],
|
||||
["#"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\u11BC","\u1172","\u1172"],
|
||||
["\u11BE","\u116E","\u116E"],
|
||||
["\u11A8","\u1166","\u1166"],
|
||||
["\u11C2","\u1175","\u1175"],
|
||||
["\u11B8","\u1162","\u1162"],
|
||||
["\u11C1","\u1161","\u1161"],
|
||||
["\u11AE","\u1173","\u1173"],
|
||||
["\u1102","₩"],
|
||||
["\u1106","\u1173","\u1173"], // combining EU
|
||||
["\u110B","'"],
|
||||
["\u1100",'"'],
|
||||
["\u110C","\u00B7"],
|
||||
["\u1112","\u2026"],
|
||||
["\u1109","\u2014"],
|
||||
["\u110E","\u116E","\u116E"], // combining U
|
||||
["\u1111",";","\u119E"], // AREA-A
|
||||
["\u11BA","\u1164","\u1164"],
|
||||
["\u11C0","\u1165","\u1165"],
|
||||
["\u11AB","\u1168","\u1168"],
|
||||
["\u11BF","\u1167","\u1167"],
|
||||
["\u1103","¤"],
|
||||
["\u11BD","\u1169","\u1169"],
|
||||
["\u11AF","\u1163","\u1163"],
|
||||
["\u11BB","\u116D","\u116D"],
|
||||
["\u1105","\u00D7"],
|
||||
["\u11B7","\u119E","\u119E"],
|
||||
[",","<"],
|
||||
[".",">"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[" "],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\n"],
|
||||
["\x08"],
|
||||
["¤","~"],
|
||||
["-","_"],
|
||||
["=","+"],
|
||||
["[","{"],
|
||||
["]","}"],
|
||||
["\\","|"],
|
||||
["\u1107",":"],
|
||||
["\u1110",'/'],
|
||||
["\u110F","?","\u1169"], // combining O
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["0"],
|
||||
["1"],
|
||||
["2"],
|
||||
["3"],
|
||||
["4"],
|
||||
["5"],
|
||||
["6"],
|
||||
["7"],
|
||||
["8"],
|
||||
["9"],
|
||||
["/"],
|
||||
["*"],
|
||||
["-"],
|
||||
["+"],
|
||||
["."],
|
||||
["."],
|
||||
["\n"],
|
||||
["="],
|
||||
["("],
|
||||
[")"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined]
|
||||
],
|
||||
"code":0,
|
||||
"buf":[],
|
||||
"hasDeadkey":false
|
||||
}
|
||||
let reset = () => {
|
||||
states.code = 0
|
||||
states.buf = []
|
||||
states.hasDeadkey = false
|
||||
}
|
||||
let inRange = (s,a,b) => (a <= s && s <= b)
|
||||
let isHangul = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x1100, 0x11FF)
|
||||
let isChoseong = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x1100, 0x1112)
|
||||
let isJungseong = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x1161, 0x11A7)
|
||||
let isJongseong = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x11A8, 0x11C2)
|
||||
let isJungseongSuper = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x119E, 0x11A2)
|
||||
let isChoseongDigraph = (s) => s !== undefined && ([0x1100, 0x1103, 0x1107, 0x1109, 0x110C].includes(s.charCodeAt(0)))
|
||||
let isThisCharChoseongDigraph = (s) => s !== undefined && ([0x1101, 0x1104, 0x1108, 0x110A, 0x110D].includes(s.charCodeAt(0)))
|
||||
let isThisCharJungseongDigraph = (s) => s !== undefined && ([0x116A, 0x116B, 0x116C, 0x116F, 0x1170, 0x1171, 0x1174, 0x119F, 0x11A0, 0x11A1, 0x11A2].includes(s.charCodeAt(0)))
|
||||
let isThisCharJongseongDigraph = (s) => s !== undefined && ([0x11A9, 0x11AA, 0x11AC, 0x11AD, 0x11B0, 0x11B1, 0x11B2, 0x11B3, 0x11B4, 0x11B5, 0x11B6, 0x11B9].includes(s.charCodeAt(0))) // ㅆ is an exception!
|
||||
let isJungseongDigraphO = (s) => s !== undefined && ([0x1161, 0x1162, 0x1175].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphU = (s) => s !== undefined && ([0x1165, 0x1166, 0x1175].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphEU = (s) => s !== undefined && ([0x1175].includes(s.charCodeAt(0)))
|
||||
let isJungseongDigraphAA = (s) => s !== undefined && ([0x1165, 0x116E, 0x1175, 0x119E].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphG = (s) => s !== undefined && ([0x11A8, 0x11BA].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphN = (s) => s !== undefined && ([0x11BD, 0x11C2].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphR = (s) => s !== undefined && ([0x11A8, 0x11B7, 0x11B8, 0x11BA, 0x11C0, 0x11C1, 0x11C2].includes(s.charCodeAt(0)))
|
||||
let isJongseongDigraphB = (s) => s !== undefined && ([0x11BA].includes(s.charCodeAt(0)))
|
||||
let choseongDigraphs = {"\u1100":"\u1101", "\u1103":"\u1104", "\u1107":"\u1108", "\u1109":"\u110A", "\u110C":"\u110D"}
|
||||
let jungseongDigraphsO = {"\u1161":"\u116A", "\u1162":"\u116B", "\u1175":"\u116C"}
|
||||
let jungseongDigraphsU = {"\u1165":"\u116F", "\u1166":"\u1170", "\u1175":"\u1171"}
|
||||
let jungseongDigraphsEU = {"\u1175":"\u1174"}
|
||||
let jungseongDigraphsAA = {"\u1165":"\u119F", "\u116E":"\u11A0", "\u1175":"\u11A1", "\u119E":"\u11A2"}
|
||||
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 isJungseongDeadkey = (keynum) => [37,43,44,76].includes(keynum)
|
||||
let detachChoseongDigraph = {
|
||||
"\u1101":["\u1100","\u1100"],
|
||||
"\u1104":["\u1103","\u1103"],
|
||||
"\u1108":["\u1107","\u1107"],
|
||||
"\u110A":["\u1109","\u1109"],
|
||||
"\u110D":["\u110C","\u110C"]
|
||||
}
|
||||
let detachJungseongDigraph = {
|
||||
"\u116A":["\u1169","\u1161"],
|
||||
"\u116B":["\u1169","\u1162"],
|
||||
"\u116C":["\u1169","\u1175"],
|
||||
"\u116F":["\u116E","\u1165"],
|
||||
"\u1170":["\u116E","\u1166"],
|
||||
"\u1171":["\u116E","\u1175"],
|
||||
"\u1174":["\u1173","\u1175"],
|
||||
"\u119F":["\u119E","\u1165"],
|
||||
"\u11A0":["\u119E","\u116E"],
|
||||
"\u11A1":["\u119E","\u1175"],
|
||||
"\u11A2":["\u119E","\u119E"]
|
||||
}
|
||||
let detachJongseongDigraph = {
|
||||
"\u11A9":["\u11A8","\u11A8"],
|
||||
"\u11AA":["\u11A8","\u11BA"],
|
||||
"\u11AC":["\u11AB","\u11BD"],
|
||||
"\u11AD":["\u11AB","\u11C2"],
|
||||
"\u11B0":["\u11AF","\u11A8"],
|
||||
"\u11B1":["\u11AF","\u11B7"],
|
||||
"\u11B2":["\u11AF","\u11B8"],
|
||||
"\u11B3":["\u11AF","\u11BA"],
|
||||
"\u11B4":["\u11AF","\u11C0"],
|
||||
"\u11B5":["\u11AF","\u11C1"],
|
||||
"\u11B6":["\u11AF","\u11C2"],
|
||||
"\u11B9":["\u11B8","\u11BA"],
|
||||
"\u11BB":["\u11BA","\u11BA"]
|
||||
}
|
||||
let normaliseLUT = {
|
||||
// Hangul Jamo Initials → Hangul Compatibility Jamo
|
||||
"\u1100":"\u3131","\u1101":"\u3132","\u1102":"\u3134","\u1103":"\u3137","\u1104":"\u3138",
|
||||
"\u1105":"\u3139","\u1106":"\u3141","\u1107":"\u3142","\u1108":"\u3143","\u1109":"\u3145",
|
||||
"\u110A":"\u3146","\u110B":"\u3147","\u110C":"\u3148","\u110D":"\u3149","\u110E":"\u314A",
|
||||
"\u110F":"\u314B","\u1110":"\u314C","\u1111":"\u314D","\u1112":"\u314E",
|
||||
// Hangul Jamo Peaks → Hangul Compatibility Jamo
|
||||
"\u1161":"\u314F","\u1162":"\u3150","\u1163":"\u3151","\u1164":"\u3152","\u1165":"\u3153",
|
||||
"\u1166":"\u3154","\u1167":"\u3155","\u1168":"\u3156","\u1169":"\u3157","\u116A":"\u3158",
|
||||
"\u116B":"\u3159","\u116C":"\u315A","\u116D":"\u315B","\u116E":"\u315C","\u116F":"\u315D",
|
||||
"\u1170":"\u315E","\u1171":"\u315F","\u1172":"\u3160","\u1173":"\u3161","\u1174":"\u3162",
|
||||
"\u1175":"\u3163",
|
||||
// Hangul Jamo Finals → Hangul Compatibility Jamo
|
||||
"\u11A8":"\u3131","\u11A9":"\u3132","\u11AA":"\u3133","\u11AB":"\u3134","\u11AC":"\u3135",
|
||||
"\u11AD":"\u3136","\u11AE":"\u3137","\u11AF":"\u3139","\u11B0":"\u313A","\u11B1":"\u313B",
|
||||
"\u11B2":"\u313C","\u11B3":"\u313D","\u11B4":"\u313E","\u11B5":"\u313F","\u11B6":"\u3140",
|
||||
"\u11B7":"\u3141","\u11B8":"\u3142","\u11B9":"\u3144","\u11BA":"\u3145","\u11BB":"\u3146",
|
||||
"\u11BC":"\u3147","\u11BD":"\u3148","\u11BE":"\u314A","\u11BF":"\u314B","\u11C0":"\u314C",
|
||||
"\u11C1":"\u314D","\u11C2":"\u314E"
|
||||
}
|
||||
let normaliseBuf = (it) => normaliseLUT[it] || it
|
||||
let bufAssemble = (isPreview) => {
|
||||
// nothing on the buffer
|
||||
if (states.buf[0] === undefined && states.buf[1] === undefined && states.buf[2] === undefined)
|
||||
return ''
|
||||
// Hangul: I x F
|
||||
else if (isPreview && states.buf[1] === undefined && isHangul(states.buf[0]))
|
||||
return [states.buf[0], "\u1160", states.buf[2]].join('')
|
||||
// Hangul: x P F
|
||||
else if (isPreview && states.buf[0] === undefined && isHangul(states.buf[1]))
|
||||
return ["\u115F", states.buf[1], states.buf[2]].join('')
|
||||
// Hangul: x x F
|
||||
else if (isPreview && isHangul(states.buf[2]) && states.buf[0] === undefined && states.buf[1] === undefined )
|
||||
return ["\u115F", "\u1160", states.buf[2]].join('')
|
||||
// Hangul: I P F → Hangul Syllables (\uAC00..\uD7A3)
|
||||
else if (!isJungseongSuper(states.buf[1]) && 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)
|
||||
}
|
||||
// Hangul: I P → Hangul Syllables (\uAC00..\uD7A3)
|
||||
else if (!isJungseongSuper(states.buf[1]) && 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))
|
||||
}
|
||||
// Normalise unterminated hangul assembly
|
||||
else if (!isPreview && !isJungseongSuper(states.buf[1]))
|
||||
return states.buf.map(it => normaliseBuf(it)).join('')
|
||||
else
|
||||
return states.buf.join('')
|
||||
}
|
||||
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
|
||||
return Object.freeze({"n":"신세벌식 P2","v":"one","c":"CuriousTo\uA75Bvald","m":"candidates",
|
||||
"t":states.keylayouts.map(it => [it[0],it[1]]),
|
||||
// return: [displayed output, composed output]
|
||||
"accept":(headkey,shiftin,altgrin)=>{
|
||||
let layer = 1*shiftin// + 2*altgrin
|
||||
states.code = 1
|
||||
|
||||
let s = states.keylayouts[headkey][layer]
|
||||
let s2 = states.keylayouts[headkey][2]
|
||||
let bufIndex = isJungseong(s) ? 1 : isJongseong(s) ? 2 : 0
|
||||
|
||||
let isDeadkey = isJungseongDeadkey(headkey)
|
||||
let hasChoseong = isChoseong(states.buf[0])
|
||||
let hasJungseong = isJungseong(states.buf[1])
|
||||
let shiftForJungseong = hasChoseong && !hasJungseong && s2 != undefined
|
||||
let deadkeyAcceptable = isDeadkey && !states.hasDeadkey && shiftForJungseong
|
||||
|
||||
if (isHangul(s)) {
|
||||
// auto-change alternative layer if choseong is in the buffer already
|
||||
// unshift when jungseong is there
|
||||
// Korean threesetters call this feature "Galmadeuri" Input
|
||||
let autoshifted = false
|
||||
// if deadkeyAcceptable? -OR- shiftForJungseong? -OR- (notdeadkey? -AND- A as in GWA)
|
||||
if (deadkeyAcceptable || shiftForJungseong || (!isDeadkey && states.hasDeadkey)) {
|
||||
// console.log(`Shiftin--keycode=${headkey}, isDeadkey=${isDeadkey}, shiftForJungseong=${shiftForJungseong}, hasChoseong=${hasChoseong}, hasJungseong=${hasJungseong}; deadkeyAcceptable=${deadkeyAcceptable}, shiftForJungseong=${shiftForJungseong}, (!isDeadkey && states.hasDeadkey)=${(!isDeadkey && states.hasDeadkey)}`)
|
||||
s = s2
|
||||
bufIndex = 1
|
||||
autoshifted = true
|
||||
states.hasDeadkey = deadkeyAcceptable
|
||||
}
|
||||
else {
|
||||
states.hasDeadkey = false
|
||||
}
|
||||
|
||||
// console.log(`accepting hangul '${s}' at buf[${bufIndex}], autoshifted=${autoshifted}, states.hasDeadkey=${states.hasDeadkey}`)
|
||||
|
||||
// ㄲ ㄸ ㅃ ㅆ ㅉ (only allow when the jung/jongseong is not typed)
|
||||
if (0 == bufIndex && !states.buf[1] && isChoseongDigraph(states.buf[0]) && states.buf[0] == s) {
|
||||
states.buf[0] = choseongDigraphs[s]
|
||||
}
|
||||
// ㅘ ㅙ ㅚ
|
||||
else if (1 == bufIndex && "\u1169" == states.buf[1] && isJungseongDigraphO(s)) {
|
||||
states.buf[1] = jungseongDigraphsO[s]
|
||||
}
|
||||
// ㅝ ㅞ ㅟ
|
||||
else if (1 == bufIndex && "\u116E" == states.buf[1] && isJungseongDigraphU(s)) {
|
||||
states.buf[1] = jungseongDigraphsU[s]
|
||||
}
|
||||
// ㅢ
|
||||
else if (1 == bufIndex && "\u1173" == states.buf[1] && isJungseongDigraphEU(s)) {
|
||||
states.buf[1] = jungseongDigraphsEU[s]
|
||||
}
|
||||
// ᆟ ᆠ ᆡ ᆢ
|
||||
else if (1 == bufIndex && "\u119E" == states.buf[1] && isJungseongDigraphAA(s)) {
|
||||
states.buf[1] = jungseongDigraphsAA[s]
|
||||
}
|
||||
// ㄲ ㄳ
|
||||
else if (2 == bufIndex && "\u11A8" == states.buf[2] && isJongseongDigraphG(s)) {
|
||||
states.buf[2] = jongseongDigraphsG[s]
|
||||
}
|
||||
// ㄵ ㄶ
|
||||
else if (2 == bufIndex && "\u11AB" == states.buf[2] && isJongseongDigraphN(s)) {
|
||||
states.buf[2] = jongseongDigraphsN[s]
|
||||
}
|
||||
// ㄺ ㄻ ㄼ ㄽ ㄾ ㄿ ㅀ
|
||||
else if (2 == bufIndex && "\u11AF" == states.buf[2] && isJongseongDigraphR(s)) {
|
||||
states.buf[2] = jongseongDigraphsR[s]
|
||||
}
|
||||
// ㅄ
|
||||
else if (2 == bufIndex && "\u11B8" == states.buf[2] && isJongseongDigraphB(s)) {
|
||||
states.buf[2] = jongseongDigraphsB[s]
|
||||
}
|
||||
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
|
||||
else if (states.buf[bufIndex] !== undefined) {
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let sendout = bufAssemble(); reset()
|
||||
states.buf[bufIndex] = s
|
||||
// let newbufstr = bufDebugStringify(states.buf)
|
||||
// console.log(`sending out: ${oldbufstr} -> ${sendout} ; ${newbufstr}`)
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
else {
|
||||
states.buf[bufIndex] = s
|
||||
// console.log(`assembling: ${bufDebugStringify(states.buf)} -> ${bufAssemble()}`)
|
||||
}
|
||||
|
||||
return [bufAssemble(1), ""]
|
||||
}
|
||||
else {
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let sendout = bufAssemble() + (s || ''); reset()
|
||||
// console.log(`sending out: ${oldbufstr} -> ${sendout}`)
|
||||
return [bufAssemble(1), sendout]
|
||||
}
|
||||
},
|
||||
"backspace":()=>{
|
||||
// disassemble jung/jongseong digraphs
|
||||
// let oldbufstr = bufDebugStringify(states.buf)
|
||||
let last = states.buf.pop()
|
||||
|
||||
if (last !== undefined) {
|
||||
// detach jongseong
|
||||
if (isThisCharJongseongDigraph(last))
|
||||
states.buf[2] = detachJongseongDigraph[last][0]
|
||||
// detach jungseong
|
||||
else if (isThisCharJungseongDigraph(last))
|
||||
states.buf[1] = detachJungseongDigraph[last][0]
|
||||
// detach choseong
|
||||
else if (isThisCharChoseongDigraph(last))
|
||||
states.buf[0] = detachChoseongDigraph[last][0]
|
||||
}
|
||||
|
||||
if (states.buf.length == 0) reset()
|
||||
|
||||
// let newbufstr = bufDebugStringify(states.buf)
|
||||
// console.log(`popping assembly: ${oldbufstr} -> ${newbufstr}`)
|
||||
|
||||
return bufAssemble(1)
|
||||
},
|
||||
"end":()=>{
|
||||
// console.log(`end composing`)
|
||||
let ret = bufAssemble()
|
||||
reset()
|
||||
return ret
|
||||
},
|
||||
"reset":()=>{ reset() },
|
||||
"composing":()=>(states.code!=0)
|
||||
})
|
||||
@@ -24,7 +24,7 @@
|
||||
# dsty: density (grams per litre)
|
||||
#
|
||||
# fmod: forcemod -- related to attack points
|
||||
# Attack points = `4 * forcemod.sqrt()` for each strike
|
||||
# Attack points = `16 * forcemod.sqrt()` for each strike
|
||||
#
|
||||
# endurance: multiplier, using copper as reference; determines durability of tools/weapons/armours/etc.
|
||||
# the base value for endurance differes to tool to tool. When integer is used, resulting value must be ROUNDED.
|
||||
|
||||
|
@@ -17,7 +17,7 @@ object Calculate {
|
||||
* TODO Newtons as unit?
|
||||
*/
|
||||
@JvmStatic fun pickaxePower(actor: ActorWithBody, material: Material?): Float {
|
||||
return (4.0 * (material?.forceMod?.toDouble() ?: 1.0).sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
||||
return (16.0 * (material?.forceMod?.toDouble() ?: 1.0).sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user