mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-13 19:39:34 +07:00
We now load translation percentages on initialization so we won't need to mid-game, fixed "create" and the "resume" both trying to do the same things
This commit is contained in:
parent
ebfd79636f
commit
a41874e1a5
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 347
|
versionCode 348
|
||||||
versionName "3.4.0-patch3"
|
versionName "3.4.0-patch4"
|
||||||
|
|
||||||
archivesBaseName = "Unciv"
|
archivesBaseName = "Unciv"
|
||||||
}
|
}
|
||||||
|
@ -69,27 +69,32 @@ class UncivGame(val version: String) : Game() {
|
|||||||
else{
|
else{
|
||||||
translations.tryReadTranslationForCurrentLanguage()
|
translations.tryReadTranslationForCurrentLanguage()
|
||||||
}
|
}
|
||||||
|
translations.loadPercentageCompleteOfLanguages()
|
||||||
|
|
||||||
if (settings.userId == "") { // assign permanent user id
|
if (settings.userId == "") { // assign permanent user id
|
||||||
settings.userId = UUID.randomUUID().toString()
|
settings.userId = UUID.randomUUID().toString()
|
||||||
settings.save()
|
settings.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
CameraStageBaseScreen.resetFonts()
|
CameraStageBaseScreen.resetFonts()
|
||||||
if (GameSaver().getSave("Autosave").exists()) {
|
autoLoadGame()
|
||||||
try {
|
|
||||||
loadGame("Autosave")
|
|
||||||
} catch (ex: Exception) { // silent fail if we can't read the autosave
|
|
||||||
startNewGame()
|
|
||||||
}
|
|
||||||
} else setScreen(LanguagePickerScreen())
|
|
||||||
|
|
||||||
thread { startMusic() }
|
thread { startMusic() }
|
||||||
isInitialized = true
|
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(){
|
fun startMusic(){
|
||||||
|
|
||||||
val musicFile = Gdx.files.local(musicLocation)
|
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
|
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() {
|
override fun resume() {
|
||||||
super.resume()
|
super.resume()
|
||||||
|
if(!isInitialized) return // The stuff from Create() is still happening, so the main screen will load eventually
|
||||||
ImageGetter.refreshAltas()
|
ImageGetter.refreshAltas()
|
||||||
|
|
||||||
// This is to solve a rare problem that I still don't understand its cause -
|
// 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.
|
// 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,
|
// 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.
|
// and the original (and empty) initial GameInfo remained.
|
||||||
if(!::gameInfo.isInitialized || gameInfo.civilizations.isEmpty())
|
// if(!::gameInfo.isInitialized || gameInfo.civilizations.isEmpty())
|
||||||
return create()
|
// return autoLoadGame()
|
||||||
|
|
||||||
if(::worldScreen.isInitialized) worldScreen.dispose() // I hope this will solve some of the many OuOfMemory exceptions...
|
if(::worldScreen.isInitialized) worldScreen.dispose() // I hope this will solve some of the many OuOfMemory exceptions...
|
||||||
loadGame(gameInfo)
|
loadGame(gameInfo)
|
||||||
|
@ -8,6 +8,8 @@ import kotlin.collections.HashMap
|
|||||||
|
|
||||||
class Translations : LinkedHashMap<String, TranslationEntry>(){
|
class Translations : LinkedHashMap<String, TranslationEntry>(){
|
||||||
|
|
||||||
|
val percentCompleteOfLanguages = HashMap<String,Int>()
|
||||||
|
|
||||||
fun get(text:String,language:String): String {
|
fun get(text:String,language:String): String {
|
||||||
if(!hasTranslation(text,language)) return text
|
if(!hasTranslation(text,language)) return text
|
||||||
return get(text)!![language]!!
|
return get(text)!![language]!!
|
||||||
@ -54,7 +56,11 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
|
|||||||
for (translation in languageTranslations) {
|
for (translation in languageTranslations) {
|
||||||
if (!containsKey(translation.key))
|
if (!containsKey(translation.key))
|
||||||
this[translation.key] = TranslationEntry(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
|
val translationFilesTime = System.currentTimeMillis() - translationStart
|
||||||
@ -119,7 +125,7 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPercentageCompleteOfLanguages(): HashMap<String, Int> {
|
fun loadPercentageCompleteOfLanguages() {
|
||||||
|
|
||||||
val translationStart = System.currentTimeMillis()
|
val translationStart = System.currentTimeMillis()
|
||||||
|
|
||||||
@ -127,21 +133,18 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
|
|||||||
Gdx.files.internal("jsons/translationsByLanguage/template.properties")
|
Gdx.files.internal("jsons/translationsByLanguage/template.properties")
|
||||||
.reader().forEachLine { if(it.contains(" = ")) allTranslations+=1 }
|
.reader().forEachLine { if(it.contains(" = ")) allTranslations+=1 }
|
||||||
|
|
||||||
val languageToPercentCompleted = HashMap<String,Int>()
|
|
||||||
for(language in getLanguagesWithTranslationFile()){
|
for(language in getLanguagesWithTranslationFile()){
|
||||||
val translationFileName = "jsons/translationsByLanguage/$language.properties"
|
val translationFileName = "jsons/translationsByLanguage/$language.properties"
|
||||||
var translationsOfThisLanguage=0
|
var translationsOfThisLanguage=0
|
||||||
Gdx.files.internal(translationFileName).reader()
|
Gdx.files.internal(translationFileName).reader()
|
||||||
.forEachLine { if(it.contains(" = ") && !it.endsWith(" = "))
|
.forEachLine { if(it.contains(" = ") && !it.endsWith(" = "))
|
||||||
translationsOfThisLanguage+=1 }
|
translationsOfThisLanguage+=1 }
|
||||||
languageToPercentCompleted[language] = translationsOfThisLanguage*100/allTranslations
|
percentCompleteOfLanguages[language] = translationsOfThisLanguage*100/allTranslations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val translationFilesTime = System.currentTimeMillis() - translationStart
|
val translationFilesTime = System.currentTimeMillis() - translationStart
|
||||||
println("Loading percentage complete of languages - "+translationFilesTime+"ms")
|
println("Loading percentage complete of languages - "+translationFilesTime+"ms")
|
||||||
|
|
||||||
return languageToPercentCompleted
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.models.translations.Translations
|
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.pickerscreens.PickerScreen
|
import com.unciv.ui.pickerscreens.PickerScreen
|
||||||
import com.unciv.ui.utils.ImageGetter
|
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"+
|
"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()
|
" 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
|
languageTables.addAll(languageCompletionPercentage
|
||||||
.map { LanguageTable(it.key,if(it.key=="English") 100 else it.value) }
|
.map { LanguageTable(it.key,if(it.key=="English") 100 else it.value) }
|
||||||
.sortedByDescending { it.percentComplete} )
|
.sortedByDescending { it.percentComplete} )
|
||||||
|
@ -269,7 +269,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
|
|||||||
val languageSelectBox = SelectBox<Language>(skin)
|
val languageSelectBox = SelectBox<Language>(skin)
|
||||||
val languageArray = Array<Language>()
|
val languageArray = Array<Language>()
|
||||||
val ruleSet = worldScreen.gameInfo.ruleSet
|
val ruleSet = worldScreen.gameInfo.ruleSet
|
||||||
Translations().getPercentageCompleteOfLanguages()
|
UncivGame.Current.translations.percentCompleteOfLanguages
|
||||||
.map { Language(it.key, if(it.key=="English") 100 else it.value) }
|
.map { Language(it.key, if(it.key=="English") 100 else it.value) }
|
||||||
.sortedByDescending { it.percentComplete }
|
.sortedByDescending { it.percentComplete }
|
||||||
.forEach { languageArray.add(it) }
|
.forEach { languageArray.add(it) }
|
||||||
|
Loading…
Reference in New Issue
Block a user