diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index 9275b8bce..92406c92d 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -63,7 +63,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo } } - val disposables = HashSet() + /** things to be disposed of when the current instance of the game disposed of */ +// val disposables = HashSet() lateinit var worldDisk: VirtualDisk; internal set lateinit var playerDisk: VirtualDisk; internal set @@ -231,7 +232,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo actorContainerInactive.forEach { it.dispose() } world.dispose() - disposables.forEach { it.tryDispose() } +// disposables.forEach { it.tryDispose() } } //////////// diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index e5ddb8d9c..baad78fc2 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -98,7 +98,7 @@ open class ActorWithBody : Actor { val mouseUp: Boolean get() = hitbox.containsPoint((world?.width ?: 0) * TILE_SIZED, Terrarum.mouseX, Terrarum.mouseY) - @Transient private val tooltipHash = System.nanoTime() + @Transient protected val tooltipHash = System.nanoTime() var hitboxTranslateX: Int = 0// relative to spritePosX protected set @@ -678,13 +678,16 @@ open class ActorWithBody : Actor { } } - if (tooltipText == null || !mouseUp) { + if (tooltipText == null || !mouseUp || flagDespawn) { tooltipShowing[tooltipHash] = false } // isStationary = (hitbox - oldHitbox).magnitudeSquared < PHYS_EPSILON_VELO isStationary = isCloseEnough(hitbox.startX, oldHitbox.startX) && // this is supposed to be more accurate, idk isCloseEnough(hitbox.startY, oldHitbox.startY) + + + printdbg(this, tooltipShowing.keys.sorted()) } fun getDrag(externalForce: Vector2): Vector2 { @@ -1929,6 +1932,7 @@ open class ActorWithBody : Actor { internal open fun flagDespawn() { flagDespawn = true + tooltipShowing.remove(tooltipHash) } open fun getSpriteHead(): TextureRegion? { @@ -2252,6 +2256,7 @@ open class ActorWithBody : Actor { App.disposables.add(sprite) App.disposables.add(spriteGlow) App.disposables.add(spriteEmissive) + tooltipShowing.remove(tooltipHash) } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 7becb3c9b..2bfdcc6e2 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -185,6 +185,53 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { return !cannotSpawn } + /** + * @param posX top-left + * @param posY top-left + */ + open fun makeNoiseAndDust(posX: Int, posY: Int) { + val posYb = posY + blockBox.height - 1 + val posXc = posX + blockBox.width / 2 + + // make some noise + var soundSource = + if (spawnNeedsWall) 1 + else if (spawnNeedsFloor) 0 + else 2 + // 1: wall, 0: floor, 2: if wall is not solid, use wall; else, use floor + val wallTile = world!!.getTileFromWall(posXc, posYb) + val terrTile = world!!.getTileFromTerrain(posXc, posYb + 1) + + if (soundSource == 2) { + soundSource = if (BlockCodex[wallTile].isSolid) + 1 + else + 0 + } + + when (soundSource) { + 1 -> PickaxeCore.makeNoiseTileBurst(this, wallTile) + 0 -> PickaxeCore.makeNoiseTileBurst(this, terrTile) + } + + // make some dust + if (soundSource == 0) { + val y = posY + blockBox.height + for (x in posX until posX + blockBox.width) { + val tile = world!!.getTileFromTerrain(x, y) + PickaxeCore.makeDust(tile, x, y - 1, 4 + (Math.random() + Math.random()).roundToInt()) + } + } + else { + for (y in posY until posY + blockBox.height) { + for (x in posX until posX + blockBox.width) { + val tile = world!!.getTileFromWall(x, y) + PickaxeCore.makeDust(tile, x, y, 2 + (Math.random() + Math.random()).roundToInt()) + } + } + } + } + /** * Adds this instance of the fixture to the world. Physical dimension is derived from [blockBox]. * @@ -245,53 +292,6 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { return true } - /** - * @param posX top-left - * @param posY top-left - */ - open fun makeNoiseAndDust(posX: Int, posY: Int) { - val posYb = posY + blockBox.height - 1 - val posXc = posX + blockBox.width / 2 - - // make some noise - var soundSource = - if (spawnNeedsWall) 1 - else if (spawnNeedsFloor) 0 - else 2 - // 1: wall, 0: floor, 2: if wall is not solid, use wall; else, use floor - val wallTile = world!!.getTileFromWall(posXc, posYb) - val terrTile = world!!.getTileFromTerrain(posXc, posYb + 1) - - if (soundSource == 2) { - soundSource = if (BlockCodex[wallTile].isSolid) - 1 - else - 0 - } - - when (soundSource) { - 1 -> PickaxeCore.makeNoiseTileBurst(this, wallTile) - 0 -> PickaxeCore.makeNoiseTileBurst(this, terrTile) - } - - // make some dust - if (soundSource == 0) { - val y = posY + blockBox.height - for (x in posX until posX + blockBox.width) { - val tile = world!!.getTileFromTerrain(x, y) - PickaxeCore.makeDust(tile, x, y - 1, 4 + (Math.random() + Math.random()).roundToInt()) - } - } - else { - for (y in posY until posY + blockBox.height) { - for (x in posX until posX + blockBox.width) { - val tile = world!!.getTileFromWall(x, y) - PickaxeCore.makeDust(tile, x, y, 2 + (Math.random() + Math.random()).roundToInt()) - } - } - } - } - /** * Identical to `spawn(Int, Int)` except it takes user-defined hitbox dimension instead of taking value from [blockBox]. * Useful if [blockBox] cannot be determined on the time of the constructor call. @@ -457,8 +457,6 @@ interface CuedByWireChange { fun updateForWireChange(cue: IngameInstance.BlockChangeQueueItem) } -interface DeferredSpawn - /** * Standard 32-bit binary flags. * diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt index c3b150e53..c750c1753 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt @@ -4,6 +4,8 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase +import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes +import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import org.dyn4j.geometry.Vector2 @@ -39,7 +41,9 @@ class FixtureLogicSignalEmitter : Electric { setWireEmissionAt(0, 0, Vector2(1.0, 0.0)) } - override fun dispose() { } + override fun dispose() { + tooltipShowing.remove(tooltipHash) + } companion object { const val MASS = 1.0 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt index 41a141ce3..30f6b92c8 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt @@ -16,7 +16,7 @@ import kotlin.properties.Delegates /** * Created by minjaesong on 2017-01-07. */ -internal class FixtureTapestry : FixtureBase, DeferredSpawn { +internal class FixtureTapestry : FixtureBase { @Transient override val spawnNeedsWall = true @Transient override val spawnNeedsFloor = false @@ -106,9 +106,17 @@ internal class FixtureTapestry : FixtureBase, DeferredSpawn { pixmap.dispose() - INGAME.disposables.add(texture) - } + App.disposables.add(texture) + spawn( + intTilewiseHitbox.canonicalX.toInt(), + intTilewiseHitbox.canonicalY.toInt(), + actorThatInstalledThisFixture, + tilewiseHitboxWidth, + tilewiseHitboxHeight + ) + } + override var tooltipText: String? = "TEST\nSTRING"//if (artName.length + artAuthor.length > 0) "$artName\n$artAuthor" else null }