25 lines
741 B
Kotlin
25 lines
741 B
Kotlin
package ru.dbotthepony.kstarbound.defs.dungeon
|
|
|
|
import ru.dbotthepony.kommons.util.KOptional
|
|
|
|
abstract class TileMap {
|
|
fun interface TileCallback<T> {
|
|
operator fun invoke(x: Int, y: Int, tile: DungeonTile): KOptional<T>
|
|
}
|
|
|
|
fun interface TileCallback0 {
|
|
operator fun invoke(x: Int, y: Int, tile: DungeonTile)
|
|
}
|
|
|
|
abstract fun <T> walkTiles(callback: TileCallback<T>): KOptional<T>
|
|
abstract fun <T> walkTilesAt(x: Int, y: Int, callback: TileCallback<T>): KOptional<T>
|
|
|
|
fun iterateTiles(callback: TileCallback0) {
|
|
walkTiles<Unit> { x, y, tile -> callback(x, y, tile); KOptional() }
|
|
}
|
|
|
|
fun iterateTilesAt(x: Int, y: Int, callback: TileCallback0) {
|
|
walkTilesAt<Unit>(x, y) { x, y, tile -> callback(x, y, tile); KOptional() }
|
|
}
|
|
}
|