You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.6 KiB
87 lines
2.6 KiB
package wow.doge.mygame.game.subsystems.input
|
|
|
|
import com.jme3.input.KeyInput
|
|
import com.jme3.input.MouseInput
|
|
import com.jme3.input.controls.KeyTrigger
|
|
import com.jme3.input.controls.MouseAxisTrigger
|
|
import monix.{eval => me}
|
|
import wow.doge.mygame.implicits._
|
|
import wow.doge.mygame.utils.wrappers.jme.InputManager
|
|
|
|
class InputMappings(inputManager: InputManager) {
|
|
|
|
def setup =
|
|
for {
|
|
_ <- setupMovementKeys
|
|
_ <- setupAnalogMovementKeys
|
|
_ <- setupCameraKeys
|
|
_ <- cursorToggle
|
|
} yield ()
|
|
|
|
def setupMovementKeys =
|
|
inputManager.withEnumMappings(PlayerMovementInput) {
|
|
case PlayerMovementInput.WalkRight =>
|
|
new KeyTrigger(KeyInput.KEY_D) :: Nil
|
|
case PlayerMovementInput.WalkLeft =>
|
|
new KeyTrigger(KeyInput.KEY_A) :: Nil
|
|
case PlayerMovementInput.WalkForward =>
|
|
new KeyTrigger(KeyInput.KEY_W) :: Nil
|
|
case PlayerMovementInput.WalkBackward =>
|
|
new KeyTrigger(KeyInput.KEY_S) :: Nil
|
|
case PlayerMovementInput.Jump =>
|
|
new KeyTrigger(KeyInput.KEY_SPACE) :: Nil
|
|
}
|
|
|
|
def setupAnalogMovementKeys =
|
|
inputManager.withEnumMappings(PlayerAnalogMovementInput) {
|
|
case PlayerAnalogMovementInput.TurnRight =>
|
|
Seq(new KeyTrigger(KeyInput.KEY_D))
|
|
case PlayerAnalogMovementInput.TurnLeft =>
|
|
Seq(new KeyTrigger(KeyInput.KEY_A))
|
|
}
|
|
|
|
def setupCameraKeys =
|
|
inputManager.withEnumMappings(PlayerCameraInput) {
|
|
case PlayerCameraInput.CameraRotateLeft =>
|
|
Seq(
|
|
new KeyTrigger(KeyInput.KEY_LEFT),
|
|
new MouseAxisTrigger(MouseInput.AXIS_X, false)
|
|
)
|
|
case PlayerCameraInput.CameraRotateRight =>
|
|
Seq(
|
|
new KeyTrigger(KeyInput.KEY_RIGHT),
|
|
new MouseAxisTrigger(MouseInput.AXIS_X, true)
|
|
)
|
|
case PlayerCameraInput.CameraRotateUp =>
|
|
Seq(
|
|
new KeyTrigger(KeyInput.KEY_UP),
|
|
new MouseAxisTrigger(MouseInput.AXIS_Y, false)
|
|
)
|
|
case PlayerCameraInput.CameraRotateDown =>
|
|
Seq(
|
|
new KeyTrigger(KeyInput.KEY_DOWN),
|
|
new MouseAxisTrigger(MouseInput.AXIS_Y, true)
|
|
)
|
|
}
|
|
|
|
def cursorToggle =
|
|
inputManager.withMapping(
|
|
MiscInput.ToggleCursor,
|
|
new KeyTrigger(KeyInput.KEY_Z)
|
|
) >>
|
|
inputManager
|
|
.enumEntryObservableAction(MiscInput.ToggleCursor)
|
|
.doOnNext(action =>
|
|
action.binding match {
|
|
case MiscInput.ToggleCursor =>
|
|
if (action.value)(inputManager.cursorVisible =
|
|
!inputManager.cursorVisible).toTask
|
|
else me.Task.unit
|
|
}
|
|
)
|
|
.completedL
|
|
.toIO
|
|
.hideErrors
|
|
.startAndForget
|
|
|
|
}
|