summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-10-07 02:35:36 +0500
committerilotterytea <iltsu@alright.party>2024-10-07 02:35:36 +0500
commit2451b7d78a1f0bd9df1d01f254c30a14b731688a (patch)
tree3d36f3c4ff1788dc7c1f43ee205e38285fc54544 /core
parent3de9d004e99851f38f8700839fa2f7aa6f1c0172 (diff)
upd: splitToTextureRegions returns now ArrayList because default arrays fucking suck
Diffstat (limited to 'core')
-rw-r--r--core/src/kz/ilotterytea/maxon/anim/SpriteUtils.java9
-rw-r--r--core/src/kz/ilotterytea/maxon/pets/Pet.java9
-rw-r--r--core/src/kz/ilotterytea/maxon/player/DecalPlayer.java12
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java26
4 files changed, 32 insertions, 24 deletions
diff --git a/core/src/kz/ilotterytea/maxon/anim/SpriteUtils.java b/core/src/kz/ilotterytea/maxon/anim/SpriteUtils.java
index 3bc5712..d7ca027 100644
--- a/core/src/kz/ilotterytea/maxon/anim/SpriteUtils.java
+++ b/core/src/kz/ilotterytea/maxon/anim/SpriteUtils.java
@@ -3,10 +3,10 @@ package kz.ilotterytea.maxon.anim;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import java.util.Arrays;
+import java.util.ArrayList;
public class SpriteUtils {
- public static TextureRegion[] splitToTextureRegions(
+ public static ArrayList<TextureRegion> splitToTextureRegions(
Texture texture,
int tileWidth,
int tileHeight,
@@ -14,14 +14,15 @@ public class SpriteUtils {
int rows
) {
TextureRegion[][] tmp = TextureRegion.split(texture, tileWidth, tileHeight);
- TextureRegion[] frames = new TextureRegion[(texture.getWidth() / columns) + (texture.getHeight() / rows)];
+
+ ArrayList<TextureRegion> frames = new ArrayList<>();
int index = 0;
for (TextureRegion[] regArray : tmp) {
for (TextureRegion reg : regArray) {
if (reg != null) {
- frames[index++] = reg;
+ frames.add(reg);
}
}
}
diff --git a/core/src/kz/ilotterytea/maxon/pets/Pet.java b/core/src/kz/ilotterytea/maxon/pets/Pet.java
index 7c69a0b..521df0c 100644
--- a/core/src/kz/ilotterytea/maxon/pets/Pet.java
+++ b/core/src/kz/ilotterytea/maxon/pets/Pet.java
@@ -11,6 +11,9 @@ import kz.ilotterytea.maxon.ui.AnimatedImage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
+
public class Pet {
private final String id, name, description;
private final double price, multiplier;
@@ -30,7 +33,7 @@ public class Pet {
public static Pet create(String id, double price, double multiplier, int iconColumns, int iconRows) {
MaxonGame game = MaxonGame.getInstance();
- TextureRegion[] regions;
+ ArrayList<TextureRegion> regions;
try {
Texture texture = game.assetManager.get("sprites/pets/" + id + ".png", Texture.class);
@@ -44,7 +47,7 @@ public class Pet {
} catch (GdxRuntimeException e) {
logger.warn("Failed to load icon spritesheet for ID {}", id);
- regions = new TextureRegion[]{new TextureRegion(MaxonConstants.MISSING_TEXTURE)};
+ regions = new ArrayList<>(List.of(new TextureRegion(MaxonConstants.MISSING_TEXTURE)));
}
AnimatedImage icon = new AnimatedImage(regions, 5);
@@ -59,7 +62,7 @@ public class Pet {
description = "pet." + id + ".desc";
}
- Decal decal = Decal.newDecal(0.5f, 0.5f, regions[0], true);
+ Decal decal = Decal.newDecal(0.5f, 0.5f, regions.get(0), true);
return new Pet(id, name, description, price, multiplier, icon, decal);
}
diff --git a/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java b/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java
index 5ce2abe..d7cb680 100644
--- a/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java
+++ b/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java
@@ -11,20 +11,22 @@ import com.badlogic.gdx.math.collision.BoundingBox;
import com.badlogic.gdx.math.collision.Ray;
import kz.ilotterytea.maxon.MaxonGame;
+import java.util.ArrayList;
+
public class DecalPlayer {
- private final TextureRegion[] regions;
+ private final ArrayList<TextureRegion> regions;
private int regionIndex;
private final Decal decal;
private final BoundingBox box;
private final Savegame savegame;
- public DecalPlayer(Savegame savegame, TextureRegion[] regions) {
+ public DecalPlayer(Savegame savegame, ArrayList<TextureRegion> regions) {
this.savegame = savegame;
this.regions = regions;
this.regionIndex = 0;
- this.decal = Decal.newDecal(this.regions[this.regionIndex]);
+ this.decal = Decal.newDecal(this.regions.get(this.regionIndex));
this.decal.setScale(0.025f);
this.decal.setPosition(2.0f, 1.75f, 2.0f);
@@ -67,11 +69,11 @@ public class DecalPlayer {
private void updateTextureRegion() {
this.regionIndex++;
- if (this.regions[this.regionIndex] == null) {
+ if (this.regions.get(this.regionIndex) == null) {
this.regionIndex = 0;
}
- this.decal.setTextureRegion(this.regions[this.regionIndex]);
+ this.decal.setTextureRegion(this.regions.get(this.regionIndex));
}
public Decal getDecal() {
diff --git a/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java b/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java
index e6278c5..d1f5b90 100644
--- a/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java
+++ b/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java
@@ -6,37 +6,39 @@ import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Disposable;
+import java.util.ArrayList;
+
public class AnimatedImage extends Image implements Disposable {
- private final TextureRegion[] regions;
+ private final ArrayList<TextureRegion> regions;
private final int fps;
private int index = 0, seconds = 0;
private boolean stopAnim = false;
- public AnimatedImage(TextureRegion[] regions) {
- super(regions[0]);
+ public AnimatedImage(ArrayList<TextureRegion> regions) {
+ super(regions.get(0));
this.regions = regions;
this.fps = 0;
}
- public AnimatedImage(TextureRegion[] regions, int fps) {
- super(regions[0]);
+ public AnimatedImage(ArrayList<TextureRegion> regions, int fps) {
+ super(regions.get(0));
this.regions = regions;
this.fps = fps;
}
@Override public void act(float delta) {
if (!stopAnim && seconds >= fps) {
- if (index > regions.length - 1) {
+ if (index > regions.size() - 1) {
index = 0;
}
try {
- if (regions[index + 1] == null) {
+ if (regions.get(index + 1) == null) {
index = 0;
}
- } catch (ArrayIndexOutOfBoundsException ignored) {}
+ } catch (IndexOutOfBoundsException ignored) {}
- super.setDrawable(new TextureRegionDrawable(regions[index]));
+ super.setDrawable(new TextureRegionDrawable(regions.get(index)));
index++;
seconds = 0;
}
@@ -45,18 +47,18 @@ public class AnimatedImage extends Image implements Disposable {
super.act(delta);
}
- public TextureRegion getFrame(int index) { return regions[index]; }
+ public TextureRegion getFrame(int index) { return regions.get(index); }
public int getIndex() { return index; }
public Drawable getDrawable() { return super.getDrawable(); }
public void nextFrame() {
index++;
- if (index > regions.length - 1 || regions[index] == null) {
+ if (index > regions.size() - 1 || regions.get(index) == null) {
index = 0;
}
- super.setDrawable(new TextureRegionDrawable(regions[index]));
+ super.setDrawable(new TextureRegionDrawable(regions.get(index)));
}
public void disableAnim() { stopAnim = true; }