chore(purity): eliminate suppressions

This commit is contained in:
yairm210 2025-07-29 18:12:09 +03:00
parent ba6b20925e
commit 5cda15ff3c
4 changed files with 15 additions and 13 deletions

View File

@ -473,7 +473,7 @@ class Civilization : IsPartOfGameInfoSerialization {
* Returns a dictionary of ALL resource names, and the amount that the civ has of each
* Stockpiled resources return the stockpiled amount
*/
@Readonly @Suppress("purity") // component1, component2
@Readonly
fun getCivResourcesByName(): HashMap<String, Int> {
@LocalState
val hashMap = HashMap<String, Int>(gameInfo.ruleset.tileResources.size)

View File

@ -26,6 +26,7 @@ import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.translations.tr
import com.unciv.ui.components.UnitMovementMemoryType
import yairm210.purity.annotations.Cache
import yairm210.purity.annotations.LocalState
import yairm210.purity.annotations.Readonly
import java.text.DecimalFormat
@ -67,7 +68,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
var automated: Boolean = false
// We can infer who we are escorting based on our tile
var escorting: Boolean = false
@Cache private var escorting: Boolean = false
var automatedRoadConnectionDestination: Vector2? = null
// Temp disable, since this data broke saves

View File

@ -258,7 +258,7 @@ enum class Countables(
open val noPlaceholders = !text.contains('[')
// Leave these in place only for the really simple cases
open fun matches(parameterText: String) = if (noPlaceholders) parameterText == text
@Readonly open fun matches(parameterText: String) = if (noPlaceholders) parameterText == text
else parameterText.equalsPlaceholderText(placeholderText)
/** Needs to return the ENTIRE countable, not just parameters. */
@ -267,7 +267,7 @@ enum class Countables(
/** This indicates whether a parameter *is of this countable type*, not *whether its parameters are correct*
* E.g. "[fakeBuilding] Buildings" is obviously a countable of type "[buildingFilter] Buildings", therefore matches will return true.
* But it has another problem, which is that the building filter is bad, so its getErrorSeverity will return "ruleset specific" */
open fun matches(parameterText: String, ruleset: Ruleset): Boolean = false
@Readonly open fun matches(parameterText: String, ruleset: Ruleset): Boolean = false
@Readonly @Suppress("purity") abstract fun eval(parameterText: String, gameContext: GameContext): Int?
open val documentationHeader get() =
@ -290,7 +290,7 @@ enum class Countables(
getErrorSeverity(parameterText.getPlaceholderParameters().first(), ruleset)
companion object {
@Readonly @Suppress("purity")
@Readonly
fun getMatching(parameterText: String, ruleset: Ruleset?) = Countables.entries
.firstOrNull {
if (it.matchesWithRuleset)

View File

@ -476,17 +476,17 @@ private fun String.translateIndividualWord(language: String, hideIcons: Boolean,
* For example, a string like 'The city of [New [York]]' will return ['New [York]'],
* allowing us to have nested translations!
*/
@Readonly
@Pure @Suppress("purity") // IntRange.forEach should be recognized as pure
fun String.getPlaceholderParameters(): List<String> {
if (!this.contains('[')) return emptyList()
val stringToParse = this.removeConditionals()
@LocalState
val parameters = ArrayList<String>()
@LocalState val parameters = ArrayList<String>()
var depthOfBraces = 0
var startOfCurrentParameter = -1
for (i in stringToParse.indices) {
val stringIndices = stringToParse.indices
stringIndices.forEach { i ->
if (stringToParse[i] == '[') {
if (depthOfBraces == 0) startOfCurrentParameter = i+1
depthOfBraces++
@ -499,16 +499,17 @@ fun String.getPlaceholderParameters(): List<String> {
return parameters
}
@Readonly
@Pure
fun String.getPlaceholderText(): String {
var stringToReturn = this.removeConditionals()
val placeholderParameters = stringToReturn.getPlaceholderParameters()
for (placeholderParameter in placeholderParameters)
@LocalState val placeholderParameters = stringToReturn.getPlaceholderParameters()
placeholderParameters.forEach { placeholderParameter ->
stringToReturn = stringToReturn.replaceFirst("[$placeholderParameter]", "[]")
}
return stringToReturn
}
@Readonly
@Pure
fun String.equalsPlaceholderText(str: String): Boolean {
if (isEmpty()) return str.isEmpty()
if (str.isEmpty()) return false // Empty strings have no .first()