Allow default unitset and tileset for base ruleset mods

This commit is contained in:
yairm210
2024-08-04 10:17:22 +03:00
parent dba6d755ad
commit e01ba625ba
11 changed files with 40 additions and 25 deletions

View File

@ -245,6 +245,7 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci
}
val fullModList = newGameInfo.gameParameters.getModsAndBaseRuleset()
musicController.setModList(fullModList)
settings.tileSet
}
/** Re-creates the current [worldScreen], if there is any. */

View File

@ -660,11 +660,6 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
val tilesWithLowestRow = tileMap.tileList.groupBy { it.getRow() }.minBy { it.key }.value
if (tilesWithLowestRow.size > 2) tileMap.mapParameters.shape = MapShape.rectangular
// Set all to worldwrap if we have a good number of columns for it
// TODO REMOVE THIS SOON since this means default rectangle maps are world-wrap-ified!
val columns = tileMap.tileList.groupBy { it.getColumn() }.size
tileMap.mapParameters.worldWrap = columns % 2 == 0
if (currentPlayer == "") currentPlayer =
if (gameParameters.isOnlineMultiplayer) civilizations.first { it.isHuman() && !it.isSpectator() }.civName // For MP, spectator doesn't get a 'turn'
else civilizations.first { it.isHuman() }.civName // for non-MP games, you can be a spectator of an AI-only match, and you *do* get a turn, sort of

View File

@ -14,6 +14,8 @@ class ModOptions : IHasUniques {
var unitsToRemove = HashSet<String>()
var nationsToRemove = HashSet<String>()
val constants = ModConstants()
var defaultUnitset: String? = null
var defaultTileset: String? = null
//endregion
//region Metadata, automatic

View File

@ -149,6 +149,9 @@ object RulesetCache : HashMap<String, Ruleset>() {
// This is so we don't keep using the base ruleset's uniques *by reference* and add to in ad infinitum
newRuleset.modOptions.uniques = ArrayList()
newRuleset.modOptions.isBaseRuleset = true
// Default tileset and unitset are according to base ruleset
newRuleset.modOptions.defaultTileset = mod.modOptions.defaultTileset
newRuleset.modOptions.defaultUnitset = mod.modOptions.defaultUnitset
}
newRuleset.add(mod)
newRuleset.mods += mod.name

View File

@ -4,6 +4,8 @@ import com.unciv.UncivGame
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.RoadStatus
import com.unciv.models.metadata.GameSettings
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.tilesets.TileSetCache
import com.unciv.models.tilesets.TileSetConfig
import com.unciv.ui.images.ImageAttempter
@ -30,6 +32,13 @@ class TileSetStrings(
unitSet: String? = UncivGame.Current.settings.unitSet,
fallbackDepth: Int = 1
) {
constructor(ruleset: Ruleset, settings: GameSettings) : this(
ruleset.modOptions.defaultTileset ?: settings.tileSet,
ruleset.modOptions.defaultUnitset ?: settings.unitSet
)
/** Separator used to mark variants, e.g. nation style or era specific */
val tag = "-"
@ -48,7 +57,7 @@ class TileSetStrings(
val unexploredTile by lazy { orFallback { tileSetLocation + "UnexploredTile" } }
val crosshair by lazy { orFallback { getString(tileSetLocation, "Crosshair") } }
val highlight by lazy { orFallback { getString(tileSetLocation, "Highlight") } }
val roadsMap = RoadStatus.values()
val roadsMap = RoadStatus.entries
.filterNot { it == RoadStatus.None }
.associateWith { tileSetLocation + it.name }
val naturalWonder = tileSetLocation + "Tiles/NaturalWonder"

View File

@ -337,7 +337,7 @@ class CityScreen(
private fun addTiles() {
val viewRange = max(city.getExpandRange(), city.getWorkRange())
val tileSetStrings = TileSetStrings()
val tileSetStrings = TileSetStrings(city.civ.gameInfo.ruleset, game.settings)
val cityTileGroups = city.getCenterTile().getTilesInDistance(viewRange)
.filter { selectedCiv.hasExplored(it) }
.map { CityTileGroup(city, it, tileSetStrings, fireworks != null) }

View File

@ -3,6 +3,7 @@ package com.unciv.ui.screens.civilopediascreen
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.Container
import com.unciv.UncivGame
import com.unciv.logic.map.tile.Tile
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.tile.Terrain
@ -43,7 +44,7 @@ internal object CivilopediaImageGetters {
tile.baseTerrain = terrain.name
}
tile.setTerrainTransients()
val group = TileGroup(tile, TileSetStrings(), imageSize * 36f / 54f) // TileGroup normally spills out of its bounding box
val group = TileGroup(tile, TileSetStrings(ruleset, UncivGame.Current.settings), imageSize * 36f / 54f) // TileGroup normally spills out of its bounding box
group.isForceVisible = true
group.isForMapEditorIcon = true
group.update()
@ -91,7 +92,7 @@ internal object CivilopediaImageGetters {
ImageGetter.getReligionPortrait(name, size)
}
val unitType = { name: String, size: Float ->
val path = UnitMovementType.values().firstOrNull { "Domain: [${it.name}]" == name }
val path = UnitMovementType.entries.firstOrNull { "Domain: [${it.name}]" == name }
?.let {"UnitTypeIcons/Domain${it.name}" }
?: "UnitTypeIcons/$name"
if (ImageGetter.imageExists(path)) ImageGetter.getImage(path).apply { setSize(size) }

View File

@ -69,7 +69,9 @@ class EditorMapHolder(
private fun addTiles(stage: Stage) {
val tileSetStrings = TileSetStrings()
val tileSetStrings =
if (editorScreen != null) TileSetStrings(editorScreen.ruleset, editorScreen.game.settings)
else TileSetStrings()
val daTileGroups = tileMap.values.map { TileGroup(it, tileSetStrings) }
tileGroupMap = TileGroupMap(this, daTileGroups, continuousScrollingX)

View File

@ -225,7 +225,7 @@ class MapEditorEditImprovementsTab(
getImprovements(),
iconDisplay = FormattedLine.IconDisplay.NoLink
) {
val road = RoadStatus.values().firstOrNull { r -> r.name == it }
val road = RoadStatus.entries.firstOrNull { r -> r.name == it }
if (road != null)
editTab.setBrush(BrushHandlerType.Road, it, "Improvement/$it") { tile ->
tile.roadStatus = if (tile.roadStatus == road) RoadStatus.None else road
@ -256,7 +256,7 @@ class MapEditorEditImprovementsTab(
companion object {
private fun TileImprovement.group() = when {
RoadStatus.values().any { it.name == name } -> 2
RoadStatus.entries.any { it.name == name } -> 2
"Great Improvement" in uniques -> 3
uniqueTo != null -> 4
"Unpillagable" in uniques -> 5
@ -304,7 +304,7 @@ class MapEditorEditStartsTab(
val icon = "Nation/$it"
val pediaLink = if (it == Constants.spectator) "" else icon
val isMajorCiv = ruleset.nations[it]?.isMajorCiv ?: false
val selectedUsage = if (isMajorCiv) TileMap.StartingLocation.Usage.values()[usageOptionGroup.checkedIndex]
val selectedUsage = if (isMajorCiv) TileMap.StartingLocation.Usage.entries[usageOptionGroup.checkedIndex]
else TileMap.StartingLocation.Usage.Normal
editTab.setBrush(BrushHandlerType.Direct, it.spectatorToAnyCiv(), icon, pediaLink) { tile ->
// toggle the starting location here, note this allows
@ -332,7 +332,7 @@ class MapEditorEditStartsTab(
table.defaults().pad(5f)
table.add("Use for new game \"Select players\" button:".toLabel()).colspan(3).row()
val defaultUsage = TileMap.StartingLocation.Usage.default
for (usage in TileMap.StartingLocation.Usage.values()) {
for (usage in TileMap.StartingLocation.Usage.entries) {
val checkBox = CheckBox(usage.label.tr(), skin)
table.add(checkBox)
usageOptionGroup.add(checkBox)
@ -447,7 +447,7 @@ class MapEditorEditRiversTab(
private fun Tile.makeTileGroup(): TileGroup {
ruleset = this@MapEditorEditRiversTab.ruleset
setTerrainTransients()
return TileGroup(this, TileSetStrings(), iconSize * 36f/54f).apply {
return TileGroup(this, TileSetStrings(ruleset, UncivGame.Current.settings), iconSize * 36f/54f).apply {
isForceVisible = true
isForMapEditorIcon = true
update()

View File

@ -101,7 +101,7 @@ class WorldMapHolder(
internal fun addTiles() {
val tileSetStrings = TileSetStrings()
val tileSetStrings = TileSetStrings(worldScreen.gameInfo.ruleset, worldScreen.game.settings)
currentTileSetStrings = tileSetStrings
val tileGroupsNew = tileMap.values.map { WorldTileGroup(it, tileSetStrings) }
tileGroupMap = TileGroupMap(this, tileGroupsNew, continuousScrollingX)

View File

@ -153,15 +153,17 @@ Incompatibility filtering works so far between extension and base mods, but feel
The file can have the following attributes, not including the values Unciv sets automatically:
| Attribute | Type | | Notes |
|-------------------|---------|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| isBaseRuleset | Boolean | false | Replaces vanilla ruleset if true |
| uniques | List | empty | Mod-wide specials, [see here](../../uniques.md#modoptions-uniques) |
| techsToRemove | List | empty | List of [Technologies](2-Civilization-related-JSON-files.md#techsjson) or [technologyFilter](../../Unique-parameters.md#technologyfilter) to remove (isBaseRuleset=false only) |
| buildingsToRemove | List | empty | List of [Buildings or Wonders](2-Civilization-related-JSON-files.md#buildingsjson) or [buildingFilter](../../Unique-parameters.md#buildingfilter) to remove (isBaseRuleset=false only) |
| unitsToRemove | List | empty | List of [Units](4-Unit-related-JSON-files.md#unitsjson) or [unitFilter](../../Unique-parameters.md#baseunitfilter) to remove (isBaseRuleset=false only) |
| nationsToRemove | List | empty | List of [Nations](2-Civilization-related-JSON-files.md#nationsjson) or [nationFilter](../../Unique-parameters.md#nationfilter) to remove (isBaseRuleset=false only) |
| constants | Object | empty | See [ModConstants](#modconstants) |
| Attribute | Type | default | Notes |
|-------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| isBaseRuleset | Boolean | false | Replaces vanilla ruleset if true |
| uniques | List | empty | Mod-wide specials, [see here](../../uniques.md#modoptions-uniques) |
| techsToRemove | List | empty | List of [Technologies](2-Civilization-related-JSON-files.md#techsjson) or [technologyFilter](../../Unique-parameters.md#technologyfilter) to remove (isBaseRuleset=false only) |
| buildingsToRemove | List | empty | List of [Buildings or Wonders](2-Civilization-related-JSON-files.md#buildingsjson) or [buildingFilter](../../Unique-parameters.md#buildingfilter) to remove (isBaseRuleset=false only) |
| unitsToRemove | List | empty | List of [Units](4-Unit-related-JSON-files.md#unitsjson) or [unitFilter](../../Unique-parameters.md#baseunitfilter) to remove (isBaseRuleset=false only) |
| nationsToRemove | List | empty | List of [Nations](2-Civilization-related-JSON-files.md#nationsjson) or [nationFilter](../../Unique-parameters.md#nationfilter) to remove (isBaseRuleset=false only) |
| constants | Object | empty | See [ModConstants](#modconstants) |
| defaultTileset | String | empty | Only applicable for base rulesets |
| defaultUnitset | String | empty | Only applicable for base rulesets |
The values normally set automatically from github metadata are: