signal switches

This commit is contained in:
minjaesong
2024-03-01 01:58:16 +09:00
parent 902a086a4f
commit 6c3ec20b3d
25 changed files with 222 additions and 33 deletions

View File

@@ -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 */
}
}

View File

@@ -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 */
}
}

View File

@@ -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 */
]
}
}

View File

@@ -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
1 id classname tags
6 5 net.torvald.terrarum.modulebasegame.gameitems.ItemTikiTorch FIXTURE,LIGHT
7 6 net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest FIXTURE,STORAGE
8 7 net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger TOOL,WIRE
9 8 net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalEmitter FIXTURE FIXTURE,SIGNAL
10 9 net.torvald.terrarum.modulebasegame.gameitems.WireCutterAll TOOL,WIRE
11 10 net.torvald.terrarum.modulebasegame.gameitems.ItemTypewriter FIXTURE,PRINTING
12 11 net.torvald.terrarum.modulebasegame.gameitems.ItemWallCalendar FIXTURE
32 32 net.torvald.terrarum.modulebasegame.gameitems.ItemCherryBomb EXPLOSIVE,THROWABLE
33 33 net.torvald.terrarum.modulebasegame.gameitems.ItemTorch FIXTURE,LIGHT
34 # ingots 34 net.torvald.terrarum.modulebasegame.gameitems.ItemSignalSwitchManual FIXTURE,SIGNAL
35 # ingots
36 26 net.torvald.terrarum.modulebasegame.gameitems.IngotSteel INGOT
37 112 net.torvald.terrarum.modulebasegame.gameitems.IngotCopper INGOT
38 113 net.torvald.terrarum.modulebasegame.gameitems.IngotIron INGOT

Binary file not shown.

View File

@@ -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",

View File

@@ -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": "통나무",

Binary file not shown.

View File

@@ -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)
1 id drop name renderclass accept inputcount inputtype outputtype javaclass inventoryimg branching tags
2 8192 8192 WIRE_RED signal digital_bit 3 N/A N/A net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire basegame.items,0,4 1 SIGNALWIRE
3 8193 8193 WIRE_GREEN signal digital_bit 3 N/A N/A net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire basegame.items,1,4 1 SIGNALWIRE
4 8194 8194 WIRE_BLUE signal digital_bit 3 N/A N/A net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire basegame.items,2,4 1 SIGNALWIRE
5 #8195 8195 WIRE_BUNDLE signal digital_3bits 3 N/A N/A net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire basegame.items,0,0 1 SIGNALWIRE
6 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
7 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
8 8198 8198 WIRE_ETHERNET network 10base2 3 N/A N/A net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire basegame.items,5,4 1 ETHERNETWIRE
9 # accept: which wiretype (defined elsewhere) the wires acceps. Use comma to separate multiple. N/A for electronic components (aka not wires)
10 # inputcount: how many sides are input (outputcount is deduced from the inputcount). N/A for wires
11 # inputtype: which wiretype it accepts. N/A for wires

View File

@@ -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(

View File

@@ -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

View File

@@ -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<CSVRecord>) {
private fun register(module: String, path: String, records: List<CSVRecord>, 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

View File

@@ -24,4 +24,18 @@ class WireProp {
* Mainly intended to be used by third-party modules
*/
val extra = Codex()
@Transient var tags = HashSet<String>()
fun hasTag(s: String) = tags.contains(s)
fun hasAnyTagOf(vararg s: String) = s.any { hasTag(it) }
fun hasAnyTag(s: Collection<String>) = s.any { hasTag(it) }
fun hasAnyTag(s: Array<String>) = s.any { hasTag(it) }
fun hasAllTagOf(vararg s: String) = s.all { hasTag(it) }
fun hasAllTag(s: Collection<String>) = s.all { hasTag(it) }
fun hasAllTag(s: Array<String>) = s.all { hasTag(it) }
fun hasNoTagOf(vararg s: String) = s.none { hasTag(it) }
fun hasNoTag(s: Collection<String>) = s.none { hasTag(it) }
fun hasNoTag(s: Array<String>) = s.none { hasTag(it) }
}

View File

@@ -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

View File

@@ -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++

View File

@@ -332,6 +332,10 @@ class InventoryPair : Comparable<InventoryPair> {
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)

View File

@@ -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

View File

@@ -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))
}
}
}
}

View File

@@ -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

View File

@@ -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 = ""
}
}

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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<String>): List<RecipeIngredientRecord> {
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

Binary file not shown.