DEADSOFTWARE

Fix crash in craft
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / input / handler / mouse / CursorMouseInputHandler.kt
index 6a4b5a4eb968101d134eeeefa7aa9b9e290b51bd..585a5ab09d181a62cb0ff1767664118282c4047c 100644 (file)
@@ -41,20 +41,6 @@ class CursorMouseInputHandler @Inject constructor(
     private fun GameWorld.isCurrentBlockAutoselectable() =
         getForeMap(player.cursorX, player.cursorY).isAutoselectable
 
-    private fun checkCursorBounds() {
-        if (player.gameMode == 0) {
-            val minCursorX = player.mapX - SURVIVAL_CURSOR_RANGE
-            val maxCursorX = player.mapX + SURVIVAL_CURSOR_RANGE
-            val minCursorY = player.middleMapY - SURVIVAL_CURSOR_RANGE
-            val maxCursorY = player.middleMapY + SURVIVAL_CURSOR_RANGE
-
-            player.cursorX = MathUtils.clamp(player.cursorX, minCursorX, maxCursorX)
-            player.cursorY = MathUtils.clamp(player.cursorY, minCursorY, maxCursorY)
-        }
-
-        player.cursorY = MathUtils.clamp(player.cursorY, 0, gameWorld.height - 1)
-    }
-
     private fun setPlayerDirectionToCursor() {
         if (player.controlMode != Player.ControlMode.CURSOR) {
             return
@@ -70,6 +56,7 @@ class CursorMouseInputHandler @Inject constructor(
     private fun handleWalkTouch() {
         player.cursorX = player.mapX + player.direction.basis
         player.cursorY = player.upperMapY
+        player.headRotation = 0f
 
         for (i in 1..2) {
             if (gameWorld.isCurrentBlockAutoselectable()) {
@@ -137,7 +124,7 @@ class CursorMouseInputHandler @Inject constructor(
             !mainConfig.isTouch -> handleMouse(action)
         }
 
-        checkCursorBounds()
+        player.checkCursorBounds(gameWorld)
         setPlayerDirectionToCursor()
 
         if (player.cursorX != pastCursorX || player.cursorY != pastCursorY) {