From 0f196f59c6a4cb76ab8409da62ff1f35505f94a8 Mon Sep 17 00:00:00 2001 From: Dico Karssiens Date: Sun, 11 Nov 2018 14:06:45 +0000 Subject: Changes I made before breaking my local repository. Hoping this works. --- .../parcels2/defaultimpl/DefaultParcelContainer.kt | 144 ++++++++++----------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt') diff --git a/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt b/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt index 1193af3..b49cad4 100644 --- a/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt +++ b/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt @@ -1,73 +1,73 @@ -package io.dico.parcels2.defaultimpl - -import io.dico.parcels2.Parcel -import io.dico.parcels2.ParcelContainer -import io.dico.parcels2.ParcelId -import io.dico.parcels2.ParcelWorld - -class DefaultParcelContainer(val world: ParcelWorld) : ParcelContainer { - private var parcels: Array> - - init { - parcels = initArray(world.options.axisLimit, world) - } - - fun resizeIfSizeChanged() { - if (parcels.size != world.options.axisLimit * 2 + 1) { - resize(world.options.axisLimit) - } - } - - fun resize(axisLimit: Int) { - parcels = initArray(axisLimit, world, this) - } - - fun initArray(axisLimit: Int, world: ParcelWorld, cur: DefaultParcelContainer? = null): Array> { - val arraySize = 2 * axisLimit + 1 - return Array(arraySize) { - val x = it - axisLimit - Array(arraySize) { - val z = it - axisLimit - cur?.getParcelById(x, z) ?: ParcelImpl(world, x, z) - } - } - } - - override fun getParcelById(x: Int, z: Int): Parcel? { - return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit) - } - - override fun getParcelById(id: ParcelId): Parcel? { - if (!world.id.equals(id.worldId)) throw IllegalArgumentException() - return when (id) { - is Parcel -> id - else -> getParcelById(id.x, id.z) - } - } - - override fun nextEmptyParcel(): Parcel? { - return walkInCircle().find { it.owner == null } - } - - private fun walkInCircle(): Iterable = Iterable { - iterator { - val center = world.options.axisLimit - yield(parcels[center][center]) - for (radius in 0..center) { - var x = center - radius; - var z = center - radius - repeat(radius * 2) { yield(parcels[x++][z]) } - repeat(radius * 2) { yield(parcels[x][z++]) } - repeat(radius * 2) { yield(parcels[x--][z]) } - repeat(radius * 2) { yield(parcels[x][z--]) } - } - } - } - - fun getAllParcels(): Iterator = iterator { - for (array in parcels) { - yieldAll(array.iterator()) - } - } - +package io.dico.parcels2.defaultimpl + +import io.dico.parcels2.Parcel +import io.dico.parcels2.ParcelContainer +import io.dico.parcels2.ParcelId +import io.dico.parcels2.ParcelWorld + +class DefaultParcelContainer(val world: ParcelWorld) : ParcelContainer { + private var parcels: Array> + + init { + parcels = initArray(world.options.axisLimit, world) + } + + fun resizeIfSizeChanged() { + if (parcels.size != world.options.axisLimit * 2 + 1) { + resize(world.options.axisLimit) + } + } + + fun resize(axisLimit: Int) { + parcels = initArray(axisLimit, world, this) + } + + fun initArray(axisLimit: Int, world: ParcelWorld, cur: DefaultParcelContainer? = null): Array> { + val arraySize = 2 * axisLimit + 1 + return Array(arraySize) { + val x = it - axisLimit + Array(arraySize) { + val z = it - axisLimit + cur?.getParcelById(x, z) ?: ParcelImpl(world, x, z) + } + } + } + + override fun getParcelById(x: Int, z: Int): Parcel? { + return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit) + } + + override fun getParcelById(id: ParcelId): Parcel? { + if (!world.id.equals(id.worldId)) throw IllegalArgumentException() + return when (id) { + is Parcel -> id + else -> getParcelById(id.x, id.z) + } + } + + override fun nextEmptyParcel(): Parcel? { + return walkInCircle().find { it.owner == null } + } + + private fun walkInCircle(): Iterable = Iterable { + iterator { + val center = world.options.axisLimit + yield(parcels[center][center]) + for (radius in 0..center) { + var x = center - radius; + var z = center - radius + repeat(radius * 2) { yield(parcels[x++][z]) } + repeat(radius * 2) { yield(parcels[x][z++]) } + repeat(radius * 2) { yield(parcels[x--][z]) } + repeat(radius * 2) { yield(parcels[x][z--]) } + } + } + } + + fun getAllParcels(): Iterator = iterator { + for (array in parcels) { + yieldAll(array.iterator()) + } + } + } \ No newline at end of file -- cgit v1.2.3 From a475226ffcf17a7327b78e5c1e6ba6ac0dfd10c7 Mon Sep 17 00:00:00 2001 From: Dico Karssiens Date: Sun, 6 Jan 2019 12:02:34 +0000 Subject: Perform some fixes --- .../parcels2/defaultimpl/DefaultParcelContainer.kt | 144 ++++++++++----------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt') diff --git a/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt b/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt index b49cad4..f3cd8d7 100644 --- a/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt +++ b/src/main/kotlin/io/dico/parcels2/defaultimpl/DefaultParcelContainer.kt @@ -1,73 +1,73 @@ -package io.dico.parcels2.defaultimpl - -import io.dico.parcels2.Parcel -import io.dico.parcels2.ParcelContainer -import io.dico.parcels2.ParcelId -import io.dico.parcels2.ParcelWorld - -class DefaultParcelContainer(val world: ParcelWorld) : ParcelContainer { - private var parcels: Array> - - init { - parcels = initArray(world.options.axisLimit, world) - } - - fun resizeIfSizeChanged() { - if (parcels.size != world.options.axisLimit * 2 + 1) { - resize(world.options.axisLimit) - } - } - - fun resize(axisLimit: Int) { - parcels = initArray(axisLimit, world, this) - } - - fun initArray(axisLimit: Int, world: ParcelWorld, cur: DefaultParcelContainer? = null): Array> { - val arraySize = 2 * axisLimit + 1 - return Array(arraySize) { - val x = it - axisLimit - Array(arraySize) { - val z = it - axisLimit - cur?.getParcelById(x, z) ?: ParcelImpl(world, x, z) - } - } - } - - override fun getParcelById(x: Int, z: Int): Parcel? { - return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit) - } - - override fun getParcelById(id: ParcelId): Parcel? { - if (!world.id.equals(id.worldId)) throw IllegalArgumentException() - return when (id) { - is Parcel -> id - else -> getParcelById(id.x, id.z) - } - } - - override fun nextEmptyParcel(): Parcel? { - return walkInCircle().find { it.owner == null } - } - - private fun walkInCircle(): Iterable = Iterable { - iterator { - val center = world.options.axisLimit - yield(parcels[center][center]) - for (radius in 0..center) { - var x = center - radius; - var z = center - radius - repeat(radius * 2) { yield(parcels[x++][z]) } - repeat(radius * 2) { yield(parcels[x][z++]) } - repeat(radius * 2) { yield(parcels[x--][z]) } - repeat(radius * 2) { yield(parcels[x][z--]) } - } - } - } - - fun getAllParcels(): Iterator = iterator { - for (array in parcels) { - yieldAll(array.iterator()) - } - } - +package io.dico.parcels2.defaultimpl + +import io.dico.parcels2.Parcel +import io.dico.parcels2.ParcelContainer +import io.dico.parcels2.ParcelId +import io.dico.parcels2.ParcelWorld + +class DefaultParcelContainer(val world: ParcelWorld) : ParcelContainer { + private var parcels: Array> + + init { + parcels = initArray(world.options.axisLimit, world) + } + + fun resizeIfSizeChanged() { + if (parcels.size != world.options.axisLimit * 2 + 1) { + resize(world.options.axisLimit) + } + } + + fun resize(axisLimit: Int) { + parcels = initArray(axisLimit, world, this) + } + + fun initArray(axisLimit: Int, world: ParcelWorld, cur: DefaultParcelContainer? = null): Array> { + val arraySize = 2 * axisLimit + 1 + return Array(arraySize) { + val x = it - axisLimit + Array(arraySize) { + val z = it - axisLimit + cur?.getParcelById(x, z) ?: ParcelImpl(world, x, z) + } + } + } + + override fun getParcelById(x: Int, z: Int): Parcel? { + return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit) + } + + override fun getParcelById(id: ParcelId): Parcel? { + if (!world.id.equals(id.worldId)) throw IllegalArgumentException() + return when (id) { + is Parcel -> id + else -> getParcelById(id.x, id.z) + } + } + + override suspend fun nextEmptyParcel(): Parcel? { + return walkInCircle().find { it.owner == null } + } + + private fun walkInCircle(): Iterable = Iterable { + iterator { + val center = world.options.axisLimit + yield(parcels[center][center]) + for (radius in 0..center) { + var x = center - radius; + var z = center - radius + repeat(radius * 2) { yield(parcels[x++][z]) } + repeat(radius * 2) { yield(parcels[x][z++]) } + repeat(radius * 2) { yield(parcels[x--][z]) } + repeat(radius * 2) { yield(parcels[x][z--]) } + } + } + } + + fun getAllParcels(): Iterator = iterator { + for (array in parcels) { + yieldAll(array.iterator()) + } + } + } \ No newline at end of file -- cgit v1.2.3