From c627096503ba571fb6f9297c79c1556a81265209 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 8 Mar 2024 04:15:07 +0900 Subject: [PATCH] wrench --- assets/mods/basegame/crafting/tools.json | 4 ++ assets/mods/basegame/items/itemid.csv | 1 + assets/mods/basegame/items/items.tga | 2 +- assets/mods/basegame/locales/en/itemdesc.json | 1 + assets/mods/basegame/locales/en/items.json | 1 + .../mods/basegame/locales/koKR/itemdesc.json | 3 +- assets/mods/basegame/locales/koKR/items.json | 3 +- .../terrarum/modulebasegame/TerrarumIngame.kt | 30 ++++++----- .../gameactors/FixtureLogicSignalBlocker.kt | 17 ++++--- .../gameactors/FixtureLogicSignalLatch.kt | 20 ++++---- .../FixtureLogicSignalRepeaterHorz.kt | 18 ++++--- .../modulebasegame/gameitems/ItemWrench.kt | 50 +++++++++++++++++++ work_files/graphics/items/basegame_items.kra | 4 +- 13 files changed, 113 insertions(+), 41 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemWrench.kt diff --git a/assets/mods/basegame/crafting/tools.json b/assets/mods/basegame/crafting/tools.json index f6881d762..dea469a14 100644 --- a/assets/mods/basegame/crafting/tools.json +++ b/assets/mods/basegame/crafting/tools.json @@ -61,5 +61,9 @@ "item@basegame:9": { /* wire cutter */ "workbench": "basiccrafting,metalworking", "ingredients": [[1, 1, "item@basegame:112", 1, "item@basegame:113"]] /* 1 copper ingot, 1 iron ingot */ + }, + "item@basegame:47": { /* wrench */ + "workbench": "basiccrafting,metalworking", + "ingredients": [[1, 4, "item@basegame:113"]] /* 4 iron ingots */ } } \ No newline at end of file diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 587359d32..eb93a1a1c 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -45,6 +45,7 @@ id;classname;tags 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 +47;net.torvald.terrarum.modulebasegame.gameitems.ItemWrench;TOOL,WRENCH # 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 aee21d97e..1785c33f3 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:79832cc7ef4a90bd339f7d9746e9742882fe6d1792b1b4c09c78dbba8addbfb3 +oid sha256:3c29d099ef220106c4db610fd0cbabff8380e82d032a0ec23a2b55a68c5bb57e size 2408466 diff --git a/assets/mods/basegame/locales/en/itemdesc.json b/assets/mods/basegame/locales/en/itemdesc.json index 3382dd82b..ffb5d1319 100644 --- a/assets/mods/basegame/locales/en/itemdesc.json +++ b/assets/mods/basegame/locales/en/itemdesc.json @@ -42,6 +42,7 @@ "TOOLTIP_item@basegame:28": "A music vending machine (free to play)", "TOOLTIP_item@basegame:29": "A coal lookalike that burns just as well and is renewable", "TOOLTIP_item@basegame:36": "Creates wires from metal ingots", + "TOOLTIP_item@basegame:47": "Reorients electronic components", "TOOLTIP_item@basegame:114": "A precious fuel for the steel production", diff --git a/assets/mods/basegame/locales/en/items.json b/assets/mods/basegame/locales/en/items.json index 87f152b69..af9c10f6c 100644 --- a/assets/mods/basegame/locales/en/items.json +++ b/assets/mods/basegame/locales/en/items.json @@ -84,6 +84,7 @@ "ITEM_WOODEN_MALLET": "Wooden Mallet", "ITEM_WORKBENCH": "Workbench", "ITEM_WORLD_PORTAL": "Teleportation Station", + "ITEM_WRENCH": "Wrench", "ACTORBLOCK_ALLOW_MOVE_DOWN": "Urist Arôlcustith", "ACTORBLOCK_FULL_COLLISION": "Urist Berdanrifot", diff --git a/assets/mods/basegame/locales/koKR/itemdesc.json b/assets/mods/basegame/locales/koKR/itemdesc.json index 4b3ab9a70..db202ebfa 100644 --- a/assets/mods/basegame/locales/koKR/itemdesc.json +++ b/assets/mods/basegame/locales/koKR/itemdesc.json @@ -41,6 +41,7 @@ "TOOLTIP_item@basegame:28": "음악 자판기입이다 (무료 플레이)", "TOOLTIP_item@basegame:29": "석탄과 비슷하고 똑같이 잘 타지만 재생 가능합니다", "TOOLTIP_item@basegame:36": "금속 주괴를 사용해 철사를 뽑아냅니다", + "TOOLTIP_item@basegame:47": "전자 장치의 방향을 바꿉니다", "TOOLTIP_item@basegame:114": "강철 생산의 소중한 연료입니다", @@ -51,5 +52,5 @@ "TOOLTIP_item@basegame:35": "신호의 상태를 보여줍니다", "TOOLTIP_item@basegame:44": "지나가는 신호를 자르기 신호에 따라 자릅니다", "TOOLTIP_item@basegame:45": "들어오는 신호를 걸쇠 신호에 따라 잠시 저장합니다", - "TOOLTIP_item@basegame:46": "들어오는 신호를 짧게 잠시 지연시킵니다" + "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 adb1129d1..24d135a25 100644 --- a/assets/mods/basegame/locales/koKR/items.json +++ b/assets/mods/basegame/locales/koKR/items.json @@ -83,5 +83,6 @@ "ITEM_WOOD_STICK": "막대기", "ITEM_WOODEN_MALLET": "나무 망치", "ITEM_WORKBENCH": "작업대", - "ITEM_WORLD_PORTAL": "텔레포트 스테이션" + "ITEM_WORLD_PORTAL": "텔레포트 스테이션", + "ITEM_WRENCH": "렌치" } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index e00e9e08b..e0bbc21e3 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -691,6 +691,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { private var worldPrimaryClickLatch = false + private var worldSecondaryClickLatch = false private fun fireFixtureInteractEvent(fixture: FixtureBase, mwx: Double, mwy: Double) { if (fixture.mouseUp) { @@ -719,6 +720,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { // don't want to open the UI and use the item at the same time, would ya? if (itemOnGrip?.isConsumable == true) { // click filtering (latch stuff) is handled by IngameController (see inventoryCategoryAllowClickAndDrag) + // To disable click dragging for tool/block/etc., put `override val disallowToolDragging = true` to the item's code val consumptionSuccessful = itemOnGrip.startPrimaryUse(actor, delta) if (consumptionSuccessful > -1) (actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful) @@ -757,6 +759,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { // #3. If no fixture under mouse or FixtureInteractionBlocked, use the item else if (itemOnGrip != null) { // click filtering (latch stuff) is handled by IngameController (see inventoryCategoryAllowClickAndDrag) + // To disable click dragging for tool/block/etc., put `override val disallowToolDragging = true` to the item's code val consumptionSuccessful = itemOnGrip.startPrimaryUse(actor, delta) if (consumptionSuccessful > -1) (actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful) @@ -790,22 +793,25 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { override fun worldSecondaryClickStart(actor: ActorWithBody, delta: Float) { val itemOnGrip = ItemCodex[(actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)] - // #1. Perform item's secondaryUse - // don't want to open the UI and use the item at the same time, would ya? - val consumptionSuccessful = itemOnGrip?.startSecondaryUse(actor, delta) ?: -1 - if (consumptionSuccessful > -1) - (actor as Pocketed).inventory.consumeItem(itemOnGrip!!, consumptionSuccessful) - // #2. If #1 failed, try to pick up the fixture - else { - mouseInInteractableRange(actor) { mwx, mwy, mtx, mty -> - pickupFixture(actor, delta, mwx, mwy, mtx, mty) - 0L + if (!worldSecondaryClickLatch) { + // #1. Perform item's secondaryUse + val consumptionSuccessful = itemOnGrip?.startSecondaryUse(actor, delta) ?: -1 + if (consumptionSuccessful > -1) + (actor as Pocketed).inventory.consumeItem(itemOnGrip!!, consumptionSuccessful) + // #2. If #1 failed, try to pick up the fixture + else { + mouseInInteractableRange(actor) { mwx, mwy, mtx, mty -> + pickupFixture(actor, delta, mwx, mwy, mtx, mty) + 0L + } } + + worldSecondaryClickLatch = true } } override fun worldSecondaryClickEnd(actor: ActorWithBody, delta: Float) { -// println("Secondary click start!") + worldSecondaryClickLatch = false } @@ -1673,7 +1679,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { } } - private fun getActorsUnderMouse(mwx: Double, mwy: Double): List { + fun getActorsUnderMouse(mwx: Double, mwy: Double): List { val actorsUnderMouse: List = getActorsAt(mwx, mwy).filter { it !is InternalActor }.sortedBy { (mwx - it.hitbox.centeredX).sqr() + (mwy - it.hitbox.centeredY).sqr() } // sorted by the distance from the mouse diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt index 831aba41a..8554cb22c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalBlocker.kt @@ -2,6 +2,7 @@ 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 @@ -70,17 +71,18 @@ class FixtureLogicSignalBlocker : Electric, Reorientable { } } - override fun orientClockwise() { - orientation = (orientation + 1) % 4 + private fun reorient() { (sprite as SheetSpriteAnimation).currentFrame = orientation (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation - setEmitterAndSink(); updateK() + } + + override fun orientClockwise() { + orientation = (orientation + 1) fmod 4 + reorient(); setEmitterAndSink(); updateK() } override fun orientAnticlockwise() { - orientation = (orientation - 1) % 4 - (sprite as SheetSpriteAnimation).currentFrame = orientation - (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation - setEmitterAndSink(); updateK() + orientation = (orientation - 1) fmod 4 + reorient(); setEmitterAndSink(); updateK() } init { @@ -104,6 +106,7 @@ class FixtureLogicSignalBlocker : Electric, Reorientable { override fun reload() { super.reload() + reorient() setEmitterAndSink() updateK() } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt index c23d63d76..a27bab354 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalLatch.kt @@ -2,6 +2,7 @@ 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 @@ -38,7 +39,7 @@ class FixtureLogicSignalLatch : Electric, Reorientable { 2 -> { setWireSinkAt(1, 0, "digital_bit") // D setWireEmitterAt(0, 0, "digital_bit") // Q - setWireSinkAt(1, 0, "digital_bit") // CLK + setWireSinkAt(1, 1, "digital_bit") // CLK setWireSinkAt(1, 2, "digital_bit") // S setWireSinkAt(0, 2, "digital_bit") // R } @@ -46,18 +47,18 @@ class FixtureLogicSignalLatch : Electric, Reorientable { } } + private fun reorient() { + (sprite as SheetSpriteAnimation).currentFrame = orientation / 2 + (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2 + } override fun orientClockwise() { - orientation = (orientation + 2) % 4 - (sprite as SheetSpriteAnimation).currentFrame = orientation / 2 - (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2 - setEmitterAndSink(); updateQ() + orientation = (orientation + 2) fmod 4 + reorient(); setEmitterAndSink(); updateQ() } override fun orientAnticlockwise() { - orientation = (orientation - 2) % 4 - (sprite as SheetSpriteAnimation).currentFrame = orientation / 2 - (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2 - setEmitterAndSink(); updateQ() + orientation = (orientation - 2) fmod 4 + reorient(); setEmitterAndSink(); updateQ() } @@ -82,6 +83,7 @@ class FixtureLogicSignalLatch : Electric, Reorientable { override fun reload() { super.reload() + reorient() setEmitterAndSink() updateQ() } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt index 37f007ea6..045ccd237 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalRepeaterHorz.kt @@ -3,6 +3,7 @@ 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.gameworld.fmod import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase import net.torvald.terrarum.toInt @@ -40,18 +41,18 @@ class FixtureLogicSignalRepeaterHorz : Electric, Reorientable { } } + private fun reorient() { + (sprite as SheetSpriteAnimation).currentFrame = orientation / 2 + (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2 + } override fun orientClockwise() { - orientation = (orientation + 2) % 4 - (sprite as SheetSpriteAnimation).currentFrame = orientation / 2 - (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2 - setEmitterAndSink(); updateQ() + orientation = (orientation + 2) fmod 4 + reorient(); setEmitterAndSink(); updateQ() } override fun orientAnticlockwise() { - orientation = (orientation - 2) % 4 - (sprite as SheetSpriteAnimation).currentFrame = orientation / 2 - (spriteEmissive as SheetSpriteAnimation).currentFrame = orientation / 2 - setEmitterAndSink(); updateQ() + orientation = (orientation - 2) fmod 4 + reorient(); setEmitterAndSink(); updateQ() } init { @@ -76,6 +77,7 @@ class FixtureLogicSignalRepeaterHorz : Electric, Reorientable { override fun reload() { super.reload() + reorient() setEmitterAndSink() updateQ() } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemWrench.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemWrench.kt new file mode 100644 index 000000000..61130be92 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemWrench.kt @@ -0,0 +1,50 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.INGAME +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.gameitems.FixtureInteractionBlocked +import net.torvald.terrarum.gameitems.GameItem +import net.torvald.terrarum.gameitems.ItemID +import net.torvald.terrarum.gameitems.mouseInInteractableRange +import net.torvald.terrarum.modulebasegame.TerrarumIngame +import net.torvald.terrarum.modulebasegame.gameactors.Reorientable + +/** + * Created by minjaesong on 2024-03-08. + */ +class ItemWrench(originalID: ItemID) : GameItem(originalID), FixtureInteractionBlocked { + + override val disallowToolDragging = true + override var dynamicID: ItemID = originalID + override var baseMass = 0.1 + override var baseToolSize: Double? = baseMass + override var inventoryCategory = Category.TOOL + override val canBeDynamic = false + override val materialId = "STAL" // this is to just increase the reach + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(5, 2) + + init { + stackable = false + isUnique = true + equipPosition = GameItem.EquipPosition.HAND_GRIP + originalName = "ITEM_WRENCH" + } + + override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty -> + (INGAME as TerrarumIngame).getActorsUnderMouse(mwx, mwy).filterIsInstance().firstOrNull()?.let { fixture -> + fixture.orientClockwise() + 0L + } ?: -1L + } + + override fun startSecondaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { mwx, mwy, mtx, mty -> + (INGAME as TerrarumIngame).getActorsUnderMouse(mwx, mwy).filterIsInstance().firstOrNull()?.let { fixture -> + fixture.orientAnticlockwise() + 0L + } ?: -1L + } +} \ 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 8eaa1f68d..f74214ba6 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:cbee1f6e53ef080508caadc372bd4fcc734535d2e3033364a26aba7acb64b1a7 -size 1474023 +oid sha256:0eadfbf8702ff52350e0642a9e91b5cdf0bcd9c49df8410bd42355f29a6bfb04 +size 1523346