mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
fixtures can be despawned by "mining" them
This commit is contained in:
@@ -133,7 +133,7 @@ object IngameRenderer : Disposable {
|
||||
* actually matter */
|
||||
@JvmStatic fun initialise() {
|
||||
if (!initialisedExternally) {
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
|
||||
// also initialise these sinigletons
|
||||
BlocksDrawer
|
||||
|
||||
@@ -453,6 +453,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
override fun worldPrimaryClickStart(delta: Float) {
|
||||
//println("[Ingame] worldPrimaryClickStart $delta")
|
||||
|
||||
val itemOnGrip = ItemCodex[actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)]
|
||||
// bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
|
||||
var uiOpened = false
|
||||
|
||||
@@ -463,28 +464,29 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
// scan for the one with non-null UI.
|
||||
// what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
|
||||
for (kk in actorsUnderMouse.indices) {
|
||||
actorsUnderMouse[kk].mainUI?.let {
|
||||
uiOpened = true
|
||||
if (itemOnGrip?.inventoryCategory != GameItem.Category.TOOL) { // don't open the UI when player's holding a tool
|
||||
for (kk in actorsUnderMouse.indices) {
|
||||
actorsUnderMouse[kk].mainUI?.let {
|
||||
uiOpened = true
|
||||
|
||||
// property 'uiFixture' is a dedicated property that the TerrarumIngame recognises.
|
||||
// when it's not null, the UI will be updated and rendered
|
||||
// when the UI is closed, it'll be replaced with a null value
|
||||
uiFixture = it
|
||||
// property 'uiFixture' is a dedicated property that the TerrarumIngame recognises.
|
||||
// when it's not null, the UI will be updated and rendered
|
||||
// when the UI is closed, it'll be replaced with a null value
|
||||
uiFixture = it
|
||||
|
||||
it.setPosition(0, 0)
|
||||
it.setAsOpen()
|
||||
it.setPosition(0, 0)
|
||||
it.setAsOpen()
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
// don't want to open the UI and use the item at the same time, would ya?
|
||||
if (!uiOpened) {
|
||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||
val consumptionSuccessful = ItemCodex[itemOnGrip]?.startPrimaryUse(delta) ?: false
|
||||
val consumptionSuccessful = itemOnGrip?.startPrimaryUse(delta) ?: false
|
||||
if (consumptionSuccessful)
|
||||
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
|
||||
actorNowPlaying?.inventory?.consumeItem(itemOnGrip!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
|
||||
// a Class impl is chosen to make resize-handling easier, there's not much benefit making this a singleton anyway
|
||||
|
||||
init {
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
}
|
||||
|
||||
override var screenToLoad: IngameInstance? = screenToBeLoaded
|
||||
|
||||
@@ -52,7 +52,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
this.inventory = inventory
|
||||
|
||||
if (mainUI != null)
|
||||
App.disposableSingletonsPool.add(mainUI)
|
||||
App.disposables.add(mainUI)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
}
|
||||
|
||||
override fun updateForTerrainChange(cue: IngameInstance.BlockChangeQueueItem) {
|
||||
// TODO check for despawn code here
|
||||
|
||||
}
|
||||
|
||||
private fun fillFillerBlock(bypassEvent: Boolean = false) {
|
||||
@@ -151,14 +151,11 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
* Removes this instance of the fixture from the world
|
||||
*/
|
||||
open fun despawn() {
|
||||
val posX = worldBlockPos!!.x
|
||||
val posY = worldBlockPos!!.y
|
||||
println("${this.javaClass.simpleName} dispose")
|
||||
|
||||
// remove filler block
|
||||
forEachBlockbox { x, y ->
|
||||
if (world!!.getTileFromTerrain(x, y) == blockBox.collisionType) {
|
||||
world!!.setTileTerrain(x, y, Block.AIR, false)
|
||||
}
|
||||
world!!.setTileTerrain(x, y, Block.AIR, false)
|
||||
}
|
||||
|
||||
worldBlockPos = null
|
||||
@@ -166,6 +163,12 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
|
||||
this.isVisible = false
|
||||
|
||||
if (this is Electric) {
|
||||
wireEmitterTypes.clear()
|
||||
wireEmission.clear()
|
||||
wireConsumption.clear()
|
||||
}
|
||||
|
||||
// TODO drop self as an item (instance of DroppedItem)
|
||||
}
|
||||
|
||||
@@ -173,11 +176,16 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
super.update(delta)
|
||||
// if not flagged to despawn and not actually despawned (which sets worldBlockPos as null), always fill up fillerBlock
|
||||
if (!flagDespawn && worldBlockPos != null) {
|
||||
fillFillerBlock(true)
|
||||
}
|
||||
else if (flagDespawn) {
|
||||
despawn()
|
||||
// for removal-by-player because player is removing the filler block by pick
|
||||
forEachBlockbox { x, y ->
|
||||
if (world!!.getTileFromTerrain(x, y) != blockBox.collisionType) {
|
||||
flagDespawn = true
|
||||
}
|
||||
}
|
||||
|
||||
if (flagDespawn) despawn()
|
||||
}
|
||||
// actual actor removal is performed by the TerrarumIngame
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.blockproperties.WireCodex
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -41,15 +40,5 @@ class FixtureLogicSignalEmitter : FixtureBase, Electric {
|
||||
const val MASS = 1.0
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
// set emit
|
||||
/*worldBlockPos?.let { (x, y) ->
|
||||
WireCodex.getAll().filter { it.accepts == "digital_bit" }.forEach { prop ->
|
||||
// only set a state of wire that actually exists on the world
|
||||
if (world?.getWireGraphOf(x, y, prop.id) != null)
|
||||
world?.setWireEmitStateOf(x, y, prop.id, wireEmission[0]!!)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter
|
||||
|
||||
@@ -18,7 +17,7 @@ class ItemLogicSignalEmitter(originalID: ItemID) : GameItem(originalID) {
|
||||
override val originalName = "ITEM_LOGIC_SIGNAL_EMITTER"
|
||||
override var baseMass = FixtureLogicSignalEmitter.MASS
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.FIXTURE
|
||||
override var inventoryCategory = Category.MISC
|
||||
override val isUnique = false
|
||||
override val isDynamic = false
|
||||
override val material = Material()
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureStorageChest
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
||||
|
||||
@@ -19,12 +18,12 @@ class ItemStorageChest(originalID: ItemID) : GameItem(originalID) {
|
||||
override val originalName = "ITEM_STORAGE_CHEST"
|
||||
override var baseMass = FixtureTikiTorch.MASS
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.FIXTURE
|
||||
override var inventoryCategory = Category.MISC
|
||||
override val isUnique = false
|
||||
override val isDynamic = false
|
||||
override val material = Material()
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
|
||||
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_32")
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
init {
|
||||
|
||||
@@ -2,28 +2,36 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-05-16.
|
||||
*/
|
||||
class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
|
||||
class ItemTikiTorch(originalID: ItemID) : GameItem(originalID) {
|
||||
|
||||
init {
|
||||
CommonResourcePool.addToLoadingList("sprites-fixtures-tiki_torch.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32, flipY = true)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
}
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override val originalName = "ITEM_TIKI_TORCH"
|
||||
override var baseMass = FixtureTikiTorch.MASS
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.FIXTURE
|
||||
override var inventoryCategory = Category.MISC
|
||||
override val isUnique = false
|
||||
override val isDynamic = false
|
||||
override val material = Material()
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_48")
|
||||
get() = CommonResourcePool.getAsTextureRegionPack("sprites-fixtures-tiki_torch.tga").get(0,0)
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
init {
|
||||
Reference in New Issue
Block a user