This commit is contained in:
minjaesong
2024-03-08 04:15:07 +09:00
parent 9994235342
commit c627096503
13 changed files with 113 additions and 41 deletions

View File

@@ -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<ActorWithBody> {
fun getActorsUnderMouse(mwx: Double, mwy: Double): List<ActorWithBody> {
val actorsUnderMouse: List<ActorWithBody> = 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

View File

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

View File

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

View File

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

View File

@@ -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<Reorientable>().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<Reorientable>().firstOrNull()?.let { fixture ->
fixture.orientAnticlockwise()
0L
} ?: -1L
}
}