ktlint_standard_comment-wrapping = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_property-naming = disabled
+ktlint_standard_backing-property-naming = disabled
+ktlint_standard_function-expression-body = disabled
[**/generated/**]
generated_code = true
- '**.kts'
-jobs:
- ktlint:
- runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v3
+ - name: set up JDK 17
+ uses: actions/setup-java@v3
with:
- fetch-depth: 1
- - run: |
- curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.2.1/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
- - name: run ktlint
- run: |
- ktlint --reporter=checkstyle,output=build/ktlint-report.xml
- continue-on-error: true
- - uses: yutailang0119/action-ktlint@v4
- with:
- report-path: build/*.xml # Support glob patterns by https://www.npmjs.com/package/@actions/glob
- ignore-warnings: true # Ignore Lint Warnings
- continue-on-error: false # If annotations contain error of severity, action-ktlint exit 1.
+ java-version: '17'
+ distribution: 'temurin'
+ cache: gradle
+
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+ - name: Check Ktlint with Gradle
+ run: ./gradlew ktlintCheck buildSrc:ktlintCheck
plugins {
id("com.android.application")
id("kotlin-android")
- ktlintGradle
}
private val keystorePropertiesFile = rootProject.file("keystore.properties")
private val sharedPreferences by lazy { context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE) }
- override fun getPreference(key: String): String? {
- return sharedPreferences.getString(key, null)
- }
+ override fun getPreference(key: String): String? = sharedPreferences.getString(key, null)
override fun setPreference(key: String, value: String?) {
with(sharedPreferences.edit()) {
allprojects {
version = ApplicationInfo.versionName
+ apply(plugin = "org.jlleitschuh.gradle.ktlint")
+
+ ktlint {
+ version.set("1.6.0")
+ }
+
repositories {
mavenLocal()
mavenCentral()
plugins {
`kotlin-dsl`
+ id("org.jlleitschuh.gradle.ktlint") version "12.3.0"
}
repositories {
mavenCentral()
}
+
+ktlint {
+ version.set("1.6.0")
+}
const val packageName = "ru.deadsoftware.cavedroid"
val sourceCompatibility = JavaVersion.VERSION_17
-}
\ No newline at end of file
+}
-import org.gradle.kotlin.dsl.version
-
object Dependencies {
object LibGDX {
}
const val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.agp}"
-
-}
\ No newline at end of file
+}
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.project
-private fun DependencyHandler.implementation(dependency: String) =
- add("implementation", dependency)
+private fun DependencyHandler.implementation(dependency: String) = add("implementation", dependency)
-private fun DependencyHandler.ksp(dependency: String) =
- add("ksp", dependency)
+private fun DependencyHandler.ksp(dependency: String) = add("ksp", dependency)
fun DependencyHandler.useModule(moduleName: String) {
add("implementation", project(moduleName))
* [Source](https://github.com/JLLeitschuh/ktlint-gradle)
*/
const val ktlintGradle = "12.3.0"
-}
\ No newline at end of file
+}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
assert(y in 0f..1f)
}
- fun getFlipped(flipX: Boolean, flipY: Boolean): SpriteOrigin {
- return SpriteOrigin(
- x = if (flipX) 1 - x else x,
- y = if (flipY) 1 - y else y,
- )
- }
+ fun getFlipped(flipX: Boolean, flipY: Boolean): SpriteOrigin = SpriteOrigin(
+ x = if (flipX) 1 - x else x,
+ y = if (flipY) 1 - y else y,
+ )
fun applyToSprite(sprite: Sprite) {
sprite.setOrigin(sprite.width * x, sprite.height * y)
return null
}
-fun <T> MutableCollection<T>.removeFirst(predicate: (T) -> Boolean): Boolean {
- return retrieveFirst(predicate) != null
-}
+fun <T> MutableCollection<T>.removeFirst(predicate: (T) -> Boolean): Boolean = retrieveFirst(predicate) != null
kotlin
ksp
kotlinxSerialization
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private val blockTexturesCache = HashMap<String, Texture>()
- override fun getBlockTexture(textureName: String): Texture {
- return resolveTexture(textureName, BLOCKS_TEXTURES_PATH, blockTexturesCache)
- }
+ override fun getBlockTexture(textureName: String): Texture = resolveTexture(textureName, BLOCKS_TEXTURES_PATH, blockTexturesCache)
override fun initialize() {
// no-op
}
}
- override fun getBlockDamageSprite(stage: Int): Sprite {
- return requireNotNull(blockDamageSprites)[stage]
- }
+ override fun getBlockDamageSprite(stage: Int): Sprite = requireNotNull(blockDamageSprites)[stage]
override fun initialize() {
loadBlockDamage()
return glyphLayout.height
}
- override fun getFont(): BitmapFont {
- return requireNotNull(font)
- }
+ override fun getFont(): BitmapFont = requireNotNull(font)
override fun initialize() {
font = BitmapFont(Gdx.files.internal(FONT_FILE_PATH), true)
private val itemTexturesCache = HashMap<String, Texture>()
- override fun getItemTexture(textureName: String): Texture {
- return resolveTexture(textureName, ITEMS_TEXTURES_PATH, itemTexturesCache)
- }
+ override fun getItemTexture(textureName: String): Texture = resolveTexture(textureName, ITEMS_TEXTURES_PATH, itemTexturesCache)
override fun initialize() {
// no-op
)
}
- override fun getPlayerSprites(): MobSprite.Player {
- return requireNotNull(playerSprite)
- }
+ override fun getPlayerSprites(): MobSprite.Player = requireNotNull(playerSprite)
- override fun getPigSprites(): MobSprite.Pig {
- return requireNotNull(pigSprite)
- }
+ override fun getPigSprites(): MobSprite.Pig = requireNotNull(pigSprite)
override fun initialize() {
loadPlayerSprite()
loadTextureRegions()
}
- override fun getTextureRegionByName(name: String): TextureRegion? {
- return requireNotNull(textureRegions)[name]
- }
+ override fun getTextureRegionByName(name: String): TextureRegion? = requireNotNull(textureRegions)[name]
override fun dispose() {
super.dispose()
private val guiMap = HashMap<String, TouchButton>()
- override fun getTouchButtons(): Map<String, TouchButton> {
- return guiMap
- }
-
- private fun getMouseKey(name: String): Int {
- return when (name) {
- "Left" -> Input.Buttons.LEFT
- "Right" -> Input.Buttons.RIGHT
- "Middle" -> Input.Buttons.MIDDLE
- "Back" -> Input.Buttons.BACK
- "Forward" -> Input.Buttons.FORWARD
- else -> -1
- }
+ override fun getTouchButtons(): Map<String, TouchButton> = guiMap
+
+ private fun getMouseKey(name: String): Int = when (name) {
+ "Left" -> Input.Buttons.LEFT
+ "Right" -> Input.Buttons.RIGHT
+ "Middle" -> Input.Buttons.MIDDLE
+ "Back" -> Input.Buttons.BACK
+ "Forward" -> Input.Buttons.FORWARD
+ else -> -1
}
private fun loadTouchButtons() {
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
kotlin
ksp
kotlinxSerialization
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
}
}
- private fun mapCommonParams(key: String, dto: BlockDto): CommonBlockParams {
- return CommonBlockParams(
- key = key,
- collisionMargins = BlockMargins(
- left = dto.left,
- top = dto.top,
- right = dto.right,
- bottom = dto.bottom,
- ),
- hitPoints = dto.hp,
- dropInfo = mapBlockDropInfo(dto),
- hasCollision = dto.collision,
- isBackground = dto.background,
- isTransparent = dto.transparent,
- requiresBlock = dto.blockRequired,
- animationInfo = mapBlockAnimationInfo(dto),
- texture = getTexture(dto.texture),
- spriteMargins = BlockMargins(
- left = dto.spriteLeft,
- top = dto.spriteTop,
- right = dto.spriteRight,
- bottom = dto.spriteBottom,
- ),
- toolLevel = dto.toolLevel,
- toolType = mapToolType(dto),
- damage = dto.damage,
- tint = dto.tint,
- isFallable = dto.fallable,
- )
- }
+ private fun mapCommonParams(key: String, dto: BlockDto): CommonBlockParams = CommonBlockParams(
+ key = key,
+ collisionMargins = BlockMargins(
+ left = dto.left,
+ top = dto.top,
+ right = dto.right,
+ bottom = dto.bottom,
+ ),
+ hitPoints = dto.hp,
+ dropInfo = mapBlockDropInfo(dto),
+ hasCollision = dto.collision,
+ isBackground = dto.background,
+ isTransparent = dto.transparent,
+ requiresBlock = dto.blockRequired,
+ animationInfo = mapBlockAnimationInfo(dto),
+ texture = getTexture(dto.texture),
+ spriteMargins = BlockMargins(
+ left = dto.spriteLeft,
+ top = dto.spriteTop,
+ right = dto.spriteRight,
+ bottom = dto.spriteBottom,
+ ),
+ toolLevel = dto.toolLevel,
+ toolType = mapToolType(dto),
+ damage = dto.damage,
+ tint = dto.tint,
+ isFallable = dto.fallable,
+ )
- private fun mapToolType(dto: BlockDto): Class<out Item.Tool>? {
- return when (dto.toolType) {
- "shovel" -> Item.Shovel::class.java
- "sword" -> Item.Sword::class.java
- "pickaxe" -> Item.Pickaxe::class.java
- "axe" -> Item.Axe::class.java
- "shears" -> Item.Shears::class.java
+ private fun mapToolType(dto: BlockDto): Class<out Item.Tool>? = when (dto.toolType) {
+ "shovel" -> Item.Shovel::class.java
+ "sword" -> Item.Sword::class.java
+ "pickaxe" -> Item.Pickaxe::class.java
+ "axe" -> Item.Axe::class.java
+ "shears" -> Item.Shears::class.java
- else -> null
- }
+ else -> null
}
private fun mapBlockDropInfo(dto: BlockDto): BlockDropInfo? {
}
}
- private fun mapCommonParams(key: String, dto: ItemDto): CommonItemParams {
- return CommonItemParams(
- key = key,
- name = dto.name,
- inHandSpriteOrigin = SpriteOrigin(
- x = dto.originX,
- y = dto.origin_y,
- ),
- maxStack = dto.maxStack,
- burningTimeMs = dto.burningTime,
- smeltProductKey = dto.smeltProduct,
- )
- }
+ private fun mapCommonParams(key: String, dto: ItemDto): CommonItemParams = CommonItemParams(
+ key = key,
+ name = dto.name,
+ inHandSpriteOrigin = SpriteOrigin(
+ x = dto.originX,
+ y = dto.origin_y,
+ ),
+ maxStack = dto.maxStack,
+ burningTimeMs = dto.burningTime,
+ smeltProductKey = dto.smeltProduct,
+ )
private fun loadSprite(dto: ItemDto): Sprite? {
if (dto.type == "none" || dto.type == "block" || dto.texture == ItemsRepositoryImpl.FALLBACK_ITEM_KEY) {
loadCraftingRecipes()
}
- override fun getItemByKey(key: String): Item {
- return itemsMap.getOrFallback(key, fallbackItem) {
- "No item with key '$key' found. Returning $FALLBACK_ITEM_KEY"
- }
+ override fun getItemByKey(key: String): Item = itemsMap.getOrFallback(key, fallbackItem) {
+ "No item with key '$key' found. Returning $FALLBACK_ITEM_KEY"
}
- override fun getItemByIndex(index: Int): Item {
- return if (index in itemsMap.values.indices) {
- itemsMap.values.elementAt(index)
- } else {
- fallbackItem
- }
+ override fun getItemByIndex(index: Int): Item = if (index in itemsMap.values.indices) {
+ itemsMap.values.elementAt(index)
+ } else {
+ fallbackItem
}
- override fun getBlockByKey(key: String): Block {
- return blocksMap.getOrFallback(key, fallbackBlock) {
- "No block with key '$key' found. Returning $FALLBACK_BLOCK_KEY"
- }
+ override fun getBlockByKey(key: String): Block = blocksMap.getOrFallback(key, fallbackBlock) {
+ "No block with key '$key' found. Returning $FALLBACK_BLOCK_KEY"
}
- override fun <T : Block> getBlocksByType(type: Class<T>): List<T> {
- return blocksMap.values.filterIsInstance(type)
- }
+ override fun <T : Block> getBlocksByType(type: Class<T>): List<T> = blocksMap.values.filterIsInstance(type)
override fun getCraftingResult(input: List<Item>): InventoryItem {
val startIndex = input.indexOfFirst { !it.isNone() }.takeIf { it >= 0 }
return output?.toInventoryItem() ?: fallbackItem.toInventoryItem()
}
- override fun getAllItems(): Collection<Item> {
- return itemsMap.values
- }
+ override fun getAllItems(): Collection<Item> = itemsMap.values
override fun dispose() {
_initialized = false
kotlin
ksp
kotlinxSerialization
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
@MenuScope
class MenuButtonMapper @Inject constructor() {
- fun map(dto: MenuButtonDto): MenuButton {
- return when (dto.type) {
- "boolean_option" -> MenuButton.BooleanOption(
- label = dto.label.toString(),
- isVisible = mapVisibility(dto.visibility),
- actionKey = dto.actionKey.orEmpty(),
- optionKeys = dto.options.orEmpty(),
- isEnabled = dto.enabled ?: true,
- )
-
- "default", null -> MenuButton.Simple(
- label = dto.label.toString(),
- isVisible = mapVisibility(dto.visibility),
- actionKey = dto.actionKey.orEmpty(),
- isEnabled = dto.enabled ?: true,
- )
-
- else ->
- throw IllegalArgumentException("Unknown button type: ${dto.type}")
- }
+ fun map(dto: MenuButtonDto): MenuButton = when (dto.type) {
+ "boolean_option" -> MenuButton.BooleanOption(
+ label = dto.label.toString(),
+ isVisible = mapVisibility(dto.visibility),
+ actionKey = dto.actionKey.orEmpty(),
+ optionKeys = dto.options.orEmpty(),
+ isEnabled = dto.enabled ?: true,
+ )
+
+ "default", null -> MenuButton.Simple(
+ label = dto.label.toString(),
+ isVisible = mapVisibility(dto.visibility),
+ actionKey = dto.actionKey.orEmpty(),
+ isEnabled = dto.enabled ?: true,
+ )
+
+ else ->
+ throw IllegalArgumentException("Unknown button type: ${dto.type}")
}
- fun setButtonEnabled(button: MenuButton, isEnabled: Boolean): MenuButton {
- return when (button) {
- is MenuButton.Simple -> button.copy(isEnabled = isEnabled)
- is MenuButton.BooleanOption -> button.copy(isEnabled = isEnabled)
- }
+ fun setButtonEnabled(button: MenuButton, isEnabled: Boolean): MenuButton = when (button) {
+ is MenuButton.Simple -> button.copy(isEnabled = isEnabled)
+ is MenuButton.BooleanOption -> button.copy(isEnabled = isEnabled)
}
private fun mapVisibility(dto: MenuButtonVisibilityDto?): Boolean {
kotlin
ksp
kotlinxSerialization
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private val getFallbackItemUseCase: GetFallbackItemUseCase,
) {
- fun mapSaveData(chest: Chest): SaveDataDto.ChestSaveDataDto {
- return SaveDataDto.ChestSaveDataDto(
- version = SAVE_DATA_VERSION,
- size = chest.size,
- items = chest.items.map(inventoryItemMapper::mapSaveData),
- )
- }
+ fun mapSaveData(chest: Chest): SaveDataDto.ChestSaveDataDto = SaveDataDto.ChestSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ size = chest.size,
+ items = chest.items.map(inventoryItemMapper::mapSaveData),
+ )
fun mapChest(saveDataDto: SaveDataDto.ChestSaveDataDto): Chest {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getItemByKeyUseCase: GetItemByKeyUseCase,
) {
- fun mapSaveData(containerController: ContainerController): SaveDataDto.ContainerControllerSaveDataDto {
- return SaveDataDto.ContainerControllerSaveDataDto(
- version = SAVE_DATA_VERSION,
- containerMap = containerController.containerMap.mapNotNull { (key, container) ->
- when (container) {
- is Furnace -> furnaceMapper.mapSaveData(container)
- is Chest -> chestMapper.mapSaveData(container)
- else -> null
- }?.let { value -> key.toString() to value }
- }.toMap(),
- )
- }
+ fun mapSaveData(containerController: ContainerController): SaveDataDto.ContainerControllerSaveDataDto = SaveDataDto.ContainerControllerSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ containerMap = containerController.containerMap.mapNotNull { (key, container) ->
+ when (container) {
+ is Furnace -> furnaceMapper.mapSaveData(container)
+ is Chest -> chestMapper.mapSaveData(container)
+ else -> null
+ }?.let { value -> key.toString() to value }
+ }.toMap(),
+ )
fun mapContainerController(
saveDataDto: SaveDataDto.ContainerControllerSaveDataDto,
@Reusable
class ControlModeMapper @Inject constructor() {
- fun mapSaveData(direction: Player.ControlMode): SaveDataDto.ControlModeSaveDataDto {
- return SaveDataDto.ControlModeSaveDataDto(
- version = SAVE_DATA_VERSION,
- value = when (direction) {
- Player.ControlMode.WALK -> 0
- Player.ControlMode.CURSOR -> 1
- },
- )
- }
+ fun mapSaveData(direction: Player.ControlMode): SaveDataDto.ControlModeSaveDataDto = SaveDataDto.ControlModeSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ value = when (direction) {
+ Player.ControlMode.WALK -> 0
+ Player.ControlMode.CURSOR -> 1
+ },
+ )
fun mapControlMode(saveDataDto: SaveDataDto.ControlModeSaveDataDto): Player.ControlMode {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
@Reusable
class DirectionMapper @Inject constructor() {
- fun mapSaveData(direction: Direction): SaveDataDto.DirectionSaveDataDto {
- return SaveDataDto.DirectionSaveDataDto(
- version = SAVE_DATA_VERSION,
- value = when (direction) {
- Direction.LEFT -> 0
- Direction.RIGHT -> 1
- },
- )
- }
+ fun mapSaveData(direction: Direction): SaveDataDto.DirectionSaveDataDto = SaveDataDto.DirectionSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ value = when (direction) {
+ Direction.LEFT -> 0
+ Direction.RIGHT -> 1
+ },
+ )
fun mapDirection(saveDataDto: SaveDataDto.DirectionSaveDataDto): Direction {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val itemsRepository: ItemsRepository,
) {
- fun mapSaveData(dropController: DropController): SaveDataDto.DropControllerSaveDataDto {
- return SaveDataDto.DropControllerSaveDataDto(
- version = SAVE_DATA_VERSION,
- drops = dropController.getAllDrop().map(dropMapper::mapSaveData),
- )
- }
+ fun mapSaveData(dropController: DropController): SaveDataDto.DropControllerSaveDataDto = SaveDataDto.DropControllerSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ drops = dropController.getAllDrop().map(dropMapper::mapSaveData),
+ )
fun mapDropController(
saveDataDto: SaveDataDto.DropControllerSaveDataDto,
private val getItemByKeyUseCase: GetItemByKeyUseCase,
) {
- fun mapSaveData(drop: Drop): SaveDataDto.DropSaveDataDto {
- return SaveDataDto.DropSaveDataDto(
- version = SAVE_DATA_VERSION,
- x = drop.x,
- y = drop.y,
- width = drop.width,
- height = drop.height,
- velocityX = drop.velocity.x,
- velocityY = drop.velocity.y,
- itemKey = drop.item.params.key,
- amount = drop.amount,
- pickedUp = drop.isPickedUp,
- )
- }
+ fun mapSaveData(drop: Drop): SaveDataDto.DropSaveDataDto = SaveDataDto.DropSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ x = drop.x,
+ y = drop.y,
+ width = drop.width,
+ height = drop.height,
+ velocityX = drop.velocity.x,
+ velocityY = drop.velocity.y,
+ itemKey = drop.item.params.key,
+ amount = drop.amount,
+ pickedUp = drop.isPickedUp,
+ )
fun mapDrop(saveDataDto: SaveDataDto.DropSaveDataDto): Drop {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getBlockByKeyUseCase: GetBlockByKeyUseCase,
) {
- fun mapSaveData(fallingBlock: FallingBlock): SaveDataDto.FallingBlockSaveDataDto {
- return SaveDataDto.FallingBlockSaveDataDto(
- version = SAVE_DATA_VERSION,
- x = fallingBlock.x,
- y = fallingBlock.y,
- width = fallingBlock.width,
- height = fallingBlock.height,
- velocityX = fallingBlock.velocity.x,
- velocityY = fallingBlock.velocity.y,
- animDelta = fallingBlock.animDelta,
- anim = fallingBlock.anim,
- direction = directionMapper.mapSaveData(fallingBlock.direction),
- dead = fallingBlock.isDead,
- canJump = fallingBlock.canJump,
- flyMode = fallingBlock.isFlyMode,
- maxHealth = fallingBlock.maxHealth,
- health = fallingBlock.health,
- blockKey = fallingBlock.block.params.key,
- )
- }
+ fun mapSaveData(fallingBlock: FallingBlock): SaveDataDto.FallingBlockSaveDataDto = SaveDataDto.FallingBlockSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ x = fallingBlock.x,
+ y = fallingBlock.y,
+ width = fallingBlock.width,
+ height = fallingBlock.height,
+ velocityX = fallingBlock.velocity.x,
+ velocityY = fallingBlock.velocity.y,
+ animDelta = fallingBlock.animDelta,
+ anim = fallingBlock.anim,
+ direction = directionMapper.mapSaveData(fallingBlock.direction),
+ dead = fallingBlock.isDead,
+ canJump = fallingBlock.canJump,
+ flyMode = fallingBlock.isFlyMode,
+ maxHealth = fallingBlock.maxHealth,
+ health = fallingBlock.health,
+ blockKey = fallingBlock.block.params.key,
+ )
fun mapFallingBlock(saveDataDto: SaveDataDto.FallingBlockSaveDataDto): FallingBlock {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getItemByKey: GetItemByKeyUseCase,
) {
- fun mapSaveData(furnace: Furnace): SaveDataDto.FurnaceSaveDataDto {
- return SaveDataDto.FurnaceSaveDataDto(
- version = SAVE_DATA_VERSION,
- size = furnace.size,
- currentFuelItemKey = furnace.currentFuelKey,
- items = furnace.items.map(inventoryItemMapper::mapSaveData),
- startBurnTimeMs = furnace.startBurnTimeMs,
- startSmeltTimeMs = furnace.smeltStarTimeMs,
- burnProgress = furnace.burnProgress,
- smeltProgress = furnace.smeltProgress,
- )
- }
+ fun mapSaveData(furnace: Furnace): SaveDataDto.FurnaceSaveDataDto = SaveDataDto.FurnaceSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ size = furnace.size,
+ currentFuelItemKey = furnace.currentFuelKey,
+ items = furnace.items.map(inventoryItemMapper::mapSaveData),
+ startBurnTimeMs = furnace.startBurnTimeMs,
+ startSmeltTimeMs = furnace.smeltStarTimeMs,
+ burnProgress = furnace.burnProgress,
+ smeltProgress = furnace.smeltProgress,
+ )
fun mapFurnace(saveDataDto: SaveDataDto.FurnaceSaveDataDto): Furnace {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getItemByKeyUseCase: GetItemByKeyUseCase,
) {
- fun mapSaveData(inventoryItem: InventoryItem): SaveDataDto.InventoryItemSaveDataDto {
- return SaveDataDto.InventoryItemSaveDataDto(
- version = SAVE_DATA_VERSION,
- itemKey = inventoryItem.item.params.key,
- amount = inventoryItem.amount,
- )
- }
+ fun mapSaveData(inventoryItem: InventoryItem): SaveDataDto.InventoryItemSaveDataDto = SaveDataDto.InventoryItemSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ itemKey = inventoryItem.item.params.key,
+ amount = inventoryItem.amount,
+ )
fun mapInventoryItem(saveDataDto: SaveDataDto.InventoryItemSaveDataDto): InventoryItem {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getFallbackItem: GetFallbackItemUseCase,
) {
- fun mapSaveData(inventory: Inventory): SaveDataDto.InventorySaveDataDto {
- return SaveDataDto.InventorySaveDataDto(
- version = SAVE_DATA_VERSION,
- size = inventory.size,
- items = inventory.items.map(inventoryItemMapper::mapSaveData),
- )
- }
+ fun mapSaveData(inventory: Inventory): SaveDataDto.InventorySaveDataDto = SaveDataDto.InventorySaveDataDto(
+ version = SAVE_DATA_VERSION,
+ size = inventory.size,
+ items = inventory.items.map(inventoryItemMapper::mapSaveData),
+ )
fun mapInventory(saveDataDto: SaveDataDto.InventorySaveDataDto): Inventory {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getFallbackItemUseCase: GetFallbackItemUseCase,
) {
- fun mapSaveData(mobController: MobController): SaveDataDto.MobControllerSaveDataDto {
- return SaveDataDto.MobControllerSaveDataDto(
- version = SAVE_DATA_VERSION,
- mobs = mobController.mobs.mapNotNull { mob ->
- when (mob) {
- is Pig -> pigMapper.mapSaveData(mob)
- is FallingBlock -> fallingBlockMapper.mapSaveData(mob)
- else -> null
- }
- },
- player = playerMapper.mapSaveData(mobController.player),
- )
- }
+ fun mapSaveData(mobController: MobController): SaveDataDto.MobControllerSaveDataDto = SaveDataDto.MobControllerSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ mobs = mobController.mobs.mapNotNull { mob ->
+ when (mob) {
+ is Pig -> pigMapper.mapSaveData(mob)
+ is FallingBlock -> fallingBlockMapper.mapSaveData(mob)
+ else -> null
+ }
+ },
+ player = playerMapper.mapSaveData(mobController.player),
+ )
fun mapMobController(
saveDataDto: SaveDataDto.MobControllerSaveDataDto,
private val getPigSpriteUseCase: GetPigSpritesUseCase,
) {
- fun mapSaveData(pig: Pig): SaveDataDto.PigSaveDataDto {
- return SaveDataDto.PigSaveDataDto(
- version = SAVE_DATA_VERSION,
- x = pig.x,
- y = pig.y,
- width = pig.width,
- height = pig.height,
- velocityX = pig.velocity.x,
- velocityY = pig.velocity.y,
- animDelta = pig.animDelta,
- anim = pig.anim,
- direction = directionMapper.mapSaveData(pig.direction),
- dead = pig.isDead,
- canJump = pig.canJump,
- flyMode = pig.isFlyMode,
- maxHealth = pig.maxHealth,
- health = pig.health,
- )
- }
+ fun mapSaveData(pig: Pig): SaveDataDto.PigSaveDataDto = SaveDataDto.PigSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ x = pig.x,
+ y = pig.y,
+ width = pig.width,
+ height = pig.height,
+ velocityX = pig.velocity.x,
+ velocityY = pig.velocity.y,
+ animDelta = pig.animDelta,
+ anim = pig.anim,
+ direction = directionMapper.mapSaveData(pig.direction),
+ dead = pig.isDead,
+ canJump = pig.canJump,
+ flyMode = pig.isFlyMode,
+ maxHealth = pig.maxHealth,
+ health = pig.health,
+ )
fun mapPig(saveDataDto: SaveDataDto.PigSaveDataDto): Pig {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val getFallbackItemUseCase: GetFallbackItemUseCase,
) {
- fun mapSaveData(player: Player): SaveDataDto.PlayerSaveDataDto {
- return SaveDataDto.PlayerSaveDataDto(
- version = SAVE_DATA_VERSION,
- x = player.x,
- y = player.y,
- width = player.width,
- height = player.height,
- velocityX = player.velocity.x,
- velocityY = player.velocity.y,
- animDelta = player.animDelta,
- anim = player.anim,
- direction = directionMapper.mapSaveData(player.direction),
- dead = player.isDead,
- canJump = player.canJump,
- flyMode = player.isFlyMode,
- maxHealth = player.maxHealth,
- health = player.health,
- hitting = player.isHitting,
- hittingWithDamage = player.isHittingWithDamage,
- hitAnim = player.hitAnim,
- hitAnimDelta = player.hitAnimDelta,
- inventory = inventoryMapper.mapSaveData(player.inventory),
- gameMode = player.gameMode,
- swim = player.swim,
- headRotation = player.headRotation,
- blockDamage = player.blockDamage,
- cursorX = player.cursorX,
- cursorY = player.cursorY,
- spawnPointX = player.spawnPoint?.x ?: 0f,
- spawnPointY = player.spawnPoint?.y ?: 0f,
- controlMode = controlModeMapper.mapSaveData(player.controlMode),
- activeSlot = player.activeSlot,
- )
- }
+ fun mapSaveData(player: Player): SaveDataDto.PlayerSaveDataDto = SaveDataDto.PlayerSaveDataDto(
+ version = SAVE_DATA_VERSION,
+ x = player.x,
+ y = player.y,
+ width = player.width,
+ height = player.height,
+ velocityX = player.velocity.x,
+ velocityY = player.velocity.y,
+ animDelta = player.animDelta,
+ anim = player.anim,
+ direction = directionMapper.mapSaveData(player.direction),
+ dead = player.isDead,
+ canJump = player.canJump,
+ flyMode = player.isFlyMode,
+ maxHealth = player.maxHealth,
+ health = player.health,
+ hitting = player.isHitting,
+ hittingWithDamage = player.isHittingWithDamage,
+ hitAnim = player.hitAnim,
+ hitAnimDelta = player.hitAnimDelta,
+ inventory = inventoryMapper.mapSaveData(player.inventory),
+ gameMode = player.gameMode,
+ swim = player.swim,
+ headRotation = player.headRotation,
+ blockDamage = player.blockDamage,
+ cursorX = player.cursorX,
+ cursorY = player.cursorY,
+ spawnPointX = player.spawnPoint?.x ?: 0f,
+ spawnPointY = player.spawnPoint?.y ?: 0f,
+ controlMode = controlModeMapper.mapSaveData(player.controlMode),
+ activeSlot = player.activeSlot,
+ )
fun mapPlayer(saveDataDto: SaveDataDto.PlayerSaveDataDto): Player {
saveDataDto.verifyVersion(SAVE_DATA_VERSION)
private val mobControllerMapper: MobControllerMapper,
) : SaveDataRepository {
- private fun Int.toByteArray(): ByteArray {
- return ByteBuffer.allocate(Int.SIZE_BYTES)
- .putInt(this)
- .array()
- }
+ private fun Int.toByteArray(): ByteArray = ByteBuffer.allocate(Int.SIZE_BYTES)
+ .putInt(this)
+ .array()
- private fun Short.toByteArray(): ByteArray {
- return ByteBuffer.allocate(Short.SIZE_BYTES)
- .putShort(this)
- .array()
- }
+ private fun Short.toByteArray(): ByteArray = ByteBuffer.allocate(Short.SIZE_BYTES)
+ .putShort(this)
+ .array()
private fun buildBlocksDictionary(
foreMap: Array<Array<Block>>,
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
repositories.forEach(AssetsRepository::dispose)
}
- fun getBlockTexture(textureName: String): Texture {
- return blockAssetsRepository.getBlockTexture(textureName)
- }
+ fun getBlockTexture(textureName: String): Texture = blockAssetsRepository.getBlockTexture(textureName)
- fun getItemTexture(textureName: String): Texture {
- return itemsAssetsRepository.getItemTexture(textureName)
- }
+ fun getItemTexture(textureName: String): Texture = itemsAssetsRepository.getItemTexture(textureName)
- fun getBlockDamageFrameCount(): Int {
- return blockDamageAssetsRepository.damageStages
- }
+ fun getBlockDamageFrameCount(): Int = blockDamageAssetsRepository.damageStages
- fun getBlockDamageSprite(stage: Int): Sprite {
- return blockDamageAssetsRepository.getBlockDamageSprite(stage)
- }
+ fun getBlockDamageSprite(stage: Int): Sprite = blockDamageAssetsRepository.getBlockDamageSprite(stage)
- fun getStringWidth(string: String): Float {
- return fontAssetsRepository.getStringWidth(string)
- }
+ fun getStringWidth(string: String): Float = fontAssetsRepository.getStringWidth(string)
- fun getStringHeight(string: String): Float {
- return fontAssetsRepository.getStringHeight(string)
- }
+ fun getStringHeight(string: String): Float = fontAssetsRepository.getStringHeight(string)
- fun getFont(): BitmapFont {
- return fontAssetsRepository.getFont()
- }
+ fun getFont(): BitmapFont = fontAssetsRepository.getFont()
- fun getPlayerSprites(): MobSprite.Player {
- return mobAssetsRepository.getPlayerSprites()
- }
+ fun getPlayerSprites(): MobSprite.Player = mobAssetsRepository.getPlayerSprites()
- fun getPigSprites(): MobSprite.Pig {
- return mobAssetsRepository.getPigSprites()
- }
+ fun getPigSprites(): MobSprite.Pig = mobAssetsRepository.getPigSprites()
- fun getTouchButtons(): Map<String, TouchButton> {
- return touchButtonsAssetsRepository.getTouchButtons()
- }
+ fun getTouchButtons(): Map<String, TouchButton> = touchButtonsAssetsRepository.getTouchButtons()
- fun getTextureRegionByName(name: String): TextureRegion? {
- return textureRegionsAssetsRepository.getTextureRegionByName(name)
- }
+ fun getTextureRegionByName(name: String): TextureRegion? = textureRegionsAssetsRepository.getTextureRegionByName(name)
}
protected val loadedTextures = LinkedList<Texture>()
- protected fun loadTexture(path: String): Texture {
- return Texture(Gdx.files.internal(path)).also { texture ->
- loadedTextures.add(texture)
- }
+ protected fun loadTexture(path: String): Texture = Texture(Gdx.files.internal(path)).also { texture ->
+ loadedTextures.add(texture)
}
protected fun flippedRegion(
y: Int,
width: Int,
height: Int,
- ): TextureRegion {
- return TextureRegion(texture, x, y + height, width, -height)
- }
+ ): TextureRegion = TextureRegion(texture, x, y + height, width, -height)
protected fun flippedSprite(
texture: Texture,
- ): Sprite {
- return Sprite(texture).apply { flip(false, true) }
- }
+ ): Sprite = Sprite(texture).apply { flip(false, true) }
protected fun flippedSprite(
texture: Texture,
y: Int,
width: Int,
height: Int,
- ): Sprite {
- return Sprite(flippedRegion(texture, x, y, width, height))
- }
+ ): Sprite = Sprite(flippedRegion(texture, x, y, width, height))
protected fun resolveTexture(
textureName: String,
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(): Int {
- return gameAssetsHolder.getBlockDamageFrameCount()
- }
+ operator fun invoke(): Int = gameAssetsHolder.getBlockDamageFrameCount()
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun get(stage: Int): Sprite {
- return gameAssetsHolder.getBlockDamageSprite(stage)
- }
+ operator fun get(stage: Int): Sprite = gameAssetsHolder.getBlockDamageSprite(stage)
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun get(name: String): Texture {
- return gameAssetsHolder.getBlockTexture(name)
- }
+ operator fun get(name: String): Texture = gameAssetsHolder.getBlockTexture(name)
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(): BitmapFont {
- return gameAssetsHolder.getFont()
- }
+ operator fun invoke(): BitmapFont = gameAssetsHolder.getFont()
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun get(name: String): Texture {
- return gameAssetsHolder.getItemTexture(name)
- }
+ operator fun get(name: String): Texture = gameAssetsHolder.getItemTexture(name)
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(): MobSprite.Pig {
- return gameAssetsHolder.getPigSprites()
- }
+ operator fun invoke(): MobSprite.Pig = gameAssetsHolder.getPigSprites()
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(): MobSprite.Player {
- return gameAssetsHolder.getPlayerSprites()
- }
+ operator fun invoke(): MobSprite.Player = gameAssetsHolder.getPlayerSprites()
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(string: String): Float {
- return gameAssetsHolder.getStringHeight(string)
- }
+ operator fun invoke(string: String): Float = gameAssetsHolder.getStringHeight(string)
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(string: String): Float {
- return gameAssetsHolder.getStringWidth(string)
- }
+ operator fun invoke(string: String): Float = gameAssetsHolder.getStringWidth(string)
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun get(name: String): TextureRegion? {
- return gameAssetsHolder.getTextureRegionByName(name)
- }
+ operator fun get(name: String): TextureRegion? = gameAssetsHolder.getTextureRegionByName(name)
}
private val gameAssetsHolder: GameAssetsHolder,
) {
- operator fun invoke(): Map<String, TouchButton> {
- return gameAssetsHolder.getTouchButtons()
- }
+ operator fun invoke(): Map<String, TouchButton> = gameAssetsHolder.getTouchButtons()
}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
fun yOnViewport(y: Int) = viewport.height / Gdx.graphics.height * y.toFloat()
- fun getViewportCoordinates(x: Int, y: Int): Pair<Float, Float> {
- return xOnViewport(x) to yOnViewport(y)
- }
+ fun getViewportCoordinates(x: Int, y: Int): Pair<Float, Float> = xOnViewport(x) to yOnViewport(y)
}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
} ?: 0
}
- override fun hashCode(): Int {
- return params.key.hashCode()
- }
+ override fun hashCode(): Int = params.key.hashCode()
- override fun equals(other: Any?): Boolean {
- return params.key == (other as Item).params.key
- }
+ override fun equals(other: Any?): Boolean = params.key == (other as Item).params.key
fun initialize() {
initAnimation()
return this is None
}
- fun getRectangle(x: Int, y: Int): Rectangle {
- return Rectangle(
- /* x = */ x * BLOCK_SIZE_PX + params.collisionMargins.left,
- /* y = */ y * BLOCK_SIZE_PX + params.collisionMargins.top,
- /* width = */ width,
- /* height = */ height,
- )
- }
+ fun getRectangle(x: Int, y: Int): Rectangle = Rectangle(
+ /* x = */ x * BLOCK_SIZE_PX + params.collisionMargins.left,
+ /* y = */ y * BLOCK_SIZE_PX + params.collisionMargins.top,
+ /* width = */ width,
+ /* height = */ height,
+ )
- sealed class Container() : Block()
+ sealed class Container : Block()
data class None(
override val params: CommonBlockParams,
override val sprite: Sprite
get() = getSprite(false)
- private fun getSprite(isActive: Boolean): Sprite {
- return animation?.let { animation ->
- if (isActive) {
- animation[1]
- } else {
- animation[0]
- }
- } ?: sprite
- }
+ private fun getSprite(isActive: Boolean): Sprite = animation?.let { animation ->
+ if (isActive) {
+ animation[1]
+ } else {
+ animation[0]
+ }
+ } ?: sprite
fun draw(spriter: SpriteBatch, x: Float, y: Float, isActive: Boolean) {
getSprite(isActive).apply {
return -1
}
- fun canPickItem(item: Item): Boolean {
- return getAvailableSlotForItem(item) >= 0
- }
+ fun canPickItem(item: Item): Boolean = getAvailableSlotForItem(item) >= 0
fun addItem(item: Item) {
_items.copyInto(
add(-count)
}
- fun canBeAdded(count: Int = 1): Boolean {
- return amount + count <= item.params.maxStack
- }
+ fun canBeAdded(count: Int = 1): Boolean = amount + count <= item.params.maxStack
private fun drawAmountText(
spriteBatch: SpriteBatch,
companion object {
@OptIn(ExperimentalContracts::class)
fun InventoryItem?.isNoneOrNull(): Boolean {
- contract { returns(false) implies(this@isNoneOrNull != null) }
+ contract { returns(false) implies (this@isNoneOrNull != null) }
return this?.item == null || this.item.isNone()
}
}
abstract val params: CommonItemParams
abstract val sprite: Sprite
- override fun hashCode(): Int {
- return params.key.hashCode()
- }
+ override fun hashCode(): Int = params.key.hashCode()
- override fun equals(other: Any?): Boolean {
- return params.key == (other as Item).params.key
- }
+ override fun equals(other: Any?): Boolean = params.key == (other as Item).params.key
fun isNone(): Boolean {
contract { returns(true) implies (this@Item is None) }
}
@JvmOverloads
- fun toInventoryItem(amount: Int = 1): InventoryItem {
- return InventoryItem(this, amount)
- }
+ fun toInventoryItem(amount: Int = 1): InventoryItem = InventoryItem(this, amount)
data class Normal(
override val params: CommonItemParams,
private val itemsRepository: ItemsRepository,
) {
- operator fun get(key: String): Block {
- return itemsRepository.getBlockByKey(key)
- }
+ operator fun get(key: String): Block = itemsRepository.getBlockByKey(key)
}
private val itemsRepository: ItemsRepository,
) {
- operator fun <T : Block> get(type: Class<T>): List<T> {
- return itemsRepository.getBlocksByType(type)
- }
+ operator fun <T : Block> get(type: Class<T>): List<T> = itemsRepository.getBlocksByType(type)
}
private val itemsRepository: ItemsRepository,
) {
- operator fun get(input: List<Item>): InventoryItem {
- return itemsRepository.getCraftingResult(input)
- }
+ operator fun get(input: List<Item>): InventoryItem = itemsRepository.getCraftingResult(input)
}
private val itemsRepository: ItemsRepository,
) {
- operator fun invoke(): Block.None {
- return itemsRepository.fallbackBlock
- }
+ operator fun invoke(): Block.None = itemsRepository.fallbackBlock
}
private val itemsRepository: ItemsRepository,
) {
- operator fun invoke(): Item.None {
- return itemsRepository.fallbackItem
- }
+ operator fun invoke(): Item.None = itemsRepository.fallbackItem
}
private val itemsRepository: ItemsRepository,
) {
- operator fun get(index: Int): Item {
- return itemsRepository.getItemByIndex(index)
- }
+ operator fun get(index: Int): Item = itemsRepository.getItemByIndex(index)
}
private val itemsRepository: ItemsRepository,
) {
- operator fun get(key: String): Item {
- return itemsRepository.getItemByKey(key)
- }
+ operator fun get(key: String): Item = itemsRepository.getItemByKey(key)
}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
return value
}
- fun isEmpty(): Boolean {
- return mobController == null &&
- dropController == null &&
- containerController == null
- }
+ fun isEmpty(): Boolean = mobController == null &&
+ dropController == null &&
+ containerController == null
}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
val y: Int,
val z: Int,
) {
- override fun toString(): String {
- return "($x;$y;$z)"
- }
+ override fun toString(): String = "($x;$y;$z)"
companion object {
field = MathUtils.clamp(value, 0f, 1f)
}
- fun canSmelt(): Boolean {
- return (result.isNoneOrNull() || (result.item.params.key == input.item.params.smeltProductKey)) &&
- !input.isNoneOrNull() && input.item.params.smeltProductKey != null &&
- (!fuel.isNoneOrNull() || burnProgress > 0f)
- }
+ fun canSmelt(): Boolean = (result.isNoneOrNull() || (result.item.params.key == input.item.params.smeltProductKey)) &&
+ !input.isNoneOrNull() &&
+ input.item.params.smeltProductKey != null &&
+ (!fuel.isNoneOrNull() || burnProgress > 0f)
private fun startBurning() {
requireNotNull(fuel.item.params.burningTimeMs) { "Cant start burning without fuel" }
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
return Intersector.overlaps(magnetArea, rectangle)
}
- private fun getMagnetArea(): Rectangle {
- return Rectangle(
- /* x = */ x - MAGNET_DISTANCE,
- /* y = */ y - MAGNET_DISTANCE,
- /* width = */ width + MAGNET_DISTANCE * 2,
- /* height = */ height + MAGNET_DISTANCE * 2,
- )
- }
+ private fun getMagnetArea(): Rectangle = Rectangle(
+ /* x = */ x - MAGNET_DISTANCE,
+ /* y = */ y - MAGNET_DISTANCE,
+ /* width = */ width + MAGNET_DISTANCE * 2,
+ /* height = */ height + MAGNET_DISTANCE * 2,
+ )
companion object {
private fun getInitialVelocity(): Vector2 = Vector2(MathUtils.random(-100f, 100f), -100f)
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
abstract val speed: Float
- private fun isAnimationIncreasing(): Boolean {
- return anim > 0 && animDelta > 0 || anim < 0 && animDelta < 0
- }
+ private fun isAnimationIncreasing(): Boolean = anim > 0 && animDelta > 0 || anim < 0 && animDelta < 0
private fun checkHealth() {
health = MathUtils.clamp(health, 0, maxHealth)
checkHealth()
}
- fun getHitBox(): Rectangle {
- return Rectangle(
- /* x = */ x - HIT_RANGE,
- /* y = */ y + HIT_RANGE,
- /* width = */ width + HIT_RANGE * 2f,
- /* height = */ height + HIT_RANGE * 2f,
- )
- }
+ fun getHitBox(): Rectangle = Rectangle(
+ /* x = */ x - HIT_RANGE,
+ /* y = */ y + HIT_RANGE,
+ /* width = */ width + HIT_RANGE * 2f,
+ /* height = */ height + HIT_RANGE * 2f,
+ )
fun update(mobWorldAdapter: MobWorldAdapter, delta: Float) {
behavior.update(this, mobWorldAdapter, delta)
open fun getDropItems(
itemByKey: GetItemByKeyUseCase,
- ): List<InventoryItem> {
- return emptyList()
- }
+ ): List<InventoryItem> = emptyList()
abstract fun draw(spriteBatch: SpriteBatch, x: Float, y: Float, delta: Float)
}
}
- override fun getDropItems(itemByKey: GetItemByKeyUseCase): List<InventoryItem> {
- return listOf(itemByKey["porkchop_raw"].toInventoryItem())
- }
+ override fun getDropItems(itemByKey: GetItemByKeyUseCase): List<InventoryItem> = listOf(itemByKey["porkchop_raw"].toInventoryItem())
override fun draw(
spriteBatch: SpriteBatch,
}
}
- override fun getDropItems(itemByKey: GetItemByKeyUseCase): List<InventoryItem> {
- return inventory.items
- }
+ override fun getDropItems(itemByKey: GetItemByKeyUseCase): List<InventoryItem> = inventory.items
override fun draw(spriteBatch: SpriteBatch, x: Float, y: Float, delta: Float) {
updateAnimation(delta)
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private val containerWorldAdapter: ContainerWorldAdapter,
private val containerFactory: ContainerFactory,
private val dropAdapter: DropAdapter,
-) : OnBlockPlacedListener, OnBlockDestroyedListener {
+) : OnBlockPlacedListener,
+ OnBlockDestroyedListener {
val containerMap = mutableMapOf<ContainerCoordinates, Container>()
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
import ru.fredboy.cavedroid.entity.mob.abstraction.MobWorldAdapter
import ru.fredboy.cavedroid.entity.mob.model.FallingBlock
-class FallingBlockMobBehavior : BaseMobBehavior<FallingBlock>(
- mobType = FallingBlock::class,
-) {
+class FallingBlockMobBehavior :
+ BaseMobBehavior<FallingBlock>(
+ mobType = FallingBlock::class,
+ ) {
override fun FallingBlock.updateMob(worldAdapter: MobWorldAdapter, delta: Float) {
if (velocity.isZero) {
import ru.fredboy.cavedroid.entity.mob.abstraction.MobWorldAdapter
import ru.fredboy.cavedroid.entity.mob.model.Pig
-class PigMobBehavior : BaseMobBehavior<Pig>(
- mobType = Pig::class,
-) {
+class PigMobBehavior :
+ BaseMobBehavior<Pig>(
+ mobType = Pig::class,
+ ) {
override fun Pig.updateMob(worldAdapter: MobWorldAdapter, delta: Float) {
if (MathUtils.randomBoolean(delta)) {
import ru.fredboy.cavedroid.entity.mob.abstraction.MobWorldAdapter
import ru.fredboy.cavedroid.entity.mob.model.Player
-class PlayerMobBehavior : BaseMobBehavior<Player>(
- mobType = Player::class,
-) {
+class PlayerMobBehavior :
+ BaseMobBehavior<Player>(
+ mobType = Player::class,
+ ) {
private fun Block?.isHittable() = this != null && !isNone() && params.hitPoints >= 0
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
) {
if (selectedItem != null &&
selectedItem?.item?.isNone() != true &&
- pointer >= 0 && selectItemPointer >= 0 &&
+ pointer >= 0 &&
+ selectItemPointer >= 0 &&
pointer != selectItemPointer
) {
return
val clickedItem = items[index]
selectedItem?.let { selectedItem ->
- if (!clickedItem.isNoneOrNull() && items[index].item == selectedItem.item &&
+ if (!clickedItem.isNoneOrNull() &&
+ items[index].item == selectedItem.item &&
items[index].amount + selectedItem.amount <= selectedItem.item.params.maxStack
) {
items[index].amount += selectedItem.amount
import ru.fredboy.cavedroid.game.window.GameWindowType
import ru.fredboy.cavedroid.game.window.GameWindowsConfigs
-class CreativeInventoryWindow() : AbstractInventoryWindow() {
+class CreativeInventoryWindow : AbstractInventoryWindow() {
override val type = GameWindowType.CREATIVE_INVENTORY
override var selectedItem: InventoryItem? = null
- fun getMaxScroll(itemsRepository: ItemsRepository): Int {
- return itemsRepository.getAllItems().size / GameWindowsConfigs.Creative.itemsInRow
- }
+ fun getMaxScroll(itemsRepository: ItemsRepository): Int = itemsRepository.getAllItems().size / GameWindowsConfigs.Creative.itemsInRow
}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
notifyBlockPlaced(x, y, layer, value)
}
- private fun isSameSlab(slab1: Block, slab2: Block): Boolean {
- return slab1 is Block.Slab && slab2 is Block.Slab &&
- (slab1.params.key == slab2.otherPartBlockKey || slab1.otherPartBlockKey == slab2.params.key)
- }
+ private fun isSameSlab(slab1: Block, slab2: Block): Boolean = slab1 is Block.Slab &&
+ slab2 is Block.Slab &&
+ (slab1.params.key == slab2.otherPartBlockKey || slab1.otherPartBlockKey == slab2.params.key)
- fun hasForeAt(x: Int, y: Int): Boolean {
- return !getMap(x, y, Layer.FOREGROUND).isNone()
- }
+ fun hasForeAt(x: Int, y: Int): Boolean = !getMap(x, y, Layer.FOREGROUND).isNone()
- fun hasBackAt(x: Int, y: Int): Boolean {
- return !getMap(x, y, Layer.BACKGROUND).isNone()
- }
+ fun hasBackAt(x: Int, y: Int): Boolean = !getMap(x, y, Layer.BACKGROUND).isNone()
- fun getForeMap(x: Int, y: Int): Block {
- return getMap(x, y, Layer.FOREGROUND)
- }
+ fun getForeMap(x: Int, y: Int): Block = getMap(x, y, Layer.FOREGROUND)
fun setForeMap(x: Int, y: Int, block: Block, dropOld: Boolean = false) {
setMap(x, y, Layer.FOREGROUND, block, dropOld)
setForeMap(x, y, itemsRepository.fallbackBlock)
}
- fun getBackMap(x: Int, y: Int): Block {
- return getMap(x, y, Layer.BACKGROUND)
- }
+ fun getBackMap(x: Int, y: Int): Block = getMap(x, y, Layer.BACKGROUND)
fun setBackMap(x: Int, y: Int, block: Block, dropOld: Boolean = false) {
setMap(x, y, Layer.BACKGROUND, block, dropOld)
}
- fun canPlaceToForeground(x: Int, y: Int, value: Block): Boolean {
- return !hasForeAt(x, y) || value.isNone() || !getForeMap(x, y).params.hasCollision
- }
+ fun canPlaceToForeground(x: Int, y: Int, value: Block): Boolean = !hasForeAt(x, y) || value.isNone() || !getForeMap(x, y).params.hasCollision
fun placeToForeground(x: Int, y: Int, value: Block, dropOld: Boolean = false): Boolean {
val wasPlaced = if (canPlaceToForeground(x, y, value)) {
}
fun placeToBackground(x: Int, y: Int, value: Block, dropOld: Boolean = false): Boolean {
- val wasPlaced = if (value.isNone() || getBackMap(x, y).isNone() && value.params.hasCollision &&
+ val wasPlaced = if (value.isNone() ||
+ getBackMap(x, y).isNone() &&
+ value.params.hasCollision &&
(!value.params.isTransparent || value.params.key == "glass" || value.isChest() || value.isSlab())
) {
setBackMap(x, y, value, dropOld)
companion object {
- fun getDefault(): WorldGeneratorConfig {
- return WorldGeneratorConfig(
- width = 1024,
- height = 256,
- seed = TimeUtils.millis(),
- maxSurfaceHeight = 208,
- minSurfaceHeight = 128,
- biomes = Biome.entries.toList(),
- minBiomeSize = 64,
- seaLevel = 192,
- )
- }
+ fun getDefault(): WorldGeneratorConfig = WorldGeneratorConfig(
+ width = 1024,
+ height = 256,
+ seed = TimeUtils.millis(),
+ maxSurfaceHeight = 208,
+ minSurfaceHeight = 128,
+ biomes = Biome.entries.toList(),
+ minBiomeSize = 64,
+ seaLevel = 192,
+ )
}
}
internal class WorldAdapterImpl @Inject constructor(
private val gameWorld: GameWorld,
private val itemsRepository: ItemsRepository,
-) : DropWorldAdapter, ContainerWorldAdapter, MobWorldAdapter {
+) : DropWorldAdapter,
+ ContainerWorldAdapter,
+ MobWorldAdapter {
override val height: Int
get() = gameWorld.height
gameWorld.setBackMap(x, y, block)
}
- override fun getForegroundBlock(x: Int, y: Int): Block {
- return gameWorld.getForeMap(x, y)
- }
+ override fun getForegroundBlock(x: Int, y: Int): Block = gameWorld.getForeMap(x, y)
- override fun getBackgroundBlock(x: Int, y: Int): Block {
- return gameWorld.getBackMap(x, y)
- }
+ override fun getBackgroundBlock(x: Int, y: Int): Block = gameWorld.getBackMap(x, y)
override fun destroyForegroundBlock(x: Int, y: Int, shouldDrop: Boolean) {
gameWorld.destroyForeMap(x, y, shouldDrop)
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private var touchDownX = 0f
private var touchDownY = 0f
- override fun keyDown(keycode: Int): Boolean {
- return handleKeyboardAction(keycode, true)
- }
+ override fun keyDown(keycode: Int): Boolean = handleKeyboardAction(keycode, true)
- override fun keyUp(keycode: Int): Boolean {
- return handleKeyboardAction(keycode, false)
- }
+ override fun keyUp(keycode: Int): Boolean = handleKeyboardAction(keycode, false)
- override fun keyTyped(p0: Char): Boolean {
- return false
- }
+ override fun keyTyped(p0: Char): Boolean = false
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
val (touchX, touchY) = gameContextRepository.getCameraContext().getViewportCoordinates(screenX, screenY)
)
}
- override fun touchCancelled(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {
- return false
- }
+ override fun touchCancelled(p0: Int, p1: Int, p2: Int, p3: Int): Boolean = false
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
val (touchX, touchY) = gameContextRepository.getCameraContext().getViewportCoordinates(screenX, screenY)
return handleMouseAction(action)
}
- override fun mouseMoved(p0: Int, p1: Int): Boolean {
- return false
- }
+ override fun mouseMoved(p0: Int, p1: Int): Boolean = false
override fun scrolled(amountX: Float, amountY: Float): Boolean {
val action: MouseInputAction? = mouseInputActionMapper
this.screenX <= this.cameraViewport.width / 2 + hotbar.regionWidth / 2
}
-fun isInsideWindow(action: MouseInputAction, windowTexture: TextureRegion): Boolean {
- return action.screenY > action.cameraViewport.height / 2 - windowTexture.regionHeight / 2 &&
- action.screenY < action.cameraViewport.height / 2 + windowTexture.regionHeight / 2 &&
- action.screenX > action.cameraViewport.width / 2 - windowTexture.regionWidth / 2 &&
- action.screenX < action.cameraViewport.width / 2 + windowTexture.regionWidth / 2
-}
+fun isInsideWindow(action: MouseInputAction, windowTexture: TextureRegion): Boolean = action.screenY > action.cameraViewport.height / 2 - windowTexture.regionHeight / 2 &&
+ action.screenY < action.cameraViewport.height / 2 + windowTexture.regionHeight / 2 &&
+ action.screenX > action.cameraViewport.width / 2 - windowTexture.regionWidth / 2 &&
+ action.screenX < action.cameraViewport.width / 2 + windowTexture.regionWidth / 2
private val dropController: DropController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.OpenInventory &&
- !action.isKeyDown && gameWindowsManager.currentWindowType != GameWindowType.NONE
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.OpenInventory &&
+ !action.isKeyDown &&
+ gameWindowsManager.currentWindowType != GameWindowType.NONE
override fun handle(action: KeyboardInputAction) {
val selectedItem = gameWindowsManager.currentWindow?.selectedItem
private val dropController: DropController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.DropItem &&
- action.isKeyDown && gameWindowsManager.currentWindowType == GameWindowType.NONE &&
- !mobController.player.activeItem.item.isNone()
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.DropItem &&
+ action.isKeyDown &&
+ gameWindowsManager.currentWindowType == GameWindowType.NONE &&
+ !mobController.player.activeItem.item.isNone()
private fun createDrop(item: Item, playerX: Float, playerY: Float, amount: Int) {
dropController.addDrop(
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Down &&
- mobController.player.isFlyMode &&
- (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Down &&
+ mobController.player.isFlyMode &&
+ (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
if (action.isKeyDown) {
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Up &&
- !mobController.player.swim &&
- mobController.player.isFlyMode &&
- (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Up &&
+ !mobController.player.swim &&
+ mobController.player.isFlyMode &&
+ (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
if (action.isKeyDown) {
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Right &&
- (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Right &&
+ (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
if (action.isKeyDown) {
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Up &&
- mobController.player.canJump && !mobController.player.isFlyMode &&
- action.isKeyDown &&
- (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Up &&
+ mobController.player.canJump &&
+ !mobController.player.isFlyMode &&
+ action.isKeyDown &&
+ (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
mobController.player.jump()
private val mobsController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return applicationContextRepository.isTouch() &&
- mobsController.player.controlMode == Player.ControlMode.CURSOR && action.isKeyDown &&
- (
- action.actionKey is KeyboardInputActionKey.Left ||
- action.actionKey is KeyboardInputActionKey.Right ||
- action.actionKey is KeyboardInputActionKey.Up ||
- action.actionKey is KeyboardInputActionKey.Down
- )
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = applicationContextRepository.isTouch() &&
+ mobsController.player.controlMode == Player.ControlMode.CURSOR &&
+ action.isKeyDown &&
+ (
+ action.actionKey is KeyboardInputActionKey.Left ||
+ action.actionKey is KeyboardInputActionKey.Right ||
+ action.actionKey is KeyboardInputActionKey.Up ||
+ action.actionKey is KeyboardInputActionKey.Down
+ )
override fun handle(action: KeyboardInputAction) {
val player = mobsController.player
private val gameWindowsManager: GameWindowsManager,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.OpenInventory &&
- !action.isKeyDown && gameWindowsManager.currentWindowType == GameWindowType.NONE
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.OpenInventory &&
+ !action.isKeyDown &&
+ gameWindowsManager.currentWindowType == GameWindowType.NONE
override fun handle(action: KeyboardInputAction) {
if (mobController.player.gameMode == 1) {
private val saveDataRepository: SaveDataRepository,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Pause && action.isKeyDown
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Pause && action.isKeyDown
override fun handle(action: KeyboardInputAction) {
if (gameWindowsManager.currentWindowType != GameWindowType.NONE) {
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.SelectHotbarSlot &&
- action.isKeyDown
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.SelectHotbarSlot &&
+ action.isKeyDown
override fun handle(action: KeyboardInputAction) {
mobController.player.activeSlot = (action.actionKey as KeyboardInputActionKey.SelectHotbarSlot).slot
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Up && !action.isKeyDown &&
- mobController.player.swim &&
- (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Up &&
+ !action.isKeyDown &&
+ mobController.player.swim &&
+ (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
mobController.player.swim = false
private val gameWorld: GameWorld,
) : IKeyboardInputHandler {
- private fun checkSwim(): Boolean {
- return gameWorld.getForeMap(mobController.player.mapX, mobController.player.lowerMapY).isFluid()
- }
+ private fun checkSwim(): Boolean = gameWorld.getForeMap(mobController.player.mapX, mobController.player.lowerMapY).isFluid()
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.Up && action.isKeyDown &&
- !mobController.player.swim &&
- !mobController.player.canJump &&
- checkSwim() && !mobController.player.isFlyMode &&
- (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.Up &&
+ action.isKeyDown &&
+ !mobController.player.swim &&
+ !mobController.player.canJump &&
+ checkSwim() &&
+ !mobController.player.isFlyMode &&
+ (mobController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
mobController.player.swim = true
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.SwitchControlsMode && !action.isKeyDown &&
- applicationContextRepository.isTouch()
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.SwitchControlsMode &&
+ !action.isKeyDown &&
+ applicationContextRepository.isTouch()
override fun handle(action: KeyboardInputAction) {
if (mobController.player.controlMode == Player.ControlMode.WALK) {
private val gameContextRepository: GameContextRepository,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.ShowDebug && action.isKeyDown
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.ShowDebug && action.isKeyDown
override fun handle(action: KeyboardInputAction) {
gameContextRepository.setShowInfo(!gameContextRepository.shouldShowInfo())
private val mobController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.SwitchGameMode && action.isKeyDown
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.SwitchGameMode && action.isKeyDown
override fun handle(action: KeyboardInputAction) {
if (mobController.player.gameMode == 1) {
private val gameContextRepository: GameContextRepository,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return action.actionKey is KeyboardInputActionKey.ShowMap && action.isKeyDown
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = action.actionKey is KeyboardInputActionKey.ShowMap && action.isKeyDown
override fun handle(action: KeyboardInputAction) {
gameContextRepository.setShowMap(!gameContextRepository.shouldShowMap())
private val mobsController: MobController,
) : IKeyboardInputHandler {
- override fun checkConditions(action: KeyboardInputAction): Boolean {
- return mobsController.player.gameMode == 1 && action.actionKey is KeyboardInputActionKey.Up &&
- !mobsController.player.swim &&
- !mobsController.player.isFlyMode && !mobsController.player.canJump && action.isKeyDown &&
- (mobsController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
- }
+ override fun checkConditions(action: KeyboardInputAction): Boolean = mobsController.player.gameMode == 1 &&
+ action.actionKey is KeyboardInputActionKey.Up &&
+ !mobsController.player.swim &&
+ !mobsController.player.isFlyMode &&
+ !mobsController.player.canJump &&
+ action.isKeyDown &&
+ (mobsController.player.controlMode == Player.ControlMode.WALK || !applicationContextRepository.isTouch())
override fun handle(action: KeyboardInputAction) {
mobsController.player.isFlyMode = true
protected abstract val windowTexture: TextureRegion
- override fun checkConditions(action: MouseInputAction): Boolean {
- return gameWindowsManager.currentWindowType == windowType &&
- isInsideWindow(action, windowTexture) &&
- (
- action.actionKey is MouseInputActionKey.Left ||
- action.actionKey is MouseInputActionKey.Right ||
- action.actionKey is MouseInputActionKey.Screen
- ) &&
- (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen)
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = gameWindowsManager.currentWindowType == windowType &&
+ isInsideWindow(action, windowTexture) &&
+ (
+ action.actionKey is MouseInputActionKey.Left ||
+ action.actionKey is MouseInputActionKey.Right ||
+ action.actionKey is MouseInputActionKey.Screen
+ ) &&
+ (action.actionKey.touchUp || action.actionKey is MouseInputActionKey.Screen)
protected fun updateCraftResult(window: AbstractInventoryWindowWithCraftGrid) {
window.craftResult = itemsRepository.getCraftingResult(window.craftingItems.map(InventoryItem::item))
) {
val selectedItem = window.selectedItem
- if (!selectedItem.isNoneOrNull() && (
+ if (!selectedItem.isNoneOrNull() &&
+ (
selectedItem.item != items[index].item ||
!selectedItem.canBeAdded(items[index].amount)
)
private val textureRegions: GetTextureRegionByNameUseCase,
) : IMouseInputHandler {
- override fun checkConditions(action: MouseInputAction): Boolean {
- return gameWindowsManager.currentWindowType == GameWindowType.NONE &&
- !action.isInsideHotbar(textureRegions) &&
- action.actionKey is MouseInputActionKey.Left
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = gameWindowsManager.currentWindowType == GameWindowType.NONE &&
+ !action.isInsideHotbar(textureRegions) &&
+ action.actionKey is MouseInputActionKey.Left
override fun handle(action: MouseInputAction) {
if (action.actionKey.touchUp) {
private val furnaceInventoryTexture get() = requireNotNull(textureRegions["furnace"])
private val chestInventoryTexture get() = requireNotNull(textureRegions["chest"])
- override fun checkConditions(action: MouseInputAction): Boolean {
- return gameWindowsManager.currentWindowType != GameWindowType.NONE &&
- (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) &&
- action.actionKey.touchUp &&
- !isInsideWindow(action, getCurrentWindowTexture())
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = gameWindowsManager.currentWindowType != GameWindowType.NONE &&
+ (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) &&
+ action.actionKey.touchUp &&
+ !isInsideWindow(action, getCurrentWindowTexture())
- private fun getCurrentWindowTexture(): TextureRegion {
- return when (val window = gameWindowsManager.currentWindowType) {
- GameWindowType.CREATIVE_INVENTORY -> creativeInventoryTexture
- GameWindowType.SURVIVAL_INVENTORY -> survivalInventoryTexture
- GameWindowType.CRAFTING_TABLE -> craftingInventoryTexture
- GameWindowType.FURNACE -> furnaceInventoryTexture
- GameWindowType.CHEST -> chestInventoryTexture
- else -> throw UnsupportedOperationException("Cant close window ${window.name}")
- }
+ private fun getCurrentWindowTexture(): TextureRegion = when (val window = gameWindowsManager.currentWindowType) {
+ GameWindowType.CREATIVE_INVENTORY -> creativeInventoryTexture
+ GameWindowType.SURVIVAL_INVENTORY -> survivalInventoryTexture
+ GameWindowType.CRAFTING_TABLE -> craftingInventoryTexture
+ GameWindowType.FURNACE -> furnaceInventoryTexture
+ GameWindowType.CHEST -> chestInventoryTexture
+ else -> throw UnsupportedOperationException("Cant close window ${window.name}")
}
override fun handle(action: MouseInputAction) {
private var dragStartY = 0f
- override fun checkConditions(action: MouseInputAction): Boolean {
- return gameWindowsManager.currentWindowType == GameWindowType.CREATIVE_INVENTORY &&
- (gameWindowsManager.isDragging || isInsideWindow(action, creativeInventoryTexture)) &&
- (
- checkStartDragConditions(action) || checkEndDragConditions(action) ||
- checkDragConditions(action) || action.actionKey is MouseInputActionKey.Scroll
- )
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = gameWindowsManager.currentWindowType == GameWindowType.CREATIVE_INVENTORY &&
+ (gameWindowsManager.isDragging || isInsideWindow(action, creativeInventoryTexture)) &&
+ (
+ checkStartDragConditions(action) ||
+ checkEndDragConditions(action) ||
+ checkDragConditions(action) ||
+ action.actionKey is MouseInputActionKey.Scroll
+ )
- private fun checkStartDragConditions(action: MouseInputAction): Boolean {
- return (action.actionKey is MouseInputActionKey.Screen) &&
- !action.actionKey.touchUp && !gameWindowsManager.isDragging
- }
+ private fun checkStartDragConditions(action: MouseInputAction): Boolean = (action.actionKey is MouseInputActionKey.Screen) &&
+ !action.actionKey.touchUp &&
+ !gameWindowsManager.isDragging
- private fun checkEndDragConditions(action: MouseInputAction): Boolean {
- return action.actionKey is MouseInputActionKey.Screen &&
- action.actionKey.touchUp && gameWindowsManager.isDragging
- }
+ private fun checkEndDragConditions(action: MouseInputAction): Boolean = action.actionKey is MouseInputActionKey.Screen &&
+ action.actionKey.touchUp &&
+ gameWindowsManager.isDragging
- private fun checkDragConditions(action: MouseInputAction): Boolean {
- return applicationContextRepository.isTouch() && action.actionKey is MouseInputActionKey.Dragged &&
- abs(action.screenY - dragStartY) >= DRAG_SENSITIVITY
- }
+ private fun checkDragConditions(action: MouseInputAction): Boolean = applicationContextRepository.isTouch() &&
+ action.actionKey is MouseInputActionKey.Dragged &&
+ abs(action.screenY - dragStartY) >= DRAG_SENSITIVITY
private fun clampScrollAmount() {
gameWindowsManager.creativeScrollAmount =
private val Block.isAutoselectable
get() = !isNone() && params.hasCollision
- private fun GameWorld.isCurrentBlockAutoselectable() =
- getForeMap(player.cursorX, player.cursorY).isAutoselectable
+ private fun GameWorld.isCurrentBlockAutoselectable() = getForeMap(player.cursorX, player.cursorY).isAutoselectable
private fun setPlayerDirectionToCursor() {
if (player.controlMode != Player.ControlMode.CURSOR) {
) /
GameWindowsConfigs.Creative.itemsGridRowHeight
- if (xOnGrid < 0 || xOnGrid >= GameWindowsConfigs.Creative.itemsInRow ||
- yOnGrid < 0 || yOnGrid >= GameWindowsConfigs.Creative.itemsInCol
+ if (xOnGrid < 0 ||
+ xOnGrid >= GameWindowsConfigs.Creative.itemsInRow ||
+ yOnGrid < 0 ||
+ yOnGrid >= GameWindowsConfigs.Creative.itemsInCol
) {
return null
}
return item.params.name
}
- override fun checkConditions(action: MouseInputAction): Boolean {
- return action.actionKey is MouseInputActionKey.None
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = action.actionKey is MouseInputActionKey.None
override fun handle(action: MouseInputAction) {
val pastCursorX = player.cursorX
private var buttonHoldTask: Timer.Task? = null
- override fun checkConditions(action: MouseInputAction): Boolean {
- return buttonHoldTask?.isScheduled == true ||
- (
- (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) &&
- action.isInsideHotbar(textureRegions) ||
- action.actionKey is MouseInputActionKey.Scroll
- ) &&
- gameWindowsManager.currentWindowType == GameWindowType.NONE
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = buttonHoldTask?.isScheduled == true ||
+ (
+ (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) &&
+ action.isInsideHotbar(textureRegions) ||
+ action.actionKey is MouseInputActionKey.Scroll
+ ) &&
+ gameWindowsManager.currentWindowType == GameWindowType.NONE
private fun cancelHold() {
buttonHoldTask?.cancel()
)
}
- private fun getActionSlot(action: MouseInputAction): Int {
- return (
- (
- action.screenX -
- (action.cameraViewport.width / 2 - hotbarTexture.regionWidth / 2)
- ) /
- HOTBAR_CELL_WIDTH
- ).toInt()
- }
+ private fun getActionSlot(action: MouseInputAction): Int = (
+ (
+ action.screenX -
+ (action.cameraViewport.width / 2 - hotbarTexture.regionWidth / 2)
+ ) /
+ HOTBAR_CELL_WIDTH
+ ).toInt()
private fun handleHold(action: MouseInputAction) {
// buttonHoldTask = null
val yOnContent = (yOnWindow - GameWindowsConfigs.Chest.contentsMarginTop) /
GameWindowsConfigs.Chest.itemsGridRowHeight
- val isInsideInventoryGrid = xOnGrid >= 0 && xOnGrid < GameWindowsConfigs.Chest.itemsInRow &&
- yOnGrid >= 0 && yOnGrid < GameWindowsConfigs.Chest.itemsInCol
-
- val isInsideContentGrid = xOnContent >= 0 && xOnContent < GameWindowsConfigs.Chest.contentsInRow &&
- yOnContent >= 0 && yOnContent < GameWindowsConfigs.Chest.contentsInCol
+ val isInsideInventoryGrid = xOnGrid >= 0 &&
+ xOnGrid < GameWindowsConfigs.Chest.itemsInRow &&
+ yOnGrid >= 0 &&
+ yOnGrid < GameWindowsConfigs.Chest.itemsInCol
+
+ val isInsideContentGrid = xOnContent >= 0 &&
+ xOnContent < GameWindowsConfigs.Chest.contentsInRow &&
+ yOnContent >= 0 &&
+ yOnContent < GameWindowsConfigs.Chest.contentsInCol
if (isInsideInventoryGrid) {
handleInsideInventoryGrid(action, xOnGrid.toInt(), yOnGrid.toInt())
val yOnCraft = (yOnWindow - GameWindowsConfigs.Crafting.craftOffsetY) /
GameWindowsConfigs.Crafting.itemsGridRowHeight
- val isInsideInventoryGrid = xOnGrid >= 0 && xOnGrid < GameWindowsConfigs.Crafting.itemsInRow &&
- yOnGrid >= 0 && yOnGrid < GameWindowsConfigs.Crafting.itemsInCol
-
- val isInsideCraftGrid = xOnCraft >= 0 && xOnCraft < GameWindowsConfigs.Crafting.craftGridSize &&
- yOnCraft >= 0 && yOnCraft < GameWindowsConfigs.Crafting.craftGridSize
+ val isInsideInventoryGrid = xOnGrid >= 0 &&
+ xOnGrid < GameWindowsConfigs.Crafting.itemsInRow &&
+ yOnGrid >= 0 &&
+ yOnGrid < GameWindowsConfigs.Crafting.itemsInCol
+
+ val isInsideCraftGrid = xOnCraft >= 0 &&
+ xOnCraft < GameWindowsConfigs.Crafting.craftGridSize &&
+ yOnCraft >= 0 &&
+ yOnCraft < GameWindowsConfigs.Crafting.craftGridSize
val isInsideCraftResult = xOnWindow > GameWindowsConfigs.Crafting.craftResultOffsetX &&
xOnWindow < GameWindowsConfigs.Crafting.craftResultOffsetX + GameWindowsConfigs.Crafting.itemsGridColWidth &&
private val creativeInventoryTexture get() = requireNotNull(textureRegions["creative"])
- override fun checkConditions(action: MouseInputAction): Boolean {
- return gameWindowsManager.currentWindowType == GameWindowType.CREATIVE_INVENTORY &&
- !gameWindowsManager.isDragging &&
- (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) &&
- action.actionKey.touchUp && isInsideWindow(action, creativeInventoryTexture)
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = gameWindowsManager.currentWindowType == GameWindowType.CREATIVE_INVENTORY &&
+ !gameWindowsManager.isDragging &&
+ (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Screen) &&
+ action.actionKey.touchUp &&
+ isInsideWindow(action, creativeInventoryTexture)
override fun handle(action: MouseInputAction) {
val creativeTexture = creativeInventoryTexture
) /
GameWindowsConfigs.Creative.itemsGridRowHeight
- if (xOnGrid < 0 || xOnGrid >= GameWindowsConfigs.Creative.itemsInRow ||
- yOnGrid < 0 || yOnGrid >= GameWindowsConfigs.Creative.itemsInCol
+ if (xOnGrid < 0 ||
+ xOnGrid >= GameWindowsConfigs.Creative.itemsInRow ||
+ yOnGrid < 0 ||
+ yOnGrid >= GameWindowsConfigs.Creative.itemsInCol
) {
return
}
yOnWindow > GameWindowsConfigs.Furnace.smeltResultOffsetY &&
yOnWindow < GameWindowsConfigs.Furnace.smeltResultOffsetY + GameWindowsConfigs.Furnace.itemsGridRowHeight
- val isInsideInventoryGrid = xOnGrid >= 0 && xOnGrid < GameWindowsConfigs.Furnace.itemsInRow &&
- yOnGrid >= 0 && yOnGrid < GameWindowsConfigs.Furnace.itemsInCol
+ val isInsideInventoryGrid = xOnGrid >= 0 &&
+ xOnGrid < GameWindowsConfigs.Furnace.itemsInRow &&
+ yOnGrid >= 0 &&
+ yOnGrid < GameWindowsConfigs.Furnace.itemsInCol
if (isInsideInventoryGrid) {
handleInsideInventoryGrid(action, xOnGrid.toInt(), yOnGrid.toInt())
val yOnCraft = (yOnWindow - GameWindowsConfigs.Survival.craftOffsetY) /
GameWindowsConfigs.Survival.itemsGridRowHeight
- val isInsideInventoryGrid = xOnGrid >= 0 && xOnGrid < GameWindowsConfigs.Survival.itemsInRow &&
- yOnGrid >= 0 && yOnGrid < GameWindowsConfigs.Survival.itemsInCol
-
- val isInsideCraftGrid = xOnCraft >= 0 && xOnCraft < GameWindowsConfigs.Survival.craftGridSize &&
- yOnCraft >= 0 && yOnCraft < GameWindowsConfigs.Survival.craftGridSize
+ val isInsideInventoryGrid = xOnGrid >= 0 &&
+ xOnGrid < GameWindowsConfigs.Survival.itemsInRow &&
+ yOnGrid >= 0 &&
+ yOnGrid < GameWindowsConfigs.Survival.itemsInCol
+
+ val isInsideCraftGrid = xOnCraft >= 0 &&
+ xOnCraft < GameWindowsConfigs.Survival.craftGridSize &&
+ yOnCraft >= 0 &&
+ yOnCraft < GameWindowsConfigs.Survival.craftGridSize
val isInsideCraftResult = xOnWindow > GameWindowsConfigs.Survival.craftResultOffsetX &&
xOnWindow < GameWindowsConfigs.Survival.craftResultOffsetX + GameWindowsConfigs.Survival.itemsGridColWidth &&
private var buttonHoldTask: Timer.Task? = null
- override fun checkConditions(action: MouseInputAction): Boolean {
- return buttonHoldTask?.isScheduled == true ||
- !action.isInsideHotbar(textureRegions) &&
- gameWindowsManager.currentWindowType == GameWindowType.NONE &&
- action.actionKey is MouseInputActionKey.Right
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = buttonHoldTask?.isScheduled == true ||
+ !action.isInsideHotbar(textureRegions) &&
+ gameWindowsManager.currentWindowType == GameWindowType.NONE &&
+ action.actionKey is MouseInputActionKey.Right
private fun cancelHold() {
buttonHoldTask?.cancel()
if (!value) {
resetVelocity()
if (TimeUtils.timeSinceMillis(activateTimeMs) < 200L &&
- mobController.player.controlMode != Player.ControlMode.CURSOR && mobController.player.canJump
+ mobController.player.controlMode != Player.ControlMode.CURSOR &&
+ mobController.player.canJump
) {
mobController.player.jump()
}
}
}
- override fun checkConditions(action: MouseInputAction): Boolean {
- return gameWindowsManager.currentWindowType == GameWindowType.NONE &&
- applicationContextRepository.isTouch() && action.actionKey is MouseInputActionKey.Touch && (action.actionKey.pointer == gameContextRepository.getJoystick().pointer || !active) && (
- (action.actionKey is MouseInputActionKey.Dragged) ||
- (action.screenX < action.cameraViewport.width / 2 && !action.actionKey.touchUp || active)
- ) && !(action.actionKey is MouseInputActionKey.Screen && action.isInsideHotbar(textureRegions))
- }
+ override fun checkConditions(action: MouseInputAction): Boolean = gameWindowsManager.currentWindowType == GameWindowType.NONE &&
+ applicationContextRepository.isTouch() &&
+ action.actionKey is MouseInputActionKey.Touch &&
+ (action.actionKey.pointer == gameContextRepository.getJoystick().pointer || !active) &&
+ (
+ (action.actionKey is MouseInputActionKey.Dragged) ||
+ (action.screenX < action.cameraViewport.width / 2 && !action.actionKey.touchUp || active)
+ ) &&
+ !(action.actionKey is MouseInputActionKey.Screen && action.isInsideHotbar(textureRegions))
private fun handleTouchDown(action: MouseInputAction) {
val key = action.actionKey as MouseInputActionKey.Screen
mouseY: Float,
cameraViewport: Rectangle,
pointer: Int,
- ): MouseInputAction {
- return MouseInputAction(
- screenX = getScreenX(mouseX),
- screenY = getScreenY(mouseY),
- actionKey = MouseInputActionKey.Dragged(pointer),
- cameraViewport = cameraViewport,
- )
- }
+ ): MouseInputAction = MouseInputAction(
+ screenX = getScreenX(mouseX),
+ screenY = getScreenY(mouseY),
+ actionKey = MouseInputActionKey.Dragged(pointer),
+ cameraViewport = cameraViewport,
+ )
fun mapScrolled(
mouseX: Float,
amountX: Float,
amountY: Float,
cameraViewport: Rectangle,
- ): MouseInputAction {
- return MouseInputAction(
- screenX = getScreenX(mouseX),
- screenY = getScreenY(mouseY),
- actionKey = MouseInputActionKey.Scroll(amountX, amountY),
- cameraViewport = cameraViewport,
- )
- }
+ ): MouseInputAction = MouseInputAction(
+ screenX = getScreenX(mouseX),
+ screenY = getScreenY(mouseY),
+ actionKey = MouseInputActionKey.Scroll(amountX, amountY),
+ cameraViewport = cameraViewport,
+ )
- private fun mapActionKey(button: Int, touchUp: Boolean, pointer: Int): MouseInputActionKey? {
- return when (button) {
- Input.Buttons.LEFT -> MouseInputActionKey.Left(touchUp)
- Input.Buttons.RIGHT -> MouseInputActionKey.Right(touchUp)
- Input.Buttons.MIDDLE -> MouseInputActionKey.Middle(touchUp)
- -1 -> MouseInputActionKey.Screen(touchUp, pointer)
- else -> null
- }
+ private fun mapActionKey(button: Int, touchUp: Boolean, pointer: Int): MouseInputActionKey? = when (button) {
+ Input.Buttons.LEFT -> MouseInputActionKey.Left(touchUp)
+ Input.Buttons.RIGHT -> MouseInputActionKey.Right(touchUp)
+ Input.Buttons.MIDDLE -> MouseInputActionKey.Middle(touchUp)
+ -1 -> MouseInputActionKey.Screen(touchUp, pointer)
+ else -> null
}
- private fun getScreenX(mouseX: Float): Float {
- return mouseX * (applicationContextRepository.getWidth() / Gdx.graphics.width)
- }
+ private fun getScreenX(mouseX: Float): Float = mouseX * (applicationContextRepository.getWidth() / Gdx.graphics.width)
- private fun getScreenY(mouseY: Float): Float {
- return mouseY * (applicationContextRepository.getHeight() / Gdx.graphics.height)
- }
+ private fun getScreenY(mouseY: Float): Float = mouseY * (applicationContextRepository.getHeight() / Gdx.graphics.height)
}
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private val getStringWidth: GetStringWidthUseCase,
private val getStringHeight: GetStringHeightUseCase,
private val getFont: GetFontUseCase,
-) : AbstractWindowRenderer(), IGameRenderer {
+) : AbstractWindowRenderer(),
+ IGameRenderer {
override val renderLayer get() = WindowsRenderer.Companion.RENDER_LAYER
private val getStringWidth: GetStringWidthUseCase,
private val getStringHeight: GetStringHeightUseCase,
private val getFont: GetFontUseCase,
-) : AbstractWindowRenderer(), IGameRenderer {
+) : AbstractWindowRenderer(),
+ IGameRenderer {
override val renderLayer get() = WindowsRenderer.Companion.RENDER_LAYER
private val getStringWidth: GetStringWidthUseCase,
private val getStringHeight: GetStringHeightUseCase,
private val getFont: GetFontUseCase,
-) : AbstractWindowRenderer(), IGameRenderer {
+) : AbstractWindowRenderer(),
+ IGameRenderer {
override val renderLayer get() = WindowsRenderer.Companion.RENDER_LAYER
private val getStringWidth: GetStringWidthUseCase,
private val getStringHeight: GetStringHeightUseCase,
private val getFont: GetFontUseCase,
-) : AbstractWindowRenderer(), IGameRenderer {
+) : AbstractWindowRenderer(),
+ IGameRenderer {
override val renderLayer get() = WindowsRenderer.Companion.RENDER_LAYER
private val getStringWidth: GetStringWidthUseCase,
private val getStringHeight: GetStringHeightUseCase,
private val getFont: GetFontUseCase,
-) : AbstractWindowRenderer(), IGameRenderer {
+) : AbstractWindowRenderer(),
+ IGameRenderer {
override val renderLayer get() = WindowsRenderer.Companion.RENDER_LAYER
plugins {
kotlin
ksp
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private val isTouchScreen: Boolean,
private val isDebug: Boolean,
private val preferencesStore: PreferencesStore,
-) : Game(), ApplicationController {
+) : Game(),
+ ApplicationController {
lateinit var applicationComponent: ApplicationComponent
private set
private var gameComponent: GameComponent? = null
- private fun getGameContext(isLoadGame: Boolean): GameContext {
- return GameContext(
- isLoadGame = isLoadGame,
- showInfo = false,
- showMap = false,
- joystick = Joystick(Player.SPEED),
- cameraContext = CameraContext(
- viewport = Rectangle(
- /* x = */ 0f,
- /* y = */ 0f,
- /* width = */ applicationContextRepository.getWidth(),
- /* height = */ applicationContextRepository.getHeight(),
- ),
- camera = OrthographicCamera().apply {
- setToOrtho(
- /* yDown = */ true,
- /* viewportWidth = */ applicationContextRepository.getWidth(),
- /* viewportHeight = */ applicationContextRepository.getHeight(),
- )
- },
+ private fun getGameContext(isLoadGame: Boolean): GameContext = GameContext(
+ isLoadGame = isLoadGame,
+ showInfo = false,
+ showMap = false,
+ joystick = Joystick(Player.SPEED),
+ cameraContext = CameraContext(
+ viewport = Rectangle(
+ /* x = */ 0f,
+ /* y = */ 0f,
+ /* width = */ applicationContextRepository.getWidth(),
+ /* height = */ applicationContextRepository.getHeight(),
),
- )
- }
+ camera = OrthographicCamera().apply {
+ setToOrtho(
+ /* yDown = */ true,
+ /* viewportWidth = */ applicationContextRepository.getWidth(),
+ /* viewportHeight = */ applicationContextRepository.getHeight(),
+ )
+ },
+ ),
+ )
private fun getGameComponent(isLoadGame: Boolean): GameComponent {
val gameContext = getGameContext(isLoadGame)
saveDataRepository: SaveDataRepository,
itemsRepository: ItemsRepository,
dropWorldAdapter: DropWorldAdapter,
- ): DropController {
- return if (gameContextRepository.isLoadGame()) {
- saveDataRepository.loadDropController(
- gameDataFolder = applicationContextRepository.getGameDirectory(),
- dropWorldAdapter = dropWorldAdapter,
- )
- } else {
- DropController(
- itemsRepository = itemsRepository,
- dropWorldAdapter = dropWorldAdapter,
- )
- }
+ ): DropController = if (gameContextRepository.isLoadGame()) {
+ saveDataRepository.loadDropController(
+ gameDataFolder = applicationContextRepository.getGameDirectory(),
+ dropWorldAdapter = dropWorldAdapter,
+ )
+ } else {
+ DropController(
+ itemsRepository = itemsRepository,
+ dropWorldAdapter = dropWorldAdapter,
+ )
}
@Provides
containerWorldAdapter: ContainerWorldAdapter,
containerFactory: ContainerFactory,
dropAdapter: DropAdapter,
- ): ContainerController {
- return if (gameContextRepository.isLoadGame()) {
- saveDataRepository.loadContainerController(
- gameDataFolder = applicationContextRepository.getGameDirectory(),
- containerWorldAdapter = containerWorldAdapter,
- containerFactory = containerFactory,
- dropAdapter = dropAdapter,
- )
- } else {
- ContainerController(
- getItemByKeyUseCase = getItemByKeyUseCase,
- containerWorldAdapter = containerWorldAdapter,
- containerFactory = containerFactory,
- dropAdapter = dropAdapter,
- )
- }
+ ): ContainerController = if (gameContextRepository.isLoadGame()) {
+ saveDataRepository.loadContainerController(
+ gameDataFolder = applicationContextRepository.getGameDirectory(),
+ containerWorldAdapter = containerWorldAdapter,
+ containerFactory = containerFactory,
+ dropAdapter = dropAdapter,
+ )
+ } else {
+ ContainerController(
+ getItemByKeyUseCase = getItemByKeyUseCase,
+ containerWorldAdapter = containerWorldAdapter,
+ containerFactory = containerFactory,
+ dropAdapter = dropAdapter,
+ )
}
@Provides
mobAssetsRepository: MobAssetsRepository,
getFallbackItemUseCase: GetFallbackItemUseCase,
mobWorldAdapter: MobWorldAdapter,
- ): MobController {
- return if (gameContextRepository.isLoadGame()) {
- saveDataRepository.loadMobController(
- gameDataFolder = applicationContextRepository.getGameDirectory(),
- mobWorldAdapter = mobWorldAdapter,
- )
- } else {
- MobController(
- mobAssetsRepository = mobAssetsRepository,
- getFallbackItemUseCase = getFallbackItemUseCase,
- mobWorldAdapter = mobWorldAdapter,
- )
- }
+ ): MobController = if (gameContextRepository.isLoadGame()) {
+ saveDataRepository.loadMobController(
+ gameDataFolder = applicationContextRepository.getGameDirectory(),
+ mobWorldAdapter = mobWorldAdapter,
+ )
+ } else {
+ MobController(
+ mobAssetsRepository = mobAssetsRepository,
+ getFallbackItemUseCase = getFallbackItemUseCase,
+ mobWorldAdapter = mobWorldAdapter,
+ )
}
@Provides
gameController.loadGame()
}
- override fun canPerform(): Boolean {
- return saveDataRepository.exists(applicationContextRepository.getGameDirectory())
- }
+ override fun canPerform(): Boolean = saveDataRepository.exists(applicationContextRepository.getGameDirectory())
companion object {
const val KEY = "load_game_action"
return true
}
- override fun keyDown(keycode: Int): Boolean {
- return false
- }
+ override fun keyDown(keycode: Int): Boolean = false
- override fun keyUp(keycode: Int): Boolean {
- return false
- }
+ override fun keyUp(keycode: Int): Boolean = false
- override fun keyTyped(character: Char): Boolean {
- return false
- }
+ override fun keyTyped(character: Char): Boolean = false
override fun touchDown(
screenX: Int,
screenY: Int,
pointer: Int,
button: Int,
- ): Boolean {
- return false
- }
+ ): Boolean = false
override fun touchCancelled(
screenX: Int,
screenY: Int,
pointer: Int,
button: Int,
- ): Boolean {
- return false
- }
+ ): Boolean = false
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return false
- }
+ override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean = false
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return false
- }
+ override fun mouseMoved(screenX: Int, screenY: Int): Boolean = false
- override fun scrolled(amountX: Float, amountY: Float): Boolean {
- return false
- }
+ override fun scrolled(amountX: Float, amountY: Float): Boolean = false
companion object {
private const val TAG = "MenuInputProcessor"
private val applicationContextRepository: ApplicationContextRepository,
) : IMenuBooleanOption {
- override fun getOption(): Boolean {
- return applicationContextRepository.useDynamicCamera()
- }
+ override fun getOption(): Boolean = applicationContextRepository.useDynamicCamera()
override fun toggleOption() {
applicationContextRepository.setUseDynamicCamera(!getOption())
private val applicationContextRepository: ApplicationContextRepository,
) : IMenuBooleanOption {
- override fun getOption(): Boolean {
- return applicationContextRepository.isFullscreen()
- }
+ override fun getOption(): Boolean = applicationContextRepository.isFullscreen()
override fun toggleOption() {
applicationContextRepository.setFullscreen(!getOption())
plugins {
kotlin
- ktlintGradle
}
java.sourceCompatibility = ApplicationInfo.sourceCompatibility
private val prefs = Preferences.userNodeForPackage(DesktopPreferencesStore::class.java)
- override fun getPreference(key: String): String? {
- return prefs.get(key, null)
- }
+ override fun getPreference(key: String): String? = prefs.get(key, null)
override fun setPreference(key: String, value: String?) {
prefs.put(key, value)