mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 15:16:07 +09:00
Lua Computer: collection of minor updates, none notable (read romapidoc)
Former-commit-id: 80e3f0d13c2dc5bcff0843e509f416e9314cd52e Former-commit-id: e7e35bfd23d70db84f568f0c5388f3a1d89222bc
This commit is contained in:
48
src/net/torvald/terrarum/virtualcomputer/luaapi/Input.kt
Normal file
48
src/net/torvald/terrarum/virtualcomputer/luaapi/Input.kt
Normal file
@@ -0,0 +1,48 @@
|
||||
package net.torvald.terrarum.virtualcomputer.luaapi
|
||||
|
||||
import li.cil.repack.org.luaj.vm2.Globals
|
||||
import li.cil.repack.org.luaj.vm2.LuaTable
|
||||
import li.cil.repack.org.luaj.vm2.LuaValue
|
||||
import li.cil.repack.org.luaj.vm2.lib.OneArgFunction
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-25.
|
||||
*/
|
||||
class Input(globals: Globals, computer: BaseTerrarumComputer) {
|
||||
|
||||
init {
|
||||
globals["input"] = LuaTable()
|
||||
globals["input"]["isKeyDown"] = IsKeyDown(computer)
|
||||
}
|
||||
|
||||
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 computer: BaseTerrarumComputer) : 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 = computer.input.isKeyDown(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 = computer.input.isKeyDown(k)
|
||||
if (down) return LuaValue.valueOf(true)
|
||||
}
|
||||
}
|
||||
|
||||
return LuaValue.valueOf(computer.input.isKeyDown(keyCode.checkint()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user