mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
signal repeater
This commit is contained in:
@@ -58,5 +58,11 @@
|
||||
"ingredients": [
|
||||
[2, 1, "basegame:21", 1, "item@basegame:116"] /* 1 marbles, 1 tin, 2 copper */
|
||||
]
|
||||
},
|
||||
"item@basegame:46": { /* signal repeater */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[1, 1, "basegame:21", 1, "item@basegame:116"] /* 1 marbles, 1 tin, 2 copper */
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ id;classname;tags
|
||||
43;net.torvald.terrarum.modulebasegame.gameitems.ItemTableRosewood;FIXTURE,SURFACE
|
||||
44;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalBlocker;FIXTURE,SIGNAL
|
||||
45;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalLatch;FIXTURE,SIGNAL
|
||||
46;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalRepeaterHorz;FIXTURE,SIGNAL
|
||||
|
||||
# ingots
|
||||
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT
|
||||
|
||||
|
Binary file not shown.
@@ -52,5 +52,6 @@
|
||||
"TOOLTIP_item@basegame:34": "Selectively emits a signal",
|
||||
"TOOLTIP_item@basegame:35": "Shows a signal status",
|
||||
"TOOLTIP_item@basegame:44": "Cuts the signal using the cutting signal",
|
||||
"TOOLTIP_item@basegame:45": "Latches onto the signal on the latch signal"
|
||||
"TOOLTIP_item@basegame:45": "Latches onto the signal on the latch signal",
|
||||
"TOOLTIP_item@basegame:46": "Delays a signal by a short amount"
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
"ITEM_LOGIC_SIGNAL_BLOCKER": "Logic Signal Blocker",
|
||||
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
|
||||
"ITEM_LOGIC_SIGNAL_LATCH": "Logic Signal Latch",
|
||||
"ITEM_LOGIC_SIGNAL_REPEATER": "Logic Signal Repeater",
|
||||
"ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch",
|
||||
"ITEM_LOGS_BIRCH": "Birch Logs",
|
||||
"ITEM_LOGS_EBONY": "Ebony Logs",
|
||||
|
||||
@@ -50,5 +50,6 @@
|
||||
"TOOLTIP_item@basegame:34": "선택적으로 신호를 만들어냅니다",
|
||||
"TOOLTIP_item@basegame:35": "신호의 상태를 보여줍니다",
|
||||
"TOOLTIP_item@basegame:44": "지나가는 신호를 자르기 신호에 따라 자릅니다",
|
||||
"TOOLTIP_item@basegame:45": "들어오는 신호를 걸쇠 신호에 따라 잠시 저장합니다"
|
||||
"TOOLTIP_item@basegame:45": "들어오는 신호를 걸쇠 신호에 따라 잠시 저장합니다",
|
||||
"TOOLTIP_item@basegame:46": "들어오는 신호를 짧게 잠시 지연시킵니다"
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
"ITEM_LOGIC_SIGNAL_BLOCKER": "신호 차단기",
|
||||
"ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기",
|
||||
"ITEM_LOGIC_SIGNAL_LATCH": "신호 걸쇠",
|
||||
"ITEM_LOGIC_SIGNAL_REPEATER": "신호 리피터",
|
||||
"ITEM_LOGIC_SIGNAL_SWITCH": "신호 스위치",
|
||||
"ITEM_LOGS_BIRCH": "백단 통나무",
|
||||
"ITEM_LOGS_EBONY": "흑단 통나무",
|
||||
|
||||
BIN
assets/mods/basegame/sprites/fixtures/signal_repeater.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_repeater.tga
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/sprites/fixtures/signal_repeater_emsv.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_repeater_emsv.tga
LFS
Normal file
Binary file not shown.
@@ -0,0 +1,114 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration
|
||||
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-08.
|
||||
*/
|
||||
class FixtureLogicSignalRepeaterHorz : Electric, Reorientable {
|
||||
|
||||
|
||||
@Transient override val spawnNeedsWall = false
|
||||
@Transient override val spawnNeedsFloor = false
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 2, 1),
|
||||
nameFun = { Lang["ITEM_LOGIC_SIGNAL_REPEATER"] }
|
||||
)
|
||||
|
||||
override var orientation = 0 // 0 2, where 2 is a mirror-image rather than rotation
|
||||
|
||||
private fun setEmitterAndSink() {
|
||||
clearStatus()
|
||||
when (orientation) {
|
||||
0 -> {
|
||||
setWireSinkAt(0, 0, "digital_bit") // D
|
||||
setWireEmitterAt(1, 0, "digital_bit") // Q
|
||||
}
|
||||
2 -> {
|
||||
setWireSinkAt(1, 0, "digital_bit") // D
|
||||
setWireEmitterAt(0, 0, "digital_bit") // Q
|
||||
}
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun orientClockwise() {
|
||||
orientation = (orientation + 2) % 4
|
||||
(sprite as SheetSpriteAnimation).currentFrame = orientation / 2
|
||||
(spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2
|
||||
setEmitterAndSink(); updateQ()
|
||||
}
|
||||
override fun orientAnticlockwise() {
|
||||
orientation = (orientation - 2) % 4
|
||||
(sprite as SheetSpriteAnimation).currentFrame = orientation / 2
|
||||
(spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2
|
||||
setEmitterAndSink(); updateQ()
|
||||
}
|
||||
|
||||
init {
|
||||
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_repeater.tga")
|
||||
val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_repeater_emsv.tga")
|
||||
|
||||
density = 1400.0
|
||||
setHitboxDimension(2*TILE_SIZE, 1*TILE_SIZE, 0, 1)
|
||||
|
||||
makeNewSprite(TextureRegionPack(itemImage.texture, 2*TILE_SIZE, 1*TILE_SIZE)).let {
|
||||
it.setRowsAndFrames(4,2)
|
||||
it.delays = FloatArray(4) { Float.POSITIVE_INFINITY }
|
||||
}
|
||||
makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, 2*TILE_SIZE, 1*TILE_SIZE)).let {
|
||||
it.setRowsAndFrames(4,2)
|
||||
it.delays = FloatArray(4) { Float.POSITIVE_INFINITY }
|
||||
}
|
||||
|
||||
setEmitterAndSink()
|
||||
}
|
||||
|
||||
|
||||
override fun reload() {
|
||||
super.reload()
|
||||
setEmitterAndSink()
|
||||
updateQ()
|
||||
}
|
||||
|
||||
private val D: Boolean
|
||||
get() = when (orientation) {
|
||||
0 -> getWireStateAt(0, 0, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
2 -> getWireStateAt(1, 0, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
|
||||
private fun updateQ() {
|
||||
val (x, y) = when (orientation) {
|
||||
0 -> 1 to 0
|
||||
2 -> 0 to 0
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
// "capture" the input pin states
|
||||
val D = this.D
|
||||
|
||||
setWireEmissionAt(x, y, Vector2(D.toInt().toDouble(), 0.0))
|
||||
|
||||
// update sprite
|
||||
val one = isSignalHigh(0, 0)
|
||||
val two = isSignalHigh(1, 0)
|
||||
|
||||
val state = one.toInt(0) or two.toInt(1)
|
||||
|
||||
(sprite as SheetSpriteAnimation).currentRow = state
|
||||
(spriteEmissive as SheetSpriteAnimation).currentRow = state
|
||||
}
|
||||
|
||||
override fun updateSignal() {
|
||||
updateQ()
|
||||
}
|
||||
}
|
||||
@@ -60,4 +60,31 @@ class ItemLogicSignalLatch(originalID: ItemID) : FixtureItemBase(originalID, "ne
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-03-08.
|
||||
*/
|
||||
class ItemLogicSignalRepeaterHorz(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalRepeaterHorz") {
|
||||
|
||||
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(12, 3)
|
||||
|
||||
override var baseToolSize: Double? = baseMass
|
||||
override var originalName = "ITEM_LOGIC_SIGNAL_REPEATER"
|
||||
|
||||
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.
Reference in New Issue
Block a user