From c3cdae12d44f875e1fe070a1f8f7301bf19e22e0 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 4 Aug 2018 23:57:53 +0300 Subject: [PATCH] Tutorials are now defined per language! --- ...{Tutorials.json => Tutorials_English.json} | 10 +++---- .../com/unciv/models/gamebasics/GameBasics.kt | 7 ----- .../unciv/ui/utils/CameraStageBaseScreen.kt | 26 ++++++++++++++++++- 3 files changed, 30 insertions(+), 13 deletions(-) rename android/assets/jsons/{Tutorials.json => Tutorials_English.json} (95%) diff --git a/android/assets/jsons/Tutorials.json b/android/assets/jsons/Tutorials_English.json similarity index 95% rename from android/assets/jsons/Tutorials.json rename to android/assets/jsons/Tutorials_English.json index f289a028..a8df7395 100644 --- a/android/assets/jsons/Tutorials.json +++ b/android/assets/jsons/Tutorials_English.json @@ -1,12 +1,12 @@ - -{ - PolicyPickerScreen: [ - [ +{ // Each entry s a tutorial, but the tutorial may be spread over separate paragraphs. + // so for example: + PolicyPickerScreen: [ // Activated when entering policy picker screen + [ // This is simply a more comfortable format than "all in one line with \n". "Each turn, the culture you gain from all your ", " cities is added to your Civilization's culture.", "When you have enough culture, you may pick a ", " Social Policy, each one giving you a certain bonus." - ], + ], // this will be displayed as 4 lines of text in-game as well [ "The policies are organized into branches, with each", " branch providing a bonus ability when all policies ", diff --git a/core/src/com/unciv/models/gamebasics/GameBasics.kt b/core/src/com/unciv/models/gamebasics/GameBasics.kt index 09e7a841..baac81ab 100644 --- a/core/src/com/unciv/models/gamebasics/GameBasics.kt +++ b/core/src/com/unciv/models/gamebasics/GameBasics.kt @@ -24,7 +24,6 @@ object GameBasics { val Civilizations = LinkedHashMap() val PolicyBranches = LinkedHashMap() val Difficulties = LinkedHashMap() - val Tutorials = LinkedHashMap>() val Translations = Translations(Gdx.files.internal("jsons/Translations.json").readString()) fun getFromJson(tClass: Class, name: String): T { @@ -51,12 +50,6 @@ object GameBasics { Civilizations += createHashmap(getFromJson(Array::class.java, "Civilizations")) Difficulties += createHashmap(getFromJson(Array::class.java, "Difficulties")) - // ...Yes. Total Voodoo. I wish I didn't have to do this. - val x = LinkedHashMap>>() - val tutorials = getFromJson(x.javaClass, "Tutorials") - for (tut in tutorials) - Tutorials[tut.key] = tut.value.map{it.joinToString("\r\n")} - val techColumns = getFromJson(Array::class.java, "Techs") for (techColumn in techColumns) { for (tech in techColumn.techs) { diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 5313421d..ad32f2d5 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -20,6 +20,7 @@ import com.badlogic.gdx.utils.viewport.ExtendViewport import com.unciv.UnCivGame import com.unciv.models.gamebasics.GameBasics import java.util.* +import kotlin.collections.HashMap open class CameraStageBaseScreen : Screen { @@ -59,11 +60,34 @@ open class CameraStageBaseScreen : Screen { override fun dispose() {} + fun getTutorialsOfLanguage(language: String): HashMap> { + if(!Gdx.files.internal("jsons/Tutorials_$language.json").exists()) return hashMapOf() + + // ...Yes. Disgusting. I wish I didn't have to do this. + val x = LinkedHashMap>>() + val tutorials: LinkedHashMap>> = + GameBasics.getFromJson(x.javaClass, "Tutorials_$language") + val tutorialMap = HashMap>() + for (tut in tutorials){ + val list = mutableListOf() + for(paragraph in tut.value) + list += paragraph.joinToString("\n") + tutorialMap[tut.key] = list + } + return tutorialMap + } + + fun getTutorials(name:String, language:String):List{ + val tutorialsOfLanguage = getTutorialsOfLanguage(language) + if(tutorialsOfLanguage.containsKey(name)) return tutorialsOfLanguage[name]!! + return getTutorialsOfLanguage("English")[name]!! + } + fun displayTutorials(name: String) { if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return UnCivGame.Current.settings.tutorialsShown.add(name) UnCivGame.Current.settings.save() - val texts = GameBasics.Tutorials[name]!! + val texts = getTutorials(name,UnCivGame.Current.settings.language) tutorialTexts.addAll(texts) if (!isTutorialShowing) displayTutorial() }