From: fredboy Date: Sat, 20 Apr 2024 19:08:49 +0000 (+0700) Subject: Fix saves X-Git-Tag: alpha0.6.0~14 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=289536374d18bb05cde615c04d9fe576d6ac26bc;p=cavedroid.git Fix saves --- diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameComponent.java b/core/src/ru/deadsoftware/cavedroid/game/GameComponent.java index a0562ce..0bf5c2d 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameComponent.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameComponent.java @@ -12,4 +12,6 @@ public interface GameComponent { GameProc getGameProc(); GameInputProcessor getGameInputProcessor(); + + GameItemsHolder getGameItemsHolder(); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index f8c44b3..fb20d8f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -288,7 +288,7 @@ public class GameInput { private void holdMB() { if (mTouchDownBtn == Input.Buttons.RIGHT) { - useItem(mCurX, mCurY, mPlayer.inventory[mPlayer.slot], true); + useItem(mCurX, mCurY, mPlayer.inventory[mPlayer.slot].getItem(), true); mTouchedDown = false; } else { if (insideHotbar(mTouchDownX, mTouchDownY)) { @@ -411,7 +411,7 @@ public class GameInput { } System.arraycopy(mPlayer.inventory, 0, mPlayer.inventory, 1, 8); - mPlayer.inventory[0] = mGameItemsHolder.getItemFromCreativeInventory(itemPos); + mPlayer.inventory[0] = mGameItemsHolder.getItemFromCreativeInventory(itemPos).toInventoryItem(); } else if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY)) { mMainConfig.setGameUiWindow(GameUiWindow.NONE); } else if (screenY < hotbar.getRegionHeight() && @@ -420,7 +420,7 @@ public class GameInput { mPlayer.slot = (int) ((screenX - (mMainConfig.getWidth() / 2 - hotbar.getRegionWidth() / 2)) / 20); } else if (button == Input.Buttons.RIGHT) { useItem(mCurX, mCurY, - mPlayer.inventory[mPlayer.slot], false); + mPlayer.inventory[mPlayer.slot].getItem(), false); } else if (button == Input.Buttons.LEFT) { mBlockDamage = 0; } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameModule.java b/core/src/ru/deadsoftware/cavedroid/game/GameModule.java index 0637f59..29175da 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameModule.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameModule.java @@ -4,6 +4,7 @@ import dagger.Module; import dagger.Provides; import ru.deadsoftware.cavedroid.MainConfig; import ru.deadsoftware.cavedroid.game.mobs.MobsController; +import ru.deadsoftware.cavedroid.game.model.block.Block; import ru.deadsoftware.cavedroid.game.objects.DropController; import ru.deadsoftware.cavedroid.game.world.GameWorld; @@ -15,8 +16,14 @@ public class GameModule { @CheckForNull private static GameSaver.Data data; - public static void load(MainConfig mainConfig) { - data = GameSaver.load(mainConfig); + public static boolean loaded = false; + + private static void load(MainConfig mainConfig, GameItemsHolder gameItemsHolder) { + if (loaded) { + return; + } + data = GameSaver.load(mainConfig, gameItemsHolder); + loaded = true; } private static void makeDataNullIfEmpty() { @@ -27,30 +34,35 @@ public class GameModule { @Provides @GameScope - public static DropController provideDropController() { + public static DropController provideDropController(MainConfig mainConfig, GameItemsHolder gameItemsHolder) { + load(mainConfig, gameItemsHolder); DropController controller = data != null ? data.retrieveDropController() : new DropController(); makeDataNullIfEmpty(); + controller.initDrops(gameItemsHolder); return controller; } @Provides @GameScope - public static MobsController provideMobsController(GameItemsHolder gameItemsHolder) { + public static MobsController provideMobsController(MainConfig mainConfig, GameItemsHolder gameItemsHolder) { + load(mainConfig, gameItemsHolder); MobsController controller = data != null ? data.retrieveMobsController() : new MobsController(gameItemsHolder); makeDataNullIfEmpty(); + controller.getPlayer().initInventory(gameItemsHolder); return controller; } @Provides @GameScope - public static GameWorld provideGameWorld(DropController dropController, + public static GameWorld provideGameWorld(MainConfig mainConfig, + DropController dropController, MobsController mobsController, GameItemsHolder gameItemsHolder) { - // TODO: 4/20/24 RE-enable saves -// int[][] fm = data != null ? data.retrieveForeMap() : null; -// int[][] bm = data != null ? data.retrieveBackMap() : null; + load(mainConfig, gameItemsHolder); + Block[][] fm = data != null ? data.retrieveForeMap() : null; + Block[][] bm = data != null ? data.retrieveBackMap() : null; makeDataNullIfEmpty(); - return new GameWorld(dropController, mobsController, gameItemsHolder, null, null); + return new GameWorld(dropController, mobsController, gameItemsHolder, fm, bm); } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java index ef33b8e..1a0a044 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java @@ -29,8 +29,7 @@ public class GameProc implements Disposable { MobsController mobsController, GameWorldFluidsLogicControllerTask gameWorldFluidsLogicControllerTask, GameWorldBlocksLogicControllerTask gameWorldBlocksLogicControllerTask, - GameItemsHolder gameItemsHolder, - AssetLoader assetLoader + GameItemsHolder gameItemsHolder ) { mGamePhysics = gamePhysics; mGameInput = gameInput; diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java index 43973bc..a3a9f01 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java @@ -212,8 +212,8 @@ public class GameRenderer extends Renderer { } } for (int i = 0; i < 9; i++) { - if (mMobsController.getPlayer().inventory[i] != null && mMobsController.getPlayer().inventory[i] != mGameItemsHolder.getFallbackItem()) { - spriter.draw(mMobsController.getPlayer().inventory[i].getSprite(), + if (mMobsController.getPlayer().inventory[i] != null && mMobsController.getPlayer().inventory[i].getItem() != mGameItemsHolder.getFallbackItem()) { + spriter.draw(mMobsController.getPlayer().inventory[i].getItem().getSprite(), x + 8 + i * 18, y + creative.getRegionHeight() - 24); } } @@ -257,8 +257,8 @@ public class GameRenderer extends Renderer { drawHealth(hotbarX, hotbar.getRegionHeight()); for (int i = 0; i < 9; i++) { - if (mMobsController.getPlayer().inventory[i] != null && mMobsController.getPlayer().inventory[i] != mGameItemsHolder.getFallbackItem()) { - spriter.draw(mMobsController.getPlayer().inventory[i].getSprite(), + if (mMobsController.getPlayer().inventory[i] != null && mMobsController.getPlayer().inventory[i].getItem() != mGameItemsHolder.getFallbackItem()) { + spriter.draw(mMobsController.getPlayer().inventory[i].getItem().getSprite(), getWidth() / 2 - (float) hotbar.getRegionWidth() / 2 + 3 + i * 20, 3); } @@ -391,7 +391,7 @@ public class GameRenderer extends Renderer { drawString("Mobs: " + mMobsController.getMobs().size(), 0, 70); drawString("Drops: " + mDropController.getSize(), 0, 80); drawString("Block: " + mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY()).getParams().getKey(), 0, 90); - drawString("Hand: " + mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot].getParams().getKey(), 0, 100); + drawString("Hand: " + mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot].getItem().getParams().getKey(), 0, 100); drawString("Game mode: " + player.gameMode, 0, 110); spriter.end(); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java index 51dbd5b..53d1472 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java @@ -4,12 +4,15 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import ru.deadsoftware.cavedroid.MainConfig; import ru.deadsoftware.cavedroid.game.mobs.MobsController; +import ru.deadsoftware.cavedroid.game.model.block.Block; import ru.deadsoftware.cavedroid.game.objects.DropController; import ru.deadsoftware.cavedroid.game.world.GameWorld; import javax.annotation.CheckForNull; import java.io.*; import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; public class GameSaver { @@ -21,9 +24,9 @@ public class GameSaver { @CheckForNull private DropController mDropController; @CheckForNull - private int[][] mForeMap, mBackMap; + private Block[][] mForeMap, mBackMap; - public Data(MobsController mobsController, DropController dropController, int[][] foreMap, int[][] backMap) { + public Data(MobsController mobsController, DropController dropController, Block[][] foreMap, Block[][] backMap) { mMobsController = mobsController; mDropController = dropController; mForeMap = foreMap; @@ -44,16 +47,16 @@ public class GameSaver { return dropController; } - public int[][] retrieveForeMap() { + public Block[][] retrieveForeMap() { assert mForeMap != null; - int[][] foreMap = mForeMap; + Block[][] foreMap = mForeMap; mForeMap = null; return foreMap; } - public int[][] retrieveBackMap() { + public Block[][] retrieveBackMap() { assert mBackMap != null; - int[][] backMap = mBackMap; + Block[][] backMap = mBackMap; mBackMap = null; return backMap; } @@ -69,7 +72,46 @@ public class GameSaver { return ByteBuffer.allocate(4).putInt(i).array(); } - private static void saveMap(FileHandle file, int[][] map) throws IOException { + private static Map buildBlocksDictionary(Block[][] foreMap, Block[][] backMap) { + final HashMap dict = new HashMap<>(); + + int id = 0; + for (int i = 0; i < foreMap.length; i++) { + for (int j = 0; j < foreMap[i].length; j++) { + for (int k = 0; k < 2; k++) { + final Block block = k == 0 ? foreMap[i][j] : backMap[i][j]; + final String key = block.getParams().getKey(); + if (!dict.containsKey(key)) { + dict.put(key, id++); + } + } + } + } + + return dict; + } + + private static void saveDict(FileHandle file, Map dict) { + final String[] arr = new String[dict.size()]; + + for (Map.Entry entry : dict.entrySet()) { + arr[entry.getValue()] = entry.getKey(); + } + + final StringBuilder builder = new StringBuilder(); + for (String key : arr) { + builder.append(key); + builder.append('\n'); + } + + file.writeString(builder.toString(), false); + } + + private static String[] loadDict(FileHandle file) { + return file.readString().split("\n"); + } + + private static void saveMap(FileHandle file, Block[][] map, Map dict) throws IOException { int run, block; int width = map.length; int height = map[0].length; @@ -81,14 +123,15 @@ public class GameSaver { out.write(intToBytes(height)); for (int y = 0; y < height; y++) { - block = map[0][y]; + block = dict.get(map[0][y].getParams().getKey()); run = 0; - for (int[] ints : map) { - if (ints[y] != block) { + for (Block[] blocks : map) { + int newValue = dict.get(blocks[y].getParams().getKey()); + if (newValue != block) { out.write(intToBytes(run)); out.write(intToBytes(block)); run = 0; - block = ints[y]; + block = dict.get(blocks[y].getParams().getKey()); } run++; } @@ -100,8 +143,8 @@ public class GameSaver { out.close(); } - private static int[][] loadMap(FileHandle file) throws Exception { - int[][] map; + private static Block[][] loadMap(GameItemsHolder gameItemsHolder, FileHandle file, String[] dict) throws Exception { + Block[][] map; int version, width, height; int run, block; @@ -112,13 +155,13 @@ public class GameSaver { if (SAVE_VERSION == version) { width = in.readInt(); height = in.readInt(); - map = new int[width][height]; + map = new Block[width][height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x += run) { run = in.readInt(); block = in.readInt(); for (int i = x; i < x + run; i++) { - map[i][y] = block; + map[i][y] = gameItemsHolder.getBlock(dict[block]); } } } @@ -131,7 +174,7 @@ public class GameSaver { } @CheckForNull - public static Data load(MainConfig mainConfig) { + public static Data load(MainConfig mainConfig, GameItemsHolder gameItemsHolder) { String folder = mainConfig.getGameFolder(); FileHandle file = Gdx.files.absolute(folder + "/saves/game.sav"); @@ -150,8 +193,9 @@ public class GameSaver { in.close(); - int[][] foreMap = loadMap(Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/foremap.sav")); - int[][] backMap = loadMap(Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/backmap.sav")); + final String[] dict = loadDict(Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/dict")); + Block[][] foreMap = loadMap(gameItemsHolder, Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/foremap.sav"), dict); + Block[][] backMap = loadMap(gameItemsHolder, Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/backmap.sav"), dict); if (dropController == null || mobsController == null) { throw new Exception("couldn't load"); @@ -169,35 +213,36 @@ public class GameSaver { DropController dropController, MobsController mobsController, GameWorld gameWorld) { - - Gdx.app.debug(TAG, "Saves are disabled for this build"); - return; - - -/* String folder = mainConfig.getGameFolder(); + String folder = mainConfig.getGameFolder(); FileHandle file = Gdx.files.absolute(folder + "/saves/"); file.mkdirs(); file = Gdx.files.absolute(folder + "/saves/game.sav"); + final Block[][] foreMap, backMap; + foreMap = gameWorld.getFullForeMap(); + backMap = gameWorld.getFullBackMap(); + + final Map dict = buildBlocksDictionary(foreMap, backMap); + try { ObjectOutputStream out = new ObjectOutputStream(file.write(false)); out.writeInt(SAVE_VERSION); out.writeObject(dropController); out.writeObject(mobsController); out.close(); - // TODO: 4/20/24 save map -// saveMap(Gdx.files.absolute(folder + "/saves/foremap.sav"), gameWorld.getFullForeMap()); -// saveMap(Gdx.files.absolute(folder + "/saves/backmap.sav"), gameWorld.getFullBackMap()); + + saveDict(Gdx.files.absolute(folder + "/saves/dict"), dict); + saveMap(Gdx.files.absolute(folder + "/saves/foremap.sav"), gameWorld.getFullForeMap(), dict); + saveMap(Gdx.files.absolute(folder + "/saves/backmap.sav"), gameWorld.getFullBackMap(), dict); } catch (Exception e) { e.printStackTrace(); - }*/ + } } public static boolean exists(MainConfig mainConfig) { - return false; -// String folder = mainConfig.getGameFolder(); -// return (Gdx.files.absolute(folder + "/saves/game.sav").exists() && -// Gdx.files.absolute(folder + "/saves/foremap.sav").exists() && -// Gdx.files.absolute(folder + "/saves/backmap.sav").exists()); + String folder = mainConfig.getGameFolder(); + return (Gdx.files.absolute(folder + "/saves/game.sav").exists() && + Gdx.files.absolute(folder + "/saves/foremap.sav").exists() && + Gdx.files.absolute(folder + "/saves/backmap.sav").exists()); } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java b/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java index e2c83bc..1d47b90 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameScreen.java @@ -17,6 +17,8 @@ public class GameScreen implements Screen { private GameProc mGameProc; @CheckForNull private GameInputProcessor mGameInputProcessor; + @CheckForNull + private GameItemsHolder mGameItemsHolder; @Inject public GameScreen(MainConfig mainConfig) { @@ -28,6 +30,8 @@ public class GameScreen implements Screen { mGameProc.dispose(); } + GameModule.loaded = true; + GameComponent gameComponent = DaggerGameComponent.builder() .mainComponent(mMainConfig.getMainComponent()).build(); @@ -44,7 +48,7 @@ public class GameScreen implements Screen { mGameProc.dispose(); } - GameModule.load(mMainConfig); + GameModule.loaded = false; GameComponent gameComponent = DaggerGameComponent.builder() .mainComponent(mMainConfig.getMainComponent()).build(); diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java index 3c33ee5..bce9a2c 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavedroid.game.GameItemsHolder; +import ru.deadsoftware.cavedroid.game.model.item.InventoryItem; import ru.deadsoftware.cavedroid.game.model.item.Item; import ru.deadsoftware.cavedroid.game.objects.Drop; import ru.deadsoftware.cavedroid.game.world.GameWorld; @@ -12,6 +13,8 @@ import ru.deadsoftware.cavedroid.misc.Assets; import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin; import ru.deadsoftware.cavedroid.misc.utils.SpriteUtilsKt; +import javax.annotation.CheckForNull; + public class Player extends Mob { private static final float SPEED = 69.072f; @@ -22,7 +25,7 @@ public class Player extends Mob { private float hitAnim = 0f; private float hitAnimDelta = ANIMATION_SPEED; - public final Item[] inventory; + public final InventoryItem[] inventory; public int slot; public int gameMode; public boolean swim; @@ -30,13 +33,24 @@ public class Player extends Mob { public Player(GameItemsHolder gameItemsHolder) { super(0, 0, 4, 30, randomDir(), Type.MOB, MAX_HEALTH); - inventory = new Item[9]; + inventory = new InventoryItem[9]; for (int i = 0; i < 9; i++) { - inventory[i] = gameItemsHolder.getFallbackItem(); + inventory[i] = gameItemsHolder.getFallbackItem().toInventoryItem(); } swim = false; } + public void initInventory(GameItemsHolder gameItemsHolder) { + for (InventoryItem invItem : inventory) { + invItem.init(gameItemsHolder); + } + } + + @CheckForNull + public Item inventory(int i) { + return inventory[i].getItem(); + } + public void respawn(GameWorld gameWorld, GameItemsHolder itemsHolder) { Vector2 pos = getSpawnPoint(gameWorld, itemsHolder); this.x = pos.x; @@ -48,8 +62,8 @@ public class Player extends Mob { public void pickUpDrop(Drop drop) { for (int i = 0; i < inventory.length; i++) { - if (inventory[i] == null || inventory[i].getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY) || inventory[i] == drop.getItem()) { - inventory[i] = drop.getItem(); + if (inventory(i) == null || inventory(i).getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY) || inventory(i) == drop.getItem()) { + inventory[i] = drop.getItem().toInventoryItem(); drop.setPickedUp(true); break; } @@ -78,7 +92,7 @@ public class Player extends Mob { } public void setCurrentInventorySlotItem(Item item) { - inventory[slot] = item; + inventory[slot] = item.toInventoryItem(); } @Override @@ -116,7 +130,7 @@ public class Player extends Mob { } private void drawItem(SpriteBatch spriteBatch, float x, float y, float anim) { - final Item item = inventory[slot]; + final Item item = inventory(slot); if (item == null || item.getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY)) { return; diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt new file mode 100644 index 0000000..1e1f43e --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt @@ -0,0 +1,27 @@ +package ru.deadsoftware.cavedroid.game.model.item + +import ru.deadsoftware.cavedroid.game.GameItemsHolder +import java.io.Serializable + +class InventoryItem @JvmOverloads constructor( + val itemKey: String, + val amount: Int = 1, +) : Serializable { + + @Transient + lateinit var item: Item + private set + + @JvmOverloads + constructor(_item: Item, amount: Int = 1) : this(_item.params.key, amount) { + item = _item + } + + fun init(gameItemsHolder: GameItemsHolder) { + if (this::item.isInitialized) { + return + } + item = gameItemsHolder.getItem(itemKey) + } + +} diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt index a479a4f..fe2bc46 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt @@ -33,6 +33,11 @@ sealed class Item { contract { returns(true) implies (this@Item is Placeable) } return this is Placeable } + + @JvmOverloads + fun toInventoryItem(amount: Int = 1): InventoryItem { + return InventoryItem(this, amount) + } sealed class Tool : Item() { abstract val mobDamageMultiplier: Float diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.kt b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.kt index b9a141c..151e486 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.kt @@ -3,17 +3,35 @@ package ru.deadsoftware.cavedroid.game.objects import com.badlogic.gdx.math.Intersector import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Vector2 +import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.model.item.Item class Drop( x: Float, y: Float, - val item: Item, + _item: Item, ) : Rectangle(x, y, DROP_SIZE, DROP_SIZE) { + val itemKey = _item.params.key val velocity = getInitialVelocity() var pickedUp = false + @Transient + lateinit var item: Item + private set + + init { + item = _item + } + + fun initItem(gameItemsHolder: GameItemsHolder) { + if (this::item.isInitialized) { + return + } + + item = gameItemsHolder.getItem(itemKey) + } + fun canMagnetTo(rectangle: Rectangle): Boolean { val magnetArea = getMagnetArea() return Intersector.overlaps(magnetArea, rectangle) diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/DropController.java b/core/src/ru/deadsoftware/cavedroid/game/objects/DropController.java index 084180d..826fd68 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/DropController.java +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/DropController.java @@ -1,5 +1,6 @@ package ru.deadsoftware.cavedroid.game.objects; +import ru.deadsoftware.cavedroid.game.GameItemsHolder; import ru.deadsoftware.cavedroid.game.GameScope; import ru.deadsoftware.cavedroid.game.model.item.Item; @@ -21,6 +22,10 @@ public class DropController implements Serializable { public DropController() { } + public void initDrops(GameItemsHolder gameItemsHolder) { + mDrops.forEach((drop) -> drop.initItem(gameItemsHolder)); + } + public void addDrop(float x, float y, Item item) { mDrops.add(new Drop(x, y, item)); }