mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
signal blocker wip
This commit is contained in:
@@ -42,6 +42,7 @@ id;classname;tags
|
|||||||
41;net.torvald.terrarum.modulebasegame.gameitems.ItemTableEbony;FIXTURE,SURFACE
|
41;net.torvald.terrarum.modulebasegame.gameitems.ItemTableEbony;FIXTURE,SURFACE
|
||||||
42;net.torvald.terrarum.modulebasegame.gameitems.ItemTableBirch;FIXTURE,SURFACE
|
42;net.torvald.terrarum.modulebasegame.gameitems.ItemTableBirch;FIXTURE,SURFACE
|
||||||
43;net.torvald.terrarum.modulebasegame.gameitems.ItemTableRosewood;FIXTURE,SURFACE
|
43;net.torvald.terrarum.modulebasegame.gameitems.ItemTableRosewood;FIXTURE,SURFACE
|
||||||
|
44;net.torvald.terrarum.modulebasegame.gameitems.ItemSignalBlocker;FIXTURE,SIGNAL
|
||||||
|
|
||||||
# ingots
|
# ingots
|
||||||
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT
|
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT
|
||||||
|
|||||||
|
Binary file not shown.
@@ -37,6 +37,7 @@
|
|||||||
"ITEM_INGOT_TIN": "Tin Ingot",
|
"ITEM_INGOT_TIN": "Tin Ingot",
|
||||||
"ITEM_INGOT_ZINC": "Zinc Ingot",
|
"ITEM_INGOT_ZINC": "Zinc Ingot",
|
||||||
"ITEM_JUKEBOX": "Jukebox",
|
"ITEM_JUKEBOX": "Jukebox",
|
||||||
|
"ITEM_LOGIC_SIGNAL_BLOCKER": "Logic Signal Blocker",
|
||||||
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
|
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
|
||||||
"ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch",
|
"ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch",
|
||||||
"ITEM_LOGS_BIRCH": "Birch Logs",
|
"ITEM_LOGS_BIRCH": "Birch Logs",
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
"ITEM_INGOT_TIN": "주석괴",
|
"ITEM_INGOT_TIN": "주석괴",
|
||||||
"ITEM_INGOT_ZINC": "아연괴",
|
"ITEM_INGOT_ZINC": "아연괴",
|
||||||
"ITEM_JUKEBOX": "주크박스",
|
"ITEM_JUKEBOX": "주크박스",
|
||||||
|
"ITEM_LOGIC_SIGNAL_BLOCKER": "신호 차단기",
|
||||||
"ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기",
|
"ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기",
|
||||||
"ITEM_LOGIC_SIGNAL_SWITCH": "신호 스위치",
|
"ITEM_LOGIC_SIGNAL_SWITCH": "신호 스위치",
|
||||||
"ITEM_LOGS_BIRCH": "백단 통나무",
|
"ITEM_LOGS_BIRCH": "백단 통나무",
|
||||||
|
|||||||
BIN
assets/mods/basegame/sprites/fixtures/signal_blocker.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_blocker.tga
LFS
Normal file
Binary file not shown.
@@ -89,6 +89,15 @@ open class Electric : FixtureBase {
|
|||||||
/** Triggered when 'digital_bit' is held low. This function WILL NOT be triggered simultaneously with the falling edge. Level detection only considers the real component (labeled as 'x') of the vector */
|
/** Triggered when 'digital_bit' is held low. This function WILL NOT be triggered simultaneously with the falling edge. Level detection only considers the real component (labeled as 'x') of the vector */
|
||||||
open fun onSignalLow(readFrom: BlockBoxIndex) {}
|
open fun onSignalLow(readFrom: BlockBoxIndex) {}
|
||||||
|
|
||||||
|
fun getWireStateAt(offsetX: Int, offsetY: Int, type: String): Vector2 {
|
||||||
|
val wx = offsetX + intTilewiseHitbox.startX.toInt()
|
||||||
|
val wy = offsetY + intTilewiseHitbox.startY.toInt()
|
||||||
|
return WireCodex.getAllWiresThatAccepts(type).fold(Vector2()) { acc, (id, _) ->
|
||||||
|
INGAME.world.getWireEmitStateOf(wx, wy, id).let {
|
||||||
|
Vector2(acc.x + (it?.x ?: 0.0), acc.y + (it?.y ?: 0.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val oldSinkStatus: Array<Vector2>
|
private val oldSinkStatus: Array<Vector2>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
|
import net.torvald.terrarum.langpack.Lang
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||||
|
import net.torvald.terrarum.toInt
|
||||||
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
import org.dyn4j.geometry.Vector2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2024-03-04.
|
||||||
|
*/
|
||||||
|
interface Reorientable {
|
||||||
|
/**
|
||||||
|
* Usually includes code snippet of `orientation = (orientation + 1) % 4`
|
||||||
|
*/
|
||||||
|
fun orientClockwise()
|
||||||
|
/**
|
||||||
|
* Usually includes code snippet of `orientation = (orientation - 1) % 4`
|
||||||
|
*/
|
||||||
|
fun orientAnticlockwise()
|
||||||
|
/**
|
||||||
|
* strictly 0 1 2 3. If your fixture can only be oriented in two ways, use value 0 2.
|
||||||
|
*/
|
||||||
|
var orientation: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2024-03-04.
|
||||||
|
*/
|
||||||
|
class FixtureSignalBlocker : Electric, Reorientable {
|
||||||
|
|
||||||
|
constructor() : super(
|
||||||
|
BlockBox(BlockBox.NO_COLLISION, 2, 2),
|
||||||
|
nameFun = { Lang["ITEM_LOGIC_SIGNAL_BLOCKER"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
override var orientation = 0
|
||||||
|
|
||||||
|
private fun setEmitterAndSink() {
|
||||||
|
when (orientation) {
|
||||||
|
0 -> {
|
||||||
|
setWireSinkAt(0, 0, "digital_bit")
|
||||||
|
setWireSinkAt(0, 1, "digital_bit")
|
||||||
|
setWireEmitterAt(1, 0, "digital_bit")
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
setWireSinkAt(1, 0, "digital_bit")
|
||||||
|
setWireSinkAt(0, 0, "digital_bit")
|
||||||
|
setWireEmitterAt(1, 1, "digital_bit")
|
||||||
|
}
|
||||||
|
2 -> {
|
||||||
|
setWireSinkAt(1, 1, "digital_bit")
|
||||||
|
setWireSinkAt(1, 0, "digital_bit")
|
||||||
|
setWireEmitterAt(0, 1, "digital_bit")
|
||||||
|
}
|
||||||
|
3 -> {
|
||||||
|
setWireSinkAt(0, 1, "digital_bit")
|
||||||
|
setWireSinkAt(1, 1, "digital_bit")
|
||||||
|
setWireEmitterAt(0, 0, "digital_bit")
|
||||||
|
}
|
||||||
|
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun orientClockwise() {
|
||||||
|
orientation = (orientation + 1) % 4
|
||||||
|
setEmitterAndSink(); updateK()
|
||||||
|
}
|
||||||
|
override fun orientAnticlockwise() {
|
||||||
|
orientation = (orientation - 1) % 4
|
||||||
|
setEmitterAndSink(); updateK()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_blocker.tga")
|
||||||
|
|
||||||
|
density = 1400.0
|
||||||
|
setHitboxDimension(2*TILE_SIZE, 2*TILE_SIZE, 0, 1)
|
||||||
|
|
||||||
|
makeNewSprite(TextureRegionPack(itemImage.texture, 2*TILE_SIZE, 2*TILE_SIZE)).let {
|
||||||
|
it.setRowsAndFrames(8,4)
|
||||||
|
it.delays = floatArrayOf(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmitterAndSink()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reload() {
|
||||||
|
super.reload()
|
||||||
|
setEmitterAndSink()
|
||||||
|
updateK()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val I: Boolean
|
||||||
|
get() = when (orientation) {
|
||||||
|
0 -> getWireStateAt(0, 0, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
1 -> getWireStateAt(1, 0, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
2 -> getWireStateAt(1, 1, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
3 -> getWireStateAt(0, 1, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val J: Boolean
|
||||||
|
get() = when (orientation) {
|
||||||
|
0 -> getWireStateAt(0, 1, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
1 -> getWireStateAt(0, 0, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
2 -> getWireStateAt(1, 0, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
3 -> getWireStateAt(1, 1, "digital_bit").x >= ELECTIC_THRESHOLD_HIGH
|
||||||
|
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateK() {
|
||||||
|
val (x, y) = when (orientation) {
|
||||||
|
0 -> 1 to 0
|
||||||
|
1 -> 1 to 1
|
||||||
|
2 -> 0 to 1
|
||||||
|
3 -> 0 to 0
|
||||||
|
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||||
|
}
|
||||||
|
setWireConsumptionAt(x, y, Vector2(I nimply J, 0.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRisingEdge(readFrom: BlockBoxIndex) {
|
||||||
|
updateK()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFallingEdge(readFrom: BlockBoxIndex) {
|
||||||
|
updateK()
|
||||||
|
}
|
||||||
|
|
||||||
|
private infix fun Boolean.nimply(other: Boolean) = (this && !other).toInt().toDouble()
|
||||||
|
|
||||||
|
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2024-03-04.
|
||||||
|
*/
|
||||||
|
class ItemSignalBlocker(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureSignalBlocker") {
|
||||||
|
|
||||||
|
override var dynamicID: ItemID = originalID
|
||||||
|
override var baseMass = FixtureLogicSignalEmitter.MASS
|
||||||
|
override val canBeDynamic = false
|
||||||
|
override val materialId = ""
|
||||||
|
override val itemImage: TextureRegion
|
||||||
|
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(10, 3)
|
||||||
|
|
||||||
|
override var baseToolSize: Double? = baseMass
|
||||||
|
override var originalName = "ITEM_LOGIC_SIGNAL_BLOCKER"
|
||||||
|
|
||||||
|
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
|
super.effectWhileEquipped(actor, delta)
|
||||||
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "signal"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun effectOnUnequip(actor: ActorWithBody) {
|
||||||
|
super.effectOnUnequip(actor)
|
||||||
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user