Tutorials are now defined per language!

This commit is contained in:
Yair Morgenstern 2018-08-04 23:57:53 +03:00
parent 7983901435
commit c3cdae12d4
3 changed files with 30 additions and 13 deletions

View file

@ -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 ",

View file

@ -24,7 +24,6 @@ object GameBasics {
val Civilizations = LinkedHashMap<String, Civilization>()
val PolicyBranches = LinkedHashMap<String, PolicyBranch>()
val Difficulties = LinkedHashMap<String, Difficulty>()
val Tutorials = LinkedHashMap<String, List<String>>()
val Translations = Translations(Gdx.files.internal("jsons/Translations.json").readString())
fun <T> getFromJson(tClass: Class<T>, name: String): T {
@ -51,12 +50,6 @@ object GameBasics {
Civilizations += createHashmap(getFromJson(Array<Civilization>::class.java, "Civilizations"))
Difficulties += createHashmap(getFromJson(Array<Difficulty>::class.java, "Difficulties"))
// ...Yes. Total Voodoo. I wish I didn't have to do this.
val x = LinkedHashMap<String,com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>>()
val tutorials = getFromJson(x.javaClass, "Tutorials")
for (tut in tutorials)
Tutorials[tut.key] = tut.value.map{it.joinToString("\r\n")}
val techColumns = getFromJson(Array<TechColumn>::class.java, "Techs")
for (techColumn in techColumns) {
for (tech in techColumn.techs) {

View file

@ -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<String, List<String>> {
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<String,com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>>()
val tutorials: LinkedHashMap<String, com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>> =
GameBasics.getFromJson(x.javaClass, "Tutorials_$language")
val tutorialMap = HashMap<String,List<String>>()
for (tut in tutorials){
val list = mutableListOf<String>()
for(paragraph in tut.value)
list += paragraph.joinToString("\n")
tutorialMap[tut.key] = list
}
return tutorialMap
}
fun getTutorials(name:String, language:String):List<String>{
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()
}