diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index 530ad8121..3ad3f72d1 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -66,7 +66,62 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() { private val mouseStatus = BitSet(8) private val controllerButtonStatus = BitSet(64) - fun update(delta: Float) { + private fun updateKeyboard() { + ///////////////////// + // GAMEPAD CONTROL // + ///////////////////// + + + ////////////////////// + // KEYBOARD CONTROL // + ////////////////////// + + //KeyToggler.update(terrarumIngame.canPlayerControl) + //printdbg(this, terrarumIngame.canPlayerControl) + + // control key events + var noKeyHeldDown = true + for (key in 1..Input.Keys.MAX_KEYCODE) { + val keyDown = Gdx.input.isKeyPressed(key) + + noKeyHeldDown = noKeyHeldDown and keyDown + + if (keyDown && !keyStatus[key]) + tKeyDown(key) + else if (!keyDown && keyStatus[key]) + tKeyUp(key) + + keyStatus[key] = keyDown + + + + if (key == Input.Keys.ENTER && keyDown) { + printdbg(this, "ENTER down") + } + } + // control mouse/touch events + val newmx = Gdx.input.x + val newmy = Gdx.input.y + for (touch in 0..4) { + val touchDown = Gdx.input.isButtonPressed(touch) + + if (touchDown && !mouseStatus[touch]) + tTouchDown(newmx, newmy, 0, touch) + else if (!touchDown && keyStatus[touch]) + tTouchUp(newmx, newmy, 0, touch) + + if (touchDown && mouseStatus.bitCount() != 0) { + tTouchDragged(newmx, newmy, 0) + } + + mouseStatus[touch] = touchDown + } + + inputMouseX = newmx + inputMouseY = newmy + } + + fun update() { /////////////////// // MOUSE CONTROL // @@ -100,52 +155,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() { } - ///////////////////// - // GAMEPAD CONTROL // - ///////////////////// - - - ////////////////////// - // KEYBOARD CONTROL // - ////////////////////// - - //KeyToggler.update(terrarumIngame.canPlayerControl) - //printdbg(this, terrarumIngame.canPlayerControl) - - // control key events - var noKeyHeldDown = true - for (key in 1..Input.Keys.MAX_KEYCODE) { - val keyDown = Gdx.input.isKeyPressed(key) - - noKeyHeldDown = noKeyHeldDown and keyDown - - if (keyDown && !keyStatus[key]) - tKeyDown(key) - else if (!keyDown && keyStatus[key]) - tKeyUp(key) - - keyStatus[key] = keyDown - } - // control mouse/touch events - val newmx = Gdx.input.x - val newmy = Gdx.input.y - for (touch in 0..4) { - val touchDown = Gdx.input.isButtonPressed(touch) - - if (touchDown && !mouseStatus[touch]) - tTouchDown(newmx, newmy, 0, touch) - else if (!touchDown && keyStatus[touch]) - tTouchUp(newmx, newmy, 0, touch) - - if (touchDown && mouseStatus.bitCount() != 0) { - tTouchDragged(newmx, newmy, 0) - } - - mouseStatus[touch] = touchDown - } - - inputMouseX = newmx - inputMouseY = newmy + updateKeyboard() } private var f12Down = false diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 5acde3156..85f1cdecc 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -516,6 +516,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { gameFullyLoaded = true } + + ingameController.update() + + // define custom update rate val updateRate = if (KeyToggler.isOn(Input.Keys.APOSTROPHE)) 1f / 8f else AppLoader.UPDATE_RATE @@ -554,7 +558,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { // synchronised Ingame Input Updater // will also queue up the block/wall/wire placed events - ingameController.update(delta) + ingameController.update() if (!paused) { diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 93b4eb8df..2c48803aa 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -15,6 +15,7 @@ import net.torvald.terrarum.imagefont.TinyAlphNum import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory +import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.WorldCamera @@ -163,7 +164,7 @@ class BasicDebugInfoWindow : UICanvas() { val wireCount = wires?.size?.toString() ?: "no" - printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG($wireCount wires) $ccY($mtX, $mtY)") + printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG($wireCount wires) $ccY($mtX,$mtY;$ccO${LandUtil.getBlockAddr(ingame!!.world, mouseTileX, mouseTileY)}$ccY)") printLine(batch, 10, "fluid@cursor ${ccO}Type $ccG${fluid.type.value} ${ccO}Fill $ccG${fluid.amount}f") }