wire connecting will take ROUNDWORLD into account

This commit is contained in:
minjaesong
2022-07-13 23:19:47 +09:00
parent c5360cdcb8
commit 69c5ceb61f

View File

@@ -107,36 +107,31 @@ object BlockBase {
/** /**
* This function assumes xy and oxy are neighboured and tiles are correctly placed * This function assumes xy and oxy are neighboured and tiles are correctly placed
*/ */
private fun setConnectivity(world: GameWorld, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) { private fun setConnectivity(world: GameWorld, vec: Int, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) {
val thisNodeCnx = world.getWireGraphOf(x, y, item)!! world.getWireGraphOf(x, y, item)!!.let { world.setWireGraphOf(x, y, item, vec.wireNodeMirror() or it) }
val otherNodeCnx = world.getWireGraphOf(ox, oy, item)!! world.getWireGraphOf(ox, oy, item)!!.let { world.setWireGraphOf(ox, oy, item, vec or it) }
}
val vec = if (x - ox == 1) 4 // direction from thisNode towards the otherNode. [1, 2, 4, 8] = [RIGHT, DOWN, LEFT, UP]
else if (x - ox == -1) 1 private fun isNeighbouring(ww: Int, x1: Int, y1: Int, x2: Int, y2: Int): Boolean {
else if (y - oy == 1) 8 // xy is always coerced into the world's dimension
else 2 // i know the code below is lengthy and redundant but whatever
val antivec = if (x - ox == 1) 1 return if ( x1 == 0 && x2 == ww-1 && y1 == y2) true
else if (x - ox == -1) 4 else if ( x1 == ww-1 && x2 == 0 && y1 == y2) true
else if (y - oy == 1) 2 else if ((x1 - x2).abs() == 1 && y1 == y2) true
else 8 else if ((y1 - y2).abs() == 1 && x1 == x2) true
else false
world.setWireGraphOf(x, y, item, vec or thisNodeCnx)
world.setWireGraphOf(ox, oy, item, antivec or otherNodeCnx)
} }
// TODO: take ROUNDWORLD into account on node connection
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) { fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) {
val itemID = gameItem.originalID val itemID = gameItem.originalID
val ingame = Terrarum.ingame!! as TerrarumIngame val ingame = Terrarum.ingame!! as TerrarumIngame
val mouseTileX = Terrarum.mouseTileX val mouseTileX = Terrarum.mouseTileX
val mouseTileY = Terrarum.mouseTileY val mouseTileY = Terrarum.mouseTileY
val ww = ingame.world.width
if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) || if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) ||
// reset dragged-on status when there's drag-discontinuity (not dragging towards the neighbouring tiles) !isNeighbouring(ww, mouseTileX, mouseTileY, oldTileX, oldTileY)) {
!((oldTileX - mouseTileX).abs() == 1 && (oldTileY - mouseTileY).abs() == 0 ||
(oldTileX - mouseTileX).abs() == 0 && (oldTileY - mouseTileY).abs() == 1)
) {
initialMouseDownTileX = mouseTileX initialMouseDownTileX = mouseTileX
initialMouseDownTileY = mouseTileY initialMouseDownTileY = mouseTileY
oldTileX = mouseTileX oldTileX = mouseTileX
@@ -151,7 +146,9 @@ object BlockBase {
val thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null val thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
val oldToNewVector = if (mouseTileX - oldTileX == 1) 1 val oldToNewVector = if (mouseTileX == ww - 1 && oldTileX == 0) 4
else if (mouseTileX == 0 && oldTileX == ww - 1) 1
else if (mouseTileX - oldTileX == 1) 1
else if (mouseTileX - oldTileX == -1) 4 else if (mouseTileX - oldTileX == -1) 4
else if (mouseTileY - oldTileY == 1) 2 else if (mouseTileY - oldTileY == 1) 2
else if (mouseTileY - oldTileY == -1) 8 else if (mouseTileY - oldTileY == -1) 8
@@ -184,12 +181,12 @@ object BlockBase {
ret -1 ret -1
} }
else if (thisTileOccupied && oldTileOccupied) { else if (thisTileOccupied && oldTileOccupied) {
setConnectivity(ingame.world, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY) setConnectivity(ingame.world, oldToNewVector, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY)
ret = 0 ret = 0
} }
else { else {
placeWirePieceTo(ingame.world, itemID, mouseTileX, mouseTileY) placeWirePieceTo(ingame.world, itemID, mouseTileX, mouseTileY)
setConnectivity(ingame.world, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY) setConnectivity(ingame.world, oldToNewVector, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY)
ret = 1 ret = 1
} }
} }