better wire branching control

This commit is contained in:
minjaesong
2025-02-09 21:56:46 +09:00
parent 34d8f1504f
commit 22786f9a28
6 changed files with 23 additions and 18 deletions

View File

@@ -197,7 +197,7 @@ class WireCodex {
prop.inputCount = record.intVal("inputcount")
prop.inputType = record.get("inputtype") ?: prop.accepts
prop.outputType = record.get("outputtype") ?: prop.accepts
prop.canBranch = record.boolVal("branching")
prop.branching = record.intVal("branching")
prop.tags = record.get("tags").split(',').map { it.trim().toUpperCase() }.toHashSet()
wireProps[prop.id] = prop

View File

@@ -19,7 +19,7 @@ class WireProp : TaggedProp {
var inputType: String = ""
var outputType: String = ""
var canBranch: Boolean = true
var branching: Int = 0 // 0: can't; 1: tee-only, 2: cross-only, 3: tee and cross
/**
* Mainly intended to be used by third-party modules

View File

@@ -90,7 +90,7 @@ class ActorValue : KVHashMap {
return ActorValue(newActor, hashMap).also {
val listOfBlobs = it.hashMap.entries.filter { (it.value as? String)?.startsWith(BLOB) ?: false }
listOfBlobs.forEach {
}
}
// TODO clone blobs

View File

@@ -118,10 +118,12 @@ object BlockBase {
/**
* This function assumes xy and oxy are neighboured and tiles are correctly placed
*
* @param branching 0: no branching, 1: tee-only, 2: cross-only, 3: tee and cross
*/
private fun setConnectivity(mode: String, world: GameWorld, vec: Int, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) {
when (mode) {
"axle" -> {
private fun setConnectivity(branching: Int, world: GameWorld, vec: Int, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) {
when (branching) {
0 -> {
// vec is guaranteed to be 5 or 10
world.setWireGraphOf(x, y, item, vec)
world.setWireGraphOf(ox, oy, item, vec)
@@ -143,12 +145,14 @@ object BlockBase {
else false
}
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float, wirePlaceMode: String) = mouseInInteractableRange(actor) { mx, my, mtx, mty ->
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) { mx, my, mtx, mty ->
val itemID = gameItem.originalID
val ingame = Terrarum.ingame!! as TerrarumIngame
val ww = ingame.world.width
val wirePlaceMode = WireCodex[itemID].branching
if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) ||
!isNeighbouring(ww, mtx, mty, oldTileX, oldTileY)) {
initialMouseDownTileX = mtx
@@ -166,7 +170,7 @@ object BlockBase {
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
val oldToNewVector = when (wirePlaceMode) {
"axle" -> {
0 -> {
// determine new vector by dividing the block cell in X-shape
val mxt = mx - mtx * TILE_SIZE
val myt = my - mty * TILE_SIZE
@@ -190,7 +194,7 @@ object BlockBase {
}
}
val connectedEachOther = when (wirePlaceMode) {
"axle" -> thisTileOccupied && oldTileOccupied
0 -> thisTileOccupied && oldTileOccupied
else -> wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx)
}
val thisTileWasDraggedOn = initialMouseDownTileX != mtx || initialMouseDownTileY != mty

View File

@@ -32,7 +32,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
return BlockBase.wireStartPrimaryUse(actor,this, delta, "signal_wire")
return BlockBase.wireStartPrimaryUse(actor,this, delta)
}
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
@@ -69,7 +69,7 @@ class WirePieceAxle(originalID: ItemID, private val atlasID: String, private val
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
return BlockBase.wireStartPrimaryUse(actor,this, delta, "axle")
return BlockBase.wireStartPrimaryUse(actor,this, delta)
}
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {