summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0f7f855)
raw | patch | inline | side by side (parent: 0f7f855)
author | fred-boy <fredboy@protonmail.com> | |
Mon, 15 Jun 2020 20:52:44 +0000 (03:52 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Tue, 16 Jun 2020 11:57:48 +0000 (18:57 +0700) |
core/src/ru/deadsoftware/cavedroid/game/objects/Item.java | [deleted file] | patch | blob | history |
core/src/ru/deadsoftware/cavedroid/game/objects/Item.kt | [new file with mode: 0644] | patch | blob |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Item.java b/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
--- /dev/null
@@ -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