summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-06-08 16:30:25 +0500
committerilotterytea <iltsu@alright.party>2024-06-09 19:27:32 +0500
commit604832dddef852a0a874b9dfbf3540a8a56736c0 (patch)
tree07604a0be9258f2c7568ad64d9dc0c7160b227f6
parentdc99bd738b1a4b38112f767c3253724d0ff0587c (diff)
feat/upd: new savegame loader + updated constructors
-rw-r--r--core/src/kz/ilotterytea/maxon/MaxonConstants.java6
-rw-r--r--core/src/kz/ilotterytea/maxon/MaxonGame.java6
-rw-r--r--core/src/kz/ilotterytea/maxon/player/DecalPlayer.java6
-rw-r--r--core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java40
-rw-r--r--core/src/kz/ilotterytea/maxon/player/Savegame.java130
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/GameScreen.java49
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/MenuScreen.java18
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/SplashScreen.java6
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java9
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java26
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/OptionsTable.java4
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java26
-rw-r--r--core/src/kz/ilotterytea/maxon/utils/serialization/GameDataSystem.java120
13 files changed, 201 insertions, 245 deletions
diff --git a/core/src/kz/ilotterytea/maxon/MaxonConstants.java b/core/src/kz/ilotterytea/maxon/MaxonConstants.java
index 08df03c..298e6d8 100644
--- a/core/src/kz/ilotterytea/maxon/MaxonConstants.java
+++ b/core/src/kz/ilotterytea/maxon/MaxonConstants.java
@@ -9,9 +9,11 @@ import java.text.SimpleDateFormat;
public class MaxonConstants {
public static final String GAME_NAME = "Maxon Petting Simulator";
+ public static final String GAME_APP_ID = "maxon";
public static final String GAME_VERSION = "Alpha 1.2";
public static final String GAME_GHTAG = "alpha-1.2";
- public static final String GAME_PUBLISHER = "iLotterytea";
+ public static final String GAME_MAIN_DEVELOPER = "ilotterytea";
+
public static final String[][] GAME_DEVELOPERS = {
{"ilotterytea", "https://ilotterytea.kz"},
{"greddyss", "https://twitch.tv/greddyss"},
@@ -21,7 +23,7 @@ public class MaxonConstants {
{"gvardovskiy", "https://twitch.tv/gvardovskiy"}
};
- public static final String GAME_MAIN_FOLDER = OsUtils.getUserDataDirectory(".Maxoning");
+ public static final String GAME_MAIN_FOLDER = OsUtils.getUserDataDirectory(GAME_MAIN_DEVELOPER + "/" + GAME_APP_ID);
public static final String GAME_SCREENSHOT_FOLDER = GAME_MAIN_FOLDER + "/screenshots";
public static final String GAME_SAVEGAME_FOLDER = GAME_MAIN_FOLDER + "/savegames";
diff --git a/core/src/kz/ilotterytea/maxon/MaxonGame.java b/core/src/kz/ilotterytea/maxon/MaxonGame.java
index b1e40d6..1da8605 100644
--- a/core/src/kz/ilotterytea/maxon/MaxonGame.java
+++ b/core/src/kz/ilotterytea/maxon/MaxonGame.java
@@ -24,7 +24,7 @@ public class MaxonGame extends Game {
}
return instance;
}
-
+
@Override
public void create () {
batch = new SpriteBatch();
@@ -41,14 +41,14 @@ public class MaxonGame extends Game {
assetManager = new AssetManager();
- this.setScreen(new SplashScreen(this));
+ this.setScreen(new SplashScreen());
}
@Override
public void render () {
super.render();
}
-
+
@Override
public void dispose () {
batch.dispose();
diff --git a/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java b/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java
index ca6d65e..60faf9b 100644
--- a/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java
+++ b/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java
@@ -14,9 +14,9 @@ public class DecalPlayer {
private int regionIndex;
private final Decal decal;
private final BoundingBox box;
- private final MaxonSavegame savegame;
+ private final Savegame savegame;
- public DecalPlayer(MaxonSavegame savegame, TextureRegion[] regions) {
+ public DecalPlayer(Savegame savegame, TextureRegion[] regions) {
this.savegame = savegame;
this.regions = regions;
@@ -55,7 +55,7 @@ public class DecalPlayer {
if (Intersector.intersectRayBounds(ray, box, intersection)) {
updateTextureRegion();
- savegame.points++;
+ savegame.increaseMoney(1);
}
}
diff --git a/core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java b/core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java
deleted file mode 100644
index e0fe34c..0000000
--- a/core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package kz.ilotterytea.maxon.player;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-
-/**
- * Save-game data class.
- * @author NotDankEnough
- * @since Alpha 1.2 (Oct 02, 2022)
- */
-public class MaxonSavegame implements Serializable {
- /** Earned Squish Points. */
- public long points = 0L;
- /** Multiplier. */
- public long multiplier = 1;
-
- /** Home inventory. */
- public ArrayList<Integer> inv = new ArrayList<>();
- /** Outside Inventory. */
- public ArrayList<Integer> outInv = new ArrayList<>();
-
- /** Seed. */
- public long seed = System.currentTimeMillis();
-
- /** Player name. */
- public String name = System.getProperty("user.name");
- /** Pet name. */
- public String petName = "Maxon";
- /** Pet ID. */
- public byte petId = 0;
-
- /** Elapsed time from game start. */
- public long elapsedTime = 0;
-
- /** Last timestamp when save game was used. */
- public long lastTimestamp = System.currentTimeMillis();
-
- /** Location. */
- public short roomId = 0;
-} \ No newline at end of file
diff --git a/core/src/kz/ilotterytea/maxon/player/Savegame.java b/core/src/kz/ilotterytea/maxon/player/Savegame.java
new file mode 100644
index 0000000..fb955c6
--- /dev/null
+++ b/core/src/kz/ilotterytea/maxon/player/Savegame.java
@@ -0,0 +1,130 @@
+package kz.ilotterytea.maxon.player;
+
+
+import com.badlogic.gdx.Gdx;
+import com.google.gson.Gson;
+import kz.ilotterytea.maxon.MaxonConstants;
+import kz.ilotterytea.maxon.utils.OsUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.ArrayList;
+
+public class Savegame implements Serializable {
+ private static final File directory = new File(MaxonConstants.GAME_SAVEGAME_FOLDER);
+ private static final File file = new File(
+ String.format(
+ "%s/savegame.maxon",
+ (OsUtils.isAndroid || OsUtils.isIos)
+ ? Gdx.files.getExternalStoragePath()
+ : directory.getAbsolutePath()
+ )
+ );
+ private static final Gson gson = new Gson();
+ private static final Logger logger = LoggerFactory.getLogger(Savegame.class);
+
+ private double money = 0.0f, multiplier = 0.0f;
+ private final ArrayList<Integer> purchasedPets = new ArrayList<>();
+ private String name = System.getProperty("user.name", "Maxon");
+ private long elapsedTime = 0;
+ private boolean isNewlyCreated = true;
+
+ private Savegame() {}
+
+ public static Savegame load() {
+ if (!file.exists()) {
+ return new Savegame();
+ }
+
+ try {
+ FileInputStream fis = new FileInputStream(file);
+ ObjectInputStream ois = new ObjectInputStream(fis);
+
+ Savegame savegame = gson.fromJson(ois.readUTF(), Savegame.class);
+ ois.close();
+
+ savegame.isNewlyCreated = false;
+
+ logger.info("Loaded the savegame");
+
+ return savegame;
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to load savegame", e);
+ }
+ }
+
+ public void save() {
+ if (!directory.exists()) {
+ directory.mkdirs();
+ }
+
+ try {
+ FileOutputStream fos = new FileOutputStream(file);
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+
+ oos.writeUTF(gson.toJson(this));
+ oos.close();
+
+ logger.info("Saved the game");
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to save the game", e);
+ }
+ }
+
+ public double getMoney() {
+ return money;
+ }
+
+ public void setMoney(double money) {
+ this.money = money;
+ }
+
+ public void increaseMoney(double money) {
+ this.money += money;
+ }
+
+ public void decreaseMoney(double money) {
+ this.money -= money;
+ }
+
+ public double getMultiplier() {
+ return multiplier;
+ }
+
+ public void setMultiplier(double multiplier) {
+ this.multiplier = multiplier;
+ }
+
+ public void increaseMultiplier(double multiplier) {
+ this.multiplier += multiplier;
+ }
+
+ public void decreaseMultiplier(double multiplier) {
+ this.multiplier -= multiplier;
+ }
+
+ public ArrayList<Integer> getPurchasedPets() {
+ return purchasedPets;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getElapsedTime() {
+ return elapsedTime;
+ }
+
+ public void setElapsedTime(long elapsedTime) {
+ this.elapsedTime = elapsedTime;
+ }
+
+ public boolean isNewlyCreated() {
+ return isNewlyCreated;
+ }
+}
diff --git a/core/src/kz/ilotterytea/maxon/screens/GameScreen.java b/core/src/kz/ilotterytea/maxon/screens/GameScreen.java
index 649cd1e..6922077 100644
--- a/core/src/kz/ilotterytea/maxon/screens/GameScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/GameScreen.java
@@ -26,11 +26,10 @@ import kz.ilotterytea.maxon.inputprocessors.CrossProcessor;
import kz.ilotterytea.maxon.player.DecalPlayer;
import kz.ilotterytea.maxon.player.MaxonItem;
import kz.ilotterytea.maxon.player.MaxonItemRegister;
-import kz.ilotterytea.maxon.player.MaxonSavegame;
+import kz.ilotterytea.maxon.player.Savegame;
import kz.ilotterytea.maxon.screens.game.shop.ShopUI;
import kz.ilotterytea.maxon.ui.*;
import kz.ilotterytea.maxon.utils.math.Math;
-import kz.ilotterytea.maxon.utils.serialization.GameDataSystem;
import com.rafaskoberg.gdx.typinglabel.TypingLabel;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
@@ -48,11 +47,10 @@ import java.util.Map;
public class GameScreen implements Screen, InputProcessor {
final MaxonGame game;
- final int slotId;
final long playTimestamp;
boolean isShopping = false, isInventoryEnabled = false;
- MaxonSavegame player;
+ private Savegame savegame;
Stage stage;
private Skin skin, uiSkin;
@@ -82,13 +80,10 @@ public class GameScreen implements Screen, InputProcessor {
private ArrayList<Decal> decals;
private DecalPlayer decalPlayer;
- private final MaxonSavegame savegame;
+ public GameScreen() {
+ this.savegame = Savegame.load();
- public GameScreen(MaxonGame game, MaxonSavegame sav, int slotId) throws IOException, ClassNotFoundException {
- this.savegame = sav;
-
- this.game = game;
- this.slotId = slotId;
+ this.game = MaxonGame.getInstance();
this.playTimestamp = System.currentTimeMillis();
create3D();
@@ -97,7 +92,7 @@ public class GameScreen implements Screen, InputProcessor {
decals = new ArrayList<>();
TextureRegion[] playerTextureRegions = SpriteUtils.splitToTextureRegions(game.assetManager.get("sprites/sheet/loadingCircle.png", Texture.class), 112, 112, 10, 5);
- decalPlayer = new DecalPlayer(sav, playerTextureRegions);
+ decalPlayer = new DecalPlayer(savegame, playerTextureRegions);
decals.add(decalPlayer.getDecal());
playlist = new Playlist(
@@ -109,7 +104,6 @@ public class GameScreen implements Screen, InputProcessor {
playlist.setShuffleMode(true);
if (game.prefs.getBoolean("music", true)) playlist.next();
- player = sav;
items = new ArrayList<>();
createStageUI();
@@ -122,7 +116,7 @@ public class GameScreen implements Screen, InputProcessor {
Timer.schedule(new Timer.Task() {
@Override
public void run() {
- GameDataSystem.save(player, "latest.sav");
+ savegame.save();
}
}, 10, 10);
@@ -135,9 +129,9 @@ public class GameScreen implements Screen, InputProcessor {
multiplier += item.multiplier;
}
- player.points += multiplier;
+ savegame.increaseMoney(multiplier);
- final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(player.multiplier)), skin, "default");
+ final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(savegame.getMultiplier())), skin, "default");
label.setPosition(
maxon.getX(),
@@ -193,14 +187,14 @@ public class GameScreen implements Screen, InputProcessor {
case 0:
int randPoints = Math.getRandomNumber(150, 3000);
label.setText(game.locale.FormattedText("gifts.points", String.valueOf(randPoints)));
- player.points += randPoints;
+ savegame.increaseMoney(randPoints);
break;
// Multiplier
case 1:
int randMp = Math.getRandomNumber(1, 10);
label.setText(game.locale.FormattedText("gifts.multiplier", String.valueOf(randMp)));
- player.multiplier += randMp;
+ savegame.increaseMoney(randMp);
break;
@@ -210,7 +204,7 @@ public class GameScreen implements Screen, InputProcessor {
assert MaxonItemRegister.get(randPet) != null;
String name = MaxonItemRegister.get(randPet).name;
label.setText(game.locale.FormattedText("gifts.new_pet", name));
- player.inv.add(randPet);
+ savegame.getPurchasedPets().add(randPet);
if (invItems.containsKey(randPet)) {
invItems.put(randPet, invItems.get(randPet) + 1);
} else {
@@ -348,7 +342,7 @@ public class GameScreen implements Screen, InputProcessor {
p_item.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
- if (player.points < item.price) {
+ if (savegame.getMoney() < item.price) {
notEnoughPointsDialog.show(stage);
Timer.schedule(new Timer.Task() {
@@ -361,9 +355,9 @@ public class GameScreen implements Screen, InputProcessor {
return;
}
- player.points -= item.price;
- player.multiplier += item.multiplier;
- player.inv.add(item.id);
+ savegame.decreaseMoney(item.price);
+ savegame.increaseMultiplier(item.multiplier);
+ savegame.getPurchasedPets().add(item.id);
if (invItems.containsKey(item.id)) {
invItems.put(item.id, invItems.get(item.id) + 1);
@@ -454,11 +448,10 @@ public class GameScreen implements Screen, InputProcessor {
@Override
public boolean keyDown(int keycode) {
if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) {
- player.lastTimestamp = System.currentTimeMillis();
- player.elapsedTime = (System.currentTimeMillis() - playTimestamp) + player.elapsedTime;
- GameDataSystem.save(player, String.format("0%s.maxon", (slotId >= 0) ? slotId : "latest"));
+ savegame.setElapsedTime((System.currentTimeMillis() - playTimestamp) + savegame.getElapsedTime());
+ savegame.save();
- game.setScreen(new MenuScreen(game));
+ game.setScreen(new MenuScreen());
dispose();
}
//if (Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isKeyPressed(Input.Keys.UP)) {
@@ -471,9 +464,9 @@ public class GameScreen implements Screen, InputProcessor {
cat.nextFrame();
maxon.setDrawable(cat.getDrawable());
- player.points += player.multiplier;
+ savegame.increaseMoney(savegame.getMultiplier());
- final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(player.multiplier)), skin, "default");
+ final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(savegame.getMultiplier())), skin, "default");
label.setPosition(
maxon.getX(),
diff --git a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java
index 9d7fec8..032e9d3 100644
--- a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java
@@ -21,10 +21,9 @@ import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import kz.ilotterytea.maxon.MaxonConstants;
import kz.ilotterytea.maxon.MaxonGame;
-import kz.ilotterytea.maxon.player.MaxonSavegame;
+import kz.ilotterytea.maxon.player.Savegame;
import kz.ilotterytea.maxon.ui.*;
import kz.ilotterytea.maxon.utils.I18N;
-import kz.ilotterytea.maxon.utils.serialization.GameDataSystem;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
import net.mgsx.gltf.scene3d.lights.DirectionalShadowLight;
@@ -42,13 +41,14 @@ public class MenuScreen implements Screen {
private final Stage stage;
private final Music menuMusic;
- MaxonSavegame sav;
+ private final Savegame savegame;
private SceneManager sceneManager;
private PerspectiveCamera camera;
- public MenuScreen(final MaxonGame game) {
- this.game = game;
+ public MenuScreen() {
+ this.game = MaxonGame.getInstance();
+ this.savegame = Savegame.load();
// Stage and skin:
this.stage = new Stage(new ScreenViewport());
@@ -62,8 +62,6 @@ public class MenuScreen implements Screen {
Skin friendsSkin = game.assetManager.get("sprites/gui/friends.skin", Skin.class);
- sav = GameDataSystem.load("00.maxon");
-
// Main Menu music:
this.menuMusic = game.assetManager.get("mus/menu/mus_menu_loop.ogg", Music.class);
menuMusic.setLooping(true);
@@ -199,7 +197,7 @@ public class MenuScreen implements Screen {
game.prefs.putString("lang", fhNext.nameWithoutExtension());
game.prefs.flush();
- game.setScreen(new SplashScreen(game));
+ game.setScreen(new SplashScreen());
menuMusic.stop();
}
});
@@ -279,7 +277,7 @@ public class MenuScreen implements Screen {
// - - - Savegame - - -
Table savegameTable = new Table();
- SavegameWidget info = new SavegameWidget(this.game, uiSkin, stage, sav);
+ SavegameWidget info = new SavegameWidget(this.game, uiSkin, stage, savegame);
savegameTable.add(info).minSize(640f, 240f);
@@ -355,7 +353,7 @@ public class MenuScreen implements Screen {
PointLightEx signLight = new PointLightEx();
- if (sav != null) {
+ if (!savegame.isNewlyCreated()) {
signLight.set(Color.PINK, new Vector3(2f, 6f, 2f), 80f, 100f);
}
diff --git a/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java b/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java
index f381bb8..a4b56eb 100644
--- a/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/SplashScreen.java
@@ -27,8 +27,8 @@ public class SplashScreen implements Screen {
private boolean assetsLoaded = false;
- public SplashScreen(MaxonGame game) {
- this.game = game;
+ public SplashScreen() {
+ this.game = MaxonGame.getInstance();
this.stage = new Stage(new ScreenViewport());
this.skin = new Skin(Gdx.files.internal("MainSpritesheet.skin"));
@@ -65,7 +65,7 @@ public class SplashScreen implements Screen {
@Override
public boolean act(float v) {
AssetLoading.registerItems(game.assetManager, game.locale);
- game.setScreen(new MenuScreen(game));
+ game.setScreen(new MenuScreen());
dispose();
return false;
}
diff --git a/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java b/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java
index 34c75fd..4c88a4b 100644
--- a/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java
@@ -19,7 +19,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import kz.ilotterytea.maxon.MaxonGame;
-import kz.ilotterytea.maxon.player.MaxonSavegame;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
import net.mgsx.gltf.scene3d.lights.DirectionalShadowLight;
@@ -29,8 +28,6 @@ import net.mgsx.gltf.scene3d.scene.SceneAsset;
import net.mgsx.gltf.scene3d.scene.SceneManager;
import net.mgsx.gltf.scene3d.utils.IBLBuilder;
-import java.io.IOException;
-
public class WelcomeScreen implements Screen {
private final MaxonGame game = MaxonGame.getInstance();
@@ -176,11 +173,7 @@ public class WelcomeScreen implements Screen {
new Action() {
@Override
public boolean act(float delta) {
- try {
- game.setScreen(new GameScreen(game, new MaxonSavegame(), 0));
- } catch (IOException | ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
+ game.setScreen(new GameScreen());
return true;
}
}
diff --git a/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java b/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java
index 43b66c8..67f2c11 100644
--- a/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java
+++ b/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java
@@ -9,7 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import kz.ilotterytea.maxon.player.MaxonItem;
import kz.ilotterytea.maxon.player.MaxonItemRegister;
-import kz.ilotterytea.maxon.player.MaxonSavegame;
+import kz.ilotterytea.maxon.player.Savegame;
import kz.ilotterytea.maxon.ui.PurchaseItem;
import kz.ilotterytea.maxon.utils.formatters.NumberFormatter;
import kz.ilotterytea.maxon.utils.math.Math;
@@ -25,12 +25,12 @@ public class ShopUI {
private ShopMode mode;
private ShopMultiplier multiplier;
- private final MaxonSavegame savegame;
+ private final Savegame savegame;
private Label pointsLabel, multiplierLabel;
private final ArrayList<PurchaseItem> purchaseItems = new ArrayList<>();
- public ShopUI(final MaxonSavegame savegame, Stage stage, Skin skin, TextureAtlas atlas) {
+ public ShopUI(final Savegame savegame, Stage stage, Skin skin, TextureAtlas atlas) {
this.savegame = savegame;
this.skin = skin;
@@ -61,7 +61,7 @@ public class ShopUI {
pointsTable.align(Align.left);
Image pointsImage = new Image(this.atlas.findRegion("points"));
- this.pointsLabel = new Label(String.valueOf(savegame.points), this.skin);
+ this.pointsLabel = new Label(String.valueOf(savegame.getMoney()), this.skin);
pointsLabel.setAlignment(Align.left);
pointsTable.add(pointsImage).size(64f, 64f).padRight(15f);
@@ -74,7 +74,7 @@ public class ShopUI {
multiplierTable.align(Align.left);
Image multiplierImage = new Image(this.atlas.findRegion("multiplier"));
- this.multiplierLabel = new Label(String.format("%s/s", savegame.multiplier), this.skin);
+ this.multiplierLabel = new Label(String.format("%s/s", savegame.getMultiplier()), this.skin);
multiplierLabel.setAlignment(Align.left);
multiplierTable.add(multiplierImage).size(64f, 64f).padRight(15f);
@@ -185,14 +185,14 @@ public class ShopUI {
}
if (mode == ShopMode.BUY) {
- savegame.points -= (long) purchaseItem.getPrice();
+ savegame.decreaseMoney(purchaseItem.getPrice());
for (int i = 0; i < multiplier.getMultiplier(); i++) {
- savegame.inv.add(purchaseItem.getItem().id);
+ savegame.getPurchasedPets().add(purchaseItem.getItem().id);
}
} else {
- savegame.points += (long) purchaseItem.getPrice();
+ savegame.increaseMoney(purchaseItem.getPrice());
for (int i = 0; i < multiplier.getMultiplier(); i++) {
- savegame.inv.remove(Integer.valueOf(purchaseItem.getItem().id));
+ savegame.getPurchasedPets().remove(Integer.valueOf(purchaseItem.getItem().id));
}
}
}
@@ -215,7 +215,7 @@ public class ShopUI {
private void updatePurchaseItems() {
for (final PurchaseItem item : this.purchaseItems) {
- int amount = (int) savegame.inv.stream().filter(c -> c == item.getItem().id).count();
+ int amount = (int) savegame.getPurchasedPets().stream().filter(c -> c == item.getItem().id).count();
double price = item.getItem().price * java.lang.Math.pow(1.15f, amount + multiplier.getMultiplier());
if (mode == ShopMode.SELL) {
@@ -225,7 +225,7 @@ public class ShopUI {
item.setPrice(price);
if (mode == ShopMode.BUY) {
- if (price > savegame.points || savegame.points - price < 0) {
+ if (price > savegame.getMoney() || savegame.getMoney() - price < 0) {
item.setDisabled(true);
} else if (item.isDisabled()) {
item.setDisabled(false);
@@ -241,8 +241,8 @@ public class ShopUI {
}
public void render() {
- this.pointsLabel.setText(NumberFormatter.format(savegame.points));
- this.multiplierLabel.setText(String.format("%s/s", NumberFormatter.format(savegame.multiplier)));
+ this.pointsLabel.setText(NumberFormatter.format((long) savegame.getMoney()));
+ this.multiplierLabel.setText(String.format("%s/s", NumberFormatter.format((long) savegame.getMultiplier())));
updatePurchaseItems();
}
diff --git a/core/src/kz/ilotterytea/maxon/ui/OptionsTable.java b/core/src/kz/ilotterytea/maxon/ui/OptionsTable.java
index 2b0a185..8ce0720 100644
--- a/core/src/kz/ilotterytea/maxon/ui/OptionsTable.java
+++ b/core/src/kz/ilotterytea/maxon/ui/OptionsTable.java
@@ -28,7 +28,7 @@ public class OptionsTable extends Table {
final Image brandLogo
) {
super();
-
+
Label optionsLabel = new Label(game.locale.TranslatableText("options.title"), skin);
optionsLabel.setAlignment(Align.center);
super.add(optionsLabel).fillX().pad(81f).row();
@@ -141,7 +141,7 @@ public class OptionsTable extends Table {
Locale locale = new Locale(fh4Locale[0], fh4Locale[1]);
switchLangButton.setText(game.locale.FormattedText("options.language", locale.getDisplayLanguage(), locale.getDisplayCountry()));
- game.setScreen(new SplashScreen(game));
+ game.setScreen(new SplashScreen());
music.stop();
}
});
diff --git a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java
index 745602d..c6d2434 100644
--- a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java
+++ b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java
@@ -10,19 +10,19 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Disposable;
import kz.ilotterytea.maxon.MaxonGame;
-import kz.ilotterytea.maxon.player.MaxonSavegame;
+import kz.ilotterytea.maxon.player.Savegame;
import kz.ilotterytea.maxon.screens.WelcomeScreen;
import kz.ilotterytea.maxon.utils.formatters.NumberFormatter;
public class SavegameWidget extends Table implements Disposable {
private final Skin skin;
- private MaxonSavegame savegame;
+ private final Savegame savegame;
private final Table dataTable, controlTable;
private final TextureAtlas atlas;
private final MaxonGame game;
private final Stage stage;
- public SavegameWidget(final MaxonGame game, Skin skin, final Stage stage, final MaxonSavegame savegame) {
+ public SavegameWidget(final MaxonGame game, Skin skin, final Stage stage, Savegame savegame) {
super();
this.game = game;
this.stage = stage;
@@ -41,7 +41,7 @@ public class SavegameWidget extends Table implements Disposable {
this.controlTable.align(Align.left);
super.add(this.controlTable).growX();
- if (savegame == null) {
+ if (savegame.isNewlyCreated()) {
createEmpty();
} else {
createWithSavegame();
@@ -85,9 +85,9 @@ public class SavegameWidget extends Table implements Disposable {
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
- if (savegame == null) {
- savegame = new MaxonSavegame();
- savegame.name = field.getText();
+ if (savegame.isNewlyCreated()) {
+ savegame.setName(field.getText());
+ savegame.save();
}
moveToNextScreen();
@@ -100,11 +100,11 @@ public class SavegameWidget extends Table implements Disposable {
// Header
Table header = new Table();
- Label name = new Label(savegame.name, skin);
+ Label name = new Label(savegame.getName(), skin);
header.add(name).grow();
- long minutes = savegame.elapsedTime / 1000 / 60;
- long seconds = savegame.elapsedTime / 1000 % 60;
+ long minutes = savegame.getElapsedTime() / 1000 / 60;
+ long seconds = savegame.getElapsedTime() / 1000 % 60;
Label time = new Label(String.format("%s:%s", NumberFormatter.pad(minutes), NumberFormatter.pad(seconds)), skin);
time.setAlignment(Align.right);
@@ -120,11 +120,11 @@ public class SavegameWidget extends Table implements Disposable {
Image pointsIcon = new Image(atlas.findRegion("points"));
data.add(pointsIcon).size(32f, 32f).padRight(8f);
- Label points = new Label(NumberFormatter.format(savegame.points), skin);
+ Label points = new Label(NumberFormatter.format((long) savegame.getMoney()), skin);
data.add(points).padRight(32f);
// Unit
- long amount = savegame.inv.size();
+ long amount = savegame.getPurchasedPets().size();
Image unitIcon = new Image(atlas.findRegion("pets"));
data.add(unitIcon).size(32f, 32f).padRight(8f);
@@ -136,7 +136,7 @@ public class SavegameWidget extends Table implements Disposable {
Image multiplierIcon = new Image(atlas.findRegion("multiplier"));
data.add(multiplierIcon).size(32f, 32f).padRight(8f);
- Label multiplier = new Label(NumberFormatter.format(savegame.multiplier), skin);
+ Label multiplier = new Label(NumberFormatter.format((long) savegame.getMultiplier()), skin);
data.add(multiplier);
this.dataTable.add(data).grow();
diff --git a/core/src/kz/ilotterytea/maxon/utils/serialization/GameDataSystem.java b/core/src/kz/ilotterytea/maxon/utils/serialization/GameDataSystem.java
deleted file mode 100644
index 4762340..0000000
--- a/core/src/kz/ilotterytea/maxon/utils/serialization/GameDataSystem.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package kz.ilotterytea.maxon.utils.serialization;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.utils.Null;
-import com.google.gson.Gson;
-import kz.ilotterytea.maxon.MaxonConstants;
-import kz.ilotterytea.maxon.player.MaxonSavegame;
-import kz.ilotterytea.maxon.utils.OsUtils;
-import org.jetbrains.annotations.NotNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.ArrayList;
-
-/**
- * External game data system control.
- * @author NotDankEnough
- * @since Alpha 1.0
- */
-public class GameDataSystem {
- private static final File dir = new File(MaxonConstants.GAME_SAVEGAME_FOLDER);
- private static final Gson gson = new Gson();
- private static final Logger log = LoggerFactory.getLogger(GameDataSystem.class.getSimpleName());
-
- /**
- * Get all savefiles from savegame directory (/.Maxoning/savegames/)
- * @return Array of MaxonSavegames
- * @see MaxonSavegame
- */
- public static ArrayList<MaxonSavegame> getSavegames() {
- if (!dir.exists()) dir.mkdirs();
-
- ArrayList<MaxonSavegame> saves = new ArrayList<>();
- File[] files = dir.listFiles();
-
- assert files != null;
- for (File file : files) {
- try {
-
- FileInputStream fis = new FileInputStream(file);
- ObjectInputStream ois = new ObjectInputStream(fis);
-
- MaxonSavegame sav = gson.fromJson(ois.readUTF(), MaxonSavegame.class);
- saves.add(sav);
-
- ois.close();
- fis.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- return saves;
- }
-
- /**
- * Convert <b>MaxonSavegame</b> class to <b>JSON</b> string and write in UTF-8 encoding (I'm sorry, encryption enjoyers).
- * @param savegame Save game object.
- * @param file_name File name.
- * @see MaxonSavegame
- */
- public static void save(@NotNull MaxonSavegame savegame, @NotNull String file_name) {
- if (!dir.exists()) dir.mkdirs();
-
- try {
- log.info("Saving the game...");
- FileOutputStream fos = new FileOutputStream(String.format("%s/%s", (OsUtils.isAndroid || OsUtils.isIos) ? Gdx.files.getExternalStoragePath() : dir.getAbsolutePath(), file_name));
- ObjectOutputStream oos = new ObjectOutputStream(fos);
-
- oos.writeUTF(gson.toJson(savegame));
- oos.close();
- log.info(String.format("Success! Savegame located at %s/%s", (OsUtils.isAndroid || OsUtils.isIos) ? Gdx.files.getExternalStoragePath() : dir.getAbsolutePath(), file_name));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Reading a <b>JSON</b> string from the file and convert to <b>MaxonSavegame</b> class.
- * @param file_name File name. If null - it will get the first file by last modified time.
- * @return Filled <b>MaxonSavegame</b> class
- * @see MaxonSavegame
- */
- public static MaxonSavegame load(@Null String file_name) {
- MaxonSavegame sav = null;
-
- if (new File(dir.getAbsolutePath() + "/" + file_name).exists() && !(OsUtils.isAndroid || OsUtils.isIos)) {
- try {
- log.info(String.format("Trying to get the savegame at %s/%s...", dir.getAbsolutePath(), file_name));
- FileInputStream fis = new FileInputStream(String.format("%s/%s", dir.getAbsolutePath(), file_name));
- ObjectInputStream oos = new ObjectInputStream(fis);
-
- sav = gson.fromJson(oos.readUTF(), MaxonSavegame.class);
- oos.close();
-
- log.info(String.format("Successfully loaded the savegame from %s/%s!", dir.getAbsolutePath(), file_name));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- if ((OsUtils.isAndroid || OsUtils.isIos) && new File(Gdx.files.getExternalStoragePath() + file_name).exists()) {
- try {
- log.info(String.format("Trying to get the savegame at %s%s...", Gdx.files.getExternalStoragePath(), file_name));
- FileInputStream fis = new FileInputStream(String.format("%s%s", Gdx.files.getExternalStoragePath(), file_name));
- ObjectInputStream oos = new ObjectInputStream(fis);
-
- sav = gson.fromJson(oos.readUTF(), MaxonSavegame.class);
- oos.close();
-
- log.info(String.format("Successfully loaded the savegame from %s%s!", Gdx.files.getExternalStoragePath(), file_name));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- return sav;
- }
-}