From 0c7f6536eae679a2f11720a9ca6d0e36d8ff9df0 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 6 Oct 2022 17:45:58 +0600 Subject: подгон к новому формату сохранений MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ilotterytea/maxoning/screens/GameScreen.java | 28 ++++++------ .../ilotterytea/maxoning/screens/MenuScreen.java | 53 ++++++++++------------ .../ilotterytea/maxoning/screens/SplashScreen.java | 2 +- 3 files changed, 39 insertions(+), 44 deletions(-) (limited to 'core/src/com/ilotterytea/maxoning/screens') 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> 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 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); } -- cgit v1.2.3