chore(purity): Remove more suppressions

This commit is contained in:
yairm210 2025-07-30 20:41:34 +03:00
parent 141a4d17bf
commit e9ee616c1f
6 changed files with 19 additions and 12 deletions

View File

@ -61,6 +61,7 @@ allprojects {
"kotlin.collections.reversed"
)
wellKnownPureClasses = setOf(
"java.util.Locale",
)
}

View File

@ -55,6 +55,7 @@ import com.unciv.models.translations.tr
import com.unciv.ui.components.extensions.toPercent
import com.unciv.ui.screens.victoryscreen.RankingType
import org.jetbrains.annotations.VisibleForTesting
import yairm210.purity.annotations.Cache
import yairm210.purity.annotations.LocalState
import yairm210.purity.annotations.Readonly
import kotlin.math.max
@ -127,9 +128,6 @@ class Civilization : IsPartOfGameInfoSerialization {
@Transient
val cityStateFunctions = CityStateFunctions(this)
@Transient
var cachedMilitaryMight = -1
@Transient
var passThroughImpassableUnlocked = false // Cached Boolean equal to passableImpassables.isNotEmpty()
@ -714,12 +712,17 @@ class Civilization : IsPartOfGameInfoSerialization {
}
}
@Readonly @Suppress("purity") // caches
@Transient @Cache
private var cachedMilitaryMight = -1
@Readonly
private fun getMilitaryMight(): Int {
if (cachedMilitaryMight < 0)
cachedMilitaryMight = calculateMilitaryMight()
return cachedMilitaryMight
}
fun resetMilitaryMightCache() { cachedMilitaryMight = -1 }
@Readonly
private fun calculateMilitaryMight(): Int {

View File

@ -317,7 +317,7 @@ class TurnManager(val civInfo: Civilization) {
civInfo.diplomacy.values.toList().forEach { it.nextTurn() } // we copy the diplomacy values so if it changes in-loop we won't crash
civInfo.cache.updateHasActiveEnemyMovementPenalty()
civInfo.cachedMilitaryMight = -1 // Reset so we don't use a value from a previous turn
civInfo.resetMilitaryMightCache()
updateWinningCiv() // Maybe we did something this turn to win
}

View File

@ -670,7 +670,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
return null
}
@Readonly @Suppress("purity") // Updates escorting state
@Readonly
fun isEscorting(): Boolean {
if (escorting) {
if (getOtherEscortUnit() != null) return true

View File

@ -1,5 +1,6 @@
package com.unciv.models.metadata
import yairm210.purity.annotations.Cache
import yairm210.purity.annotations.Readonly
import java.text.NumberFormat
import java.util.Locale
@ -67,19 +68,21 @@ enum class LocaleCode(val languageTag: String, private val fastlaneFolder: Strin
Zulu("zu-ZA")
;
fun locale(): Locale = Locale.forLanguageTag(languageTag)
@Readonly fun locale(): Locale = Locale.forLanguageTag(languageTag)
fun fastlaneFolder(): String = this.fastlaneFolder ?: locale().language
companion object {
private val bannedCharacters = listOf(' ', '_', '-', '(', ')') // Things not to have in enum names
/** Find a LocaleCode for a [language] as stored in GameSettings */
@Readonly
fun find(language: String): LocaleCode? {
val languageName = language.filterNot { it in bannedCharacters }
return LocaleCode.entries.firstOrNull { it.name == languageName }
}
/** Get a Java Locale for a [language] as stored in GameSettings */
@Readonly
fun getLocale(language: String): Locale =
find(language)?.locale() ?: Locale.getDefault()
@ -88,9 +91,9 @@ enum class LocaleCode(val languageTag: String, private val fastlaneFolder: Strin
find(language)?.fastlaneFolder() ?: "en"
// NumberFormat cache, key: language, value: NumberFormat
private val languageToNumberFormat = mutableMapOf<String, NumberFormat>()
@Cache private val languageToNumberFormat = mutableMapOf<String, NumberFormat>()
@Readonly @Suppress("purity")
@Readonly
fun getNumberFormatFromLanguage(language: String): NumberFormat =
languageToNumberFormat.getOrPut(language) {
NumberFormat.getInstance(getLocale(language))

View File

@ -500,10 +500,10 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
.any { it.params[0].toInt() > 0 && it.hasModifier(UniqueType.ConditionalVsCity) }
@Transient
var cachedForceEvaluation: Int = -1
@Transient @Cache
private var cachedForceEvaluation: Int = -1
@Readonly @Suppress("purity") // caches
@Readonly
fun getForceEvaluation(): Int {
if (cachedForceEvaluation < 0)
cachedForceEvaluation = evaluateForce()