Skip to content

Commit

Permalink
New saving fromat and rewrite in kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
fredboy committed May 21, 2024
1 parent 5ef6464 commit 76a3b56
Show file tree
Hide file tree
Showing 23 changed files with 1,010 additions and 319 deletions.
3 changes: 2 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ dependencies {
implementation 'org.jetbrains:annotations:23.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinSerializationVersion"
ksp "com.google.dagger:dagger-compiler:$daggerVersion"
}
}
32 changes: 21 additions & 11 deletions core/src/ru/deadsoftware/cavedroid/game/GameModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import ru.deadsoftware.cavedroid.game.model.block.Block;
import ru.deadsoftware.cavedroid.game.objects.drop.DropController;
import ru.deadsoftware.cavedroid.game.objects.container.ContainerController;
import ru.deadsoftware.cavedroid.game.save.GameSaveData;
import ru.deadsoftware.cavedroid.game.save.GameSaveLoader;
import ru.deadsoftware.cavedroid.game.ui.TooltipManager;
import ru.deadsoftware.cavedroid.game.world.GameWorld;

Expand All @@ -16,15 +18,15 @@
public class GameModule {

@CheckForNull
private static GameSaver.Data data;
private static GameSaveData data;

public static boolean loaded = false;

private static void load(MainConfig mainConfig, GameItemsHolder gameItemsHolder) {
private static void load(MainConfig mainConfig, GameItemsHolder gameItemsHolder, TooltipManager tooltipManager) {
if (loaded) {
return;
}
data = GameSaver.load(mainConfig, gameItemsHolder);
data = GameSaveLoader.INSTANCE.load(mainConfig, gameItemsHolder, tooltipManager);
loaded = true;
}

Expand All @@ -36,8 +38,10 @@ private static void makeDataNullIfEmpty() {

@Provides
@GameScope
public static DropController provideDropController(MainConfig mainConfig, GameItemsHolder gameItemsHolder) {
load(mainConfig, gameItemsHolder);
public static DropController provideDropController(MainConfig mainConfig,
GameItemsHolder gameItemsHolder,
TooltipManager tooltipManager) {
load(mainConfig, gameItemsHolder, tooltipManager);
DropController controller = data != null ? data.retrieveDropController() : new DropController();
makeDataNullIfEmpty();
controller.initDrops(gameItemsHolder);
Expand All @@ -46,9 +50,14 @@ public static DropController provideDropController(MainConfig mainConfig, GameIt

@Provides
@GameScope
public static ContainerController provideFurnaceController(MainConfig mainConfig, DropController dropController, GameItemsHolder gameItemsHolder) {
load(mainConfig, gameItemsHolder);
ContainerController controller = data != null ? data.retrieveFurnaceController() : new ContainerController(dropController, gameItemsHolder);
public static ContainerController provideFurnaceController(MainConfig mainConfig,
DropController dropController,
GameItemsHolder gameItemsHolder,
TooltipManager tooltipManager) {
load(mainConfig, gameItemsHolder, tooltipManager);
ContainerController controller = data != null
? data.retrieveContainerController()
: new ContainerController(dropController, gameItemsHolder);
makeDataNullIfEmpty();
controller.init(dropController, gameItemsHolder);
return controller;
Expand All @@ -59,7 +68,7 @@ public static ContainerController provideFurnaceController(MainConfig mainConfig
public static MobsController provideMobsController(MainConfig mainConfig,
GameItemsHolder gameItemsHolder,
TooltipManager tooltipManager) {
load(mainConfig, gameItemsHolder);
load(mainConfig, gameItemsHolder, tooltipManager);
MobsController controller = data != null
? data.retrieveMobsController()
: new MobsController(gameItemsHolder, tooltipManager);
Expand All @@ -74,8 +83,9 @@ public static GameWorld provideGameWorld(MainConfig mainConfig,
DropController dropController,
MobsController mobsController,
GameItemsHolder gameItemsHolder,
ContainerController containerController) {
load(mainConfig, gameItemsHolder);
ContainerController containerController,
TooltipManager tooltipManager) {
load(mainConfig, gameItemsHolder, tooltipManager);
Block[][] fm = data != null ? data.retrieveForeMap() : null;
Block[][] bm = data != null ? data.retrieveBackMap() : null;
makeDataNullIfEmpty();
Expand Down
271 changes: 0 additions & 271 deletions core/src/ru/deadsoftware/cavedroid/game/GameSaver.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.deadsoftware.cavedroid.game.input.handler.keyboard

import ru.deadsoftware.cavedroid.MainConfig
import ru.deadsoftware.cavedroid.game.GameSaver
import ru.deadsoftware.cavedroid.game.GameScope
import ru.deadsoftware.cavedroid.game.GameUiWindow
import ru.deadsoftware.cavedroid.game.input.IKeyboardInputHandler
Expand All @@ -10,6 +9,7 @@ import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.objects.drop.DropController
import ru.deadsoftware.cavedroid.game.objects.container.ContainerController
import ru.deadsoftware.cavedroid.game.save.GameSaveLoader
import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindKeyboardInputHandler
Expand All @@ -36,7 +36,7 @@ class PauseGameKeyboardInputHandler @Inject constructor(
return
}

GameSaver.save(mainConfig, dropController, mobsController, containerController, gameWorld)
GameSaveLoader.save(mainConfig, dropController, mobsController, containerController, gameWorld)
mainConfig.caveGame.quitGame()
}
}
Loading

0 comments on commit 76a3b56

Please sign in to comment.