slight elaboration on world wire changed event

This commit is contained in:
minjaesong
2021-08-03 13:39:08 +09:00
parent 7624e37bda
commit 1ae3e34392
3 changed files with 13 additions and 7 deletions

View File

@@ -71,7 +71,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
protected val terrainChangeQueue = Queue<BlockChangeQueueItem>()
protected val wallChangeQueue = Queue<BlockChangeQueueItem>()
protected val wireChangeQueue = Queue<BlockChangeQueueItem>()
protected val wireChangeQueue = Queue<BlockChangeQueueItem>() // if 'old' is set and 'new' is blank, it's a wire cutter
override fun hide() {
}
@@ -161,9 +161,9 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
* @param old previous settings of conduits in bit set format.
* @param new current settings of conduits in bit set format.
*/
open fun queueWireChangedEvent(new: ItemID, position: Long) {
open fun queueWireChangedEvent(wire: ItemID, isRemoval: Boolean, position: Long) {
val (x, y) = LandUtil.resolveBlockAddr(world, position)
wireChangeQueue.addLast(BlockChangeQueueItem("", new, x, y))
wireChangeQueue.addLast(BlockChangeQueueItem(if (isRemoval) wire else "", if (isRemoval) "" else wire, x, y))
}

View File

@@ -582,8 +582,9 @@ inline fun printStackTrace(obj: Any) = printStackTrace(obj, System.out) // becau
fun printStackTrace(obj: Any, out: PrintStream = System.out) {
if (AppLoader.IS_DEVELOPMENT_BUILD) {
Thread.currentThread().stackTrace.forEach {
out.println("[${obj.javaClass.simpleName}] ... $it")
Thread.currentThread().stackTrace.forEachIndexed { index, it ->
if (index >= 3)
out.println("[${obj.javaClass.simpleName}] ... $it")
}
}
}
@@ -631,4 +632,9 @@ class UIContainer {
interface Id_UICanvasNullable {
fun get(): UICanvas?
}
}
// haskell-inspired array selectors
// head and last use first() and last()
fun <T> Array<T>.tail() = this.sliceArray(1 until this.size)
fun <T> Array<T>.init() = this.sliceArray(0 until this.lastIndex)

View File

@@ -324,7 +324,7 @@ open class GameWorld : Disposable {
wirings[blockAddr]!!.wires.add(tile)
if (!bypassEvent)
Terrarum.ingame?.queueWireChangedEvent(tile, LandUtil.getBlockAddr(this, x, y))
Terrarum.ingame?.queueWireChangedEvent(tile, false, LandUtil.getBlockAddr(this, x, y))
}
fun getAllWiresFrom(x: Int, y: Int): SortedArrayList<ItemID>? {