mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-24 18:06:04 +07:00
Added TileSetConfigs (#3766)
* First iteration of TileSet json * Adding json support for mods * Renamed TilesetConfig to TileSetConfig + changed the config for FHex to fix the mountain natural wonder problem
This commit is contained in:
parent
881a885c14
commit
b7d6bacc5b
12
android/assets/jsons/TileSets/FantasyHexConfig.json
Normal file
12
android/assets/jsons/TileSets/FantasyHexConfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"useColorAsBaseTerrain": "false",
|
||||
"ruleVariants": {
|
||||
"Mountain+Barringer Crater": ["Barringer Crater"],
|
||||
"Mountain+Cerro de Potosi": ["Cerro de Potosi"],
|
||||
"Mountain+Grand Mesa": ["Grand Mesa"],
|
||||
"Mountain+Krakatoa": ["Krakatoa"],
|
||||
"Mountain+Mount Fuji": ["Mount Fuji"],
|
||||
"Mountain+Old Faithful": ["Old Faithful"],
|
||||
"Mountain+Rock of Gibraltar": ["Rock of Gibraltar"]
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import com.unciv.logic.GameSaver
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.tilesets.TileSetCache
|
||||
import com.unciv.models.translations.Translations
|
||||
import com.unciv.ui.LanguagePickerScreen
|
||||
import com.unciv.ui.utils.*
|
||||
@ -97,6 +98,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
||||
RulesetCache.loadRulesets(printOutput = true)
|
||||
translations.tryReadTranslationForCurrentLanguage()
|
||||
translations.loadPercentageCompleteOfLanguages()
|
||||
TileSetCache.loadTileSetConfigs(printOutput = true)
|
||||
|
||||
if (settings.userId.isEmpty()) { // assign permanent user id
|
||||
settings.userId = UUID.randomUUID().toString()
|
||||
|
62
core/src/com/unciv/models/tilesets/TileSetCache.kt
Normal file
62
core/src/com/unciv/models/tilesets/TileSetCache.kt
Normal file
@ -0,0 +1,62 @@
|
||||
package com.unciv.models.tilesets
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.unciv.JsonParser
|
||||
|
||||
object TileSetCache : HashMap<String, TileSetConfig>(){
|
||||
fun loadTileSetConfigs(consoleMode: Boolean = false, printOutput: Boolean = false){
|
||||
clear()
|
||||
var tileSetName = ""
|
||||
|
||||
//load default TileSets
|
||||
for (configFile in Gdx.files.local("jsons/TileSets").list()){
|
||||
tileSetName = configFile.nameWithoutExtension().removeSuffix("Config")
|
||||
try {
|
||||
if (this[tileSetName] == null)
|
||||
this[tileSetName] = JsonParser().getFromJson(TileSetConfig::class.java, configFile)
|
||||
else
|
||||
this[tileSetName]!!.updateConfig(JsonParser().getFromJson(TileSetConfig::class.java, configFile))
|
||||
if (printOutput) {
|
||||
println("TileSetConfig loaded successfully: ${configFile.name()}")
|
||||
println()
|
||||
}
|
||||
} catch (ex: Exception){
|
||||
if (printOutput){
|
||||
println("Exception loading TileSetConfig '${configFile.path()}':")
|
||||
println(" ${ex.localizedMessage}")
|
||||
println(" (Source file ${ex.stackTrace[0].fileName} line ${ex.stackTrace[0].lineNumber})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load mod TileSets
|
||||
val modsHandles = if (consoleMode) FileHandle("mods").list()
|
||||
else Gdx.files.local("mods").list()
|
||||
|
||||
for (modFolder in modsHandles) {
|
||||
if (modFolder.name().startsWith('.')) continue
|
||||
if (!modFolder.isDirectory) continue
|
||||
|
||||
try {
|
||||
for (configFile in modFolder.child("jsons/TileSets").list()){
|
||||
tileSetName = configFile.nameWithoutExtension().removeSuffix("Config")
|
||||
if (this[tileSetName] == null)
|
||||
this[tileSetName] = JsonParser().getFromJson(TileSetConfig::class.java, configFile)
|
||||
else
|
||||
this[tileSetName]!!.updateConfig(JsonParser().getFromJson(TileSetConfig::class.java, configFile))
|
||||
if (printOutput) {
|
||||
println("TileSetConfig loaded successfully: ${configFile.path()}")
|
||||
println()
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception){
|
||||
if (printOutput) {
|
||||
println("Exception loading TileSetConfig '${modFolder.name()}/jsons/TileSets/${tileSetName}':")
|
||||
println(" ${ex.localizedMessage}")
|
||||
println(" (Source file ${ex.stackTrace[0].fileName} line ${ex.stackTrace[0].lineNumber})")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
core/src/com/unciv/models/tilesets/TileSetConfig.kt
Normal file
13
core/src/com/unciv/models/tilesets/TileSetConfig.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.unciv.models.tilesets
|
||||
|
||||
class TileSetConfig {
|
||||
var useColorAsBaseTerrain = true
|
||||
var ruleVariants: HashMap<String, Array<String>> = HashMap()
|
||||
|
||||
fun updateConfig(other: TileSetConfig){
|
||||
useColorAsBaseTerrain = other.useColorAsBaseTerrain
|
||||
for ((tileSetString, renderOrder) in other.ruleVariants){
|
||||
ruleVariants[tileSetString] = renderOrder
|
||||
}
|
||||
}
|
||||
}
|
@ -182,10 +182,14 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings,
|
||||
resourceAndImprovementSequence = resourceAndImprovementSequence.filterNotNull()
|
||||
|
||||
val terrainImages = (sequenceOf(tileInfo.baseTerrain) + tileInfo.terrainFeatures.asSequence()).filterNotNull()
|
||||
val allTogether = (terrainImages + resourceAndImprovementSequence).joinToString("+").let { tileSetStrings.getTile(it) }
|
||||
val allTogether = (terrainImages + resourceAndImprovementSequence).joinToString("+")
|
||||
val allTogetherLocation = tileSetStrings.getTile(allTogether)
|
||||
|
||||
if (ImageGetter.imageExists(allTogether)) return listOf(allTogether)
|
||||
else return getTerrainImageLocations(terrainImages) + getImprovementAndResourceImages(resourceAndImprovementSequence)
|
||||
return when {
|
||||
tileSetStrings.tileSetConfig.ruleVariants[allTogether] != null -> tileSetStrings.tileSetConfig.ruleVariants[allTogether]!!.map { tileSetStrings.getTile(it) }
|
||||
ImageGetter.imageExists(allTogetherLocation) -> listOf(allTogetherLocation)
|
||||
else -> getTerrainImageLocations(terrainImages) + getImprovementAndResourceImages(resourceAndImprovementSequence)
|
||||
}
|
||||
}
|
||||
|
||||
fun getTerrainImageLocations(terrainSequence: Sequence<String>): List<String> {
|
||||
@ -195,8 +199,6 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings,
|
||||
}
|
||||
|
||||
fun getImprovementAndResourceImages(resourceAndImprovementSequence: Sequence<String>): List<String> {
|
||||
if(tileInfo.resource=="Silk")
|
||||
println()
|
||||
val altogether = resourceAndImprovementSequence.joinToString("+").let { tileSetStrings.getTile(it) }
|
||||
if (ImageGetter.imageExists(altogether)) return listOf(altogether)
|
||||
else return resourceAndImprovementSequence.map { tileSetStrings.getTile(it) }.toList()
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.unciv.ui.tilegroups
|
||||
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.tilesets.TileSetCache
|
||||
import com.unciv.models.tilesets.TileSetConfig
|
||||
|
||||
class TileSetStrings {
|
||||
// this is so that when we have 100s of TileGroups, they won't all individually come up with all these strings themselves,
|
||||
// it gets pretty memory-intensive (10s of MBs which is a lot for lower-end phones)
|
||||
val tileSetLocation = "TileSets/" + UncivGame.Current.settings.tileSet + "/"
|
||||
val tileSetConfig = TileSetCache[UncivGame.Current.settings.tileSet] ?: TileSetConfig()
|
||||
|
||||
val hexagon = tileSetLocation + "Hexagon"
|
||||
val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon"
|
||||
|
@ -12,6 +12,7 @@ import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.metadata.Player
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.simulation.Simulation
|
||||
import com.unciv.models.tilesets.TileSetCache
|
||||
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||
|
||||
internal object ConsoleLauncher {
|
||||
@ -35,6 +36,7 @@ internal object ConsoleLauncher {
|
||||
}
|
||||
|
||||
RulesetCache.loadRulesets(true)
|
||||
TileSetCache.loadTileSetConfigs(true)
|
||||
|
||||
val gameParameters = getGameParameters("China", "Greece")
|
||||
val mapParameters = getMapParameters()
|
||||
|
Loading…
Reference in New Issue
Block a user