mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-08 19:50:21 -04:00
chore(purity): Remove more suppressions
This commit is contained in:
parent
141a4d17bf
commit
e9ee616c1f
@ -61,6 +61,7 @@ allprojects {
|
||||
"kotlin.collections.reversed"
|
||||
)
|
||||
wellKnownPureClasses = setOf(
|
||||
"java.util.Locale",
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user