mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
making xinput to actually work (tested with xbone gamepad)
This commit is contained in:
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.controllers.Controllers
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.github.strikerx3.jxinput.XInputDevice
|
||||
import net.torvald.dataclass.CircularArray
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
@@ -11,6 +12,8 @@ import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.blockstats.BlockStats
|
||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||
import net.torvald.terrarum.console.Authenticator
|
||||
import net.torvald.terrarum.controller.GdxControllerAdapter
|
||||
import net.torvald.terrarum.controller.XinputControllerAdapter
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gamecontroller.IngameController
|
||||
@@ -269,7 +272,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
// make controls work
|
||||
Gdx.input.inputProcessor = ingameController
|
||||
Controllers.addListener(ingameController)
|
||||
ingameController.gamepad =
|
||||
if (AppLoader.getConfigBoolean("usexinput"))
|
||||
XinputControllerAdapter(XInputDevice.getDeviceFor(0))
|
||||
else
|
||||
GdxControllerAdapter(Controllers.getControllers()[0])
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.controllers.Controllers
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.spriteanimation.HasAssembledSprite
|
||||
@@ -226,9 +225,9 @@ open class ActorHumanoid(
|
||||
isRightDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyright"))
|
||||
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump"))
|
||||
|
||||
if ((Terrarum.ingame as Ingame).ingameController.hasController) {
|
||||
val gamepad = Controllers.getControllers()[0]
|
||||
val gamepad = (Terrarum.ingame as Ingame).ingameController.gamepad
|
||||
|
||||
if (gamepad != null) {
|
||||
axisX = gamepad.getAxis(AppLoader.getConfigInt("gamepadlstickx"))
|
||||
axisY = gamepad.getAxis(AppLoader.getConfigInt("gamepadlsticky"))
|
||||
axisRX = gamepad.getAxis(AppLoader.getConfigInt("gamepadrstickx"))
|
||||
@@ -241,7 +240,7 @@ open class ActorHumanoid(
|
||||
if (Math.abs(axisRY) < AppLoader.gamepadDeadzone) axisRY = 0f
|
||||
|
||||
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) ||
|
||||
gamepad.getAxis(AppLoader.getConfigInt("gamepadtriggeraxis")) < -AppLoader.gamepadDeadzone
|
||||
gamepad.getButton(AppLoader.getConfigInt("gamepadltrigger"))
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -253,7 +252,7 @@ open class ActorHumanoid(
|
||||
}
|
||||
|
||||
private inline val hasController: Boolean
|
||||
get() = if (isGamer) (Terrarum.ingame as Ingame).ingameController.hasController
|
||||
get() = if (isGamer) (Terrarum.ingame as Ingame).ingameController.hasGamepad
|
||||
else true
|
||||
|
||||
private fun processInput(delta: Float) {
|
||||
|
||||
Reference in New Issue
Block a user