mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
better wire branching control
This commit is contained in:
@@ -1,21 +1,22 @@
|
|||||||
id;drop;name;renderclass;accept;inputcount;inputtype;outputtype;javaclass;inventoryimg;branching;tags
|
id;drop;name;renderclass;accept;inputcount;inputtype;outputtype;javaclass;inventoryimg;branching;tags
|
||||||
8192;8192;WIRE_RED;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,0,4;1;"SIGNALWIRE"
|
8192;8192;WIRE_RED;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,0,4;3;"SIGNALWIRE"
|
||||||
8193;8193;WIRE_GREEN;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,1,4;1;"SIGNALWIRE"
|
8193;8193;WIRE_GREEN;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,1,4;3;"SIGNALWIRE"
|
||||||
8194;8194;WIRE_BLUE;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,2,4;1;"SIGNALWIRE"
|
8194;8194;WIRE_BLUE;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,2,4;3;"SIGNALWIRE"
|
||||||
8195;8195;WIRE_YELLOW;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,3,4;1;"SIGNALWIRE"
|
8195;8195;WIRE_YELLOW;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,3,4;3;"SIGNALWIRE"
|
||||||
8196;8196;WIRE_PURPLE;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,4,4;1;"SIGNALWIRE"
|
8196;8196;WIRE_PURPLE;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,4,4;3;"SIGNALWIRE"
|
||||||
|
|
||||||
1;1;WIRE_POWER_LOW;power;power_low;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,5,4;1;"POWERWIRE_LOW"
|
1;1;WIRE_POWER_LOW;power;power_low;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,5,4;1;"POWERWIRE_LOW"
|
||||||
2;2;WIRE_POWER_HIGH;power;power_high;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,6,4;1;"POWERWIRE_HIGH"
|
2;2;WIRE_POWER_HIGH;power;power_high;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,6,4;1;"POWERWIRE_HIGH"
|
||||||
16;16;WIRE_ETHERNET;network;10base2;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,7,4;1;"ETHERNETWIRE"
|
16;16;WIRE_ETHERNET;network;10base2;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,7,4;1;"ETHERNETWIRE"
|
||||||
|
|
||||||
#256;256;AXLE;axle;axle;1;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceAxle;basegame.items,1,5;0;"AXLE"
|
256;256;AXLE;axle;axle;1;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceAxle;basegame.items,1,5;0;"AXLE"
|
||||||
|
|
||||||
# accept: which wiretype (defined elsewhere) the wires acceps. Use comma to separate multiple. N/A for electronic components (aka not wires)
|
# accept: which wiretype (defined elsewhere) the wires acceps. Use comma to separate multiple. N/A for electronic components (aka not wires)
|
||||||
# inputcount: how many sides are input (outputcount is deduced from the inputcount). N/A for wires
|
# inputcount: how many sides are input (outputcount is deduced from the inputcount). N/A for wires
|
||||||
# inputtype: which wiretype it accepts. N/A for wires
|
# inputtype: which wiretype it accepts. N/A for wires
|
||||||
# outputtype: which wiretype it emits. N/A for wires
|
# outputtype: which wiretype it emits. N/A for wires
|
||||||
# branching: if this wire can have branches. Something like a thicknet can't have branches
|
# branching: if this wire can have branches. 0: unable, 1: tee-only, 2: cross-only, 3: tee and cross.
|
||||||
|
# Something like a thicknet can't have branches
|
||||||
#
|
#
|
||||||
# comments
|
# comments
|
||||||
# digital_3bits must come right after three wires it bundles
|
# digital_3bits must come right after three wires it bundles
|
||||||
|
|||||||
|
@@ -197,7 +197,7 @@ class WireCodex {
|
|||||||
prop.inputCount = record.intVal("inputcount")
|
prop.inputCount = record.intVal("inputcount")
|
||||||
prop.inputType = record.get("inputtype") ?: prop.accepts
|
prop.inputType = record.get("inputtype") ?: prop.accepts
|
||||||
prop.outputType = record.get("outputtype") ?: 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()
|
prop.tags = record.get("tags").split(',').map { it.trim().toUpperCase() }.toHashSet()
|
||||||
|
|
||||||
wireProps[prop.id] = prop
|
wireProps[prop.id] = prop
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class WireProp : TaggedProp {
|
|||||||
var inputType: String = ""
|
var inputType: String = ""
|
||||||
var outputType: 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
|
* Mainly intended to be used by third-party modules
|
||||||
|
|||||||
@@ -118,10 +118,12 @@ 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
|
||||||
|
*
|
||||||
|
* @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) {
|
private fun setConnectivity(branching: Int, world: GameWorld, vec: Int, item: ItemID, x: Int, y: Int, ox: Int, oy: Int) {
|
||||||
when (mode) {
|
when (branching) {
|
||||||
"axle" -> {
|
0 -> {
|
||||||
// vec is guaranteed to be 5 or 10
|
// vec is guaranteed to be 5 or 10
|
||||||
world.setWireGraphOf(x, y, item, vec)
|
world.setWireGraphOf(x, y, item, vec)
|
||||||
world.setWireGraphOf(ox, oy, item, vec)
|
world.setWireGraphOf(ox, oy, item, vec)
|
||||||
@@ -143,12 +145,14 @@ object BlockBase {
|
|||||||
else false
|
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 itemID = gameItem.originalID
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val ww = ingame.world.width
|
val ww = ingame.world.width
|
||||||
|
|
||||||
|
val wirePlaceMode = WireCodex[itemID].branching
|
||||||
|
|
||||||
if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) ||
|
if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) ||
|
||||||
!isNeighbouring(ww, mtx, mty, oldTileX, oldTileY)) {
|
!isNeighbouring(ww, mtx, mty, oldTileX, oldTileY)) {
|
||||||
initialMouseDownTileX = mtx
|
initialMouseDownTileX = mtx
|
||||||
@@ -166,7 +170,7 @@ object BlockBase {
|
|||||||
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
|
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
|
||||||
|
|
||||||
val oldToNewVector = when (wirePlaceMode) {
|
val oldToNewVector = when (wirePlaceMode) {
|
||||||
"axle" -> {
|
0 -> {
|
||||||
// determine new vector by dividing the block cell in X-shape
|
// determine new vector by dividing the block cell in X-shape
|
||||||
val mxt = mx - mtx * TILE_SIZE
|
val mxt = mx - mtx * TILE_SIZE
|
||||||
val myt = my - mty * TILE_SIZE
|
val myt = my - mty * TILE_SIZE
|
||||||
@@ -190,7 +194,7 @@ object BlockBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val connectedEachOther = when (wirePlaceMode) {
|
val connectedEachOther = when (wirePlaceMode) {
|
||||||
"axle" -> thisTileOccupied && oldTileOccupied
|
0 -> thisTileOccupied && oldTileOccupied
|
||||||
else -> wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx)
|
else -> wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx)
|
||||||
}
|
}
|
||||||
val thisTileWasDraggedOn = initialMouseDownTileX != mtx || initialMouseDownTileY != mty
|
val thisTileWasDraggedOn = initialMouseDownTileX != mtx || initialMouseDownTileY != mty
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
|
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) {
|
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 {
|
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) {
|
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
|
|||||||
Reference in New Issue
Block a user