summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 26df40f)
raw | patch | inline | side by side (parent: 26df40f)
author | fredboy <fredboy@protonmail.com> | |
Mon, 22 Apr 2024 09:25:41 +0000 (16:25 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Mon, 22 Apr 2024 09:25:41 +0000 (16:25 +0700) |
diff --git a/build.gradle b/build.gradle
index 1f0b0e166b708d4759c3a0f1cc2f9dac76094c11..375d55d4c890d2c9f1a8825106fd551a094da7ee 100644 (file)
--- a/build.gradle
+++ b/build.gradle
dependencies {
implementation project(":core")
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion"
api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 7f517df7b1ead5f070110a3ad7c50c1863f425ef..46cb8cd1fc250d8fab4582ba23cad5e67e19b114 100644 (file)
}
final Sprite sprite = item.getSprite();
+ final boolean smallSprite = !item.isTool() || item.isShears();
- if (!item.isTool()) {
+ if (smallSprite) {
sprite.setSize(Drop.DROP_SIZE, Drop.DROP_SIZE);
}
final SpriteOrigin spriteOrigin = item.getParams().getInHandSpriteOrigin();
final int handMultiplier = -getDirection().getBasis();
final float xOffset = (-1 + getDirection().getIndex()) * sprite.getWidth() + 4 + handMultiplier * (sprite.getWidth() * spriteOrigin.getX());
- final float yOffset = item.isTool() ? -sprite.getHeight() / 2 : 0;
+ final float yOffset = !smallSprite ? -sprite.getHeight() / 2 : 0;
float rotate = anim + 30;
sprite.setFlip(false, sprite.isFlipY());
sprite.setRotation(0);
sprite.setOriginCenter();
- sprite.rotate90(looksRight());
+ if (item.isTool()) {
+ sprite.rotate90(looksRight());
+ }
}
public void startHitting() {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt
index 2b6b5fcd2498e82c29e925a685473dafd1d0e360..7eeb9403a88a636f843998a18b98188bbedaf2c0 100644 (file)
return this is Slab
}
-
fun isTool(): Boolean {
contract { returns(true) implies (this@Item is Tool) }
return this is Tool
}
+ fun isShears(): Boolean {
+ contract { returns(true) implies (this@Item is Shears) }
+ return this is Shears
+ }
+
fun isUsable(): Boolean {
contract { returns(true) implies (this@Item is Placeable) }
return this is Placeable
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt
index 667d92b0e897975a5ea05e75dcc304680fe97c8f..8373e02febd5189095af8919f9ae594b7da9cb70 100644 (file)
import ru.deadsoftware.cavedroid.game.model.dto.BlockDto
import ru.deadsoftware.cavedroid.game.model.item.Item
import ru.deadsoftware.cavedroid.misc.Assets
+import ru.deadsoftware.cavedroid.misc.utils.AssetLoader
import javax.inject.Inject
@Reusable
-class BlockMapper @Inject constructor() {
+class BlockMapper @Inject constructor(
+ private val assetLoader: AssetLoader,
+) {
fun map(key: String, dto: BlockDto): Block {
val commonBlockParams = mapCommonParams(key, dto)
return null
}
- return Assets.blockTextures[textureName]
+ return Assets.resolveBlockTexture(assetLoader, textureName)
}
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt
index 6bcad04d5c454e0f516526d3abb3c8a4c5b7582f..1e6b528b5cce8c99e3b59c3f9436f557ef7e3597 100644 (file)
import ru.deadsoftware.cavedroid.game.model.item.Item
import ru.deadsoftware.cavedroid.game.model.item.Item.*
import ru.deadsoftware.cavedroid.misc.Assets
+import ru.deadsoftware.cavedroid.misc.utils.AssetLoader
import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin
import javax.inject.Inject
@Reusable
-class ItemMapper @Inject constructor() {
+class ItemMapper @Inject constructor(
+ private val assetLoader: AssetLoader,
+) {
fun map(key: String, dto: ItemDto, block: Block?, slabTopBlock: Block.Slab?, slabBottomBlock: Block.Slab?): Item {
val params = mapCommonParams(key, dto)
return null
}
- return Sprite(Assets.itemTextures[dto.texture])
+ val texture = Assets.resolveItemTexture(assetLoader, dto.texture)
+ return Sprite(texture)
.apply { flip(false, true) }
}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java
index abec0a0b2f5f0a4ecac1a6128b1a3f622445f1a1..6a4305f4a5273a2a79a36f13940e07bcb1cd7467 100644 (file)
import ru.deadsoftware.cavedroid.game.objects.TouchButton;
import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
+import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
}
}
+ private static Texture resolveTexture(AssetLoader assetLoader, String textureName, String lookUpPath, Map<String, Texture> cache) {
+ if (cache.containsKey(textureName)) {
+ return cache.get(textureName);
+ }
+
+ final Texture texture = loadTexture(assetLoader.getAssetHandle(lookUpPath + File.separator + textureName + ".png"));
+ cache.put(textureName, texture);
+
+ return texture;
+ }
+
+ public static Texture resolveItemTexture(AssetLoader assetLoader, String textureName) {
+ return resolveTexture(assetLoader, textureName, "textures/items", itemTextures);
+ }
+
+ public static Texture resolveBlockTexture(AssetLoader assetLoader, String textureName) {
+ return resolveTexture(assetLoader, textureName, "textures/blocks", blockTextures);
+ }
+
private static void loadAllPngsFromDirInto(FileHandle dir, Map<String, Texture> loadInto) {
for (FileHandle handle : dir.list((d, name) -> name.endsWith(".png"))) {
loadInto.put(handle.nameWithoutExtension(), loadTexture(handle));
diff --git a/desktop/build.gradle b/desktop/build.gradle
index 3436d706d7d6b68dda0a0bdfba095c7614331abe..70a63ba56bc3d5f3207941b4c50ac64eab09ee3e 100644 (file)
--- a/desktop/build.gradle
+++ b/desktop/build.gradle
-apply plugin: "kotlin"
+plugins {
+ id 'kotlin'
+ id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlinVersion"
+}
sourceCompatibility = 17
sourceSets.main.java.srcDirs = [ "src/" ]