summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ab4d4a)
raw | patch | inline | side by side (parent: 0ab4d4a)
author | fredboy <fredboy@protonmail.com> | |
Fri, 10 May 2024 20:53:10 +0000 (03:53 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Fri, 10 May 2024 20:53:10 +0000 (03:53 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt
index 8f0f49441addb93cc8dd1832cb3ae6168a0c8b5a..b39ee7403ee30f69ca8676f8c3906b63e4c3a79c 100644 (file)
--- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt
+++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/PauseGameKeyboardInputHandler.kt
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
private val mobsController: MobsController,
private val gameWorld: GameWorld,
private val containerController: ContainerController,
+ private val gameWindowsManager: GameWindowsManager,
) : IGameInputHandler<KeyboardInputAction> {
override fun checkConditions(action: KeyboardInputAction): Boolean {
}
override fun handle(action: KeyboardInputAction) {
+ if (gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE) {
+ gameWindowsManager.closeWindow()
+ return
+ }
+
GameSaver.save(mainConfig, dropController, mobsController, containerController, gameWorld)
mainConfig.caveGame.quitGame()
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/AbstractInventoryItemsMouseInputHandler.kt
index 4aaff27a031da16592f673cf116928d374253629..f7fa6a5e874405346bd03db187a9351b8aea1497 100644 (file)
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)
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CursorMouseInputHandler.kt
index 9093680c299d7f46d68acf79c8236eba49a0b843..585a5ab09d181a62cb0ff1767664118282c4047c 100644 (file)
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()) {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt
index f847f7d0e3dd4d1f19ed91ee37266d3355a218c0..3cd406b731f5e2e0dc8a128926a4baef24d5a246 100644 (file)
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
}
@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
diff --git a/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt b/core/src/ru/deadsoftware/cavedroid/game/ui/windows/inventory/AbstractInventoryWindow.kt
index c26bda9c92c9652803e96e934695c5a94c3da763..ed15baca1d5d49baa0d1daf5942dffb3b3c21443 100644 (file)
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
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