mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 13:04:05 +09:00
signal switches
This commit is contained in:
@@ -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)
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user