Joris PZ
12/17/2018, 9:31 PM256/19, JS 316/130, native 649/393
I did discover something useful today - you can have more than one operator fun get and set implementation in a single class.
So for today, I wrapped an val grid: Array<Array<Soil>> in a class, and defined the following methods:
operator fun get(pos: Position) = grid[pos.x][pos.y]
operator fun get(x: Int, y: Int) = grid[x][y]
operator fun set(x: Int, y: Int, type: Soil) {
grid[x][y] = type
}
operator fun set(pos: Position, type: Soil) {
grid[pos.x][pos.y] = type
}
so I can use both world[x, y] and world[pos] at my convenience (and do some bounds checking not shown above)