diff --git a/assets/mods/basegame/crafting/items.json b/assets/mods/basegame/crafting/items.json index 360547ddc..39c4c6742 100644 --- a/assets/mods/basegame/crafting/items.json +++ b/assets/mods/basegame/crafting/items.json @@ -6,5 +6,9 @@ "item@basegame:32": { /* cherry bomb */ "workbench": "", "ingredients": [[1, 1, "item@basegame:31", 1, "item@basegame:25"]] /* 1 gunpowder, 1 clay ball */ + }, + "item@basegame:34": { /* signal switch */ + "workbench": "", + "ingredients": [[2, 1, "item@basegame:112", 1, "$ROCK", 1, "$WOOD"]] /* 1 copper ingot, 1 rock, 1 planks */ } } \ No newline at end of file diff --git a/assets/mods/basegame/crafting/tools.json b/assets/mods/basegame/crafting/tools.json index d901033c6..3d7fb0909 100644 --- a/assets/mods/basegame/crafting/tools.json +++ b/assets/mods/basegame/crafting/tools.json @@ -57,5 +57,9 @@ "item@basegame:21": { /* steel sledgehammer */ "workbench": "basiccrafting,metalworking", "ingredients": [[1, 6, "item@basegame:26", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */ + }, + "item@basegame:9": { /* wire cutter */ + "workbench": "basiccrafting,metalworking", + "ingredients": [[1, 1, "item@basegame:112", 1, "item@basegame:113"]] /* 1 copper ingot, 1 iron ingot */ } } \ No newline at end of file diff --git a/assets/mods/basegame/crafting/wires.json b/assets/mods/basegame/crafting/wires.json new file mode 100644 index 000000000..b831a7855 --- /dev/null +++ b/assets/mods/basegame/crafting/wires.json @@ -0,0 +1,22 @@ +{ + "wire@basegame:8192": { /* signal wire red */ + "workbench": "", + "ingredients": [ + [10, 1, "item@basegame:112"], /* 1 copper */ + [1, 1, "$SIGNALWIRE"] /* 1 other signal wire */ + ] + }, + "wire@basegame:8193": { /* signal wire green */ + "workbench": "", + "ingredients": [ + [10, 1, "item@basegame:112"], /* 1 copper */ + [1, 1, "$SIGNALWIRE"] /* 1 other signal wire */ + ] }, + "wire@basegame:8194": { /* signal wire blue */ + "workbench": "", + "ingredients": [ + [10, 1, "item@basegame:112"], /* 1 copper */ + [1, 1, "$SIGNALWIRE"] /* 1 other signal wire */ + ] + } +} \ No newline at end of file diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 56dfd161d..40709ba18 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -6,7 +6,7 @@ id;classname;tags 5;net.torvald.terrarum.modulebasegame.gameitems.ItemTikiTorch;FIXTURE,LIGHT 6;net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest;FIXTURE,STORAGE 7;net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger;TOOL,WIRE -8;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalEmitter;FIXTURE +8;net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalEmitter;FIXTURE,SIGNAL 9;net.torvald.terrarum.modulebasegame.gameitems.WireCutterAll;TOOL,WIRE 10;net.torvald.terrarum.modulebasegame.gameitems.ItemTypewriter;FIXTURE,PRINTING 11;net.torvald.terrarum.modulebasegame.gameitems.ItemWallCalendar;FIXTURE @@ -32,6 +32,7 @@ id;classname;tags 31;net.torvald.terrarum.modulebasegame.gameitems.ItemGunpowder;POWDER,EXPLOSIVE 32;net.torvald.terrarum.modulebasegame.gameitems.ItemCherryBomb;EXPLOSIVE,THROWABLE 33;net.torvald.terrarum.modulebasegame.gameitems.ItemTorch;FIXTURE,LIGHT +34;net.torvald.terrarum.modulebasegame.gameitems.ItemSignalSwitchManual;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 055428aad..5373420f4 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:95bc99089d2503ff9ed9bdf11c1ff54748590f6678d9164d7f134200dc2f2a64 +oid sha256:0e4b734e18388dcff87c3607a90668a9b05eedb05e08d72eb4724b973a8f22c7 size 2408466 diff --git a/assets/mods/basegame/locales/en/items.json b/assets/mods/basegame/locales/en/items.json index 07a3e9d44..c29c2e207 100644 --- a/assets/mods/basegame/locales/en/items.json +++ b/assets/mods/basegame/locales/en/items.json @@ -37,6 +37,7 @@ "ITEM_INGOT_ZINC": "Zinc Ingot", "ITEM_JUKEBOX": "Jukebox", "ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter", + "ITEM_LOGIC_SIGNAL_SWITCH": "Logic Signal Switch", "ITEM_LOGS_BIRCH": "Birch Logs", "ITEM_LOGS_EBONY": "Ebony Logs", "ITEM_LOGS_OAK": "Oak Logs", diff --git a/assets/mods/basegame/locales/koKR/items.json b/assets/mods/basegame/locales/koKR/items.json index 058e332e7..81d8c5802 100644 --- a/assets/mods/basegame/locales/koKR/items.json +++ b/assets/mods/basegame/locales/koKR/items.json @@ -37,6 +37,7 @@ "ITEM_INGOT_ZINC": "아연괴", "ITEM_JUKEBOX": "주크박스", "ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기", + "ITEM_LOGIC_SIGNAL_SWITCH": "신호 스위치", "ITEM_LOGS_BIRCH": "백단 통나무", "ITEM_LOGS_EBONY": "흑단 통나무", "ITEM_LOGS_OAK": "통나무", diff --git a/assets/mods/basegame/sprites/fixtures/signal_switch.tga b/assets/mods/basegame/sprites/fixtures/signal_switch.tga new file mode 100644 index 000000000..ac530272c --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/signal_switch.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e45c993bf426081716fccc09171d72d543f65e2874c16cf4f7e603ce6775616 +size 16402 diff --git a/assets/mods/basegame/wires/wires.csv b/assets/mods/basegame/wires/wires.csv index 9b4a0327d..e1ddf397e 100644 --- a/assets/mods/basegame/wires/wires.csv +++ b/assets/mods/basegame/wires/wires.csv @@ -1,11 +1,11 @@ -id;drop;name;renderclass;accept;inputcount;inputtype;outputtype;javaclass;inventoryimg;branching -8192;8192;WIRE_RED;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,0,4;1 -8193;8193;WIRE_GREEN;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,1,4;1 -8194;8194;WIRE_BLUE;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,2,4;1 -#8195;8195;WIRE_BUNDLE;signal;digital_3bits;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,0,0;1 -8196;8196;WIRE_POWER_LOW;power;power_low;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,3,4;1 -8197;8197;WIRE_POWER_HIGH;power;power_high;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,4,4;1 -8198;8198;WIRE_ETHERNET;network;10base2;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,5,4;1 +id;drop;name;renderclass;accept;inputcount;inputtype;outputtype;javaclass;inventoryimg;branching;tags +8192;8192;WIRE_RED;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,0,4;1;"SIGNALWIRE" +8193;8193;WIRE_GREEN;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,1,4;1;"SIGNALWIRE" +8194;8194;WIRE_BLUE;signal;digital_bit;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,2,4;1;"SIGNALWIRE" +#8195;8195;WIRE_BUNDLE;signal;digital_3bits;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,0,0;1;"SIGNALWIRE" +8196;8196;WIRE_POWER_LOW;power;power_low;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,3,4;1;"POWERWIRE_LOW" +8197;8197;WIRE_POWER_HIGH;power;power_high;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,4,4;1;"POWERWIRE_HIGH" +8198;8198;WIRE_ETHERNET;network;10base2;3;N/A;N/A;net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire;basegame.items,5,4;1;"ETHERNETWIRE" # accept: which wiretype (defined elsewhere) the wires acceps. Use comma to separate multiple. N/A for electronic components (aka not wires) diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 640fa8a73..742a8988c 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -561,7 +561,9 @@ object ModMgr { )) } } - Terrarum.wireCodex.fromModule(module, "wires/") + Terrarum.wireCodex.fromModule(module, "wires/") { wire -> + + } } private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem( diff --git a/src/net/torvald/terrarum/blockproperties/OreCodex.kt b/src/net/torvald/terrarum/blockproperties/OreCodex.kt index 4449c5322..94e7fb33d 100644 --- a/src/net/torvald/terrarum/blockproperties/OreCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/OreCodex.kt @@ -53,7 +53,7 @@ class OreCodex { private fun setProp(modname: String, key: Int, record: CSVRecord) { val prop = OreProp() prop.id = "ores@$modname:$key" - prop.tags = record.get("tags").split(',').map { it.trim() }.toHashSet() + prop.tags = record.get("tags").split(',').map { it.trim().toUpperCase() }.toHashSet() prop.item = record.get("item").let { if (it == null) "" else if (it.contains(':')) it else "$modname:$it" } oreProps[prop.id] = prop diff --git a/src/net/torvald/terrarum/blockproperties/WireCodex.kt b/src/net/torvald/terrarum/blockproperties/WireCodex.kt index e377f2a94..076bd660d 100644 --- a/src/net/torvald/terrarum/blockproperties/WireCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/WireCodex.kt @@ -39,15 +39,15 @@ class WireCodex { * @param module name of the module * @param path to the "wires" directory, not path to the CSV; must end with a slash! */ - fun fromModule(module: String, path: String) { + fun fromModule(module: String, path: String, blockRegisterHook: (WireProp) -> Unit) { printdbg(this, "Building wire properties table for module $module") try { - register(module, path, CSVFetcher.readFromModule(module, path + "wires.csv")) + register(module, path, CSVFetcher.readFromModule(module, path + "wires.csv"), blockRegisterHook) } catch (e: IOException) { e.printStackTrace() } } - fun fromCSV(module: String, path: String, csvString: String) { + fun fromCSV(module: String, path: String, csvString: String, blockRegisterHook: (WireProp) -> Unit) { printdbg(this, "Building wire properties table for module $module") val csvParser = org.apache.commons.csv.CSVParser.parse( @@ -57,10 +57,10 @@ class WireCodex { val csvRecordList = csvParser.records csvParser.close() - register(module, path, csvRecordList) + register(module, path, csvRecordList, blockRegisterHook) } - private fun register(module: String, path: String, records: List) { + private fun register(module: String, path: String, records: List, blockRegisterHook: (WireProp) -> Unit) { records.forEach { setProp(module, it.intVal("id"), it) } @@ -73,9 +73,12 @@ class WireCodex { val t = TextureRegionPack(ModMgr.getGdxFile(module, "$path$wireid.tga"), TILE_SIZE, TILE_SIZE) /*return*/t } + + wireProps[id]?.let(blockRegisterHook) } CommonResourcePool.loadAll() + } fun getAll() = wireProps.values @@ -134,6 +137,7 @@ class WireCodex { prop.inputType = record.get("inputtype") ?: prop.accepts prop.outputType = record.get("outputtype") ?: prop.accepts prop.canBranch = record.boolVal("branching") + prop.tags = record.get("tags").split(',').map { it.trim().toUpperCase() }.toHashSet() wireProps[prop.id] = prop diff --git a/src/net/torvald/terrarum/blockproperties/WireProp.kt b/src/net/torvald/terrarum/blockproperties/WireProp.kt index d1bfb266b..c200dfebf 100644 --- a/src/net/torvald/terrarum/blockproperties/WireProp.kt +++ b/src/net/torvald/terrarum/blockproperties/WireProp.kt @@ -24,4 +24,18 @@ class WireProp { * Mainly intended to be used by third-party modules */ val extra = Codex() + + @Transient var tags = HashSet() + + fun hasTag(s: String) = tags.contains(s) + fun hasAnyTagOf(vararg s: String) = s.any { hasTag(it) } + fun hasAnyTag(s: Collection) = s.any { hasTag(it) } + fun hasAnyTag(s: Array) = s.any { hasTag(it) } + fun hasAllTagOf(vararg s: String) = s.all { hasTag(it) } + fun hasAllTag(s: Collection) = s.all { hasTag(it) } + fun hasAllTag(s: Array) = s.all { hasTag(it) } + fun hasNoTagOf(vararg s: String) = s.none { hasTag(it) } + fun hasNoTag(s: Collection) = s.none { hasTag(it) } + fun hasNoTag(s: Array) = s.none { hasTag(it) } + } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index a62300fca..c1cb17805 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -443,7 +443,7 @@ open class ActorWithBody : Actor { fun setPosition(pos: Point2d) = setPosition(pos.x, pos.y) fun setPosition(pos: Vector2) = setPosition(pos.x, pos.y) - + fun setPositionFromCentrePoint(pos: Vector2) = setPosition(pos.x, pos.y + (hitbox.height) / 2) /** * ONLY FOR INITIAL SETUP diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 6cd1bd530..76a04bec1 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -786,7 +786,7 @@ object IngameRenderer : Disposable { if (c > 0) Toolkit.fillArea( batch, throwPos.x.toFloat(), - throwPos.y.toFloat() - cubeSize.toFloat() / 2f, + throwPos.y.toFloat(), 2f, 2f ) @@ -801,11 +801,19 @@ object IngameRenderer : Disposable { // break if colliding with a tile - if (BlockCodex[world.getTileFromTerrain( - throwPos.x.div(TILE_SIZED).toInt(), - (throwPos.y - cubeSize / 2).div(TILE_SIZED).toInt() - )].isSolid - ) + val hitSolid = listOf( + throwPos + Vector2(-cubeSize/2, -cubeSize/2), + throwPos + Vector2(-cubeSize/2, +cubeSize/2), + throwPos + Vector2(+cubeSize/2, +cubeSize/2), + throwPos + Vector2(+cubeSize/2, -cubeSize/2), + ).any { + val wx = (it.x / TILE_SIZED).toInt() + val wy = (it.y / TILE_SIZED).toInt() + val tile = world.getTileFromTerrain(wx, wy) + BlockCodex[tile].isSolid + } + + if (hitSolid) break c++ diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureInventory.kt index 42127a2db..f6ceff032 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureInventory.kt @@ -332,6 +332,10 @@ class InventoryPair : Comparable { operator fun component2() = qty override fun compareTo(other: InventoryPair) = this.itm.compareTo(other.itm) + + override fun toString(): String { + return if (qty == -1L) "$itm" else "$itm ($qty)" + } } class InventoryTransactionFailedError(msg: String) : Error(msg) \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt index 07e342e56..c16a915b5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt @@ -7,6 +7,9 @@ import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import org.dyn4j.geometry.Vector2 +/** + * Created by minjaesong on 2021-08-08. + */ class FixtureLogicSignalEmitter : Electric { @Transient override val spawnNeedsFloor = false diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSignalSwitchManual.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSignalSwitchManual.kt new file mode 100644 index 000000000..de7032112 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSignalSwitchManual.kt @@ -0,0 +1,71 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import net.torvald.spriteanimation.SheetSpriteAnimation +import net.torvald.terrarum.App +import net.torvald.terrarum.TerrarumAppConfiguration +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase +import net.torvald.terrarum.toInt +import net.torvald.terrarum.ui.MouseLatch +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import org.dyn4j.geometry.Vector2 + +/** + * Created by minjaesong on 2024-03-01. + */ +class FixtureSignalSwitchManual : Electric { + + @Transient override val spawnNeedsFloor = false + + constructor() : super( + BlockBox(BlockBox.NO_COLLISION, 1, 1), + nameFun = { Lang["ITEM_LOGIC_SIGNAL_SWITCH"] } + ) + + private val variant = (Math.random() * 8).toInt() + private var state = false // false = off + + init { + val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_switch.tga") + + density = 1400.0 + setHitboxDimension(TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE, 0, 1) + + makeNewSprite(TextureRegionPack(itemImage.texture, TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE)).let { + it.setRowsAndFrames(2,8) + it.currentFrame = variant + it.delays = floatArrayOf(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY) + } + + actorValue[AVKey.BASEMASS] = FixtureLogicSignalEmitter.MASS + + + setWireEmitterAt(0, 0, "digital_bit") + } + + override fun reload() { + super.reload() + + (sprite as SheetSpriteAnimation).currentFrame = variant + + (sprite as SheetSpriteAnimation).currentRow = state.toInt() + setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0)) + } + + @Transient private val clickLatch = MouseLatch(listOf(App.getConfigInt("config_mousesecondary"))) + + override fun updateImpl(delta: Float) { + super.updateImpl(delta) + + // right click + if (mouseUp) { + clickLatch.latch { + state = !state + (sprite as SheetSpriteAnimation).currentRow = state.toInt() + setWireEmissionAt(0, 0, Vector2(state.toInt().toDouble(), 0.0)) + } + } + + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt index 529f75a9c..e2169c5b6 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt @@ -8,6 +8,9 @@ import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter +/** + * Created by minjaesong on 2021-08-08. + */ class ItemLogicSignalEmitter(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter") { override var dynamicID: ItemID = originalID diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSignalSwitchManual.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSignalSwitchManual.kt new file mode 100644 index 000000000..4f2d30915 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSignalSwitchManual.kt @@ -0,0 +1,37 @@ +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-01. + */ +class ItemSignalSwitchManual(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureSignalSwitchManual") { + + 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(8, 3) + + override var baseToolSize: Double? = baseMass + override var originalName = "ITEM_LOGIC_SIGNAL_SWITCH" + override var inventoryCategory = Category.MISC + + 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/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt index 2d3333e4e..781ec0ef0 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemThrowable.kt @@ -34,7 +34,7 @@ open class ItemThrowable(originalID: ItemID, private val throwableActorClassName val (throwPos, throwForce) = getThrowPosAndVector(actor) val lobbed = Class.forName(throwableActorClassName).getDeclaredConstructor().newInstance() as ActorWithBody - lobbed.setPosition(throwPos) + lobbed.setPositionFromCentrePoint(throwPos) lobbed.externalV.set(throwForce) setupLobbedActor(lobbed) diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt index 7ca45fc2f..656ada839 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/WirePieceSignalWire.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.WireCodex import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -26,6 +27,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva init { equipPosition = GameItem.EquipPosition.HAND_GRIP originalName = "ITEM_WIRE" + tags.addAll(WireCodex[originalID].tags) } override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt index fc7f2a758..6add71729 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt @@ -21,7 +21,6 @@ import net.torvald.terrarum.modulebasegame.ui.UITemplateHalfInventory.Companion. import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL import net.torvald.unicode.getKeycapPC -import kotlin.math.ceil /** * This UI has inventory, but it's just there to display all craftable items and should not be serialised. @@ -251,7 +250,7 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas( recipeClicked = recipe // printdbg(this, "Recipe selected: $recipe") recipe?.ingredients?.forEach { ingredient -> - val selectedItem = getItemForIngredient(playerInventory, ingredient) + val selectedItem = resolveIngredientKey(playerInventory, ingredient, recipe.product) selectedItems.add(selectedItem) ingredients.add(selectedItem, ingredient.qty) } @@ -357,7 +356,7 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas( else { val items = recipe.ingredients.flatMap { getItemCandidatesForIngredient(getPlayerInventory(), it).map { it.itm } - }.sorted() + }.filter { it != recipe.product }.sorted() // filter out the product itself from the ingredient val filterFun = { pair: InventoryPair -> items.binarySearch(pair.itm) >= 0 @@ -561,10 +560,13 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas( } } - fun getItemForIngredient(inventory: FixtureInventory, ingredient: CraftingCodex.CraftingIngredients): ItemID { - val candidate = getItemCandidatesForIngredient(inventory, ingredient) + fun resolveIngredientKey(inventory: FixtureInventory, ingredient: CraftingCodex.CraftingIngredients, product: ItemID): ItemID { + val candidate = getItemCandidatesForIngredient(inventory, ingredient).filter { it.itm != product } + + printdbg(this, "resolveIngredientKey product=$product, candidate=$candidate") return if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) { + // filter out the product itself from the ingredient candidate.maxByOrNull { it.qty }?.itm ?: ( (ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.hasTag(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed (ingredient: $ingredient)") @@ -581,7 +583,7 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas( fun recipeToIngredientRecord(inventory: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List): List { val hasStation = if (recipe.workbench.isBlank()) true else nearbyCraftingStations.containsAll(recipe.workbench.split(',')) return recipe.ingredients.map { ingredient -> - val selectedItem = getItemForIngredient(inventory, ingredient) + val selectedItem = resolveIngredientKey(inventory, ingredient, recipe.product) val howManyPlayerHas = inventory.searchByID(selectedItem)?.qty ?: 0L val howManyTheRecipeWants = ingredient.qty diff --git a/work_files/graphics/items/basegame_items.kra b/work_files/graphics/items/basegame_items.kra index 4f6f42745..b23362d1d 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:39fe755507572d163467e5c6dd357937456cec87d505b76a325510c07f66edfd -size 1366750 +oid sha256:ae02c2eda70f66a82c75dd7a7f505123cc77d3f9dd2dde4176f6454ed34e8562 +size 1377341 diff --git a/work_files/graphics/sprites/fixtures/signal_switch.kra b/work_files/graphics/sprites/fixtures/signal_switch.kra new file mode 100644 index 000000000..0058fe1e9 --- /dev/null +++ b/work_files/graphics/sprites/fixtures/signal_switch.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b60c362610557997999cf6e0b2234a16e82a4dcabe317023d8251b5ad21db6b +size 139987