mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
signal adder
This commit is contained in:
@@ -50,19 +50,25 @@
|
||||
"item@basegame:45": { /* signal latch */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[1, 3, "basegame:21", 1, "item@basegame:116", 2, "item@basegame:112"] /* 3 marbles, 1 tin, 2 copper */
|
||||
[1, 3, "basegame:21", 1, "item@basegame:116", 2, "item@basegame:112"] /* 3 marbles, 3 tin, 3 copper */
|
||||
]
|
||||
},
|
||||
"item@basegame:8": { /* signal emitter */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[2, 1, "basegame:21", 1, "item@basegame:116"] /* 1 marbles, 1 tin, 2 copper */
|
||||
[2, 1, "basegame:21", 1, "item@basegame:116"] /* 1 marbles, 1 tin, 1 copper */
|
||||
]
|
||||
},
|
||||
"item@basegame:46": { /* signal repeater */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[1, 1, "basegame:21", 1, "item@basegame:116"] /* 1 marbles, 1 tin, 2 copper */
|
||||
[1, 1, "basegame:21", 1, "item@basegame:116"] /* 1 marbles, 1 tin, 1 copper */
|
||||
]
|
||||
},
|
||||
"item@basegame:49": { /* signal adder */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[1, 1, "basegame:21", 1, "item@basegame:116"] /* 2 marbles, 2 tin, 2 copper */
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ id;classname;tags
|
||||
46;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalRepeaterHorz;FIXTURE,SIGNAL
|
||||
47;net.torvald.terrarum.modulebasegame.gameitems.ItemWrench;TOOL,WRENCH
|
||||
48;net.torvald.terrarum.modulebasegame.gameitems.ItemAlloyingFurnace;FIXTURE,STATION
|
||||
49;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalAdder;FIXTURE,SIGNAL
|
||||
|
||||
# ingots
|
||||
112;net.torvald.terrarum.modulebasegame.gameitems.IngotCopper;INGOT
|
||||
|
||||
|
Binary file not shown.
@@ -55,5 +55,6 @@
|
||||
"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:46": "Delays a signal by a short amount"
|
||||
"TOOLTIP_item@basegame:46": "Delays a signal by a short amount",
|
||||
"TOOLTIP_item@basegame:49": "Logically adds two signals"
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
"ITEM_INGOT_TIN": "Tin Ingot",
|
||||
"ITEM_INGOT_ZINC": "Zinc Ingot",
|
||||
"ITEM_JUKEBOX": "Jukebox",
|
||||
"ITEM_LOGIC_SIGNAL_ADDER": "Logic Signal Adder",
|
||||
"ITEM_LOGIC_SIGNAL_BLOCKER": "Logic Signal Blocker",
|
||||
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
|
||||
"ITEM_LOGIC_SIGNAL_LATCH": "Logic Signal Latch",
|
||||
|
||||
@@ -53,5 +53,6 @@
|
||||
"TOOLTIP_item@basegame:35": "신호의 상태를 보여줍니다",
|
||||
"TOOLTIP_item@basegame:44": "지나가는 신호를 자르기 신호에 따라 자릅니다",
|
||||
"TOOLTIP_item@basegame:45": "들어오는 신호를 걸쇠 신호에 따라 잠시 저장합니다",
|
||||
"TOOLTIP_item@basegame:46": "들어오는 신호를 살짝 지연시킵니다"
|
||||
"TOOLTIP_item@basegame:46": "들어오는 신호를 살짝 지연시킵니다",
|
||||
"TOOLTIP_item@basegame:49": "들어오는 신호의 합을 구합니다"
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
"ITEM_INGOT_TIN": "주석괴",
|
||||
"ITEM_INGOT_ZINC": "아연괴",
|
||||
"ITEM_JUKEBOX": "주크박스",
|
||||
"ITEM_LOGIC_SIGNAL_ADDER": "신호 가산기",
|
||||
"ITEM_LOGIC_SIGNAL_BLOCKER": "신호 차단기",
|
||||
"ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기",
|
||||
"ITEM_LOGIC_SIGNAL_LATCH": "신호 걸쇠",
|
||||
|
||||
BIN
assets/mods/basegame/sprites/fixtures/signal_adder.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_adder.tga
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/sprites/fixtures/signal_adder_emsv.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/signal_adder_emsv.tga
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,152 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
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-10.
|
||||
*/
|
||||
class FixtureLogicSignalAdder : Electric, Reorientable {
|
||||
|
||||
@Transient override val spawnNeedsWall = false
|
||||
@Transient override val spawnNeedsFloor = false
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 2, 2),
|
||||
nameFun = { Lang["ITEM_LOGIC_SIGNAL_ADDER"] }
|
||||
)
|
||||
|
||||
override var orientation = 0 // 0 1 2 3
|
||||
|
||||
private fun setEmitterAndSink() {
|
||||
clearStatus()
|
||||
when (orientation) {
|
||||
0 -> {
|
||||
setWireSinkAt(0, 0, "digital_bit")
|
||||
setWireSinkAt(0, 1, "digital_bit")
|
||||
setWireEmitterAt(1, 0, "digital_bit")
|
||||
setWireEmitterAt(1, 1, "digital_bit")
|
||||
}
|
||||
1 -> {
|
||||
setWireSinkAt(1, 0, "digital_bit")
|
||||
setWireSinkAt(0, 0, "digital_bit")
|
||||
setWireEmitterAt(1, 1, "digital_bit")
|
||||
setWireEmitterAt(0, 1, "digital_bit")
|
||||
}
|
||||
2 -> {
|
||||
setWireSinkAt(1, 1, "digital_bit")
|
||||
setWireSinkAt(1, 0, "digital_bit")
|
||||
setWireEmitterAt(0, 1, "digital_bit")
|
||||
setWireEmitterAt(0, 0, "digital_bit")
|
||||
}
|
||||
3 -> {
|
||||
setWireSinkAt(0, 1, "digital_bit")
|
||||
setWireSinkAt(1, 1, "digital_bit")
|
||||
setWireEmitterAt(0, 0, "digital_bit")
|
||||
setWireEmitterAt(1, 0, "digital_bit")
|
||||
}
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
}
|
||||
|
||||
private fun reorient() {
|
||||
(sprite as SheetSpriteAnimation).currentFrame = orientation
|
||||
(spriteEmissive as SheetSpriteAnimation).currentFrame = orientation
|
||||
}
|
||||
|
||||
override fun orientClockwise() {
|
||||
orientation = (orientation + 1) fmod 4
|
||||
reorient(); setEmitterAndSink(); updateK()
|
||||
}
|
||||
override fun orientAnticlockwise() {
|
||||
orientation = (orientation - 1) fmod 4
|
||||
reorient(); setEmitterAndSink(); updateK()
|
||||
}
|
||||
|
||||
init {
|
||||
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_adder.tga")
|
||||
val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_adder_emsv.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(16,4)
|
||||
it.delays = FloatArray(16) { Float.POSITIVE_INFINITY }
|
||||
}
|
||||
makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, 2*TILE_SIZE, 2*TILE_SIZE)).let {
|
||||
it.setRowsAndFrames(16,4)
|
||||
it.delays = FloatArray(16) { Float.POSITIVE_INFINITY }
|
||||
}
|
||||
|
||||
setEmitterAndSink()
|
||||
}
|
||||
|
||||
override fun reload() {
|
||||
super.reload()
|
||||
reorient()
|
||||
setEmitterAndSink()
|
||||
updateK()
|
||||
}
|
||||
|
||||
private val I: Boolean
|
||||
get() = when (orientation) {
|
||||
0 -> getWireStateAt(0, 0, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
1 -> getWireStateAt(1, 0, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
2 -> getWireStateAt(1, 1, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
3 -> getWireStateAt(0, 1, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
|
||||
private val J: Boolean
|
||||
get() = when (orientation) {
|
||||
0 -> getWireStateAt(0, 1, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
1 -> getWireStateAt(0, 0, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
2 -> getWireStateAt(1, 0, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
3 -> getWireStateAt(1, 1, "digital_bit").x >= ELECTRIC_THRESHOLD_HIGH
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
|
||||
private fun updateK() {
|
||||
val (x1, y1) = 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)")
|
||||
}
|
||||
val (x2, y2) = when (orientation) {
|
||||
0 -> 1 to 1
|
||||
1 -> 0 to 1
|
||||
2 -> 0 to 0
|
||||
3 -> 1 to 0
|
||||
else -> throw IllegalStateException("Orientation not in range ($orientation)")
|
||||
}
|
||||
val output1 = (I xor J).toInt().toDouble()
|
||||
val output2 = (I and J).toInt().toDouble()
|
||||
setWireEmissionAt(x1, y1, Vector2(output1, 0.0))
|
||||
setWireEmissionAt(x2, y2, Vector2(output2, 0.0))
|
||||
|
||||
// update sprite
|
||||
val one = isSignalHigh(0, 0)
|
||||
val two = isSignalHigh(1, 0)
|
||||
val four = isSignalHigh(0, 1)
|
||||
val eight = isSignalHigh(1, 1)
|
||||
|
||||
val state = one.toInt(0) or two.toInt(1) or four.toInt(2) or eight.toInt(3)
|
||||
|
||||
(sprite as SheetSpriteAnimation).currentRow = state
|
||||
(spriteEmissive as SheetSpriteAnimation).currentRow = state
|
||||
}
|
||||
|
||||
override fun updateSignal() {
|
||||
updateK()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,4 +87,31 @@ class ItemLogicSignalRepeaterHorz(originalID: ItemID) : FixtureItemBase(original
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-03-10.
|
||||
*/
|
||||
class ItemLogicSignalAdder(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalAdder") {
|
||||
|
||||
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(14, 3)
|
||||
|
||||
override var baseToolSize: Double? = baseMass
|
||||
override var originalName = "ITEM_LOGIC_SIGNAL_ADDER"
|
||||
|
||||
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