diff options
| author | ilotterytea <iltsu@alright.party> | 2022-10-06 17:45:58 +0600 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2022-10-06 17:45:58 +0600 |
| commit | 0c7f6536eae679a2f11720a9ca6d0e36d8ff9df0 (patch) | |
| tree | 28519534669c7a6583ea94d3f2d2b6a5e215b070 | |
| parent | f706eab45127213e8a26e0a732cc5467784d01f6 (diff) | |
подгон к новому формату сохранений
5 files changed, 96 insertions, 57 deletions
diff --git a/core/src/com/ilotterytea/maxoning/player/MaxonSavegame.java b/core/src/com/ilotterytea/maxoning/player/MaxonSavegame.java new file mode 100644 index 0000000..301840b --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/player/MaxonSavegame.java @@ -0,0 +1,40 @@ +package com.ilotterytea.maxoning.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 int points; + /** Multiplier. */ + public short multiplier; + + /** Home inventory. */ + public ArrayList<Integer> inv; + /** Outside Inventory. */ + public ArrayList<Integer> outInv; + + /** Seed. */ + public long seed; + + /** Player name. */ + public String name; + /** Pet name. */ + public String petName; + /** Pet ID. */ + public byte petId; + + /** Elapsed time from game start. */ + public long elapsedTime; + + /** Last timestamp when save game was used. */ + public long lastTimestamp; + + /** Location. */ + public short roomId; +}
\ No newline at end of file diff --git a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java index b3d5fdc..e0d2624 100644 --- a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java @@ -20,7 +20,7 @@ import com.ilotterytea.maxoning.anim.SpriteUtils; import com.ilotterytea.maxoning.inputprocessors.CrossProcessor; import com.ilotterytea.maxoning.player.MaxonItem; import com.ilotterytea.maxoning.player.MaxonItemRegister; -import com.ilotterytea.maxoning.player.MaxonPlayer; +import com.ilotterytea.maxoning.player.MaxonSavegame; import com.ilotterytea.maxoning.ui.*; import com.ilotterytea.maxoning.utils.serialization.GameDataSystem; import com.rafaskoberg.gdx.typinglabel.TypingLabel; @@ -32,8 +32,9 @@ import java.util.Map; public class GameScreen implements Screen, InputProcessor { final MaxonGame game; + final int slotId; - MaxonPlayer player; + MaxonSavegame player; Stage stage; Skin skin, widgetSkin; @@ -53,8 +54,9 @@ public class GameScreen implements Screen, InputProcessor { ArrayList<ArrayList<Sprite>> bgTiles; - public GameScreen(MaxonGame game, MaxonPlayer sav) throws IOException, ClassNotFoundException { + public GameScreen(MaxonGame game, MaxonSavegame sav, int slotId) throws IOException, ClassNotFoundException { this.game = game; + this.slotId = slotId; player = sav; @@ -68,7 +70,7 @@ public class GameScreen implements Screen, InputProcessor { items = new ArrayList<>(); - for (int id : player.purchasedItems) { + for (int id : player.inv) { items.add(MaxonItemRegister.get(id)); } @@ -98,7 +100,7 @@ public class GameScreen implements Screen, InputProcessor { invItems = new HashMap<>(); - for (Integer id : player.purchasedItems) { + for (Integer id : player.inv) { if (invItems.containsKey(id)) { invItems.put(id, invItems.get(id) + 1); } else { @@ -141,13 +143,13 @@ public class GameScreen implements Screen, InputProcessor { if (player.points > item.price) { player.points -= item.price; player.multiplier += item.multiplier; - player.purchasedItems.add(item.id); + player.inv.add(item.id); items.add(item); invItems.clear(); inventoryTable.clear(); - for (Integer id : player.purchasedItems) { + for (Integer id : player.inv) { if (invItems.containsKey(id)) { invItems.put(id, invItems.get(id) + 1); } else { @@ -246,7 +248,7 @@ public class GameScreen implements Screen, InputProcessor { player.points += multiplier; - final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(1 * player.multiplier)), skin, "default"); + final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(player.multiplier)), skin, "default"); label.setPosition( mainTable.getX() + actor.getActorX(), @@ -383,11 +385,7 @@ public class GameScreen implements Screen, InputProcessor { @Override public boolean keyDown(int keycode) { if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { - try { - GameDataSystem.SaveData(player); - } catch (IOException e) { - throw new RuntimeException(e); - } + GameDataSystem.save(player, String.format("%s.sav", (slotId >= 0) ? slotId : "latest")); game.setScreen(new MenuScreen(game)); dispose(); @@ -404,9 +402,9 @@ public class GameScreen implements Screen, InputProcessor { cat.nextFrame(); maxon.setDrawable(cat.getDrawable()); - player.points += 1 * player.multiplier; + player.points += player.multiplier; - final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(1 * player.multiplier)), skin, "default"); + final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", MaxonConstants.DECIMAL_FORMAT.format(player.multiplier)), skin, "default"); label.setPosition( mainTable.getX() + actor.getActorX(), diff --git a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java index 135d0e9..e8dc864 100644 --- a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java @@ -2,7 +2,6 @@ package com.ilotterytea.maxoning.screens; import com.badlogic.gdx.*; import com.badlogic.gdx.audio.Music; -import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureAtlas; @@ -15,11 +14,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.viewport.FillViewport; -import com.ilotterytea.maxoning.MaxonConstants; import com.ilotterytea.maxoning.MaxonGame; -import com.ilotterytea.maxoning.player.MaxonPlayer; +import com.ilotterytea.maxoning.player.MaxonSavegame; import com.ilotterytea.maxoning.ui.*; import com.ilotterytea.maxoning.utils.math.Math; +import com.ilotterytea.maxoning.utils.serialization.GameDataSystem; import java.io.IOException; import java.io.ObjectInputStream; @@ -265,33 +264,31 @@ public class MenuScreen implements Screen { } private void loadSavegamesToTable(Table table) { - FileHandle folder = Gdx.files.external(MaxonConstants.GAME_SAVEGAME_FOLDER); - - try { - for (FileHandle fh : folder.list()) { - final MaxonPlayer sav = (MaxonPlayer) new ObjectInputStream(fh.read()).readObject(); - SaveGameWidget widget = new SaveGameWidget( - skin, widgetSkin, sav - ); - widget.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - try { - game.setScreen(new GameScreen(game, sav)); - } catch (IOException | ClassNotFoundException e) { - throw new RuntimeException(e); - } - dispose(); + ArrayList<MaxonSavegame> saves = GameDataSystem.getSavegames(); + + // Load existing files: + for (int i = 0; i < saves.size(); i++) { + final MaxonSavegame sav = saves.get(i); + SaveGameWidget widget = new SaveGameWidget( + skin, widgetSkin, sav + ); + final int finalI = i; + widget.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + try { + game.setScreen(new GameScreen(game, sav, finalI)); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); } - }); - table.add(widget).width(512f).padBottom(8f).row(); - } - } catch (IOException | ClassNotFoundException e) { - e.printStackTrace(); + dispose(); + } + }); + table.add(widget).width(512f).padBottom(8f).row(); } - for (int i = 0; i < 3 - folder.list().length; i++) { - final MaxonPlayer sav = new MaxonPlayer(); + for (int i = 0; i < 3 - saves.size(); i++) { + final MaxonSavegame sav = new MaxonSavegame(); SaveGameWidget widget = new SaveGameWidget( skin, widgetSkin, null ); @@ -300,7 +297,7 @@ public class MenuScreen implements Screen { @Override public void clicked(InputEvent event, float x, float y) { try { - game.setScreen(new GameScreen(game, sav)); + game.setScreen(new GameScreen(game, sav, finalI)); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } diff --git a/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java b/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java index 2817948..ccae6b1 100644 --- a/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java @@ -102,7 +102,7 @@ public class SplashScreen implements Screen { AssetLoading.registerItems(game.assetManager, game.locale); if (OsUtils.isAndroid || OsUtils.isIos) { try { - game.setScreen(new GameScreen(game, GameDataSystem.load("latest.sav"))); + game.setScreen(new GameScreen(game, GameDataSystem.load("latest.sav"), -1)); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } diff --git a/core/src/com/ilotterytea/maxoning/ui/SaveGameWidget.java b/core/src/com/ilotterytea/maxoning/ui/SaveGameWidget.java index cd6fa72..aa9fa85 100644 --- a/core/src/com/ilotterytea/maxoning/ui/SaveGameWidget.java +++ b/core/src/com/ilotterytea/maxoning/ui/SaveGameWidget.java @@ -3,15 +3,18 @@ package com.ilotterytea.maxoning.ui; import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.utils.Align; -import com.ilotterytea.maxoning.player.MaxonPlayer; +import com.badlogic.gdx.utils.Null; +import com.ilotterytea.maxoning.player.MaxonSavegame; import com.ilotterytea.maxoning.utils.formatters.NumberFormatter; +import java.util.Date; + public class SaveGameWidget extends Button { public SaveGameWidget( Skin skin, Skin widgetSkin, - MaxonPlayer sav + @Null MaxonSavegame sav ) { // Setting the stack: super(widgetSkin, "slot"); @@ -20,14 +23,15 @@ public class SaveGameWidget extends Button { // // Info row: Table infoTable = new Table(); - // Top left label: - Label topleftLabel = new Label(String.format("%s Squish Points", (sav != null) ? NumberFormatter.format((long) sav.points) : "---"), skin); + // Top left label (name): + Label topleftLabel = new Label((sav != null) ? sav.name : "[EMPTY]", skin); topleftLabel.setAlignment(Align.left); infoTable.add(topleftLabel).width(256f); - // Top right label: + // Top right label (elapsed time): + Date date = new Date((sav != null) ? sav.elapsedTime : 0); Label toprightLabel = new Label( - String.format("%s purchased items", (sav != null) ? sav.purchasedItems.size() : "---"), + String.format("%s:%s", date.getHours(), date.getMinutes()), skin ); toprightLabel.setAlignment(Align.right); @@ -36,28 +40,28 @@ public class SaveGameWidget extends Button { // // Description row: Table descTable = new Table(); - // Bottom left label: + // Bottom left label (purchased items): Label bottomleftLabel = new Label( String.format( - "x%s", - (sav != null) ? NumberFormatter.format((long) sav.multiplier) : "?" + "%s purchased items", + (sav != null) ? sav.inv.size() : "?" ), skin ); bottomleftLabel.setAlignment(Align.left); descTable.add(bottomleftLabel).width(256f); - /* NOT IN USE. Bottom right label: + // Bottom right label (points/multiplier): Label pointsLabel = new Label( String.format( "%s$/x%s", - NumberFormatter.format(points), - NumberFormatter.format(multiplier) + (sav != null) ? NumberFormatter.format(sav.points) : "---", + (sav != null) ? NumberFormatter.format(sav.multiplier) : "0" ), skin ); pointsLabel.setAlignment(Align.right); - descTable.add(pointsLabel).width(256f);*/ + descTable.add(pointsLabel).width(256f); // Adding the tables to main table: Table summaryTable = new Table(); |
