mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
Civilopedia Welcome, moddable (#8940)
This commit is contained in:
@ -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)
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user