mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 15:16:07 +09:00
keyboard control ported to GDX (at least as much as I can right now)
This commit is contained in:
@@ -5,7 +5,6 @@ import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LuaTable
|
||||
import org.luaj.vm2.LuaValue
|
||||
import org.luaj.vm2.lib.OneArgFunction
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
|
||||
|
||||
/**
|
||||
@@ -13,38 +12,5 @@ import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
|
||||
*/
|
||||
class Input(globals: Globals, computer: TerrarumComputer) {
|
||||
|
||||
init {
|
||||
globals["input"] = LuaTable()
|
||||
globals["input"]["isKeyDown"] = IsKeyDown(computer)
|
||||
// input.readLine defined in ROMLIB
|
||||
}
|
||||
|
||||
companion object {
|
||||
val keys_alt = intArrayOf(Key.L_ALT, Key.L_COMMAND)
|
||||
val keys_caps = intArrayOf(Key.CAPS_LOCK, Key.BACKSPACE, Key.L_CONTROL)
|
||||
}
|
||||
|
||||
class IsKeyDown(val host: TerrarumComputer) : OneArgFunction() {
|
||||
override fun call(keyCode: LuaValue): LuaValue {
|
||||
val key = keyCode.checkint()
|
||||
|
||||
// L_Alt and L_COMMAND are homogeneous
|
||||
if (keys_alt.contains(key)) {
|
||||
for (k in keys_alt) {
|
||||
val down = Gdx.input.isKeyPressed(k)
|
||||
if (down) return LuaValue.valueOf(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Caps, Backspace, L_Control, for Colemak and HHKB
|
||||
if (keys_caps.contains(key)) {
|
||||
for (k in keys_caps) {
|
||||
val down = Gdx.input.isKeyPressed(k)
|
||||
if (down) return LuaValue.valueOf(true)
|
||||
}
|
||||
}
|
||||
|
||||
return LuaValue.valueOf(Gdx.input.isKeyPressed(keyCode.checkint()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user