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" "kotlin.collections.reversed"
) )
wellKnownPureClasses = setOf( 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.components.extensions.toPercent
import com.unciv.ui.screens.victoryscreen.RankingType import com.unciv.ui.screens.victoryscreen.RankingType
import org.jetbrains.annotations.VisibleForTesting import org.jetbrains.annotations.VisibleForTesting
import yairm210.purity.annotations.Cache
import yairm210.purity.annotations.LocalState import yairm210.purity.annotations.LocalState
import yairm210.purity.annotations.Readonly import yairm210.purity.annotations.Readonly
import kotlin.math.max import kotlin.math.max
@ -127,9 +128,6 @@ class Civilization : IsPartOfGameInfoSerialization {
@Transient @Transient
val cityStateFunctions = CityStateFunctions(this) val cityStateFunctions = CityStateFunctions(this)
@Transient
var cachedMilitaryMight = -1
@Transient @Transient
var passThroughImpassableUnlocked = false // Cached Boolean equal to passableImpassables.isNotEmpty() 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 { private fun getMilitaryMight(): Int {
if (cachedMilitaryMight < 0) if (cachedMilitaryMight < 0)
cachedMilitaryMight = calculateMilitaryMight() cachedMilitaryMight = calculateMilitaryMight()
return cachedMilitaryMight return cachedMilitaryMight
} }
fun resetMilitaryMightCache() { cachedMilitaryMight = -1 }
@Readonly @Readonly
private fun calculateMilitaryMight(): Int { 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.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.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 updateWinningCiv() // Maybe we did something this turn to win
} }

View File

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

View File

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