mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 13:21:51 +09:00
fixtures can be despawned by "mining" them
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"1";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeCopper"
|
||||
"2";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeIron"
|
||||
"3";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel"
|
||||
"5";"net.torvald.terrarum.modulebasegame.gameitems.TikiTorchTester"
|
||||
"5";"net.torvald.terrarum.modulebasegame.gameitems.ItemTikiTorch"
|
||||
"6";"net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest"
|
||||
"7";"net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger"
|
||||
"8";"net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalEmitter"
|
||||
|
||||
|
Binary file not shown.
@@ -6,6 +6,7 @@ package net.torvald.spriteanimation
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
@@ -14,7 +15,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
/**
|
||||
* This class should not be serialised; save its Animation Description Language instead.
|
||||
*/
|
||||
class SpriteAnimation(@Transient val parentActor: ActorWithBody) {
|
||||
class SpriteAnimation(@Transient val parentActor: ActorWithBody) : Disposable {
|
||||
|
||||
lateinit var textureRegion: TextureRegionPack; private set
|
||||
|
||||
@@ -206,7 +207,7 @@ class SpriteAnimation(@Transient val parentActor: ActorWithBody) {
|
||||
flipVertical = vertical
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
override fun dispose() {
|
||||
textureRegion.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class App implements ApplicationListener {
|
||||
private static FrameBuffer renderFBO;
|
||||
|
||||
public static HashSet<File> tempFilePool = new HashSet<>();
|
||||
public static HashSet<Disposable> disposableSingletonsPool = new HashSet<>();
|
||||
public static HashSet<Disposable> disposables = new HashSet<>();
|
||||
|
||||
public static char gamepadLabelStart = 0xE000; // lateinit
|
||||
public static char gamepadLabelSelect = 0xE000; // lateinit
|
||||
@@ -376,9 +376,9 @@ public class App implements ApplicationListener {
|
||||
|
||||
glInfo.create();
|
||||
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("blockmarkings_common", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16, 0, 0, 0, 0, false));
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("blockmarkings_common", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16, 0, 0, 0, 0, false, false, false));
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("blockmarking_actor", () -> new BlockMarkerActor());
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("loading_circle_64", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/gui/loading_circle_64.tga"), 64, 64, 0, 0, 0, 0, false));
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("loading_circle_64", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/gui/loading_circle_64.tga"), 64, 64, 0, 0, 0, 0, false, false, false));
|
||||
|
||||
newTempFile("wenquanyi.tga"); // temp file required by the font
|
||||
|
||||
@@ -720,7 +720,12 @@ public class App implements ApplicationListener {
|
||||
textureWhiteCircle.dispose();
|
||||
logo.getTexture().dispose();
|
||||
|
||||
disposableSingletonsPool.forEach((it) -> {try { it.dispose(); } catch (IllegalArgumentException e) {}});
|
||||
disposables.forEach((it) -> {
|
||||
try {
|
||||
it.dispose();
|
||||
}
|
||||
catch (NullPointerException | IllegalArgumentException e) { }
|
||||
});
|
||||
|
||||
ModMgr.INSTANCE.disposeMods();
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ object PostProcessor : Disposable {
|
||||
private val functionRowHelper = Texture(Gdx.files.internal("assets/graphics/function_row_help.png"))
|
||||
|
||||
init {
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
object SanicLoadScreen : LoadScreenBase() {
|
||||
|
||||
init {
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
}
|
||||
|
||||
private var arrowObjPos = 0f // 0 means at starting position, regardless of screen position
|
||||
|
||||
@@ -147,7 +147,7 @@ object Terrarum : Disposable {
|
||||
println("[Terrarum] vendor = $processorVendor")
|
||||
|
||||
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ object MinimapComposer : Disposable {
|
||||
totalWidth = minimap.width
|
||||
totalHeight = minimap.height
|
||||
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
}
|
||||
|
||||
fun update() {
|
||||
|
||||
@@ -1922,8 +1922,8 @@ open class ActorWithBody : Actor {
|
||||
this
|
||||
|
||||
override fun dispose() {
|
||||
sprite?.dispose()
|
||||
spriteGlow?.dispose()
|
||||
App.disposables.add(sprite)
|
||||
App.disposables.add(spriteGlow)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
// - not clicking anymore
|
||||
// - using any item that is not fixture (blocks, picks)
|
||||
if (!Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary")) ||
|
||||
GameItem.Category.FIXTURE != ItemCodex.get(terrarumIngame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP))?.inventoryCategory) {
|
||||
GameItem.Category.MISC != ItemCodex.get(terrarumIngame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP))?.inventoryCategory) {
|
||||
worldPrimaryClickLatched = false
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
@JvmStatic val BLOCK = "block"
|
||||
@JvmStatic val WALL = "wall"
|
||||
@JvmStatic val WIRE = "wire"
|
||||
@JvmStatic val FIXTURE = "fixture"
|
||||
// @JvmStatic val FIXTURE = "fixture"
|
||||
@JvmStatic val MISC = "misc"
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,14 @@ class ParticleVanishingText(val text: String, x: Double, y: Double, noCollision:
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
if (!flagDespawn) {
|
||||
val oldColour = batch.color.cpy()
|
||||
batch.color = drawColour
|
||||
lines.forEachIndexed { index, line ->
|
||||
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat() + TinyAlphNum.H * index) { x, y ->
|
||||
TinyAlphNum.draw(batch, line, x, y )
|
||||
}
|
||||
}
|
||||
batch.color = oldColour
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,10 +104,12 @@ open class ParticleVanishingSprite(val sprite: TextureRegionPack, val delay: Flo
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
if (!flagDespawn) {
|
||||
val oldColour = batch.color.cpy()
|
||||
batch.color = drawColour
|
||||
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat()) { x, y ->
|
||||
batch.draw(sprite.get(frame, row), x, y)
|
||||
}
|
||||
batch.color = oldColour
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,7 +208,8 @@ object WorldSimulator {
|
||||
for (y in updateYTo downTo updateYFrom) {
|
||||
val currentTile = world.getTileFromTerrain(x, y)
|
||||
val prop = BlockCodex[currentTile]
|
||||
val isAir = currentTile == Block.AIR
|
||||
// don't let the falling sand destroy the precious storage chest
|
||||
val isAir = !prop.isSolid && !prop.nameKey.contains("ACTORBLOCK")
|
||||
val support = prop.maxSupport
|
||||
val isFallable = support != -1
|
||||
|
||||
|
||||
@@ -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 {
|
||||
@@ -26,7 +26,7 @@ object Toolkit : Disposable {
|
||||
|
||||
|
||||
init {
|
||||
App.disposableSingletonsPool.add(this)
|
||||
App.disposables.add(this)
|
||||
|
||||
CommonResourcePool.addToLoadingList("toolkit_box_border") {
|
||||
TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/box_border_flat_tileable.tga"), 1, 1)
|
||||
|
||||
Reference in New Issue
Block a user