DEADSOFTWARE

Bug fixes
authorfredboy <fredboy@protonmail.com>
Fri, 10 May 2024 20:53:10 +0000 (03:53 +0700)
committerfredboy <fredboy@protonmail.com>
Fri, 10 May 2024 20:53:10 +0000 (03:53 +0700)
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt
core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt

index 8f0f49441addb93cc8dd1832cb3ae6168a0c8b5a..b39ee7403ee30f69ca8676f8c3906b63e4c3a79c 100644 (file)
@@ -3,12 +3,14 @@ package ru.deadsoftware.cavedroid.game.input.handler.keyboard
 import ru.deadsoftware.cavedroid.MainConfig
 import ru.deadsoftware.cavedroid.game.GameSaver
 import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.GameUiWindow
 import ru.deadsoftware.cavedroid.game.input.IGameInputHandler
 import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
 import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
 import ru.deadsoftware.cavedroid.game.mobs.MobsController
 import ru.deadsoftware.cavedroid.game.objects.drop.DropController
 import ru.deadsoftware.cavedroid.game.objects.container.ContainerController
+import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
 import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
@@ -19,6 +21,7 @@ class PauseGameKeyboardInputHandler @Inject constructor(
     private val mobsController: MobsController,
     private val gameWorld: GameWorld,
     private val containerController: ContainerController,
+    private val gameWindowsManager: GameWindowsManager,
 ) : IGameInputHandler<KeyboardInputAction> {
 
     override fun checkConditions(action: KeyboardInputAction): Boolean {
@@ -26,6 +29,11 @@ class PauseGameKeyboardInputHandler @Inject constructor(
     }
 
     override fun handle(action: KeyboardInputAction) {
+        if (gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE) {
+            gameWindowsManager.closeWindow()
+            return
+        }
+
         GameSaver.save(mainConfig, dropController, mobsController, containerController, gameWorld)
         mainConfig.caveGame.quitGame()
     }
index 4aaff27a031da16592f673cf116928d374253629..f7fa6a5e874405346bd03db187a9351b8aea1497 100644 (file)
@@ -59,13 +59,13 @@ abstract class AbstractInventoryItemsMouseInputHandler(
                 if (action.actionKey.pointer == window.selectItemPointer) {
                     window.onLeftCLick(items, gameItemsHolder, index, action.actionKey.pointer)
                 } else {
-                    window.onRightClick(items, index)
+                    window.onRightClick(items, gameItemsHolder, index)
                 }
             }
         } else if (action.actionKey is MouseInputActionKey.Left) {
             window.onLeftCLick(items, gameItemsHolder, index)
         } else {
-            window.onRightClick(items, index)
+            window.onRightClick(items, gameItemsHolder, index)
         }
     }
 
index 9093680c299d7f46d68acf79c8236eba49a0b843..585a5ab09d181a62cb0ff1767664118282c4047c 100644 (file)
@@ -56,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()) {
index f847f7d0e3dd4d1f19ed91ee37266d3355a218c0..3cd406b731f5e2e0dc8a128926a4baef24d5a246 100644 (file)
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color
 import com.badlogic.gdx.graphics.g2d.SpriteBatch
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer
 import ru.deadsoftware.cavedroid.game.GameItemsHolder
-import ru.deadsoftware.cavedroid.game.mobs.player.Inventory
 import ru.deadsoftware.cavedroid.misc.Assets
 import ru.deadsoftware.cavedroid.misc.utils.drawSprite
 import ru.deadsoftware.cavedroid.misc.utils.drawString
@@ -28,19 +27,27 @@ class InventoryItem @JvmOverloads constructor(
         }
 
     @Transient
-    lateinit var item: Item
-        private set
+    private var _item: Item? = null
+
+    var item: Item
+        get() {
+            requireNotNull(_item) { "_item is null" }
+            return _item.takeIf { amount > 0 } ?: throw IllegalArgumentException("Accessing item with zero amount")
+        }
+        private set (value) {
+            _item = value
+        }
 
     @JvmOverloads
-    constructor(_item: Item, amount: Int = 1) : this(_item.params.key, amount) {
-        item = _item
+    constructor(item: Item, amount: Int = 1) : this(item.params.key, amount) {
+        _item = item
     }
 
     fun init(gameItemsHolder: GameItemsHolder) {
-        if (this::item.isInitialized) {
+        if (_item != null) {
             return
         }
-        item = gameItemsHolder.getItem(itemKey)
+        _item = gameItemsHolder.getItem(itemKey)
     }
 
     @JvmOverloads
index c26bda9c92c9652803e96e934695c5a94c3da763..ed15baca1d5d49baa0d1daf5942dffb3b3c21443 100644 (file)
@@ -1,5 +1,6 @@
 package ru.deadsoftware.cavedroid.game.ui.windows.inventory
 
+import com.badlogic.gdx.math.MathUtils
 import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.GameUiWindow
 import ru.deadsoftware.cavedroid.game.model.item.InventoryItem
@@ -46,14 +47,25 @@ abstract class AbstractInventoryWindow {
         selectItemPointer = pointer
     }
 
-    fun onRightClick(items: MutableList<InventoryItem>, index: Int) {
+    fun onRightClick(items: MutableList<InventoryItem>, gameItemsHolder: GameItemsHolder, index: Int) {
         val clickedItem = items[index]
         val selectedItem = selectedItem
-            ?.takeIf {
-                !clickedItem.isNoneOrNull() || clickedItem.item.isNone() ||
-                        it.item == items[index].item && items[index].amount + 1 < it.item.params.maxStack
+
+        if (selectedItem.isNoneOrNull() && !clickedItem.isNoneOrNull()) {
+            val half = InventoryItem(clickedItem.item, MathUtils.ceil(clickedItem.amount.toFloat() / 2f))
+            this.selectedItem = half
+            clickedItem.subtract(half.amount)
+            if (clickedItem.amount == 0) {
+                items[index] = gameItemsHolder.fallbackItem.toInventoryItem()
             }
-            ?: return
+            return
+        }
+
+        if (selectedItem == null ||
+            (!clickedItem.isNoneOrNull() && selectedItem.item != clickedItem.item) ||
+            !clickedItem.canBeAdded()) {
+            return
+        }
 
         val newItem = selectedItem.item.toInventoryItem(
             (clickedItem.takeIf { !it.item.isNone() }?.amount ?: 0) + 1