From 7bf180238135ffc4924d511b7d196d0b5538e96f Mon Sep 17 00:00:00 2001 From: fred-boy Date: Tue, 16 Jun 2020 03:52:44 +0700 Subject: [PATCH] Closes #22: Rewrite Item class as Kotlin data class --- .../cavedroid/game/objects/Item.java | 40 ------------------- .../cavedroid/game/objects/Item.kt | 22 ++++++++++ 2 files changed, 22 insertions(+), 40 deletions(-) delete mode 100644 core/src/ru/deadsoftware/cavedroid/game/objects/Item.java create mode 100644 core/src/ru/deadsoftware/cavedroid/game/objects/Item.kt diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java deleted file mode 100644 index 8e664ac..0000000 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java +++ /dev/null @@ -1,40 +0,0 @@ -package ru.deadsoftware.cavedroid.game.objects; - -import com.badlogic.gdx.graphics.g2d.Sprite; - -import javax.annotation.CheckForNull; - -public class Item { - - private final String name; - private final String type; - @CheckForNull - private final Sprite tex; - - public Item(String name, String type, @CheckForNull Sprite tex) { - this.name = name; - this.type = type; - this.tex = tex; - if (this.tex != null) { - this.tex.flip(false, true); - } - } - - public Sprite getTexture() { - assert tex != null; - return tex; - } - - public String getType() { - return type; - } - - public boolean isBlock() { - return type.equals("block"); - } - - public String getName() { - return name; - } - -} \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Item.kt b/core/src/ru/deadsoftware/cavedroid/game/objects/Item.kt new file mode 100644 index 0000000..59d231d --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Item.kt @@ -0,0 +1,22 @@ +package ru.deadsoftware.cavedroid.game.objects + +import com.badlogic.gdx.graphics.g2d.Sprite + +data class Item( + val name: String, + val type: String, + val sprite: Sprite? +) { + + init { + sprite?.flip(false, true) + } + + fun requireSprite() = sprite ?: throw IllegalStateException("Sprite is null") + + fun isBlock() = type == "block" + + @Deprecated("Was renamed to Sprite to comply with variable type.", ReplaceWith("requireSprite()")) + fun getTexture() = sprite + +} \ No newline at end of file -- 2.29.2