From 99942353421f666e08bec718a954b72d60bb4176 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 8 Mar 2024 00:52:02 +0900 Subject: [PATCH] signal repeater --- assets/mods/basegame/crafting/wires.json | 6 + assets/mods/basegame/items/itemid.csv | 1 + assets/mods/basegame/items/items.tga | 2 +- assets/mods/basegame/locales/en/itemdesc.json | 3 +- assets/mods/basegame/locales/en/items.json | 1 + .../mods/basegame/locales/koKR/itemdesc.json | 3 +- assets/mods/basegame/locales/koKR/items.json | 1 + .../sprites/fixtures/signal_repeater.tga | 3 + .../sprites/fixtures/signal_repeater_emsv.tga | 3 + .../FixtureLogicSignalRepeaterHorz.kt | 114 ++++++++++++++++++ .../gameitems/ItemLogicSignalBlocker.kt | 27 +++++ work_files/graphics/items/basegame_items.kra | 4 +- 12 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 assets/mods/basegame/sprites/fixtures/signal_repeater.tga create mode 100644 assets/mods/basegame/sprites/fixtures/signal_repeater_emsv.tga create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt diff --git a/assets/mods/basegame/crafting/wires.json b/assets/mods/basegame/crafting/wires.json index 1e3a7dbf6..013714960 100644 --- a/assets/mods/basegame/crafting/wires.json +++ b/assets/mods/basegame/crafting/wires.json @@ -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 */ + ] } } \ No newline at end of file diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 127a79d0e..587359d32 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -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 diff --git a/assets/mods/basegame/items/items.tga b/assets/mods/basegame/items/items.tga index 7835ba1b1..aee21d97e 100644 --- a/assets/mods/basegame/items/items.tga +++ b/assets/mods/basegame/items/items.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:be1754a4c1bf9e64a1d5610939983ce19f29f07236a25c56e023720a4a1aab08 +oid sha256:79832cc7ef4a90bd339f7d9746e9742882fe6d1792b1b4c09c78dbba8addbfb3 size 2408466 diff --git a/assets/mods/basegame/locales/en/itemdesc.json b/assets/mods/basegame/locales/en/itemdesc.json index b3036ec29..3382dd82b 100644 --- a/assets/mods/basegame/locales/en/itemdesc.json +++ b/assets/mods/basegame/locales/en/itemdesc.json @@ -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" } \ No newline at end of file diff --git a/assets/mods/basegame/locales/en/items.json b/assets/mods/basegame/locales/en/items.json index bec74f6c7..87f152b69 100644 --- a/assets/mods/basegame/locales/en/items.json +++ b/assets/mods/basegame/locales/en/items.json @@ -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", diff --git a/assets/mods/basegame/locales/koKR/itemdesc.json b/assets/mods/basegame/locales/koKR/itemdesc.json index 87e96e6d0..4b3ab9a70 100644 --- a/assets/mods/basegame/locales/koKR/itemdesc.json +++ b/assets/mods/basegame/locales/koKR/itemdesc.json @@ -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": "들어오는 신호를 짧게 잠시 지연시킵니다" } \ No newline at end of file diff --git a/assets/mods/basegame/locales/koKR/items.json b/assets/mods/basegame/locales/koKR/items.json index 5fd64500f..adb1129d1 100644 --- a/assets/mods/basegame/locales/koKR/items.json +++ b/assets/mods/basegame/locales/koKR/items.json @@ -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": "흑단 통나무", diff --git a/assets/mods/basegame/sprites/fixtures/signal_repeater.tga b/assets/mods/basegame/sprites/fixtures/signal_repeater.tga new file mode 100644 index 000000000..176bfee0e --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/signal_repeater.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae76fae1ddb91c802033f2f2d896eb554b8fabb70fe34c65ce39f365c85858c8 +size 16402 diff --git a/assets/mods/basegame/sprites/fixtures/signal_repeater_emsv.tga b/assets/mods/basegame/sprites/fixtures/signal_repeater_emsv.tga new file mode 100644 index 000000000..d89782a25 --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/signal_repeater_emsv.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b057203956c133b2cf3888ddb809cc106f3ce52b933751194fe770a4c212e831 +size 16402 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt new file mode 100644 index 000000000..37f007ea6 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt @@ -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() + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalBlocker.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalBlocker.kt index 656bf9bee..0b94e1a9a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalBlocker.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalBlocker.kt @@ -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 = "" + } + } \ No newline at end of file diff --git a/work_files/graphics/items/basegame_items.kra b/work_files/graphics/items/basegame_items.kra index 260ea478c..8eaa1f68d 100644 --- a/work_files/graphics/items/basegame_items.kra +++ b/work_files/graphics/items/basegame_items.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c5caeaabfde5bf7ac857936fecb6b6563ac8bd544d74bdc09b41ce343dbb2021 -size 1463025 +oid sha256:cbee1f6e53ef080508caadc372bd4fcc734535d2e3033364a26aba7acb64b1a7 +size 1474023