Refactor: change GameSaver from singleton to single instance pattern & move autosave logic into GameSaver (#6846)

* Refactor: change GameSaver from singleton to single instance pattern & move autosave logic info GameSaver

Singleton just doesn't make sense anymore when we have to `init(..)` with different arguments, then we should just make a normal class out of it

* Fix not correctly checking for missing external files dir

* Refactor: use more appropriate library method

* Add logging for external files dir
This commit is contained in:
Timo T
2022-05-22 18:51:35 +02:00
committed by GitHub
parent a2c646ef8e
commit fc9668f2d0
24 changed files with 213 additions and 187 deletions

View File

@ -10,7 +10,6 @@ import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
import com.unciv.UncivGame
import com.unciv.UncivGameParameters
import com.unciv.logic.GameSaver
import com.unciv.models.metadata.GameSettings
import com.unciv.ui.utils.Fonts
import java.io.File
@ -24,14 +23,12 @@ open class AndroidLauncher : AndroidApplication() {
MultiplayerTurnCheckWorker.createNotificationChannels(applicationContext)
copyMods()
val externalFilesDir = getExternalFilesDir(null)
if (externalFilesDir != null) GameSaver.externalFilesDirForAndroid = externalFilesDir.path
val config = AndroidApplicationConfiguration().apply {
useImmersiveMode = true
}
val settings = GameSettings.getSettingsForPlatformLaunchers(filesDir.path)
val settings = GameSaver.getSettingsForPlatformLaunchers(filesDir.path)
val fontFamily = settings.fontFamily
// Manage orientation lock
@ -73,8 +70,8 @@ open class AndroidLauncher : AndroidApplication() {
if (UncivGame.isCurrentInitialized()
&& UncivGame.Current.isGameInfoInitialized()
&& UncivGame.Current.settings.multiplayerTurnCheckerEnabled
&& GameSaver.getSaves(true).any()) {
MultiplayerTurnCheckWorker.startTurnChecker(applicationContext, GameSaver, UncivGame.Current.gameInfo, UncivGame.Current.settings)
&& UncivGame.Current.gameSaver.getMultiplayerSaves().any()) {
MultiplayerTurnCheckWorker.startTurnChecker(applicationContext, UncivGame.Current.gameSaver, UncivGame.Current.gameInfo, UncivGame.Current.settings)
}
super.onPause()
}