wire connectivity wip

This commit is contained in:
minjaesong
2022-07-07 01:06:43 +09:00
parent 84158319d1
commit db0be9e088
10 changed files with 138 additions and 34 deletions

View File

@@ -104,7 +104,7 @@ class EntryPoint : ModuleEntryPoint() {
tags.addAll(tile.tags)
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
return BlockBase.blockStartPrimaryUse(actor, this, dynamicID, delta)
}

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.unicode.EMDASH
import net.torvald.terrarum.*
import net.torvald.terrarum.App.*
import net.torvald.terrarum.Terrarum.getPlayerSaveFiledesc
@@ -50,6 +49,7 @@ import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer.LIGHTMAP_OVERRENDER
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.unicode.EMDASH
import net.torvald.util.CircularArray
import org.khelekore.prtree.PRTree
import java.util.*
@@ -631,8 +631,8 @@ 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 (!uiOpened && itemOnGrip != null) {
val consumptionSuccessful = itemOnGrip.startPrimaryUse(actor, delta)
if (consumptionSuccessful)
(actor as Pocketed).inventory.consumeItem(itemOnGrip)
if (consumptionSuccessful > -1)
(actor as Pocketed).inventory.consumeItem(itemOnGrip, consumptionSuccessful)
}
// #3. If I'm not holding any item and I can do barehandaction (size big enough that barehandactionminheight check passes), perform it
else if (itemOnGrip == null) {
@@ -657,8 +657,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
/*override fun worldSecondaryClickStart(delta: Float) {
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
val consumptionSuccessful = ItemCodex[itemOnGrip]?.startSecondaryUse(delta) ?: false
if (consumptionSuccessful)
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
if (consumptionSuccessful > -1)
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!, consumptionSuccessful)
}
override fun worldSecondaryClickEnd(delta: Float) {

View File

@@ -66,11 +66,13 @@ class ActorInventory() : FixtureInventory() {
fun getQuickslotItem(slot: Int): InventoryPair? = searchByID(quickSlot[slot])
fun consumeItem(item: GameItem) {
fun consumeItem(item: GameItem, amount: Long = 1L) {
val actor = this.actor as Actor
if (item.isDynamic && amount != 1L) throw IllegalArgumentException("Dynamic item must be consumed 'once' (expected 1, got $amount)")
if (item.stackable && !item.isDynamic) {
remove(item, 1)
remove(item, amount)
}
else if (item.isUnique) {
return // don't consume a bike!

View File

@@ -49,7 +49,8 @@ open class FixtureInventory() {
// other invalid values
if (count == 0L)
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
// throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
return
if (count < 0L)
throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" +
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
@@ -94,7 +95,8 @@ open class FixtureInventory() {
println("[ActorInventory] remove $item, $count")
if (count == 0L)
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
// throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
return
if (count < 0L)
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is negative number. If you intended adding items, use add()" +
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")

View File

@@ -34,7 +34,7 @@ object BlockBase {
if (it is ActorWithBody && it.physProp.usePhysics && it.intTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return@mouseInInteractableRange ret1
if (!ret1) return@mouseInInteractableRange -1L
}
// return false if the tile underneath is:
@@ -46,7 +46,7 @@ object BlockBase {
gameItem.dynamicID == "wall@" + ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) ||
BlockCodex[ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)].nameKey.contains("ACTORBLOCK_")
)
return@mouseInInteractableRange false
return@mouseInInteractableRange 1L
// filter passed, do the job
// FIXME this is only useful for Player
@@ -67,31 +67,41 @@ object BlockBase {
)
}
true
1L
}
fun blockEffectWhenEquipped(actor: ActorWithBody, delta: Float) {
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
}
private fun Int.shiftByTwo() = this.shl(4).or(this).ushr(2).and(15)
private fun connectedEachOther(one: Int, other: Int) = one.shiftByTwo() and other != 0
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) {
val itemID = gameItem.originalID
val ingame = Terrarum.ingame!! as TerrarumIngame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
val mouseTile = Terrarum.getMouseSubtile4()
// return false if the tile is already there
if (ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.searchFor(itemID) != null)
return@mouseInInteractableRange false
val thisTileWires = ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)
val otherTileWires = ingame.world.getAllWiresFrom(mouseTile.nx, mouseTile.ny)
val thisTileWireCnx = ingame.world.getWireGraphOf(mouseTile.x, mouseTile.y, itemID)
val otherTileWireCnx = ingame.world.getWireGraphOf(mouseTile.x, mouseTile.y, itemID)
// filter passed, do the job
ingame.world.setTileWire(
mouseTile.x,
mouseTile.y,
itemID,
false
)
// cases:
// * regardless of vector, this tile was not dragged-on
// -> if this tile is occupied (use thisTileWires?.searchFor(itemID) != null): return -1
// else: place the tile, then return 1
// * regardless of vector, this tile was dragged-on, and the oldtile is neighbouring tile
// -> if this tile is occupied and connectivities are already set (use connectedEachOther(thisTileWireCnx, otherTileWireCnx)): return -1
// else if this tile is occupied: set connectivity, then return 0
// else: place the tile, set connectivity, then return 1
// (dragged-on: let net.torvald.terrarum.Terrarum record the tile that the mouse button was just down,
// and the poll again later; if tile now != recorded tile, it is dragged-on)
true
// TODO
TODO()
}
fun wireEffectWhenEquipped(gameItem: GameItem, delta: Float) {

View File

@@ -30,7 +30,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
return BlockBase.wireStartPrimaryUse(actor,this, delta)
}