Fix multiplayer sometimes duplicating games (#6999)

* Fix multiplayer sometimes duplicating games

* Fix test compilation
This commit is contained in:
Timo T
2022-06-01 21:24:44 +02:00
committed by GitHub
parent 51e3349ecc
commit 1abc65163d
7 changed files with 91 additions and 41 deletions

View File

@ -264,12 +264,10 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
init {
// We can't use Gdx.files since that is only initialized within a com.badlogic.gdx.backends.android.AndroidApplication.
// Worker instances may be stopped & recreated by the Android WorkManager, so no AndroidApplication and thus no Gdx.files available
val files = DefaultAndroidFiles(applicationContext.assets, ContextWrapper(applicationContext), false)
val files = DefaultAndroidFiles(applicationContext.assets, ContextWrapper(applicationContext), true)
// GDX's AndroidFileHandle uses Gdx.files internally, so we need to set that to our new instance
Gdx.files = files
val externalFilesDirForAndroid = applicationContext.getExternalFilesDir(null)?.path
Log.d(LOG_TAG, "Creating new GameSaver with externalFilesDir=[${externalFilesDirForAndroid}]")
gameSaver = GameSaver(files, null, externalFilesDirForAndroid)
gameSaver = GameSaver(files, null, true)
}
override fun doWork(): Result = runBlocking {

View File

@ -30,7 +30,9 @@ Sources for Info about current orientation in case need:
if (activity.requestedOrientation != orientation) activity.requestedOrientation = orientation
}
override fun getExternalFilesDir(): String? {
return activity.getExternalFilesDir(null)?.path
}
/**
* On Android, local is some android-internal data directory which may or may not be accessible by the user.
* External is probably on an SD-card or similar which is always accessible by the user.
*/
override fun shouldPreferExternalStorage(): Boolean = true
}