From e5e86aa0d782e5fa57106ba12b21d008046903c6 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:59:58 +0100 Subject: [PATCH] Avoid Civilopedia stumbling over missing Grassland (#10953) * Avoid Civilopedia stumbling over missing Grassland * A few wiki comments on Terrain * Minor linting of my own crud * Pedia linking PromotionPickerScreen * Change actionTypeToFunctions signature to use Sequence --- .../civilopediascreen/CivilopediaImageGetters.kt | 13 ++++++------- .../ui/screens/pickerscreens/PolicyPickerScreen.kt | 4 ++-- .../screens/pickerscreens/PromotionPickerScreen.kt | 9 +++++++++ .../Mod-file-structure/3-Map-related-JSON-files.md | 9 +++++++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt index 65e1ba566d..8f80b82997 100644 --- a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt +++ b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt @@ -3,7 +3,6 @@ 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.Constants import com.unciv.logic.map.tile.Tile import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.tile.Terrain @@ -26,17 +25,17 @@ internal object CivilopediaImageGetters { private fun terrainImage(terrain: Terrain, ruleset: Ruleset, imageSize: Float): Actor { val tile = Tile() tile.ruleset = ruleset + val baseTerrainFromOccursOn = + terrain.occursOn.mapNotNull { ruleset.terrains[it] }.lastOrNull { it.type.isBaseTerrain }?.name + ?: ruleset.terrains.values.firstOrNull { it.type == TerrainType.Land }?.name + ?: ruleset.terrains.keys.first() when (terrain.type) { TerrainType.NaturalWonder -> { tile.naturalWonder = terrain.name - tile.baseTerrain = terrain.turnsInto ?: terrain.occursOn.firstOrNull() ?: Constants.grassland + tile.baseTerrain = terrain.turnsInto ?: baseTerrainFromOccursOn } TerrainType.TerrainFeature -> { - tile.baseTerrain = - if (terrain.occursOn.isEmpty() || terrain.occursOn.contains(Constants.grassland)) - Constants.grassland - else - terrain.occursOn.lastOrNull()!! + tile.baseTerrain = baseTerrainFromOccursOn tile.setTerrainTransients() tile.addTerrainFeature(terrain.name) } diff --git a/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt index cc6fdd8d48..5beaabf6c1 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt @@ -229,9 +229,9 @@ class PolicyPickerScreen( } scrollPane.updateVisualScroll() - when(select) { + when (select) { in branches -> branchToGroup[select]?.toggle() - in policyNameToButton -> policyNameToButton[select]!!.also { pickPolicy(it) } + in policyNameToButton -> pickPolicy(policyNameToButton[select]!!) } } diff --git a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt index 2f97656d90..a7ebcedde1 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -16,11 +16,15 @@ import com.unciv.models.translations.tr import com.unciv.ui.audio.SoundPlayer import com.unciv.ui.components.extensions.isEnabled import com.unciv.ui.components.extensions.toTextButton +import com.unciv.ui.components.input.KeyboardBinding +import com.unciv.ui.components.input.keyShortcuts +import com.unciv.ui.components.input.onActivation import com.unciv.ui.components.input.onClick import com.unciv.ui.components.input.onDoubleClick import com.unciv.ui.images.ImageGetter import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.screens.basescreen.RecreateOnResize +import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen import kotlin.math.abs class PromotionPickerScreen( @@ -324,6 +328,11 @@ class PromotionPickerScreen( } val promotionText = node.promotion.getDescription(tree.possiblePromotions) descriptionLabel.setText("$topLine\n$promotionText") + descriptionLabel.clearListeners() + descriptionLabel.onActivation { + game.pushScreen(CivilopediaScreen(unit.baseUnit.ruleset, link = node.promotion.makeLink())) + } + descriptionLabel.keyShortcuts.add(KeyboardBinding.Civilopedia) } override fun recreate() = recreate(closeOnPick) diff --git a/docs/Modders/Mod-file-structure/3-Map-related-JSON-files.md b/docs/Modders/Mod-file-structure/3-Map-related-JSON-files.md index 01ca8a0d80..a33787b100 100644 --- a/docs/Modders/Mod-file-structure/3-Map-related-JSON-files.md +++ b/docs/Modders/Mod-file-structure/3-Map-related-JSON-files.md @@ -10,8 +10,8 @@ Each terrain entry has the following structure: | Attribute | Type | Default | Notes | | --------- | ---- | ------- | ----- | -| name | String | Required | | -| type | Enum | Required | Land, Water, TerrainFeature, NaturalWonder | +| name | String | Required | [^A] | +| type | Enum | Required | Land, Water, TerrainFeature, NaturalWonder [^B] | | occursOn | List of Strings | none | Only for terrain features and Natural Wonders: The baseTerrain it can be placed on | | turnsInto | String | none | Only for NaturalWonder: the base terrain is changed to this after placing the Natural Wonder | | weight | Integer | 10 | Only for NaturalWonder: _relative_ weight of being picked by the map generator | @@ -25,6 +25,11 @@ Each terrain entry has the following structure: | uniques | List of Strings | empty | List of [unique abilities](../uniques) this terrain has | | civilopediaText | List | empty | See [civilopediaText chapter](5-Miscellaneous-JSON-files.md#civilopedia-text) | +[^A]: Some names have special meanings. `Grassland` is used as fallback in some cases - e.g. Civilopedia prefers to displays a TerrainFeature on top of it, unless `occursOn` is not empty and does not contain it. + `River` is hardcoded to be used to look up a [Stats](../uniques.md#global-uniques) unique to determine the bonuses an actual River provides (remember, rivers live on the edges not as terrain). + River should always be a TerrainFeature and have the same uniques the one in the vanilla rulesets has - if you change that, expect surprises. +[^B]: A base ruleset mod is always expected to provide at least one Land and at least one Water terrain. We do not support Land-only or Water-only mods, even if they might be possible to pull off. + ## TileImprovements.json [Link to original](https://github.com/yairm210/Unciv/blob/master/android/assets/jsons/Civ%20V%20-%20Vanilla/TileImprovements.json)