chore: update purity

This commit is contained in:
yairm210 2025-07-15 11:35:38 +03:00
parent adeca1ac1d
commit 3d85b2fad3
4 changed files with 15 additions and 12 deletions

View File

@ -37,7 +37,7 @@ plugins {
// This is *with* gradle 8.2 downloaded according the project specs, no idea what that's about
kotlin("multiplatform") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24"
id("io.github.yairm210.purity-plugin") version "0.0.18" apply(false)
id("io.github.yairm210.purity-plugin") version "0.0.21" apply(false)
}
allprojects {
@ -48,22 +48,14 @@ allprojects {
apply(plugin = "io.github.yairm210.purity-plugin")
configure<yairm210.purity.PurityConfiguration>{
wellKnownPureFunctions = setOf(
"kotlin.let",
"kotlin.run",
"kotlin.also",
"kotlin.apply",
"kotlin.takeIf",
"kotlin.takeUnless",
"kotlin.ranges.coerceIn",
"kotlin.ranges.coerceAtLeast",
"com.unciv.logic.civilization.diplomacy.RelationshipLevel.compareTo",
)
wellKnownReadonlyFunctions = setOf(
// Looks like the Collection.contains is not considered overridden :thunk:
"java.util.AbstractCollection.contains",
"java.util.AbstractList.get",
)
wellKnownPureClasses = setOf(
"kotlin.enums.EnumEntries",
)
}

View File

@ -37,7 +37,7 @@ object MultiFilter {
return filterFunction(input)
}
@Pure
@Pure @Suppress("purity")
fun getAllSingleFilters(input: String): Sequence<String> = when {
input.hasSurrounding(andPrefix, andSuffix) && input.contains(andSeparator) ->
// Resolve "AND" filters

View File

@ -18,6 +18,7 @@ import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.utils.addToMapOfSets
import com.unciv.utils.contains
import yairm210.purity.annotations.Readonly
import java.lang.Integer.max
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.abs
@ -206,19 +207,24 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization {
return toReturn
}
@Readonly
operator fun contains(vector: Vector2) =
contains(vector.x.toInt(), vector.y.toInt())
@Readonly
operator fun get(vector: Vector2) =
get(vector.x.toInt(), vector.y.toInt())
@Readonly
fun contains(x: Int, y: Int) =
getOrNull(x, y) != null
@Readonly
operator fun get(x: Int, y: Int) =
tileMatrix[x - leftX][y - bottomY]!!
/** @return tile at hex coordinates ([x],[y]) or null if they are outside the map. Does *not* respect world wrap, use [getIfTileExistsOrNull] for that. */
@Readonly
private fun getOrNull (x: Int, y: Int): Tile? =
tileMatrix.getOrNull(x - leftX)?.getOrNull(y - bottomY)
@ -230,16 +236,19 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization {
/** @return All tiles in a hexagon of radius [distance], including the tile at [origin] and all up to [distance] steps away.
* Respects map edges and world wrap. */
@Readonly
fun getTilesInDistance(origin: Vector2, distance: Int): Sequence<Tile> =
getTilesInDistanceRange(origin, 0..distance)
/** @return All tiles in a hexagonal ring around [origin] with the distances in [range]. Excludes the [origin] tile unless [range] starts at 0.
* Respects map edges and world wrap. */
@Readonly
fun getTilesInDistanceRange(origin: Vector2, range: IntRange): Sequence<Tile> =
range.asSequence().flatMap { getTilesAtDistance(origin, it) }
/** @return All tiles in a hexagonal ring 1 tile wide around [origin] with the [distance]. Contains the [origin] if and only if [distance] is <= 0.
* Respects map edges and world wrap. */
@Readonly @Suppress("purity")
fun getTilesAtDistance(origin: Vector2, distance: Int): Sequence<Tile> =
if (distance <= 0) // silently take negatives.
sequenceOf(get(origin))
@ -287,6 +296,7 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization {
}.filterNotNull()
/** @return tile at hex coordinates ([x],[y]) or null if they are outside the map. Respects map edges and world wrap. */
@Readonly
fun getIfTileExistsOrNull(x: Int, y: Int): Tile? {
val tile = getOrNull(x, y)
if (tile != null) return tile
@ -366,6 +376,7 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization {
* Returns the closest position to (0, 0) outside the map which can be wrapped
* to the position of the given vector
*/
fun getUnWrappedPosition(position: Vector2): Vector2 {
if (!contains(position))
return position //The position is outside the map so its unwrapped already

View File

@ -531,7 +531,7 @@ fun String.fillPlaceholders(vararg strings: String): String {
return filledString
}
@Pure
@Pure @Suppress("purity")
fun String.getModifiers(): List<Unique> {
if (!this.contains('<')) return emptyList()
return pointyBraceRegex.findAll(this).map { Unique(it.groups[1]!!.value) }.toList()