diff --git a/android/build.gradle b/android/build.gradle index 2cf94e8381..9eca53e2b2 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 29 - versionCode 347 - versionName "3.4.0-patch3" + versionCode 348 + versionName "3.4.0-patch4" archivesBaseName = "Unciv" } diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 757bc8ebc0..3295c6f5ca 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -69,27 +69,32 @@ class UncivGame(val version: String) : Game() { else{ translations.tryReadTranslationForCurrentLanguage() } + translations.loadPercentageCompleteOfLanguages() if (settings.userId == "") { // assign permanent user id settings.userId = UUID.randomUUID().toString() settings.save() } + Gdx.app.postRunnable { CameraStageBaseScreen.resetFonts() - if (GameSaver().getSave("Autosave").exists()) { - try { - loadGame("Autosave") - } catch (ex: Exception) { // silent fail if we can't read the autosave - startNewGame() - } - } else setScreen(LanguagePickerScreen()) - + autoLoadGame() thread { startMusic() } isInitialized = true } } } + fun autoLoadGame(){ + if (!GameSaver().getSave("Autosave").exists()) + return setScreen(LanguagePickerScreen()) + try { + loadGame("Autosave") + } catch (ex: Exception) { // silent fail if we can't read the autosave + startNewGame() + } + } + fun startMusic(){ val musicFile = Gdx.files.local(musicLocation) @@ -128,16 +133,18 @@ class UncivGame(val version: String) : Game() { worldScreen.shouldUpdate=true // This can set the screen to the policy picker or tech picker screen, so the input processor must come before } + // This is ALWAYS called after create() on Android - google "Android life cycle" override fun resume() { super.resume() + if(!isInitialized) return // The stuff from Create() is still happening, so the main screen will load eventually ImageGetter.refreshAltas() // This is to solve a rare problem that I still don't understand its cause - // Sometimes, resume() is called and the gameInfo doesn't have any civilizations. // My guess is that resume() was called but create() wasn't, or perhaps was aborted too early, // and the original (and empty) initial GameInfo remained. - if(!::gameInfo.isInitialized || gameInfo.civilizations.isEmpty()) - return create() +// if(!::gameInfo.isInitialized || gameInfo.civilizations.isEmpty()) +// return autoLoadGame() if(::worldScreen.isInitialized) worldScreen.dispose() // I hope this will solve some of the many OuOfMemory exceptions... loadGame(gameInfo) diff --git a/core/src/com/unciv/models/translations/Translations.kt b/core/src/com/unciv/models/translations/Translations.kt index c414993d08..c30c85dd9a 100644 --- a/core/src/com/unciv/models/translations/Translations.kt +++ b/core/src/com/unciv/models/translations/Translations.kt @@ -8,6 +8,8 @@ import kotlin.collections.HashMap class Translations : LinkedHashMap(){ + val percentCompleteOfLanguages = HashMap() + fun get(text:String,language:String): String { if(!hasTranslation(text,language)) return text return get(text)!![language]!! @@ -54,7 +56,11 @@ class Translations : LinkedHashMap(){ for (translation in languageTranslations) { if (!containsKey(translation.key)) this[translation.key] = TranslationEntry(translation.key) - this[translation.key]!![language] = translation.value + + // why not in one line, Because there were actual crashes. + // I'm pretty sure I solved this already, but hey double-checking doesn't cost anything. + val entry = this[translation.key] + if(entry!=null) entry[language] = translation.value } val translationFilesTime = System.currentTimeMillis() - translationStart @@ -119,7 +125,7 @@ class Translations : LinkedHashMap(){ } } - fun getPercentageCompleteOfLanguages(): HashMap { + fun loadPercentageCompleteOfLanguages() { val translationStart = System.currentTimeMillis() @@ -127,21 +133,18 @@ class Translations : LinkedHashMap(){ Gdx.files.internal("jsons/translationsByLanguage/template.properties") .reader().forEachLine { if(it.contains(" = ")) allTranslations+=1 } - val languageToPercentCompleted = HashMap() for(language in getLanguagesWithTranslationFile()){ val translationFileName = "jsons/translationsByLanguage/$language.properties" var translationsOfThisLanguage=0 Gdx.files.internal(translationFileName).reader() .forEachLine { if(it.contains(" = ") && !it.endsWith(" = ")) translationsOfThisLanguage+=1 } - languageToPercentCompleted[language] = translationsOfThisLanguage*100/allTranslations + percentCompleteOfLanguages[language] = translationsOfThisLanguage*100/allTranslations } val translationFilesTime = System.currentTimeMillis() - translationStart println("Loading percentage complete of languages - "+translationFilesTime+"ms") - - return languageToPercentCompleted } } diff --git a/core/src/com/unciv/ui/LanguagePickerScreen.kt b/core/src/com/unciv/ui/LanguagePickerScreen.kt index eca42db048..a9d87fcad2 100644 --- a/core/src/com/unciv/ui/LanguagePickerScreen.kt +++ b/core/src/com/unciv/ui/LanguagePickerScreen.kt @@ -5,7 +5,6 @@ import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.unciv.UncivGame -import com.unciv.models.translations.Translations import com.unciv.models.translations.tr import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.utils.ImageGetter @@ -55,7 +54,8 @@ class LanguagePickerScreen: PickerScreen(){ "If you want to help translating the game into your language, \n"+ " instructions are in the Github readme! (Menu > Community > Github)",skin)).pad(10f).row() - val languageCompletionPercentage = Translations().getPercentageCompleteOfLanguages() + val languageCompletionPercentage = UncivGame.Current.translations + .percentCompleteOfLanguages languageTables.addAll(languageCompletionPercentage .map { LanguageTable(it.key,if(it.key=="English") 100 else it.value) } .sortedByDescending { it.percentComplete} ) diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 7b2a12b967..e720287000 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -269,7 +269,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr val languageSelectBox = SelectBox(skin) val languageArray = Array() val ruleSet = worldScreen.gameInfo.ruleSet - Translations().getPercentageCompleteOfLanguages() + UncivGame.Current.translations.percentCompleteOfLanguages .map { Language(it.key, if(it.key=="English") 100 else it.value) } .sortedByDescending { it.percentComplete } .forEach { languageArray.add(it) }