From 7bfff29a79c5e5e77421ec15deedac7f044ad75f Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 17 Mar 2024 18:01:27 +0900 Subject: [PATCH] seven seg display --- assets/mods/basegame/crafting/fixtures.json | 6 ++ assets/mods/basegame/crafting/wires.json | 30 ++++--- assets/mods/basegame/items/itemid.csv | 17 ++-- assets/mods/basegame/items/items.tga | 2 +- assets/mods/basegame/locales/en/items.json | 1 + assets/mods/basegame/locales/koKR/items.json | 1 + .../basegame/sprites/fixtures/sevenseg.tga | 3 + .../gameactors/FixtureLogicSignalSevenSeg.kt | 87 +++++++++++++++++++ .../gameitems/ItemLogicSignalSevenSeg.kt | 38 ++++++++ work_files/graphics/items/basegame_items.kra | 4 +- .../graphics/sprites/fixtures/sevenseg.kra | 4 +- 11 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 assets/mods/basegame/sprites/fixtures/sevenseg.tga create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSevenSeg.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalSevenSeg.kt diff --git a/assets/mods/basegame/crafting/fixtures.json b/assets/mods/basegame/crafting/fixtures.json index 483dc6445..07311433d 100644 --- a/assets/mods/basegame/crafting/fixtures.json +++ b/assets/mods/basegame/crafting/fixtures.json @@ -43,6 +43,12 @@ [1, 15, "$ROCK", 10, "item@basegame:25", 15, "item@basegame:113"] /* 1 smelter = 15 rocks, 10 clay balls, 15 iron ingot */ ] }, + "item@basegame:51": { /* electric workbench */ + "workbench": "basiccrafting", + "ingredients": [ + [1, 12, "$WOOD", 5, "item@basegame:113"] /* 12 wood, 5 iron */ + ] + }, diff --git a/assets/mods/basegame/crafting/wires.json b/assets/mods/basegame/crafting/wires.json index 7e49318fd..fd48f181f 100644 --- a/assets/mods/basegame/crafting/wires.json +++ b/assets/mods/basegame/crafting/wires.json @@ -67,39 +67,45 @@ }, "item@basegame:35": { /* copper bulb */ - "workbench": "basiccrafting", + "workbench": "soldering", "ingredients": [ - [2, 1, "item@basegame:112", 1, "item@basegame:113"] /* 1 copper, 1 iron */ + [2, 1, "item@basegame:112", 1, "item@basegame:113", 1, "item@basegame:50"] /* 1 copper, 1 iron, 1 soldering wire (temporary) */ ] }, "item@basegame:44": { /* signal blocker */ - "workbench": "basiccrafting", + "workbench": "soldering", "ingredients": [ - [1, 2, "$ROCK", 1, "item@basegame:116", 1, "item@basegame:112"] /* 2 rocks, 1 tin, 1 copper */ + [1, 2, "$ROCK", 1, "$SEMICONDUCTOR", 1, "item@basegame:112", 1, "item@basegame:50"] /* 2 rocks, 1 tin, 1 copper, 1 soldering wire (temporary) */ ] }, "item@basegame:45": { /* signal latch */ - "workbench": "basiccrafting", + "workbench": "soldering", "ingredients": [ - [1, 3, "$ROCK", 1, "item@basegame:116", 2, "item@basegame:112"] /* 3 rocks, 3 tin, 3 copper */ + [1, 3, "$ROCK", 1, "$SEMICONDUCTOR", 2, "item@basegame:112", 1, "item@basegame:50"] /* 3 rocks, 3 tin, 3 copper, 1 soldering wire (temporary) */ ] }, "item@basegame:8": { /* signal emitter */ - "workbench": "basiccrafting", + "workbench": "soldering", "ingredients": [ - [2, 1, "$ROCK", 1, "item@basegame:116"] /* 1 rocks, 1 tin, 1 copper */ + [2, 1, "$ROCK", 1, "$SEMICONDUCTOR", 1, "item@basegame:50"] /* 1 rocks, 1 tin, 1 copper, 1 soldering wire (temporary) */ ] }, "item@basegame:46": { /* signal repeater */ - "workbench": "basiccrafting", + "workbench": "soldering", "ingredients": [ - [1, 1, "$ROCK", 1, "item@basegame:116"] /* 1 rocks, 1 tin, 1 copper */ + [1, 1, "$ROCK", 1, "$SEMICONDUCTOR", 1, "item@basegame:50"] /* 1 rocks, 1 tin, 1 copper, 1 soldering wire (temporary) */ ] }, "item@basegame:49": { /* signal adder */ - "workbench": "basiccrafting", + "workbench": "soldering", "ingredients": [ - [1, 1, "$ROCK", 1, "item@basegame:116"] /* 2 rocks, 2 tin, 2 copper */ + [1, 1, "$ROCK", 1, "$SEMICONDUCTOR", 1, "item@basegame:50"] /* 2 rocks, 2 tin, 2 copper, 1 soldering wire (temporary) */ + ] + }, + "item@basegame:52": { /* seven seg disp */ + "workbench": "soldering", + "ingredients": [ + [1, 4, "$ROCK", 7, "item@basegame:35", 5, "$SEMICONDUCTOR", 2, "item@basegame:112", 1, "item@basegame:50"] /* 4 rocks, 7 copper bulbs, 5 tin, 2 copper, 1 soldering wire (temporary) */ ] } } \ No newline at end of file diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index d81f276a0..9cf8a03f3 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -50,13 +50,14 @@ id;classname;tags 49;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalAdder;FIXTURE,SIGNAL 50;net.torvald.terrarum.modulebasegame.gameitems.ItemSolderingWire; 51;net.torvald.terrarum.modulebasegame.gameitems.ItemElectricWorkbench;FIXTURE,CRAFTING +52;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalSevenSeg;FIXTURE,SIGNAL # ingots 112;net.torvald.terrarum.modulebasegame.gameitems.IngotCopper;INGOT 113;net.torvald.terrarum.modulebasegame.gameitems.IngotIron;INGOT 114;net.torvald.terrarum.modulebasegame.gameitems.ItemCoalCoke;COMBUSTIBLE 115;net.torvald.terrarum.modulebasegame.gameitems.IngotZinc;INGOT -116;net.torvald.terrarum.modulebasegame.gameitems.IngotTin;INGOT +116;net.torvald.terrarum.modulebasegame.gameitems.IngotTin;INGOT,SEMICONDUCTOR 117;net.torvald.terrarum.modulebasegame.gameitems.IngotGold;INGOT 118;net.torvald.terrarum.modulebasegame.gameitems.IngotSilver;INGOT 119;net.torvald.terrarum.modulebasegame.gameitems.IngotLead;INGOT @@ -124,12 +125,12 @@ id;classname;tags # fluids on storage # preferably autogenerated -# 10000h..100FFh : Fluid type 0 (water) x container type 0..255 -# 10100h..101FFh : Fluid type 1 (lava) x container type 0..255 -# 10200h..102FFh : Fluid type 2 (crude oil) x container type 0..255 -# 10300h..103FFh : Fluid type 3 (petroleum) x container type 0..255 -# 10400h..104FFh : Fluid type 4 (compressed air) x container type 0..255 -# 10500h..105FFh : Fluid type 5 (steam) x container type 0..255 +# 100000h..1000FFh : Fluid type 0 (water) x container type 0..255 +# 100100h..1001FFh : Fluid type 1 (lava) x container type 0..255 +# 100200h..1002FFh : Fluid type 2 (crude oil) x container type 0..255 +# 100300h..1003FFh : Fluid type 3 (petroleum) x container type 0..255 +# 100400h..1004FFh : Fluid type 4 (compressed air) x container type 0..255 +# 100500h..1005FFh : Fluid type 5 (steam) x container type 0..255 # ... -# 1FF00h..1FFFFh : Fluid type 255 (???) x container type 0..255 +# 10FF00h..10FFFFh : Fluid type 255 (???) x container type 0..255 diff --git a/assets/mods/basegame/items/items.tga b/assets/mods/basegame/items/items.tga index 4f6d1bc86..1747810df 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:fba68e3ce167441e395d781d658f35ef4eb950f666972a55fb68d893288780b5 +oid sha256:fd956077bd3073a050168f0bcbc587b193d4a069020250927d8227123b274ac9 size 2408466 diff --git a/assets/mods/basegame/locales/en/items.json b/assets/mods/basegame/locales/en/items.json index 7f5d1a378..da743e0b1 100644 --- a/assets/mods/basegame/locales/en/items.json +++ b/assets/mods/basegame/locales/en/items.json @@ -43,6 +43,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_NUMERIC_DISPLAY": "Logic Signal Numeric Display", "ITEM_LOGIC_SIGNAL_REPEATER": "Logic Signal Repeater", "ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch", "ITEM_LOGS_BIRCH": "Birch Logs", diff --git a/assets/mods/basegame/locales/koKR/items.json b/assets/mods/basegame/locales/koKR/items.json index 29fd81353..d5d9bc496 100644 --- a/assets/mods/basegame/locales/koKR/items.json +++ b/assets/mods/basegame/locales/koKR/items.json @@ -43,6 +43,7 @@ "ITEM_LOGIC_SIGNAL_BLOCKER": "신호 차단기", "ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기", "ITEM_LOGIC_SIGNAL_LATCH": "신호 걸쇠", + "ITEM_LOGIC_SIGNAL_NUMERIC_DISPLAY": "신호 숫자 표시기", "ITEM_LOGIC_SIGNAL_REPEATER": "신호 리피터", "ITEM_LOGIC_SIGNAL_SWITCH": "신호 스위치", "ITEM_LOGS_BIRCH": "백단 통나무", diff --git a/assets/mods/basegame/sprites/fixtures/sevenseg.tga b/assets/mods/basegame/sprites/fixtures/sevenseg.tga new file mode 100644 index 000000000..e3c909c96 --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/sevenseg.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e49a2c46ad9d8b74f5fe227b9b64f5b43f182d3c324bc6c5e4bb77228b738cf7 +size 524306 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSevenSeg.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSevenSeg.kt new file mode 100644 index 000000000..f5a9c0b52 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalSevenSeg.kt @@ -0,0 +1,87 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import net.torvald.spriteanimation.SheetSpriteAnimation +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE +import net.torvald.terrarum.blockproperties.Block +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase +import net.torvald.terrarum.toInt +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack + +/** + * Created by minjaesong on 2024-03-16. + */ +class FixtureLogicSignalSevenSeg : Electric { + + @Transient override val spawnNeedsFloor = true + @Transient override val spawnNeedsWall = true + + constructor() : super( + BlockBox(BlockBox.NO_COLLISION, 4, 4), + nameFun = { Lang["ITEM_LOGIC_SIGNAL_DISPLAY"] } + ) + + + @Transient private val actorBlocks = arrayOf( + arrayOf(null, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null), + arrayOf(null, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null), + arrayOf(null, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null), + arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION), + ) + override fun placeActorBlocks() { + forEachBlockbox { x, y, ox, oy -> + val tile = actorBlocks[oy][ox] + if (tile != null) { + world!!.setTileTerrain(x, y, tile, true) + } + } + } + + init { + val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/sevenseg.tga") + val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/sevenseg.tga") + + density = 1400.0 + setHitboxDimension(4*TILE_SIZE, 4*TILE_SIZE, 0, 1) + + makeNewSprite(TextureRegionPack(itemImage.texture, 4*TILE_SIZE, 4*TILE_SIZE)).let { + it.setRowsAndFrames(2,16) + it.delays = FloatArray(16) { Float.POSITIVE_INFINITY } + } + makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, 4*TILE_SIZE, 4*TILE_SIZE)).let { + it.setRowsAndFrames(2,416) + it.delays = FloatArray(16) { Float.POSITIVE_INFINITY } + } + + (sprite as SheetSpriteAnimation).currentRow = 0 + (spriteEmissive as SheetSpriteAnimation).currentRow = 1 + + setWireSinkAt(0, 3, "digital_bit") + setWireSinkAt(1, 3, "digital_bit") + setWireSinkAt(2, 3, "digital_bit") + setWireSinkAt(3, 3, "digital_bit") + } + + override fun reload() { + super.reload() + setWireSinkAt(0, 3, "digital_bit") + setWireSinkAt(1, 3, "digital_bit") + setWireSinkAt(2, 3, "digital_bit") + setWireSinkAt(3, 3, "digital_bit") + updateK() + } + + override fun updateSignal() { + updateK() + } + + private fun updateK() { + val state = isSignalHigh(0, 3).toInt(0) or + isSignalHigh(1, 3).toInt(1) or + isSignalHigh(2, 3).toInt(2) or + isSignalHigh(3, 3).toInt(3) + + (sprite as SheetSpriteAnimation).currentFrame = state + (spriteEmissive as SheetSpriteAnimation).currentFrame = state + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalSevenSeg.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalSevenSeg.kt new file mode 100644 index 000000000..9b493ce70 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalSevenSeg.kt @@ -0,0 +1,38 @@ +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-16. + */ +class ItemLogicSignalSevenSeg(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalSevenSeg") { + + 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(15, 3) + override val itemImageEmissive: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(15, 4) + + override var baseToolSize: Double? = baseMass + override var originalName = "ITEM_LOGIC_SIGNAL_NUMERIC_DISPLAY" + + 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 0c30e81b0..fb1f0d97d 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:a0e6bba296b229202ccf450de60556e80d4001c0c20e570120a2c2b42afafba8 -size 1668794 +oid sha256:414759d9ececca660a1f8872ef70234c1eb945f86bc0b670c3d6c62b4aaee7c0 +size 1694477 diff --git a/work_files/graphics/sprites/fixtures/sevenseg.kra b/work_files/graphics/sprites/fixtures/sevenseg.kra index 9eb7a0e48..05f5dab6d 100644 --- a/work_files/graphics/sprites/fixtures/sevenseg.kra +++ b/work_files/graphics/sprites/fixtures/sevenseg.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0818b9edf5657335383f45c57b13a58ba0e2211263c3805b8e1d17876cd80531 -size 312503 +oid sha256:70a32c9989c6caed2c0940132fbcaa91d8eaa90a8be5391d4e26ebfc237b78a6 +size 2358721