Civilopedia Welcome, moddable (#8940)

This commit is contained in:
SomeTroglodyte
2023-03-31 13:58:07 +02:00
committed by GitHub
parent de7177692f
commit 45d66f0580
6 changed files with 79 additions and 14 deletions

View File

@ -24,10 +24,26 @@ class TutorialController(screen: BaseScreen) {
var allTutorialsShowedCallback: (() -> Unit)? = null
private val tutorialRender = TutorialRender(screen)
//todo These should live in a ruleset allowing moddability
private val tutorials: LinkedHashMap<String, Tutorial> =
json().fromJsonFile(Array<Tutorial>::class.java, "jsons/Tutorials.json")
.associateByTo(linkedMapOf()) { it.name }
private val tutorials: LinkedHashMap<String, Tutorial> = loadTutorialsFromJson()
companion object {
// static to allow use from TutorialTranslationTests
fun loadTutorialsFromJson(includeMods: Boolean = true): LinkedHashMap<String, Tutorial> {
val result = linkedMapOf<String, Tutorial>()
for (path in tutorialFiles(includeMods)) {
json().fromJsonFile(Array<Tutorial>::class.java, path)
.associateByTo(result) { it.name }
}
return result
}
private fun tutorialFiles(includeMods: Boolean) = sequence<String> {
yield("jsons/Tutorials.json")
if (!includeMods) return@sequence
val mods = UncivGame.Current.gameInfo?.ruleset?.mods ?: return@sequence
val names = mods.asSequence().map { "mods/$it/jsons/Tutorials.json" }
yieldAll(names.filter { Gdx.files.local(it).exists() })
}
}
fun showTutorial(tutorial: TutorialTrigger) {
tutorialQueue.add(tutorial)

View File

@ -11,6 +11,7 @@ import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.models.ruleset.Belief
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.ruleset.unique.IHasUniques
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.UnitType
@ -182,6 +183,14 @@ class CivilopediaScreen(
it.color = if (it.name == entry.name) Color.BLUE else Color.WHITE
}
}
private fun selectDefaultEntry() {
val name = ruleset.mods.asSequence()
.filter { RulesetCache[it]?.modOptions?.isBaseRuleset == true }
.plus("Civilopedia")
.firstOrNull { it in entryIndex.keys }
?: return
selectEntry(name , noScrollAnimation = true)
}
init {
val imageSize = 50f
@ -287,6 +296,9 @@ class CivilopediaScreen(
if (link.isEmpty() || '/' !in link)
selectCategory(category)
// show a default entry when opened without a target
if (link.isEmpty() && category == CivilopediaCategories.Tutorial)
selectDefaultEntry()
if (link.isNotEmpty())
if ('/' in link)
selectLink(link)